blob: af8a8d67bd46e8c40ff4eb53760ee63095b92d5f [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",
Andrew Geissler82c905d2020-04-13 13:39:40 -050058 "Failed to rename network interface",
59 "Failed to process device, ignoring: Device or resource busy",
60 "Cannot find a map file",
61 "[rdrand]: Initialization Failed",
Andrew Geissler5f350902021-07-23 13:09:54 -040062 "[rndr ]: Initialization Failed",
Andrew Geissler82c905d2020-04-13 13:39:40 -050063 "[pulseaudio] authkey.c: Failed to open cookie file",
64 "[pulseaudio] authkey.c: Failed to load authentication key",
Brad Bishop6e60e8b2018-02-01 10:27:11 -050065 ]
66
67video_related = [
Brad Bishop6e60e8b2018-02-01 10:27:11 -050068]
69
70x86_common = [
71 '[drm:psb_do_init] *ERROR* Debug is',
72 'wrong ELF class',
73 'Could not enable PowerButton event',
74 'probe of LNXPWRBN:00 failed with error -22',
75 'pmd_set_huge: Cannot satisfy',
76 'failed to setup card detect gpio',
77 'amd_nb: Cannot enumerate AMD northbridges',
78 'failed to retrieve link info, disabling eDP',
79 'Direct firmware load for iwlwifi',
Brad Bishop19323692019-04-05 15:28:33 -040080 'Direct firmware load for regulatory.db',
81 'failed to load regulatory.db',
Brad Bishop6e60e8b2018-02-01 10:27:11 -050082] + common_errors
83
84qemux86_common = [
85 'wrong ELF class',
86 "fail to add MMCONFIG information, can't access extended PCI configuration space under this bridge.",
87 "can't claim BAR ",
88 'amd_nb: Cannot enumerate AMD northbridges',
Brad Bishop6e60e8b2018-02-01 10:27:11 -050089 'tsc: HPET/PMTIMER calibration failed',
Brad Bishop79641f22019-09-10 07:20:22 -040090 "modeset(0): Failed to initialize the DRI2 extension",
Brad Bishop79641f22019-09-10 07:20:22 -040091 "glamor initialization failed",
Andrew Geisslerc926e172021-05-07 16:11:35 -050092 "blk_update_request: I/O error, dev fd0, sector 0 op 0x0:(READ)",
93 "floppy: error",
Brad Bishop6e60e8b2018-02-01 10:27:11 -050094] + common_errors
95
96ignore_errors = {
97 'default' : common_errors,
98 'qemux86' : [
99 'Failed to access perfctr msr (MSR',
100 'pci 0000:00:00.0: [Firmware Bug]: reg 0x..: invalid BAR (can\'t size)',
101 ] + qemux86_common,
102 'qemux86-64' : qemux86_common,
103 'qemumips' : [
104 'Failed to load module "glx"',
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 'qemumips64' : [
109 'pci 0000:00:00.0: [Firmware Bug]: reg 0x..: invalid BAR (can\'t size)',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500110 'cacheinfo: Failed to find cpu0 device node',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500111 ] + common_errors,
112 'qemuppc' : [
113 'PCI 0000:00 Cannot reserve Legacy IO [io 0x0000-0x0fff]',
114 'host side 80-wire cable detection failed, limiting max speed',
115 'mode "640x480" test failed',
116 'Failed to load module "glx"',
117 'can\'t handle BAR above 4GB',
118 'Cannot reserve Legacy IO',
119 ] + common_errors,
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500120 'qemuppc64' : [
121 'vio vio: uevent: failed to send synthetic uevent',
122 'synth uevent: /devices/vio: failed to send uevent',
123 'PCI 0000:00 Cannot reserve Legacy IO [io 0x10000-0x10fff]',
124 ] + common_errors,
Patrick Williams213cb262021-08-07 19:21:33 -0500125 'qemuarmv5' : [
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500126 'mmci-pl18x: probe of fpga:05 failed with error -22',
127 'mmci-pl18x: probe of fpga:0b failed with error -22',
128 'Failed to load module "glx"',
129 'OF: amba_device_add() failed (-19) for /amba/smc@10100000',
130 'OF: amba_device_add() failed (-19) for /amba/mpmc@10110000',
131 'OF: amba_device_add() failed (-19) for /amba/sctl@101e0000',
132 'OF: amba_device_add() failed (-19) for /amba/watchdog@101e1000',
133 'OF: amba_device_add() failed (-19) for /amba/sci@101f0000',
Brad Bishop19323692019-04-05 15:28:33 -0400134 'OF: amba_device_add() failed (-19) for /amba/spi@101f4000',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500135 'OF: amba_device_add() failed (-19) for /amba/ssp@101f4000',
136 'OF: amba_device_add() failed (-19) for /amba/fpga/sci@a000',
137 'Failed to initialize \'/amba/timer@101e3000\': -22',
138 'jitterentropy: Initialization failed with host not compliant with requirements: 2',
Patrick Williams213cb262021-08-07 19:21:33 -0500139 'clcd-pl11x: probe of 10120000.display failed with error -2',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500140 ] + common_errors,
141 'qemuarm64' : [
142 'Fatal server error:',
143 '(EE) Server terminated with error (1). Closing log file.',
144 'dmi: Firmware registration failed.',
145 'irq: type mismatch, failed to map hwirq-27 for /intc',
Andrew Geissler82c905d2020-04-13 13:39:40 -0500146 'logind: failed to get session seat',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500147 ] + common_errors,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500148 'intel-core2-32' : [
149 'ACPI: No _BQC method, cannot determine initial brightness',
150 '[Firmware Bug]: ACPI: No _BQC method, cannot determine initial brightness',
151 '(EE) Failed to load module "psb"',
152 '(EE) Failed to load module psb',
153 '(EE) Failed to load module "psbdrv"',
154 '(EE) Failed to load module psbdrv',
155 '(EE) open /dev/fb0: No such file or directory',
156 '(EE) AIGLX: reverting to software rendering',
157 'dmi: Firmware registration failed.',
158 'ioremap error for 0x78',
159 ] + x86_common,
160 'intel-corei7-64' : [
161 'can\'t set Max Payload Size to 256',
162 'intel_punit_ipc: can\'t request region for resource',
163 '[drm] parse error at position 4 in video mode \'efifb\'',
164 'ACPI Error: Could not enable RealTimeClock event',
165 'ACPI Warning: Could not enable fixed event - RealTimeClock',
166 'hci_intel INT33E1:00: Unable to retrieve gpio',
167 'hci_intel: probe of INT33E1:00 failed',
168 'can\'t derive routing for PCI INT A',
169 'failed to read out thermal zone',
170 'Bluetooth: hci0: Setting Intel event mask failed',
171 'ttyS2 - failed to request DMA',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500172 'Bluetooth: hci0: Failed to send firmware data (-38)',
173 'atkbd serio0: Failed to enable keyboard on isa0060/serio0',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500174 ] + x86_common,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500175 'genericx86' : x86_common,
176 'genericx86-64' : [
177 'Direct firmware load for i915',
178 'Failed to load firmware i915',
179 'Failed to fetch GuC',
180 'Failed to initialize GuC',
181 'Failed to load DMC firmware',
182 'The driver is built-in, so to load the firmware you need to',
183 ] + x86_common,
184 'edgerouter' : [
Brad Bishop19323692019-04-05 15:28:33 -0400185 'not creating \'/sys/firmware/fdt\'',
186 'Failed to find cpu0 device node',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500187 'Fatal server error:',
Brad Bishop19323692019-04-05 15:28:33 -0400188 'Server terminated with error',
189 ] + common_errors,
190 'beaglebone-yocto' : [
191 'Direct firmware load for regulatory.db',
192 'failed to load regulatory.db',
193 'l4_wkup_cm',
194 'Failed to load module "glx"',
195 'Failed to make EGL context current',
196 'glamor initialization failed',
197 ] + common_errors,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500198}
199
200log_locations = ["/var/log/","/var/log/dmesg", "/tmp/dmesg_output.log"]
201
202class ParseLogsTest(OERuntimeTestCase):
203
204 @classmethod
205 def setUpClass(cls):
206 cls.errors = errors
207
208 # When systemd is enabled we need to notice errors on
209 # circular dependencies in units.
210 if 'systemd' in cls.td.get('DISTRO_FEATURES', ''):
211 cls.errors.extend([
212 'Found ordering cycle on',
213 'Breaking ordering cycle by deleting job',
214 'deleted to break ordering cycle',
215 'Ordering cycle found, skipping',
216 ])
217
218 cls.ignore_errors = ignore_errors
219 cls.log_locations = log_locations
220 cls.msg = ''
221 is_lsb, _ = cls.tc.target.run("which LSB_Test.sh")
222 if is_lsb == 0:
223 for machine in cls.ignore_errors:
224 cls.ignore_errors[machine] = cls.ignore_errors[machine] \
225 + video_related
226
227 def getMachine(self):
228 return self.td.get('MACHINE', '')
229
230 def getWorkdir(self):
231 return self.td.get('WORKDIR', '')
232
233 # Get some information on the CPU of the machine to display at the
234 # beginning of the output. This info might be useful in some cases.
235 def getHardwareInfo(self):
236 hwi = ""
237 cmd = ('cat /proc/cpuinfo | grep "model name" | head -n1 | '
238 " awk 'BEGIN{FS=\":\"}{print $2}'")
239 _, cpu_name = self.target.run(cmd)
240
241 cmd = ('cat /proc/cpuinfo | grep "cpu cores" | head -n1 | '
242 "awk {'print $4'}")
243 _, cpu_physical_cores = self.target.run(cmd)
244
245 cmd = 'cat /proc/cpuinfo | grep "processor" | wc -l'
246 _, cpu_logical_cores = self.target.run(cmd)
247
248 _, cpu_arch = self.target.run('uname -m')
249
250 hwi += 'Machine information: \n'
251 hwi += '*******************************\n'
252 hwi += 'Machine name: ' + self.getMachine() + '\n'
253 hwi += 'CPU: ' + str(cpu_name) + '\n'
254 hwi += 'Arch: ' + str(cpu_arch)+ '\n'
255 hwi += 'Physical cores: ' + str(cpu_physical_cores) + '\n'
256 hwi += 'Logical cores: ' + str(cpu_logical_cores) + '\n'
257 hwi += '*******************************\n'
258
259 return hwi
260
261 # Go through the log locations provided and if it's a folder
262 # create a list with all the .log files in it, if it's a file
263 # just add it to that list.
264 def getLogList(self, log_locations):
265 logs = []
266 for location in log_locations:
267 status, _ = self.target.run('test -f ' + str(location))
268 if status == 0:
269 logs.append(str(location))
270 else:
271 status, _ = self.target.run('test -d ' + str(location))
272 if status == 0:
273 cmd = 'find ' + str(location) + '/*.log -maxdepth 1 -type f'
274 status, output = self.target.run(cmd)
275 if status == 0:
276 output = output.splitlines()
277 for logfile in output:
278 logs.append(os.path.join(location, str(logfile)))
279 return logs
280
281 # Copy the log files to be parsed locally
282 def transfer_logs(self, log_list):
283 workdir = self.getWorkdir()
284 self.target_logs = workdir + '/' + 'target_logs'
285 target_logs = self.target_logs
286 if os.path.exists(target_logs):
287 rmtree(self.target_logs)
288 os.makedirs(target_logs)
289 for f in log_list:
290 self.target.copyFrom(str(f), target_logs)
291
292 # Get the local list of logs
293 def get_local_log_list(self, log_locations):
294 self.transfer_logs(self.getLogList(log_locations))
295 list_dir = os.listdir(self.target_logs)
296 dir_files = [os.path.join(self.target_logs, f) for f in list_dir]
297 logs = [f for f in dir_files if os.path.isfile(f)]
298 return logs
299
300 # Build the grep command to be used with filters and exclusions
301 def build_grepcmd(self, errors, ignore_errors, log):
302 grepcmd = 'grep '
303 grepcmd += '-Ei "'
304 for error in errors:
Brad Bishop08902b02019-08-20 09:16:51 -0400305 grepcmd += '\<' + error + '\>' + '|'
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500306 grepcmd = grepcmd[:-1]
307 grepcmd += '" ' + str(log) + " | grep -Eiv \'"
308
309 try:
310 errorlist = ignore_errors[self.getMachine()]
311 except KeyError:
312 self.msg += 'No ignore list found for this machine, using default\n'
313 errorlist = ignore_errors['default']
314
315 for ignore_error in errorlist:
316 ignore_error = ignore_error.replace('(', '\(')
317 ignore_error = ignore_error.replace(')', '\)')
318 ignore_error = ignore_error.replace("'", '.')
319 ignore_error = ignore_error.replace('?', '\?')
320 ignore_error = ignore_error.replace('[', '\[')
321 ignore_error = ignore_error.replace(']', '\]')
322 ignore_error = ignore_error.replace('*', '\*')
323 ignore_error = ignore_error.replace('0-9', '[0-9]')
324 grepcmd += ignore_error + '|'
325 grepcmd = grepcmd[:-1]
326 grepcmd += "\'"
327
328 return grepcmd
329
330 # Grep only the errors so that their context could be collected.
331 # Default context is 10 lines before and after the error itself
332 def parse_logs(self, errors, ignore_errors, logs,
333 lines_before = 10, lines_after = 10):
334 results = {}
335 rez = []
336 grep_output = ''
337
338 for log in logs:
339 result = None
340 thegrep = self.build_grepcmd(errors, ignore_errors, log)
341
342 try:
343 result = check_output(thegrep, shell=True).decode('utf-8')
344 except:
345 pass
346
347 if result is not None:
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800348 results[log] = {}
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500349 rez = result.splitlines()
350
351 for xrez in rez:
352 try:
353 cmd = ['grep', '-F', xrez, '-B', str(lines_before)]
354 cmd += ['-A', str(lines_after), log]
355 grep_output = check_output(cmd).decode('utf-8')
356 except:
357 pass
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800358 results[log][xrez]=grep_output
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500359
360 return results
361
362 # Get the output of dmesg and write it in a file.
363 # This file is added to log_locations.
364 def write_dmesg(self):
365 (status, dmesg) = self.target.run('dmesg > /tmp/dmesg_output.log')
366
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500367 @OETestDepends(['ssh.SSHTest.test_ssh'])
368 def test_parselogs(self):
369 self.write_dmesg()
370 log_list = self.get_local_log_list(self.log_locations)
371 result = self.parse_logs(self.errors, self.ignore_errors, log_list)
372 print(self.getHardwareInfo())
373 errcount = 0
374 for log in result:
375 self.msg += 'Log: ' + log + '\n'
376 self.msg += '-----------------------\n'
377 for error in result[log]:
378 errcount += 1
379 self.msg += 'Central error: ' + str(error) + '\n'
380 self.msg += '***********************\n'
381 self.msg += result[str(log)][str(error)] + '\n'
382 self.msg += '***********************\n'
383 self.msg += '%s errors found in logs.' % errcount
384 self.assertEqual(errcount, 0, msg=self.msg)