blob: f6e9820cdcfdce094eafb781981ab273f8773d0f [file] [log] [blame]
Brad Bishop6e60e8b2018-02-01 10:27:11 -05001import os
2
3from subprocess import check_output
4from shutil import rmtree
5from oeqa.runtime.case import OERuntimeTestCase
6from oeqa.core.decorator.depends import OETestDepends
7from oeqa.core.decorator.oeid import OETestID
8from oeqa.core.decorator.data import skipIfDataVar
9from oeqa.runtime.decorator.package import OEHasPackage
10
11#in the future these lists could be moved outside of module
12errors = ["error", "cannot", "can\'t", "failed"]
13
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",
32 "[drm] Cannot find any crtc or sizes - going 1024x768",
33 "_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",
55 "Error changing net interface name 'eth0' to "
Brad Bishop6e60e8b2018-02-01 10:27:11 -050056 ]
57
58video_related = [
59 "uvesafb",
60]
61
62x86_common = [
63 '[drm:psb_do_init] *ERROR* Debug is',
64 'wrong ELF class',
65 'Could not enable PowerButton event',
66 'probe of LNXPWRBN:00 failed with error -22',
67 'pmd_set_huge: Cannot satisfy',
68 'failed to setup card detect gpio',
69 'amd_nb: Cannot enumerate AMD northbridges',
70 'failed to retrieve link info, disabling eDP',
71 'Direct firmware load for iwlwifi',
72] + common_errors
73
74qemux86_common = [
75 'wrong ELF class',
76 "fail to add MMCONFIG information, can't access extended PCI configuration space under this bridge.",
77 "can't claim BAR ",
78 'amd_nb: Cannot enumerate AMD northbridges',
79 'uvesafb: 5000 ms task timeout, infinitely waiting',
80 'tsc: HPET/PMTIMER calibration failed',
81] + common_errors
82
83ignore_errors = {
84 'default' : common_errors,
85 'qemux86' : [
86 'Failed to access perfctr msr (MSR',
87 'pci 0000:00:00.0: [Firmware Bug]: reg 0x..: invalid BAR (can\'t size)',
88 ] + qemux86_common,
89 'qemux86-64' : qemux86_common,
90 'qemumips' : [
91 'Failed to load module "glx"',
92 'pci 0000:00:00.0: [Firmware Bug]: reg 0x..: invalid BAR (can\'t size)',
Brad Bishopd7bf8c12018-02-25 22:55:05 -050093 'cacheinfo: Failed to find cpu0 device node',
Brad Bishop6e60e8b2018-02-01 10:27:11 -050094 ] + common_errors,
95 'qemumips64' : [
96 'pci 0000:00:00.0: [Firmware Bug]: reg 0x..: invalid BAR (can\'t size)',
Brad Bishopd7bf8c12018-02-25 22:55:05 -050097 'cacheinfo: Failed to find cpu0 device node',
Brad Bishop6e60e8b2018-02-01 10:27:11 -050098 ] + common_errors,
99 'qemuppc' : [
100 'PCI 0000:00 Cannot reserve Legacy IO [io 0x0000-0x0fff]',
101 'host side 80-wire cable detection failed, limiting max speed',
102 'mode "640x480" test failed',
103 'Failed to load module "glx"',
104 'can\'t handle BAR above 4GB',
105 'Cannot reserve Legacy IO',
106 ] + common_errors,
107 'qemuarm' : [
108 'mmci-pl18x: probe of fpga:05 failed with error -22',
109 'mmci-pl18x: probe of fpga:0b failed with error -22',
110 'Failed to load module "glx"',
111 'OF: amba_device_add() failed (-19) for /amba/smc@10100000',
112 'OF: amba_device_add() failed (-19) for /amba/mpmc@10110000',
113 'OF: amba_device_add() failed (-19) for /amba/sctl@101e0000',
114 'OF: amba_device_add() failed (-19) for /amba/watchdog@101e1000',
115 'OF: amba_device_add() failed (-19) for /amba/sci@101f0000',
116 'OF: amba_device_add() failed (-19) for /amba/ssp@101f4000',
117 'OF: amba_device_add() failed (-19) for /amba/fpga/sci@a000',
118 'Failed to initialize \'/amba/timer@101e3000\': -22',
119 'jitterentropy: Initialization failed with host not compliant with requirements: 2',
120 ] + common_errors,
121 'qemuarm64' : [
122 'Fatal server error:',
123 '(EE) Server terminated with error (1). Closing log file.',
124 'dmi: Firmware registration failed.',
125 'irq: type mismatch, failed to map hwirq-27 for /intc',
126 ] + common_errors,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500127 'intel-core2-32' : [
128 'ACPI: No _BQC method, cannot determine initial brightness',
129 '[Firmware Bug]: ACPI: No _BQC method, cannot determine initial brightness',
130 '(EE) Failed to load module "psb"',
131 '(EE) Failed to load module psb',
132 '(EE) Failed to load module "psbdrv"',
133 '(EE) Failed to load module psbdrv',
134 '(EE) open /dev/fb0: No such file or directory',
135 '(EE) AIGLX: reverting to software rendering',
136 'dmi: Firmware registration failed.',
137 'ioremap error for 0x78',
138 ] + x86_common,
139 'intel-corei7-64' : [
140 'can\'t set Max Payload Size to 256',
141 'intel_punit_ipc: can\'t request region for resource',
142 '[drm] parse error at position 4 in video mode \'efifb\'',
143 'ACPI Error: Could not enable RealTimeClock event',
144 'ACPI Warning: Could not enable fixed event - RealTimeClock',
145 'hci_intel INT33E1:00: Unable to retrieve gpio',
146 'hci_intel: probe of INT33E1:00 failed',
147 'can\'t derive routing for PCI INT A',
148 'failed to read out thermal zone',
149 'Bluetooth: hci0: Setting Intel event mask failed',
150 'ttyS2 - failed to request DMA',
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500151 'Bluetooth: hci0: Failed to send firmware data (-38)',
152 'atkbd serio0: Failed to enable keyboard on isa0060/serio0',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500153 ] + x86_common,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500154 'genericx86' : x86_common,
155 'genericx86-64' : [
156 'Direct firmware load for i915',
157 'Failed to load firmware i915',
158 'Failed to fetch GuC',
159 'Failed to initialize GuC',
160 'Failed to load DMC firmware',
161 'The driver is built-in, so to load the firmware you need to',
162 ] + x86_common,
163 'edgerouter' : [
164 'Fatal server error:',
165 ] + common_errors,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500166}
167
168log_locations = ["/var/log/","/var/log/dmesg", "/tmp/dmesg_output.log"]
169
170class ParseLogsTest(OERuntimeTestCase):
171
172 @classmethod
173 def setUpClass(cls):
174 cls.errors = errors
175
176 # When systemd is enabled we need to notice errors on
177 # circular dependencies in units.
178 if 'systemd' in cls.td.get('DISTRO_FEATURES', ''):
179 cls.errors.extend([
180 'Found ordering cycle on',
181 'Breaking ordering cycle by deleting job',
182 'deleted to break ordering cycle',
183 'Ordering cycle found, skipping',
184 ])
185
186 cls.ignore_errors = ignore_errors
187 cls.log_locations = log_locations
188 cls.msg = ''
189 is_lsb, _ = cls.tc.target.run("which LSB_Test.sh")
190 if is_lsb == 0:
191 for machine in cls.ignore_errors:
192 cls.ignore_errors[machine] = cls.ignore_errors[machine] \
193 + video_related
194
195 def getMachine(self):
196 return self.td.get('MACHINE', '')
197
198 def getWorkdir(self):
199 return self.td.get('WORKDIR', '')
200
201 # Get some information on the CPU of the machine to display at the
202 # beginning of the output. This info might be useful in some cases.
203 def getHardwareInfo(self):
204 hwi = ""
205 cmd = ('cat /proc/cpuinfo | grep "model name" | head -n1 | '
206 " awk 'BEGIN{FS=\":\"}{print $2}'")
207 _, cpu_name = self.target.run(cmd)
208
209 cmd = ('cat /proc/cpuinfo | grep "cpu cores" | head -n1 | '
210 "awk {'print $4'}")
211 _, cpu_physical_cores = self.target.run(cmd)
212
213 cmd = 'cat /proc/cpuinfo | grep "processor" | wc -l'
214 _, cpu_logical_cores = self.target.run(cmd)
215
216 _, cpu_arch = self.target.run('uname -m')
217
218 hwi += 'Machine information: \n'
219 hwi += '*******************************\n'
220 hwi += 'Machine name: ' + self.getMachine() + '\n'
221 hwi += 'CPU: ' + str(cpu_name) + '\n'
222 hwi += 'Arch: ' + str(cpu_arch)+ '\n'
223 hwi += 'Physical cores: ' + str(cpu_physical_cores) + '\n'
224 hwi += 'Logical cores: ' + str(cpu_logical_cores) + '\n'
225 hwi += '*******************************\n'
226
227 return hwi
228
229 # Go through the log locations provided and if it's a folder
230 # create a list with all the .log files in it, if it's a file
231 # just add it to that list.
232 def getLogList(self, log_locations):
233 logs = []
234 for location in log_locations:
235 status, _ = self.target.run('test -f ' + str(location))
236 if status == 0:
237 logs.append(str(location))
238 else:
239 status, _ = self.target.run('test -d ' + str(location))
240 if status == 0:
241 cmd = 'find ' + str(location) + '/*.log -maxdepth 1 -type f'
242 status, output = self.target.run(cmd)
243 if status == 0:
244 output = output.splitlines()
245 for logfile in output:
246 logs.append(os.path.join(location, str(logfile)))
247 return logs
248
249 # Copy the log files to be parsed locally
250 def transfer_logs(self, log_list):
251 workdir = self.getWorkdir()
252 self.target_logs = workdir + '/' + 'target_logs'
253 target_logs = self.target_logs
254 if os.path.exists(target_logs):
255 rmtree(self.target_logs)
256 os.makedirs(target_logs)
257 for f in log_list:
258 self.target.copyFrom(str(f), target_logs)
259
260 # Get the local list of logs
261 def get_local_log_list(self, log_locations):
262 self.transfer_logs(self.getLogList(log_locations))
263 list_dir = os.listdir(self.target_logs)
264 dir_files = [os.path.join(self.target_logs, f) for f in list_dir]
265 logs = [f for f in dir_files if os.path.isfile(f)]
266 return logs
267
268 # Build the grep command to be used with filters and exclusions
269 def build_grepcmd(self, errors, ignore_errors, log):
270 grepcmd = 'grep '
271 grepcmd += '-Ei "'
272 for error in errors:
273 grepcmd += error + '|'
274 grepcmd = grepcmd[:-1]
275 grepcmd += '" ' + str(log) + " | grep -Eiv \'"
276
277 try:
278 errorlist = ignore_errors[self.getMachine()]
279 except KeyError:
280 self.msg += 'No ignore list found for this machine, using default\n'
281 errorlist = ignore_errors['default']
282
283 for ignore_error in errorlist:
284 ignore_error = ignore_error.replace('(', '\(')
285 ignore_error = ignore_error.replace(')', '\)')
286 ignore_error = ignore_error.replace("'", '.')
287 ignore_error = ignore_error.replace('?', '\?')
288 ignore_error = ignore_error.replace('[', '\[')
289 ignore_error = ignore_error.replace(']', '\]')
290 ignore_error = ignore_error.replace('*', '\*')
291 ignore_error = ignore_error.replace('0-9', '[0-9]')
292 grepcmd += ignore_error + '|'
293 grepcmd = grepcmd[:-1]
294 grepcmd += "\'"
295
296 return grepcmd
297
298 # Grep only the errors so that their context could be collected.
299 # Default context is 10 lines before and after the error itself
300 def parse_logs(self, errors, ignore_errors, logs,
301 lines_before = 10, lines_after = 10):
302 results = {}
303 rez = []
304 grep_output = ''
305
306 for log in logs:
307 result = None
308 thegrep = self.build_grepcmd(errors, ignore_errors, log)
309
310 try:
311 result = check_output(thegrep, shell=True).decode('utf-8')
312 except:
313 pass
314
315 if result is not None:
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800316 results[log] = {}
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500317 rez = result.splitlines()
318
319 for xrez in rez:
320 try:
321 cmd = ['grep', '-F', xrez, '-B', str(lines_before)]
322 cmd += ['-A', str(lines_after), log]
323 grep_output = check_output(cmd).decode('utf-8')
324 except:
325 pass
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800326 results[log][xrez]=grep_output
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500327
328 return results
329
330 # Get the output of dmesg and write it in a file.
331 # This file is added to log_locations.
332 def write_dmesg(self):
333 (status, dmesg) = self.target.run('dmesg > /tmp/dmesg_output.log')
334
335 @OETestID(1059)
336 @OETestDepends(['ssh.SSHTest.test_ssh'])
337 def test_parselogs(self):
338 self.write_dmesg()
339 log_list = self.get_local_log_list(self.log_locations)
340 result = self.parse_logs(self.errors, self.ignore_errors, log_list)
341 print(self.getHardwareInfo())
342 errcount = 0
343 for log in result:
344 self.msg += 'Log: ' + log + '\n'
345 self.msg += '-----------------------\n'
346 for error in result[log]:
347 errcount += 1
348 self.msg += 'Central error: ' + str(error) + '\n'
349 self.msg += '***********************\n'
350 self.msg += result[str(log)][str(error)] + '\n'
351 self.msg += '***********************\n'
352 self.msg += '%s errors found in logs.' % errcount
353 self.assertEqual(errcount, 0, msg=self.msg)