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