blob: a805edd79dd4d2c4bef85447990039e52380cef9 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
Patrick Williams92b42cb2022-09-03 06:53:57 -05002# Copyright OpenEmbedded Contributors
3#
Brad Bishopc342db32019-05-15 21:57:59 -04004# SPDX-License-Identifier: MIT
5#
6
Andrew Geissler220dafd2023-10-04 10:18:08 -05007import collections
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008import os
9
Brad Bishop6e60e8b2018-02-01 10:27:11 -050010from shutil import rmtree
11from oeqa.runtime.case import OERuntimeTestCase
12from oeqa.core.decorator.depends import OETestDepends
Brad Bishop6e60e8b2018-02-01 10:27:11 -050013
14common_errors = [
15 "(WW) warning, (EE) error, (NI) not implemented, (??) unknown.",
16 "dma timeout",
17 "can\'t add hid device:",
18 "usbhid: probe of ",
19 "_OSC failed (AE_ERROR)",
20 "_OSC failed (AE_SUPPORT)",
21 "AE_ALREADY_EXISTS",
22 "ACPI _OSC request failed (AE_SUPPORT)",
23 "can\'t disable ASPM",
24 "Failed to load module \"vesa\"",
25 "Failed to load module vesa",
26 "Failed to load module \"modesetting\"",
27 "Failed to load module modesetting",
28 "Failed to load module \"glx\"",
29 "Failed to load module \"fbdev\"",
30 "Failed to load module fbdev",
31 "Failed to load module glx",
Andrew Geisslereff27472021-10-29 15:35:00 -050032 "[drm] Cannot find any crtc or sizes",
Brad Bishop6e60e8b2018-02-01 10:27:11 -050033 "_OSC failed (AE_NOT_FOUND); disabling ASPM",
34 "Open ACPI failed (/var/run/acpid.socket) (No such file or directory)",
35 "NX (Execute Disable) protection cannot be enabled: non-PAE kernel!",
36 "hd.: possibly failed opcode",
37 'NETLINK INITIALIZATION FAILED',
38 'kernel: Cannot find map file',
39 'omap_hwmod: debugss: _wait_target_disable failed',
40 'VGA arbiter: cannot open kernel arbiter, no multi-card support',
41 'Failed to find URL:http://ipv4.connman.net/online/status.html',
42 'Online check failed for',
43 'netlink init failed',
44 'Fast TSC calibration',
45 "BAR 0-9",
46 "Failed to load module \"ati\"",
47 "controller can't do DEVSLP, turning off",
48 "stmmac_dvr_probe: warning: cannot get CSR clock",
49 "error: couldn\'t mount because of unsupported optional features",
50 "GPT: Use GNU Parted to correct GPT errors",
51 "Cannot set xattr user.Librepo.DownloadInProgress",
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080052 "Failed to read /var/lib/nfs/statd/state: Success",
53 "error retry time-out =",
54 "logind: cannot setup systemd-logind helper (-61), using legacy fallback",
Andrew Geissler82c905d2020-04-13 13:39:40 -050055 "Failed to rename network interface",
56 "Failed to process device, ignoring: Device or resource busy",
57 "Cannot find a map file",
58 "[rdrand]: Initialization Failed",
Andrew Geissler5f350902021-07-23 13:09:54 -040059 "[rndr ]: Initialization Failed",
Andrew Geissler82c905d2020-04-13 13:39:40 -050060 "[pulseaudio] authkey.c: Failed to open cookie file",
61 "[pulseaudio] authkey.c: Failed to load authentication key",
Andrew Geissler595f6302022-01-24 19:11:47 +000062 "was skipped because of a failed condition check",
63 "was skipped because all trigger condition checks failed",
Patrick Williams92b42cb2022-09-03 06:53:57 -050064 "xf86OpenConsole: Switching VT failed",
Andrew Geissler87f5cff2022-09-30 13:13:31 -050065 "Failed to read LoaderConfigTimeoutOneShot variable, ignoring: Operation not supported",
66 "Failed to read LoaderEntryOneShot variable, ignoring: Operation not supported",
Andrew Geissler220dafd2023-10-04 10:18:08 -050067 "invalid BAR (can't size)",
Brad Bishop6e60e8b2018-02-01 10:27:11 -050068 ]
69
Brad Bishop6e60e8b2018-02-01 10:27:11 -050070x86_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",
Andrew Geissler5199d832021-09-24 16:47:35 -050094 'failed to IDENTIFY (I/O error, err_mask=0x4)',
Brad Bishop6e60e8b2018-02-01 10:27:11 -050095] + common_errors
96
97ignore_errors = {
98 'default' : common_errors,
99 'qemux86' : [
100 'Failed to access perfctr msr (MSR',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500101 ] + qemux86_common,
102 'qemux86-64' : qemux86_common,
103 'qemumips' : [
104 'Failed to load module "glx"',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500105 'cacheinfo: Failed to find cpu0 device node',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500106 ] + common_errors,
107 'qemumips64' : [
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500108 'cacheinfo: Failed to find cpu0 device node',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500109 ] + common_errors,
110 'qemuppc' : [
111 'PCI 0000:00 Cannot reserve Legacy IO [io 0x0000-0x0fff]',
112 'host side 80-wire cable detection failed, limiting max speed',
113 'mode "640x480" test failed',
114 'Failed to load module "glx"',
115 'can\'t handle BAR above 4GB',
116 'Cannot reserve Legacy IO',
117 ] + common_errors,
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500118 'qemuppc64' : [
119 'vio vio: uevent: failed to send synthetic uevent',
120 'synth uevent: /devices/vio: failed to send uevent',
121 'PCI 0000:00 Cannot reserve Legacy IO [io 0x10000-0x10fff]',
122 ] + common_errors,
Patrick Williams213cb262021-08-07 19:21:33 -0500123 'qemuarmv5' : [
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500124 'mmci-pl18x: probe of fpga:05 failed with error -22',
125 'mmci-pl18x: probe of fpga:0b failed with error -22',
126 'Failed to load module "glx"',
127 'OF: amba_device_add() failed (-19) for /amba/smc@10100000',
128 'OF: amba_device_add() failed (-19) for /amba/mpmc@10110000',
129 'OF: amba_device_add() failed (-19) for /amba/sctl@101e0000',
130 'OF: amba_device_add() failed (-19) for /amba/watchdog@101e1000',
131 'OF: amba_device_add() failed (-19) for /amba/sci@101f0000',
Brad Bishop19323692019-04-05 15:28:33 -0400132 'OF: amba_device_add() failed (-19) for /amba/spi@101f4000',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500133 'OF: amba_device_add() failed (-19) for /amba/ssp@101f4000',
134 'OF: amba_device_add() failed (-19) for /amba/fpga/sci@a000',
135 'Failed to initialize \'/amba/timer@101e3000\': -22',
136 'jitterentropy: Initialization failed with host not compliant with requirements: 2',
Patrick Williams213cb262021-08-07 19:21:33 -0500137 'clcd-pl11x: probe of 10120000.display failed with error -2',
Patrick Williams92b42cb2022-09-03 06:53:57 -0500138 'arm-charlcd 10008000.lcd: error -ENXIO: IRQ index 0 not found'
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500139 ] + common_errors,
140 'qemuarm64' : [
141 'Fatal server error:',
142 '(EE) Server terminated with error (1). Closing log file.',
143 'dmi: Firmware registration failed.',
144 'irq: type mismatch, failed to map hwirq-27 for /intc',
Andrew Geissler82c905d2020-04-13 13:39:40 -0500145 'logind: failed to get session seat',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500146 ] + common_errors,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500147 'intel-core2-32' : [
148 'ACPI: No _BQC method, cannot determine initial brightness',
149 '[Firmware Bug]: ACPI: No _BQC method, cannot determine initial brightness',
150 '(EE) Failed to load module "psb"',
151 '(EE) Failed to load module psb',
152 '(EE) Failed to load module "psbdrv"',
153 '(EE) Failed to load module psbdrv',
154 '(EE) open /dev/fb0: No such file or directory',
155 '(EE) AIGLX: reverting to software rendering',
156 'dmi: Firmware registration failed.',
157 'ioremap error for 0x78',
158 ] + x86_common,
159 'intel-corei7-64' : [
160 'can\'t set Max Payload Size to 256',
161 'intel_punit_ipc: can\'t request region for resource',
162 '[drm] parse error at position 4 in video mode \'efifb\'',
163 'ACPI Error: Could not enable RealTimeClock event',
164 'ACPI Warning: Could not enable fixed event - RealTimeClock',
165 'hci_intel INT33E1:00: Unable to retrieve gpio',
166 'hci_intel: probe of INT33E1:00 failed',
167 'can\'t derive routing for PCI INT A',
168 'failed to read out thermal zone',
169 'Bluetooth: hci0: Setting Intel event mask failed',
170 'ttyS2 - failed to request DMA',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500171 'Bluetooth: hci0: Failed to send firmware data (-38)',
172 'atkbd serio0: Failed to enable keyboard on isa0060/serio0',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500173 ] + x86_common,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500174 'genericx86' : x86_common,
175 'genericx86-64' : [
176 'Direct firmware load for i915',
177 'Failed to load firmware i915',
178 'Failed to fetch GuC',
179 'Failed to initialize GuC',
180 'Failed to load DMC firmware',
181 'The driver is built-in, so to load the firmware you need to',
182 ] + x86_common,
183 'edgerouter' : [
Brad Bishop19323692019-04-05 15:28:33 -0400184 'not creating \'/sys/firmware/fdt\'',
185 'Failed to find cpu0 device node',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500186 'Fatal server error:',
Brad Bishop19323692019-04-05 15:28:33 -0400187 'Server terminated with error',
188 ] + common_errors,
189 'beaglebone-yocto' : [
190 'Direct firmware load for regulatory.db',
191 'failed to load regulatory.db',
192 'l4_wkup_cm',
193 'Failed to load module "glx"',
194 'Failed to make EGL context current',
195 'glamor initialization failed',
196 ] + common_errors,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500197}
198
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500199class ParseLogsTest(OERuntimeTestCase):
200
Andrew Geissler220dafd2023-10-04 10:18:08 -0500201 # Which log files should be collected
202 log_locations = ["/var/log/", "/var/log/dmesg", "/tmp/dmesg_output.log"]
203
204 # The keywords that identify error messages in the log files
205 errors = ["error", "cannot", "can't", "failed"]
206
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500207 @classmethod
208 def setUpClass(cls):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500209 # When systemd is enabled we need to notice errors on
210 # circular dependencies in units.
Andrew Geissler220dafd2023-10-04 10:18:08 -0500211 if 'systemd' in cls.td.get('DISTRO_FEATURES'):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500212 cls.errors.extend([
213 'Found ordering cycle on',
214 'Breaking ordering cycle by deleting job',
215 'deleted to break ordering cycle',
216 'Ordering cycle found, skipping',
217 ])
218
Andrew Geissler220dafd2023-10-04 10:18:08 -0500219 cls.errors = [s.casefold() for s in cls.errors]
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500220
Andrew Geissler220dafd2023-10-04 10:18:08 -0500221 try:
222 cls.ignore_errors = [s.casefold() for s in ignore_errors[cls.td.get('MACHINE')]]
223 except KeyError:
224 cls.logger.info('No ignore list found for this machine, using default')
225 cls.ignore_errors = [s.casefold() for s in ignore_errors['default']]
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500226
227 # Go through the log locations provided and if it's a folder
228 # create a list with all the .log files in it, if it's a file
229 # just add it to that list.
230 def getLogList(self, log_locations):
231 logs = []
232 for location in log_locations:
Andrew Geissler220dafd2023-10-04 10:18:08 -0500233 status, _ = self.target.run('test -f %s' % location)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500234 if status == 0:
Andrew Geissler220dafd2023-10-04 10:18:08 -0500235 logs.append(location)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500236 else:
Andrew Geissler220dafd2023-10-04 10:18:08 -0500237 status, _ = self.target.run('test -d %s' % location)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500238 if status == 0:
Andrew Geissler220dafd2023-10-04 10:18:08 -0500239 cmd = 'find %s -name \\*.log -maxdepth 1 -type f' % location
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500240 status, output = self.target.run(cmd)
241 if status == 0:
242 output = output.splitlines()
243 for logfile in output:
Andrew Geissler220dafd2023-10-04 10:18:08 -0500244 logs.append(os.path.join(location, logfile))
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500245 return logs
246
247 # Copy the log files to be parsed locally
248 def transfer_logs(self, log_list):
Andrew Geissler220dafd2023-10-04 10:18:08 -0500249 workdir = self.td.get('WORKDIR')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500250 self.target_logs = workdir + '/' + 'target_logs'
251 target_logs = self.target_logs
252 if os.path.exists(target_logs):
253 rmtree(self.target_logs)
254 os.makedirs(target_logs)
255 for f in log_list:
256 self.target.copyFrom(str(f), target_logs)
257
258 # Get the local list of logs
259 def get_local_log_list(self, log_locations):
260 self.transfer_logs(self.getLogList(log_locations))
261 list_dir = os.listdir(self.target_logs)
262 dir_files = [os.path.join(self.target_logs, f) for f in list_dir]
263 logs = [f for f in dir_files if os.path.isfile(f)]
264 return logs
265
Andrew Geissler220dafd2023-10-04 10:18:08 -0500266 def get_context(self, lines, index, before=6, after=3):
267 """
268 Given a set of lines and the index of the line that is important, return
269 a number of lines surrounding that line.
270 """
271 last = len(lines)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500272
Andrew Geissler220dafd2023-10-04 10:18:08 -0500273 start = index - before
274 end = index + after + 1
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500275
Andrew Geissler220dafd2023-10-04 10:18:08 -0500276 if start < 0:
277 end -= start
278 start = 0
279 if end > last:
280 start -= end - last
281 end = last
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500282
Andrew Geissler220dafd2023-10-04 10:18:08 -0500283 return lines[start:end]
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500284
Andrew Geissler220dafd2023-10-04 10:18:08 -0500285 def test_get_context(self):
286 """
287 A test case for the test case.
288 """
289 lines = list(range(0,10))
290 self.assertEqual(self.get_context(lines, 0, 2, 1), [0, 1, 2, 3])
291 self.assertEqual(self.get_context(lines, 5, 2, 1), [3, 4, 5, 6])
292 self.assertEqual(self.get_context(lines, 9, 2, 1), [6, 7, 8, 9])
293
294 def parse_logs(self, logs, lines_before=10, lines_after=10):
295 """
296 Search the log files @logs looking for error lines (marked by
297 @self.errors), ignoring anything listed in @self.ignore_errors.
298
299 Returns a dictionary of log filenames to a dictionary of error lines to
300 the error context (controlled by @lines_before and @lines_after).
301 """
302 results = collections.defaultdict(dict)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500303
304 for log in logs:
Andrew Geissler220dafd2023-10-04 10:18:08 -0500305 with open(log) as f:
306 lines = f.readlines()
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500307
Andrew Geissler220dafd2023-10-04 10:18:08 -0500308 for i, line in enumerate(lines):
309 line = line.strip()
310 line_lower = line.casefold()
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500311
Andrew Geissler220dafd2023-10-04 10:18:08 -0500312 if any(keyword in line_lower for keyword in self.errors):
313 if not any(ignore in line_lower for ignore in self.ignore_errors):
314 results[log][line] = "".join(self.get_context(lines, i, lines_before, lines_after))
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500315
316 return results
317
318 # Get the output of dmesg and write it in a file.
319 # This file is added to log_locations.
320 def write_dmesg(self):
321 (status, dmesg) = self.target.run('dmesg > /tmp/dmesg_output.log')
322
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500323 @OETestDepends(['ssh.SSHTest.test_ssh'])
324 def test_parselogs(self):
325 self.write_dmesg()
326 log_list = self.get_local_log_list(self.log_locations)
Andrew Geissler220dafd2023-10-04 10:18:08 -0500327 result = self.parse_logs(log_list)
328
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500329 errcount = 0
Andrew Geissler220dafd2023-10-04 10:18:08 -0500330 self.msg = ""
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500331 for log in result:
332 self.msg += 'Log: ' + log + '\n'
333 self.msg += '-----------------------\n'
334 for error in result[log]:
335 errcount += 1
Andrew Geissler220dafd2023-10-04 10:18:08 -0500336 self.msg += 'Central error: ' + error + '\n'
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500337 self.msg += '***********************\n'
Andrew Geissler220dafd2023-10-04 10:18:08 -0500338 self.msg += result[log][error] + '\n'
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500339 self.msg += '***********************\n'
340 self.msg += '%s errors found in logs.' % errcount
341 self.assertEqual(errcount, 0, msg=self.msg)