blob: 15343d7abbed7064479c199d3fcd3709ac991820 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
2# SPDX-License-Identifier: MIT
3#
4
Brad Bishop6e60e8b2018-02-01 10:27:11 -05005import os
6
7from subprocess import check_output
8from shutil import rmtree
9from oeqa.runtime.case import OERuntimeTestCase
10from oeqa.core.decorator.depends import OETestDepends
Brad Bishop6e60e8b2018-02-01 10:27:11 -050011from oeqa.core.decorator.data import skipIfDataVar
12from oeqa.runtime.decorator.package import OEHasPackage
13
14#in the future these lists could be moved outside of module
15errors = ["error", "cannot", "can\'t", "failed"]
16
17common_errors = [
18 "(WW) warning, (EE) error, (NI) not implemented, (??) unknown.",
19 "dma timeout",
20 "can\'t add hid device:",
21 "usbhid: probe of ",
22 "_OSC failed (AE_ERROR)",
23 "_OSC failed (AE_SUPPORT)",
24 "AE_ALREADY_EXISTS",
25 "ACPI _OSC request failed (AE_SUPPORT)",
26 "can\'t disable ASPM",
27 "Failed to load module \"vesa\"",
28 "Failed to load module vesa",
29 "Failed to load module \"modesetting\"",
30 "Failed to load module modesetting",
31 "Failed to load module \"glx\"",
32 "Failed to load module \"fbdev\"",
33 "Failed to load module fbdev",
34 "Failed to load module glx",
35 "[drm] Cannot find any crtc or sizes - going 1024x768",
36 "_OSC failed (AE_NOT_FOUND); disabling ASPM",
37 "Open ACPI failed (/var/run/acpid.socket) (No such file or directory)",
38 "NX (Execute Disable) protection cannot be enabled: non-PAE kernel!",
39 "hd.: possibly failed opcode",
40 'NETLINK INITIALIZATION FAILED',
41 'kernel: Cannot find map file',
42 'omap_hwmod: debugss: _wait_target_disable failed',
43 'VGA arbiter: cannot open kernel arbiter, no multi-card support',
44 'Failed to find URL:http://ipv4.connman.net/online/status.html',
45 'Online check failed for',
46 'netlink init failed',
47 'Fast TSC calibration',
48 "BAR 0-9",
49 "Failed to load module \"ati\"",
50 "controller can't do DEVSLP, turning off",
51 "stmmac_dvr_probe: warning: cannot get CSR clock",
52 "error: couldn\'t mount because of unsupported optional features",
53 "GPT: Use GNU Parted to correct GPT errors",
54 "Cannot set xattr user.Librepo.DownloadInProgress",
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080055 "Failed to read /var/lib/nfs/statd/state: Success",
56 "error retry time-out =",
57 "logind: cannot setup systemd-logind helper (-61), using legacy fallback",
58 "Error changing net interface name 'eth0' to "
Brad Bishop6e60e8b2018-02-01 10:27:11 -050059 ]
60
61video_related = [
62 "uvesafb",
63]
64
65x86_common = [
66 '[drm:psb_do_init] *ERROR* Debug is',
67 'wrong ELF class',
68 'Could not enable PowerButton event',
69 'probe of LNXPWRBN:00 failed with error -22',
70 'pmd_set_huge: Cannot satisfy',
71 'failed to setup card detect gpio',
72 'amd_nb: Cannot enumerate AMD northbridges',
73 'failed to retrieve link info, disabling eDP',
74 'Direct firmware load for iwlwifi',
Brad Bishop19323692019-04-05 15:28:33 -040075 'Direct firmware load for regulatory.db',
76 'failed to load regulatory.db',
Brad Bishop6e60e8b2018-02-01 10:27:11 -050077] + common_errors
78
79qemux86_common = [
80 'wrong ELF class',
81 "fail to add MMCONFIG information, can't access extended PCI configuration space under this bridge.",
82 "can't claim BAR ",
83 'amd_nb: Cannot enumerate AMD northbridges',
84 'uvesafb: 5000 ms task timeout, infinitely waiting',
85 'tsc: HPET/PMTIMER calibration failed',
Brad Bishop79641f22019-09-10 07:20:22 -040086 "modeset(0): Failed to initialize the DRI2 extension",
87 "uvesafb: cannot reserve video memory at",
88 "uvesafb: probe of uvesafb.0 failed with error",
89 "glamor initialization failed",
Brad Bishop6e60e8b2018-02-01 10:27:11 -050090] + common_errors
91
92ignore_errors = {
93 'default' : common_errors,
94 'qemux86' : [
95 'Failed to access perfctr msr (MSR',
96 'pci 0000:00:00.0: [Firmware Bug]: reg 0x..: invalid BAR (can\'t size)',
97 ] + qemux86_common,
98 'qemux86-64' : qemux86_common,
99 'qemumips' : [
100 'Failed to load module "glx"',
101 'pci 0000:00:00.0: [Firmware Bug]: reg 0x..: invalid BAR (can\'t size)',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500102 'cacheinfo: Failed to find cpu0 device node',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500103 ] + common_errors,
104 'qemumips64' : [
105 'pci 0000:00:00.0: [Firmware Bug]: reg 0x..: invalid BAR (can\'t size)',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500106 'cacheinfo: Failed to find cpu0 device node',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500107 ] + common_errors,
108 'qemuppc' : [
109 'PCI 0000:00 Cannot reserve Legacy IO [io 0x0000-0x0fff]',
110 'host side 80-wire cable detection failed, limiting max speed',
111 'mode "640x480" test failed',
112 'Failed to load module "glx"',
113 'can\'t handle BAR above 4GB',
114 'Cannot reserve Legacy IO',
115 ] + common_errors,
116 'qemuarm' : [
117 'mmci-pl18x: probe of fpga:05 failed with error -22',
118 'mmci-pl18x: probe of fpga:0b failed with error -22',
119 'Failed to load module "glx"',
120 'OF: amba_device_add() failed (-19) for /amba/smc@10100000',
121 'OF: amba_device_add() failed (-19) for /amba/mpmc@10110000',
122 'OF: amba_device_add() failed (-19) for /amba/sctl@101e0000',
123 'OF: amba_device_add() failed (-19) for /amba/watchdog@101e1000',
124 'OF: amba_device_add() failed (-19) for /amba/sci@101f0000',
Brad Bishop19323692019-04-05 15:28:33 -0400125 'OF: amba_device_add() failed (-19) for /amba/spi@101f4000',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500126 'OF: amba_device_add() failed (-19) for /amba/ssp@101f4000',
127 'OF: amba_device_add() failed (-19) for /amba/fpga/sci@a000',
128 'Failed to initialize \'/amba/timer@101e3000\': -22',
129 'jitterentropy: Initialization failed with host not compliant with requirements: 2',
130 ] + common_errors,
131 'qemuarm64' : [
132 'Fatal server error:',
133 '(EE) Server terminated with error (1). Closing log file.',
134 'dmi: Firmware registration failed.',
135 'irq: type mismatch, failed to map hwirq-27 for /intc',
136 ] + common_errors,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500137 'intel-core2-32' : [
138 'ACPI: No _BQC method, cannot determine initial brightness',
139 '[Firmware Bug]: ACPI: No _BQC method, cannot determine initial brightness',
140 '(EE) Failed to load module "psb"',
141 '(EE) Failed to load module psb',
142 '(EE) Failed to load module "psbdrv"',
143 '(EE) Failed to load module psbdrv',
144 '(EE) open /dev/fb0: No such file or directory',
145 '(EE) AIGLX: reverting to software rendering',
146 'dmi: Firmware registration failed.',
147 'ioremap error for 0x78',
148 ] + x86_common,
149 'intel-corei7-64' : [
150 'can\'t set Max Payload Size to 256',
151 'intel_punit_ipc: can\'t request region for resource',
152 '[drm] parse error at position 4 in video mode \'efifb\'',
153 'ACPI Error: Could not enable RealTimeClock event',
154 'ACPI Warning: Could not enable fixed event - RealTimeClock',
155 'hci_intel INT33E1:00: Unable to retrieve gpio',
156 'hci_intel: probe of INT33E1:00 failed',
157 'can\'t derive routing for PCI INT A',
158 'failed to read out thermal zone',
159 'Bluetooth: hci0: Setting Intel event mask failed',
160 'ttyS2 - failed to request DMA',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500161 'Bluetooth: hci0: Failed to send firmware data (-38)',
162 'atkbd serio0: Failed to enable keyboard on isa0060/serio0',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500163 ] + x86_common,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500164 'genericx86' : x86_common,
165 'genericx86-64' : [
166 'Direct firmware load for i915',
167 'Failed to load firmware i915',
168 'Failed to fetch GuC',
169 'Failed to initialize GuC',
170 'Failed to load DMC firmware',
171 'The driver is built-in, so to load the firmware you need to',
172 ] + x86_common,
173 'edgerouter' : [
Brad Bishop19323692019-04-05 15:28:33 -0400174 'not creating \'/sys/firmware/fdt\'',
175 'Failed to find cpu0 device node',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500176 'Fatal server error:',
Brad Bishop19323692019-04-05 15:28:33 -0400177 'Server terminated with error',
178 ] + common_errors,
179 'beaglebone-yocto' : [
180 'Direct firmware load for regulatory.db',
181 'failed to load regulatory.db',
182 'l4_wkup_cm',
183 'Failed to load module "glx"',
184 'Failed to make EGL context current',
185 'glamor initialization failed',
186 ] + common_errors,
187 'mpc8315e-rdb' : [
188 'of_irq_parse_pci: failed with',
189 'Fatal server error:',
190 'Server terminated with error',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500191 ] + common_errors,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500192}
193
194log_locations = ["/var/log/","/var/log/dmesg", "/tmp/dmesg_output.log"]
195
196class ParseLogsTest(OERuntimeTestCase):
197
198 @classmethod
199 def setUpClass(cls):
200 cls.errors = errors
201
202 # When systemd is enabled we need to notice errors on
203 # circular dependencies in units.
204 if 'systemd' in cls.td.get('DISTRO_FEATURES', ''):
205 cls.errors.extend([
206 'Found ordering cycle on',
207 'Breaking ordering cycle by deleting job',
208 'deleted to break ordering cycle',
209 'Ordering cycle found, skipping',
210 ])
211
212 cls.ignore_errors = ignore_errors
213 cls.log_locations = log_locations
214 cls.msg = ''
215 is_lsb, _ = cls.tc.target.run("which LSB_Test.sh")
216 if is_lsb == 0:
217 for machine in cls.ignore_errors:
218 cls.ignore_errors[machine] = cls.ignore_errors[machine] \
219 + video_related
220
221 def getMachine(self):
222 return self.td.get('MACHINE', '')
223
224 def getWorkdir(self):
225 return self.td.get('WORKDIR', '')
226
227 # Get some information on the CPU of the machine to display at the
228 # beginning of the output. This info might be useful in some cases.
229 def getHardwareInfo(self):
230 hwi = ""
231 cmd = ('cat /proc/cpuinfo | grep "model name" | head -n1 | '
232 " awk 'BEGIN{FS=\":\"}{print $2}'")
233 _, cpu_name = self.target.run(cmd)
234
235 cmd = ('cat /proc/cpuinfo | grep "cpu cores" | head -n1 | '
236 "awk {'print $4'}")
237 _, cpu_physical_cores = self.target.run(cmd)
238
239 cmd = 'cat /proc/cpuinfo | grep "processor" | wc -l'
240 _, cpu_logical_cores = self.target.run(cmd)
241
242 _, cpu_arch = self.target.run('uname -m')
243
244 hwi += 'Machine information: \n'
245 hwi += '*******************************\n'
246 hwi += 'Machine name: ' + self.getMachine() + '\n'
247 hwi += 'CPU: ' + str(cpu_name) + '\n'
248 hwi += 'Arch: ' + str(cpu_arch)+ '\n'
249 hwi += 'Physical cores: ' + str(cpu_physical_cores) + '\n'
250 hwi += 'Logical cores: ' + str(cpu_logical_cores) + '\n'
251 hwi += '*******************************\n'
252
253 return hwi
254
255 # Go through the log locations provided and if it's a folder
256 # create a list with all the .log files in it, if it's a file
257 # just add it to that list.
258 def getLogList(self, log_locations):
259 logs = []
260 for location in log_locations:
261 status, _ = self.target.run('test -f ' + str(location))
262 if status == 0:
263 logs.append(str(location))
264 else:
265 status, _ = self.target.run('test -d ' + str(location))
266 if status == 0:
267 cmd = 'find ' + str(location) + '/*.log -maxdepth 1 -type f'
268 status, output = self.target.run(cmd)
269 if status == 0:
270 output = output.splitlines()
271 for logfile in output:
272 logs.append(os.path.join(location, str(logfile)))
273 return logs
274
275 # Copy the log files to be parsed locally
276 def transfer_logs(self, log_list):
277 workdir = self.getWorkdir()
278 self.target_logs = workdir + '/' + 'target_logs'
279 target_logs = self.target_logs
280 if os.path.exists(target_logs):
281 rmtree(self.target_logs)
282 os.makedirs(target_logs)
283 for f in log_list:
284 self.target.copyFrom(str(f), target_logs)
285
286 # Get the local list of logs
287 def get_local_log_list(self, log_locations):
288 self.transfer_logs(self.getLogList(log_locations))
289 list_dir = os.listdir(self.target_logs)
290 dir_files = [os.path.join(self.target_logs, f) for f in list_dir]
291 logs = [f for f in dir_files if os.path.isfile(f)]
292 return logs
293
294 # Build the grep command to be used with filters and exclusions
295 def build_grepcmd(self, errors, ignore_errors, log):
296 grepcmd = 'grep '
297 grepcmd += '-Ei "'
298 for error in errors:
Brad Bishop08902b02019-08-20 09:16:51 -0400299 grepcmd += '\<' + error + '\>' + '|'
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500300 grepcmd = grepcmd[:-1]
301 grepcmd += '" ' + str(log) + " | grep -Eiv \'"
302
303 try:
304 errorlist = ignore_errors[self.getMachine()]
305 except KeyError:
306 self.msg += 'No ignore list found for this machine, using default\n'
307 errorlist = ignore_errors['default']
308
309 for ignore_error in errorlist:
310 ignore_error = ignore_error.replace('(', '\(')
311 ignore_error = ignore_error.replace(')', '\)')
312 ignore_error = ignore_error.replace("'", '.')
313 ignore_error = ignore_error.replace('?', '\?')
314 ignore_error = ignore_error.replace('[', '\[')
315 ignore_error = ignore_error.replace(']', '\]')
316 ignore_error = ignore_error.replace('*', '\*')
317 ignore_error = ignore_error.replace('0-9', '[0-9]')
318 grepcmd += ignore_error + '|'
319 grepcmd = grepcmd[:-1]
320 grepcmd += "\'"
321
322 return grepcmd
323
324 # Grep only the errors so that their context could be collected.
325 # Default context is 10 lines before and after the error itself
326 def parse_logs(self, errors, ignore_errors, logs,
327 lines_before = 10, lines_after = 10):
328 results = {}
329 rez = []
330 grep_output = ''
331
332 for log in logs:
333 result = None
334 thegrep = self.build_grepcmd(errors, ignore_errors, log)
335
336 try:
337 result = check_output(thegrep, shell=True).decode('utf-8')
338 except:
339 pass
340
341 if result is not None:
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800342 results[log] = {}
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500343 rez = result.splitlines()
344
345 for xrez in rez:
346 try:
347 cmd = ['grep', '-F', xrez, '-B', str(lines_before)]
348 cmd += ['-A', str(lines_after), log]
349 grep_output = check_output(cmd).decode('utf-8')
350 except:
351 pass
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800352 results[log][xrez]=grep_output
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500353
354 return results
355
356 # Get the output of dmesg and write it in a file.
357 # This file is added to log_locations.
358 def write_dmesg(self):
359 (status, dmesg) = self.target.run('dmesg > /tmp/dmesg_output.log')
360
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500361 @OETestDepends(['ssh.SSHTest.test_ssh'])
362 def test_parselogs(self):
363 self.write_dmesg()
364 log_list = self.get_local_log_list(self.log_locations)
365 result = self.parse_logs(self.errors, self.ignore_errors, log_list)
366 print(self.getHardwareInfo())
367 errcount = 0
368 for log in result:
369 self.msg += 'Log: ' + log + '\n'
370 self.msg += '-----------------------\n'
371 for error in result[log]:
372 errcount += 1
373 self.msg += 'Central error: ' + str(error) + '\n'
374 self.msg += '***********************\n'
375 self.msg += result[str(log)][str(error)] + '\n'
376 self.msg += '***********************\n'
377 self.msg += '%s errors found in logs.' % errcount
378 self.assertEqual(errcount, 0, msg=self.msg)