blob: 4714741aff69fe43f290a607ba3b06ba3edbbe6d [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",
62 "[pulseaudio] authkey.c: Failed to open cookie file",
63 "[pulseaudio] authkey.c: Failed to load authentication key",
Brad Bishop6e60e8b2018-02-01 10:27:11 -050064 ]
65
66video_related = [
Brad Bishop6e60e8b2018-02-01 10:27:11 -050067]
68
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',
Brad Bishop19323692019-04-05 15:28:33 -040079 'Direct firmware load for regulatory.db',
80 'failed to load regulatory.db',
Brad Bishop6e60e8b2018-02-01 10:27:11 -050081] + common_errors
82
83qemux86_common = [
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',
Brad Bishop6e60e8b2018-02-01 10:27:11 -050088 'tsc: HPET/PMTIMER calibration failed',
Brad Bishop79641f22019-09-10 07:20:22 -040089 "modeset(0): Failed to initialize the DRI2 extension",
Brad Bishop79641f22019-09-10 07:20:22 -040090 "glamor initialization failed",
Brad Bishop6e60e8b2018-02-01 10:27:11 -050091] + common_errors
92
93ignore_errors = {
94 'default' : common_errors,
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)',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500103 'cacheinfo: Failed to find cpu0 device node',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500104 ] + common_errors,
105 'qemumips64' : [
106 'pci 0000:00:00.0: [Firmware Bug]: reg 0x..: invalid BAR (can\'t size)',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500107 'cacheinfo: Failed to find cpu0 device node',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500108 ] + 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,
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500117 'qemuppc64' : [
118 'vio vio: uevent: failed to send synthetic uevent',
119 'synth uevent: /devices/vio: failed to send uevent',
120 'PCI 0000:00 Cannot reserve Legacy IO [io 0x10000-0x10fff]',
121 ] + common_errors,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500122 'qemuarm' : [
123 'mmci-pl18x: probe of fpga:05 failed with error -22',
124 'mmci-pl18x: probe of fpga:0b failed with error -22',
125 'Failed to load module "glx"',
126 'OF: amba_device_add() failed (-19) for /amba/smc@10100000',
127 'OF: amba_device_add() failed (-19) for /amba/mpmc@10110000',
128 'OF: amba_device_add() failed (-19) for /amba/sctl@101e0000',
129 'OF: amba_device_add() failed (-19) for /amba/watchdog@101e1000',
130 'OF: amba_device_add() failed (-19) for /amba/sci@101f0000',
Brad Bishop19323692019-04-05 15:28:33 -0400131 'OF: amba_device_add() failed (-19) for /amba/spi@101f4000',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500132 'OF: amba_device_add() failed (-19) for /amba/ssp@101f4000',
133 'OF: amba_device_add() failed (-19) for /amba/fpga/sci@a000',
134 'Failed to initialize \'/amba/timer@101e3000\': -22',
135 'jitterentropy: Initialization failed with host not compliant with requirements: 2',
136 ] + common_errors,
137 'qemuarm64' : [
138 'Fatal server error:',
139 '(EE) Server terminated with error (1). Closing log file.',
140 'dmi: Firmware registration failed.',
141 'irq: type mismatch, failed to map hwirq-27 for /intc',
Andrew Geissler82c905d2020-04-13 13:39:40 -0500142 'logind: failed to get session seat',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500143 ] + common_errors,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500144 'intel-core2-32' : [
145 'ACPI: No _BQC method, cannot determine initial brightness',
146 '[Firmware Bug]: ACPI: No _BQC method, cannot determine initial brightness',
147 '(EE) Failed to load module "psb"',
148 '(EE) Failed to load module psb',
149 '(EE) Failed to load module "psbdrv"',
150 '(EE) Failed to load module psbdrv',
151 '(EE) open /dev/fb0: No such file or directory',
152 '(EE) AIGLX: reverting to software rendering',
153 'dmi: Firmware registration failed.',
154 'ioremap error for 0x78',
155 ] + x86_common,
156 'intel-corei7-64' : [
157 'can\'t set Max Payload Size to 256',
158 'intel_punit_ipc: can\'t request region for resource',
159 '[drm] parse error at position 4 in video mode \'efifb\'',
160 'ACPI Error: Could not enable RealTimeClock event',
161 'ACPI Warning: Could not enable fixed event - RealTimeClock',
162 'hci_intel INT33E1:00: Unable to retrieve gpio',
163 'hci_intel: probe of INT33E1:00 failed',
164 'can\'t derive routing for PCI INT A',
165 'failed to read out thermal zone',
166 'Bluetooth: hci0: Setting Intel event mask failed',
167 'ttyS2 - failed to request DMA',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500168 'Bluetooth: hci0: Failed to send firmware data (-38)',
169 'atkbd serio0: Failed to enable keyboard on isa0060/serio0',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500170 ] + x86_common,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500171 'genericx86' : x86_common,
172 'genericx86-64' : [
173 'Direct firmware load for i915',
174 'Failed to load firmware i915',
175 'Failed to fetch GuC',
176 'Failed to initialize GuC',
177 'Failed to load DMC firmware',
178 'The driver is built-in, so to load the firmware you need to',
179 ] + x86_common,
180 'edgerouter' : [
Brad Bishop19323692019-04-05 15:28:33 -0400181 'not creating \'/sys/firmware/fdt\'',
182 'Failed to find cpu0 device node',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500183 'Fatal server error:',
Brad Bishop19323692019-04-05 15:28:33 -0400184 'Server terminated with error',
185 ] + common_errors,
186 'beaglebone-yocto' : [
187 'Direct firmware load for regulatory.db',
188 'failed to load regulatory.db',
189 'l4_wkup_cm',
190 'Failed to load module "glx"',
191 'Failed to make EGL context current',
192 'glamor initialization failed',
193 ] + common_errors,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500194}
195
196log_locations = ["/var/log/","/var/log/dmesg", "/tmp/dmesg_output.log"]
197
198class ParseLogsTest(OERuntimeTestCase):
199
200 @classmethod
201 def setUpClass(cls):
202 cls.errors = errors
203
204 # When systemd is enabled we need to notice errors on
205 # circular dependencies in units.
206 if 'systemd' in cls.td.get('DISTRO_FEATURES', ''):
207 cls.errors.extend([
208 'Found ordering cycle on',
209 'Breaking ordering cycle by deleting job',
210 'deleted to break ordering cycle',
211 'Ordering cycle found, skipping',
212 ])
213
214 cls.ignore_errors = ignore_errors
215 cls.log_locations = log_locations
216 cls.msg = ''
217 is_lsb, _ = cls.tc.target.run("which LSB_Test.sh")
218 if is_lsb == 0:
219 for machine in cls.ignore_errors:
220 cls.ignore_errors[machine] = cls.ignore_errors[machine] \
221 + video_related
222
223 def getMachine(self):
224 return self.td.get('MACHINE', '')
225
226 def getWorkdir(self):
227 return self.td.get('WORKDIR', '')
228
229 # Get some information on the CPU of the machine to display at the
230 # beginning of the output. This info might be useful in some cases.
231 def getHardwareInfo(self):
232 hwi = ""
233 cmd = ('cat /proc/cpuinfo | grep "model name" | head -n1 | '
234 " awk 'BEGIN{FS=\":\"}{print $2}'")
235 _, cpu_name = self.target.run(cmd)
236
237 cmd = ('cat /proc/cpuinfo | grep "cpu cores" | head -n1 | '
238 "awk {'print $4'}")
239 _, cpu_physical_cores = self.target.run(cmd)
240
241 cmd = 'cat /proc/cpuinfo | grep "processor" | wc -l'
242 _, cpu_logical_cores = self.target.run(cmd)
243
244 _, cpu_arch = self.target.run('uname -m')
245
246 hwi += 'Machine information: \n'
247 hwi += '*******************************\n'
248 hwi += 'Machine name: ' + self.getMachine() + '\n'
249 hwi += 'CPU: ' + str(cpu_name) + '\n'
250 hwi += 'Arch: ' + str(cpu_arch)+ '\n'
251 hwi += 'Physical cores: ' + str(cpu_physical_cores) + '\n'
252 hwi += 'Logical cores: ' + str(cpu_logical_cores) + '\n'
253 hwi += '*******************************\n'
254
255 return hwi
256
257 # Go through the log locations provided and if it's a folder
258 # create a list with all the .log files in it, if it's a file
259 # just add it to that list.
260 def getLogList(self, log_locations):
261 logs = []
262 for location in log_locations:
263 status, _ = self.target.run('test -f ' + str(location))
264 if status == 0:
265 logs.append(str(location))
266 else:
267 status, _ = self.target.run('test -d ' + str(location))
268 if status == 0:
269 cmd = 'find ' + str(location) + '/*.log -maxdepth 1 -type f'
270 status, output = self.target.run(cmd)
271 if status == 0:
272 output = output.splitlines()
273 for logfile in output:
274 logs.append(os.path.join(location, str(logfile)))
275 return logs
276
277 # Copy the log files to be parsed locally
278 def transfer_logs(self, log_list):
279 workdir = self.getWorkdir()
280 self.target_logs = workdir + '/' + 'target_logs'
281 target_logs = self.target_logs
282 if os.path.exists(target_logs):
283 rmtree(self.target_logs)
284 os.makedirs(target_logs)
285 for f in log_list:
286 self.target.copyFrom(str(f), target_logs)
287
288 # Get the local list of logs
289 def get_local_log_list(self, log_locations):
290 self.transfer_logs(self.getLogList(log_locations))
291 list_dir = os.listdir(self.target_logs)
292 dir_files = [os.path.join(self.target_logs, f) for f in list_dir]
293 logs = [f for f in dir_files if os.path.isfile(f)]
294 return logs
295
296 # Build the grep command to be used with filters and exclusions
297 def build_grepcmd(self, errors, ignore_errors, log):
298 grepcmd = 'grep '
299 grepcmd += '-Ei "'
300 for error in errors:
Brad Bishop08902b02019-08-20 09:16:51 -0400301 grepcmd += '\<' + error + '\>' + '|'
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500302 grepcmd = grepcmd[:-1]
303 grepcmd += '" ' + str(log) + " | grep -Eiv \'"
304
305 try:
306 errorlist = ignore_errors[self.getMachine()]
307 except KeyError:
308 self.msg += 'No ignore list found for this machine, using default\n'
309 errorlist = ignore_errors['default']
310
311 for ignore_error in errorlist:
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(']', '\]')
318 ignore_error = ignore_error.replace('*', '\*')
319 ignore_error = ignore_error.replace('0-9', '[0-9]')
320 grepcmd += ignore_error + '|'
321 grepcmd = grepcmd[:-1]
322 grepcmd += "\'"
323
324 return grepcmd
325
326 # Grep only the errors so that their context could be collected.
327 # Default context is 10 lines before and after the error itself
328 def parse_logs(self, errors, ignore_errors, logs,
329 lines_before = 10, lines_after = 10):
330 results = {}
331 rez = []
332 grep_output = ''
333
334 for log in logs:
335 result = None
336 thegrep = self.build_grepcmd(errors, ignore_errors, log)
337
338 try:
339 result = check_output(thegrep, shell=True).decode('utf-8')
340 except:
341 pass
342
343 if result is not None:
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800344 results[log] = {}
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500345 rez = result.splitlines()
346
347 for xrez in rez:
348 try:
349 cmd = ['grep', '-F', xrez, '-B', str(lines_before)]
350 cmd += ['-A', str(lines_after), log]
351 grep_output = check_output(cmd).decode('utf-8')
352 except:
353 pass
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800354 results[log][xrez]=grep_output
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500355
356 return results
357
358 # Get the output of dmesg and write it in a file.
359 # This file is added to log_locations.
360 def write_dmesg(self):
361 (status, dmesg) = self.target.run('dmesg > /tmp/dmesg_output.log')
362
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500363 @OETestDepends(['ssh.SSHTest.test_ssh'])
364 def test_parselogs(self):
365 self.write_dmesg()
366 log_list = self.get_local_log_list(self.log_locations)
367 result = self.parse_logs(self.errors, self.ignore_errors, log_list)
368 print(self.getHardwareInfo())
369 errcount = 0
370 for log in result:
371 self.msg += 'Log: ' + log + '\n'
372 self.msg += '-----------------------\n'
373 for error in result[log]:
374 errcount += 1
375 self.msg += 'Central error: ' + str(error) + '\n'
376 self.msg += '***********************\n'
377 self.msg += result[str(log)][str(error)] + '\n'
378 self.msg += '***********************\n'
379 self.msg += '%s errors found in logs.' % errcount
380 self.assertEqual(errcount, 0, msg=self.msg)