summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/runtime/cases/parselogs.py
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/oeqa/runtime/cases/parselogs.py')
-rw-r--r--meta/lib/oeqa/runtime/cases/parselogs.py382
1 files changed, 96 insertions, 286 deletions
diff --git a/meta/lib/oeqa/runtime/cases/parselogs.py b/meta/lib/oeqa/runtime/cases/parselogs.py
index a1791b5cca..6966923c94 100644
--- a/meta/lib/oeqa/runtime/cases/parselogs.py
+++ b/meta/lib/oeqa/runtime/cases/parselogs.py
@@ -1,204 +1,49 @@
1# 1#
2# Copyright OpenEmbedded Contributors
3#
2# SPDX-License-Identifier: MIT 4# SPDX-License-Identifier: MIT
3# 5#
4 6
7import collections
5import os 8import os
9import sys
6 10
7from subprocess import check_output
8from shutil import rmtree 11from shutil import rmtree
9from oeqa.runtime.case import OERuntimeTestCase 12from oeqa.runtime.case import OERuntimeTestCase
10from oeqa.core.decorator.depends import OETestDepends 13from oeqa.core.decorator.depends import OETestDepends
11from 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",
55 "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 "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",
62 "[pulseaudio] authkey.c: Failed to open cookie file",
63 "[pulseaudio] authkey.c: Failed to load authentication key",
64 ]
65 14
66video_related = [ 15# importlib.resources.open_text in Python <3.10 doesn't search all directories
67] 16# when a package is split across multiple directories. Until we can rely on
17# 3.10+, reimplement the searching logic.
18if sys.version_info < (3, 10):
19 def _open_text(package, resource):
20 import importlib, pathlib
21 module = importlib.import_module(package)
22 for path in module.__path__:
23 candidate = pathlib.Path(path) / resource
24 if candidate.exists():
25 return candidate.open(encoding='utf-8')
26 raise FileNotFoundError
27else:
28 from importlib.resources import open_text as _open_text
68 29
69x86_common = [
70 '[drm:psb_do_init] *ERROR* Debug is',
71 'wrong ELF class',
72 'Could not enable PowerButton event',
73 'probe of LNXPWRBN:00 failed with error -22',
74 'pmd_set_huge: Cannot satisfy',
75 'failed to setup card detect gpio',
76 'amd_nb: Cannot enumerate AMD northbridges',
77 'failed to retrieve link info, disabling eDP',
78 'Direct firmware load for iwlwifi',
79 'Direct firmware load for regulatory.db',
80 'failed to load regulatory.db',
81] + common_errors
82 30
83qemux86_common = [ 31class ParseLogsTest(OERuntimeTestCase):
84 'wrong ELF class',
85 "fail to add MMCONFIG information, can't access extended PCI configuration space under this bridge.",
86 "can't claim BAR ",
87 'amd_nb: Cannot enumerate AMD northbridges',
88 'tsc: HPET/PMTIMER calibration failed',
89 "modeset(0): Failed to initialize the DRI2 extension",
90 "glamor initialization failed",
91] + common_errors
92 32
93ignore_errors = { 33 # Which log files should be collected
94 'default' : common_errors, 34 log_locations = ["/var/log/", "/var/log/dmesg", "/tmp/dmesg_output.log"]
95 'qemux86' : [
96 'Failed to access perfctr msr (MSR',
97 'pci 0000:00:00.0: [Firmware Bug]: reg 0x..: invalid BAR (can\'t size)',
98 ] + qemux86_common,
99 'qemux86-64' : qemux86_common,
100 'qemumips' : [
101 'Failed to load module "glx"',
102 'pci 0000:00:00.0: [Firmware Bug]: reg 0x..: invalid BAR (can\'t size)',
103 'cacheinfo: Failed to find cpu0 device node',
104 ] + common_errors,
105 'qemumips64' : [
106 'pci 0000:00:00.0: [Firmware Bug]: reg 0x..: invalid BAR (can\'t size)',
107 'cacheinfo: Failed to find cpu0 device node',
108 ] + common_errors,
109 'qemuppc' : [
110 'PCI 0000:00 Cannot reserve Legacy IO [io 0x0000-0x0fff]',
111 'host side 80-wire cable detection failed, limiting max speed',
112 'mode "640x480" test failed',
113 'Failed to load module "glx"',
114 'can\'t handle BAR above 4GB',
115 'Cannot reserve Legacy IO',
116 ] + common_errors,
117 'qemuarm' : [
118 'mmci-pl18x: probe of fpga:05 failed with error -22',
119 'mmci-pl18x: probe of fpga:0b failed with error -22',
120 'Failed to load module "glx"',
121 'OF: amba_device_add() failed (-19) for /amba/smc@10100000',
122 'OF: amba_device_add() failed (-19) for /amba/mpmc@10110000',
123 'OF: amba_device_add() failed (-19) for /amba/sctl@101e0000',
124 'OF: amba_device_add() failed (-19) for /amba/watchdog@101e1000',
125 'OF: amba_device_add() failed (-19) for /amba/sci@101f0000',
126 'OF: amba_device_add() failed (-19) for /amba/spi@101f4000',
127 'OF: amba_device_add() failed (-19) for /amba/ssp@101f4000',
128 'OF: amba_device_add() failed (-19) for /amba/fpga/sci@a000',
129 'Failed to initialize \'/amba/timer@101e3000\': -22',
130 'jitterentropy: Initialization failed with host not compliant with requirements: 2',
131 ] + common_errors,
132 'qemuarm64' : [
133 'Fatal server error:',
134 '(EE) Server terminated with error (1). Closing log file.',
135 'dmi: Firmware registration failed.',
136 'irq: type mismatch, failed to map hwirq-27 for /intc',
137 'logind: failed to get session seat',
138 ] + common_errors,
139 'intel-core2-32' : [
140 'ACPI: No _BQC method, cannot determine initial brightness',
141 '[Firmware Bug]: ACPI: No _BQC method, cannot determine initial brightness',
142 '(EE) Failed to load module "psb"',
143 '(EE) Failed to load module psb',
144 '(EE) Failed to load module "psbdrv"',
145 '(EE) Failed to load module psbdrv',
146 '(EE) open /dev/fb0: No such file or directory',
147 '(EE) AIGLX: reverting to software rendering',
148 'dmi: Firmware registration failed.',
149 'ioremap error for 0x78',
150 ] + x86_common,
151 'intel-corei7-64' : [
152 'can\'t set Max Payload Size to 256',
153 'intel_punit_ipc: can\'t request region for resource',
154 '[drm] parse error at position 4 in video mode \'efifb\'',
155 'ACPI Error: Could not enable RealTimeClock event',
156 'ACPI Warning: Could not enable fixed event - RealTimeClock',
157 'hci_intel INT33E1:00: Unable to retrieve gpio',
158 'hci_intel: probe of INT33E1:00 failed',
159 'can\'t derive routing for PCI INT A',
160 'failed to read out thermal zone',
161 'Bluetooth: hci0: Setting Intel event mask failed',
162 'ttyS2 - failed to request DMA',
163 'Bluetooth: hci0: Failed to send firmware data (-38)',
164 'atkbd serio0: Failed to enable keyboard on isa0060/serio0',
165 ] + x86_common,
166 'genericx86' : x86_common,
167 'genericx86-64' : [
168 'Direct firmware load for i915',
169 'Failed to load firmware i915',
170 'Failed to fetch GuC',
171 'Failed to initialize GuC',
172 'Failed to load DMC firmware',
173 'The driver is built-in, so to load the firmware you need to',
174 ] + x86_common,
175 'edgerouter' : [
176 'not creating \'/sys/firmware/fdt\'',
177 'Failed to find cpu0 device node',
178 'Fatal server error:',
179 'Server terminated with error',
180 ] + common_errors,
181 'beaglebone-yocto' : [
182 'Direct firmware load for regulatory.db',
183 'failed to load regulatory.db',
184 'l4_wkup_cm',
185 'Failed to load module "glx"',
186 'Failed to make EGL context current',
187 'glamor initialization failed',
188 ] + common_errors,
189}
190 35
191log_locations = ["/var/log/","/var/log/dmesg", "/tmp/dmesg_output.log"] 36 # The keywords that identify error messages in the log files
37 errors = ["error", "cannot", "can't", "failed"]
192 38
193class ParseLogsTest(OERuntimeTestCase): 39 # A list of error messages that should be ignored
40 ignore_errors = []
194 41
195 @classmethod 42 @classmethod
196 def setUpClass(cls): 43 def setUpClass(cls):
197 cls.errors = errors
198
199 # When systemd is enabled we need to notice errors on 44 # When systemd is enabled we need to notice errors on
200 # circular dependencies in units. 45 # circular dependencies in units.
201 if 'systemd' in cls.td.get('DISTRO_FEATURES', ''): 46 if 'systemd' in cls.td.get('DISTRO_FEATURES'):
202 cls.errors.extend([ 47 cls.errors.extend([
203 'Found ordering cycle on', 48 'Found ordering cycle on',
204 'Breaking ordering cycle by deleting job', 49 'Breaking ordering cycle by deleting job',
@@ -206,48 +51,22 @@ class ParseLogsTest(OERuntimeTestCase):
206 'Ordering cycle found, skipping', 51 'Ordering cycle found, skipping',
207 ]) 52 ])
208 53
209 cls.ignore_errors = ignore_errors 54 cls.errors = [s.casefold() for s in cls.errors]
210 cls.log_locations = log_locations
211 cls.msg = ''
212 is_lsb, _ = cls.tc.target.run("which LSB_Test.sh")
213 if is_lsb == 0:
214 for machine in cls.ignore_errors:
215 cls.ignore_errors[machine] = cls.ignore_errors[machine] \
216 + video_related
217
218 def getMachine(self):
219 return self.td.get('MACHINE', '')
220
221 def getWorkdir(self):
222 return self.td.get('WORKDIR', '')
223
224 # Get some information on the CPU of the machine to display at the
225 # beginning of the output. This info might be useful in some cases.
226 def getHardwareInfo(self):
227 hwi = ""
228 cmd = ('cat /proc/cpuinfo | grep "model name" | head -n1 | '
229 " awk 'BEGIN{FS=\":\"}{print $2}'")
230 _, cpu_name = self.target.run(cmd)
231
232 cmd = ('cat /proc/cpuinfo | grep "cpu cores" | head -n1 | '
233 "awk {'print $4'}")
234 _, cpu_physical_cores = self.target.run(cmd)
235
236 cmd = 'cat /proc/cpuinfo | grep "processor" | wc -l'
237 _, cpu_logical_cores = self.target.run(cmd)
238
239 _, cpu_arch = self.target.run('uname -m')
240 55
241 hwi += 'Machine information: \n' 56 cls.load_machine_ignores()
242 hwi += '*******************************\n'
243 hwi += 'Machine name: ' + self.getMachine() + '\n'
244 hwi += 'CPU: ' + str(cpu_name) + '\n'
245 hwi += 'Arch: ' + str(cpu_arch)+ '\n'
246 hwi += 'Physical cores: ' + str(cpu_physical_cores) + '\n'
247 hwi += 'Logical cores: ' + str(cpu_logical_cores) + '\n'
248 hwi += '*******************************\n'
249 57
250 return hwi 58 @classmethod
59 def load_machine_ignores(cls):
60 # Add TARGET_ARCH explicitly as not every machine has that in MACHINEOVERRDES (eg qemux86-64)
61 for candidate in ["common", cls.td.get("TARGET_ARCH")] + cls.td.get("MACHINEOVERRIDES").split(":"):
62 try:
63 name = f"parselogs-ignores-{candidate}.txt"
64 for line in _open_text("oeqa.runtime.cases", name):
65 line = line.strip()
66 if line and not line.startswith("#"):
67 cls.ignore_errors.append(line.casefold())
68 except FileNotFoundError:
69 pass
251 70
252 # Go through the log locations provided and if it's a folder 71 # Go through the log locations provided and if it's a folder
253 # create a list with all the .log files in it, if it's a file 72 # create a list with all the .log files in it, if it's a file
@@ -255,23 +74,23 @@ class ParseLogsTest(OERuntimeTestCase):
255 def getLogList(self, log_locations): 74 def getLogList(self, log_locations):
256 logs = [] 75 logs = []
257 for location in log_locations: 76 for location in log_locations:
258 status, _ = self.target.run('test -f ' + str(location)) 77 status, _ = self.target.run('test -f %s' % location)
259 if status == 0: 78 if status == 0:
260 logs.append(str(location)) 79 logs.append(location)
261 else: 80 else:
262 status, _ = self.target.run('test -d ' + str(location)) 81 status, _ = self.target.run('test -d %s' % location)
263 if status == 0: 82 if status == 0:
264 cmd = 'find ' + str(location) + '/*.log -maxdepth 1 -type f' 83 cmd = 'find %s -name \\*.log -maxdepth 1 -type f' % location
265 status, output = self.target.run(cmd) 84 status, output = self.target.run(cmd)
266 if status == 0: 85 if status == 0:
267 output = output.splitlines() 86 output = output.splitlines()
268 for logfile in output: 87 for logfile in output:
269 logs.append(os.path.join(location, str(logfile))) 88 logs.append(os.path.join(location, logfile))
270 return logs 89 return logs
271 90
272 # Copy the log files to be parsed locally 91 # Copy the log files to be parsed locally
273 def transfer_logs(self, log_list): 92 def transfer_logs(self, log_list):
274 workdir = self.getWorkdir() 93 workdir = self.td.get('WORKDIR')
275 self.target_logs = workdir + '/' + 'target_logs' 94 self.target_logs = workdir + '/' + 'target_logs'
276 target_logs = self.target_logs 95 target_logs = self.target_logs
277 if os.path.exists(target_logs): 96 if os.path.exists(target_logs):
@@ -288,65 +107,55 @@ class ParseLogsTest(OERuntimeTestCase):
288 logs = [f for f in dir_files if os.path.isfile(f)] 107 logs = [f for f in dir_files if os.path.isfile(f)]
289 return logs 108 return logs
290 109
291 # Build the grep command to be used with filters and exclusions 110 def get_context(self, lines, index, before=6, after=3):
292 def build_grepcmd(self, errors, ignore_errors, log): 111 """
293 grepcmd = 'grep ' 112 Given a set of lines and the index of the line that is important, return
294 grepcmd += '-Ei "' 113 a number of lines surrounding that line.
295 for error in errors: 114 """
296 grepcmd += '\<' + error + '\>' + '|' 115 last = len(lines)
297 grepcmd = grepcmd[:-1] 116
298 grepcmd += '" ' + str(log) + " | grep -Eiv \'" 117 start = index - before
299 118 end = index + after + 1
300 try: 119
301 errorlist = ignore_errors[self.getMachine()] 120 if start < 0:
302 except KeyError: 121 end -= start
303 self.msg += 'No ignore list found for this machine, using default\n' 122 start = 0
304 errorlist = ignore_errors['default'] 123 if end > last:
305 124 start -= end - last
306 for ignore_error in errorlist: 125 end = last
307 ignore_error = ignore_error.replace('(', '\(') 126
308 ignore_error = ignore_error.replace(')', '\)') 127 return lines[start:end]
309 ignore_error = ignore_error.replace("'", '.') 128
310 ignore_error = ignore_error.replace('?', '\?') 129 def test_get_context(self):
311 ignore_error = ignore_error.replace('[', '\[') 130 """
312 ignore_error = ignore_error.replace(']', '\]') 131 A test case for the test case.
313 ignore_error = ignore_error.replace('*', '\*') 132 """
314 ignore_error = ignore_error.replace('0-9', '[0-9]') 133 lines = list(range(0,10))
315 grepcmd += ignore_error + '|' 134 self.assertEqual(self.get_context(lines, 0, 2, 1), [0, 1, 2, 3])
316 grepcmd = grepcmd[:-1] 135 self.assertEqual(self.get_context(lines, 5, 2, 1), [3, 4, 5, 6])
317 grepcmd += "\'" 136 self.assertEqual(self.get_context(lines, 9, 2, 1), [6, 7, 8, 9])
318 137
319 return grepcmd 138 def parse_logs(self, logs, lines_before=10, lines_after=10):
320 139 """
321 # Grep only the errors so that their context could be collected. 140 Search the log files @logs looking for error lines (marked by
322 # Default context is 10 lines before and after the error itself 141 @self.errors), ignoring anything listed in @self.ignore_errors.
323 def parse_logs(self, errors, ignore_errors, logs, 142
324 lines_before = 10, lines_after = 10): 143 Returns a dictionary of log filenames to a dictionary of error lines to
325 results = {} 144 the error context (controlled by @lines_before and @lines_after).
326 rez = [] 145 """
327 grep_output = '' 146 results = collections.defaultdict(dict)
328 147
329 for log in logs: 148 for log in logs:
330 result = None 149 with open(log) as f:
331 thegrep = self.build_grepcmd(errors, ignore_errors, log) 150 lines = f.readlines()
332 151
333 try: 152 for i, line in enumerate(lines):
334 result = check_output(thegrep, shell=True).decode('utf-8') 153 line = line.strip()
335 except: 154 line_lower = line.casefold()
336 pass
337 155
338 if result is not None: 156 if any(keyword in line_lower for keyword in self.errors):
339 results[log] = {} 157 if not any(ignore in line_lower for ignore in self.ignore_errors):
340 rez = result.splitlines() 158 results[log][line] = "".join(self.get_context(lines, i, lines_before, lines_after))
341
342 for xrez in rez:
343 try:
344 cmd = ['grep', '-F', xrez, '-B', str(lines_before)]
345 cmd += ['-A', str(lines_after), log]
346 grep_output = check_output(cmd).decode('utf-8')
347 except:
348 pass
349 results[log][xrez]=grep_output
350 159
351 return results 160 return results
352 161
@@ -359,17 +168,18 @@ class ParseLogsTest(OERuntimeTestCase):
359 def test_parselogs(self): 168 def test_parselogs(self):
360 self.write_dmesg() 169 self.write_dmesg()
361 log_list = self.get_local_log_list(self.log_locations) 170 log_list = self.get_local_log_list(self.log_locations)
362 result = self.parse_logs(self.errors, self.ignore_errors, log_list) 171 result = self.parse_logs(log_list)
363 print(self.getHardwareInfo()) 172
364 errcount = 0 173 errcount = 0
174 self.msg = ""
365 for log in result: 175 for log in result:
366 self.msg += 'Log: ' + log + '\n' 176 self.msg += 'Log: ' + log + '\n'
367 self.msg += '-----------------------\n' 177 self.msg += '-----------------------\n'
368 for error in result[log]: 178 for error in result[log]:
369 errcount += 1 179 errcount += 1
370 self.msg += 'Central error: ' + str(error) + '\n' 180 self.msg += 'Central error: ' + error + '\n'
371 self.msg += '***********************\n' 181 self.msg += '***********************\n'
372 self.msg += result[str(log)][str(error)] + '\n' 182 self.msg += result[log][error] + '\n'
373 self.msg += '***********************\n' 183 self.msg += '***********************\n'
374 self.msg += '%s errors found in logs.' % errcount 184 self.msg += '%s errors found in logs.' % errcount
375 self.assertEqual(errcount, 0, msg=self.msg) 185 self.assertEqual(errcount, 0, msg=self.msg)