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