blob: aa5008bba9831391b3ab61ef62891cb0e5919d5d [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001import os
2import unittest
3import subprocess
4from oeqa.oetest import oeRuntimeTest
5from oeqa.utils.decorators import *
6
7#in the future these lists could be moved outside of module
8errors = ["error", "cannot", "can\'t", "failed"]
9
10common_errors = [
11 "(WW) warning, (EE) error, (NI) not implemented, (??) unknown.",
12 "dma timeout",
13 "can\'t add hid device:",
14 "usbhid: probe of ",
15 "_OSC failed (AE_ERROR)",
16 "_OSC failed (AE_SUPPORT)",
17 "AE_ALREADY_EXISTS",
18 "ACPI _OSC request failed (AE_SUPPORT)",
19 "can\'t disable ASPM",
20 "Failed to load module \"vesa\"",
21 "Failed to load module vesa",
22 "Failed to load module \"modesetting\"",
23 "Failed to load module modesetting",
24 "Failed to load module \"glx\"",
25 "Failed to load module \"fbdev\"",
26 "Failed to load module fbdev",
27 "Failed to load module glx",
28 "[drm] Cannot find any crtc or sizes - going 1024x768",
29 "_OSC failed (AE_NOT_FOUND); disabling ASPM",
30 "Open ACPI failed (/var/run/acpid.socket) (No such file or directory)",
31 "NX (Execute Disable) protection cannot be enabled: non-PAE kernel!",
32 "hd.: possibly failed opcode",
33 'NETLINK INITIALIZATION FAILED',
34 'kernel: Cannot find map file',
35 'omap_hwmod: debugss: _wait_target_disable failed',
36 'VGA arbiter: cannot open kernel arbiter, no multi-card support',
37 'Failed to find URL:http://ipv4.connman.net/online/status.html',
38 'Online check failed for',
Patrick Williamsf1e5d692016-03-30 15:21:19 -050039 'netlink init failed',
40 'Fast TSC calibration',
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050041 "BAR 0-9",
42 "Failed to load module \"ati\"",
43 "controller can't do DEVSLP, turning off",
44 "stmmac_dvr_probe: warning: cannot get CSR clock",
45 "error: couldn\'t mount because of unsupported optional features",
Brad Bishop37a0e4d2017-12-04 01:01:44 -050046 "GPT: Use GNU Parted to correct GPT errors",
Patrick Williamsc124f4f2015-09-15 14:41:29 -050047 ]
48
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050049video_related = [
50 "uvesafb",
51]
52
Patrick Williamsc124f4f2015-09-15 14:41:29 -050053x86_common = [
54 '[drm:psb_do_init] *ERROR* Debug is',
55 'wrong ELF class',
56 'Could not enable PowerButton event',
57 'probe of LNXPWRBN:00 failed with error -22',
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050058 'pmd_set_huge: Cannot satisfy',
Patrick Williamsc0f7c042017-02-23 20:41:17 -060059 'failed to setup card detect gpio',
60 'amd_nb: Cannot enumerate AMD northbridges',
61 'failed to retrieve link info, disabling eDP',
Brad Bishop37a0e4d2017-12-04 01:01:44 -050062 'Direct firmware load for iwlwifi',
Patrick Williamsc124f4f2015-09-15 14:41:29 -050063] + common_errors
64
65qemux86_common = [
Patrick Williamsc124f4f2015-09-15 14:41:29 -050066 'wrong ELF class',
67 "fail to add MMCONFIG information, can't access extended PCI configuration space under this bridge.",
68 "can't claim BAR ",
Patrick Williamsc0f7c042017-02-23 20:41:17 -060069 'amd_nb: Cannot enumerate AMD northbridges',
70 'uvesafb: 5000 ms task timeout, infinitely waiting',
71 'tsc: HPET/PMTIMER calibration failed',
Patrick Williamsc124f4f2015-09-15 14:41:29 -050072] + common_errors
73
Brad Bishop37a0e4d2017-12-04 01:01:44 -050074ignore_errors = {
Patrick Williamsc124f4f2015-09-15 14:41:29 -050075 'default' : common_errors,
76 'qemux86' : [
77 'Failed to access perfctr msr (MSR',
Patrick Williamsc0f7c042017-02-23 20:41:17 -060078 'pci 0000:00:00.0: [Firmware Bug]: reg 0x..: invalid BAR (can\'t size)',
Patrick Williamsc124f4f2015-09-15 14:41:29 -050079 ] + qemux86_common,
80 'qemux86-64' : qemux86_common,
81 'qemumips' : [
82 'Failed to load module "glx"',
83 'pci 0000:00:00.0: [Firmware Bug]: reg 0x..: invalid BAR (can\'t size)',
84 ] + common_errors,
85 'qemumips64' : [
86 'pci 0000:00:00.0: [Firmware Bug]: reg 0x..: invalid BAR (can\'t size)',
87 ] + common_errors,
88 'qemuppc' : [
89 'PCI 0000:00 Cannot reserve Legacy IO [io 0x0000-0x0fff]',
90 'host side 80-wire cable detection failed, limiting max speed',
91 'mode "640x480" test failed',
92 'Failed to load module "glx"',
Patrick Williamsc0f7c042017-02-23 20:41:17 -060093 'can\'t handle BAR above 4GB',
94 'Cannot reserve Legacy IO',
Patrick Williamsc124f4f2015-09-15 14:41:29 -050095 ] + common_errors,
96 'qemuarm' : [
97 'mmci-pl18x: probe of fpga:05 failed with error -22',
98 'mmci-pl18x: probe of fpga:0b failed with error -22',
Patrick Williamsc0f7c042017-02-23 20:41:17 -060099 'Failed to load module "glx"',
100 'OF: amba_device_add() failed (-19) for /amba/smc@10100000',
101 'OF: amba_device_add() failed (-19) for /amba/mpmc@10110000',
102 'OF: amba_device_add() failed (-19) for /amba/sctl@101e0000',
103 'OF: amba_device_add() failed (-19) for /amba/watchdog@101e1000',
104 'OF: amba_device_add() failed (-19) for /amba/sci@101f0000',
105 'OF: amba_device_add() failed (-19) for /amba/ssp@101f4000',
106 'OF: amba_device_add() failed (-19) for /amba/fpga/sci@a000',
107 'Failed to initialize \'/amba/timer@101e3000\': -22',
108 'jitterentropy: Initialization failed with host not compliant with requirements: 2',
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500109 ] + common_errors,
110 'qemuarm64' : [
111 'Fatal server error:',
112 '(EE) Server terminated with error (1). Closing log file.',
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500113 'dmi: Firmware registration failed.',
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600114 'irq: type mismatch, failed to map hwirq-27 for /intc',
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500115 ] + common_errors,
116 'emenlow' : [
117 '[Firmware Bug]: ACPI: No _BQC method, cannot determine initial brightness',
118 '(EE) Failed to load module "psb"',
119 '(EE) Failed to load module psb',
120 '(EE) Failed to load module "psbdrv"',
121 '(EE) Failed to load module psbdrv',
122 '(EE) open /dev/fb0: No such file or directory',
123 '(EE) AIGLX: reverting to software rendering',
124 ] + x86_common,
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500125 'intel-core2-32' : [
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500126 'ACPI: No _BQC method, cannot determine initial brightness',
127 '[Firmware Bug]: ACPI: No _BQC method, cannot determine initial brightness',
128 '(EE) Failed to load module "psb"',
129 '(EE) Failed to load module psb',
130 '(EE) Failed to load module "psbdrv"',
131 '(EE) Failed to load module psbdrv',
132 '(EE) open /dev/fb0: No such file or directory',
133 '(EE) AIGLX: reverting to software rendering',
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600134 'dmi: Firmware registration failed.',
135 'ioremap error for 0x78',
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500136 ] + x86_common,
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500137 'intel-corei7-64' : x86_common,
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500138 'crownbay' : x86_common,
139 'genericx86' : x86_common,
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600140 'genericx86-64' : [
141 'Direct firmware load for i915',
142 'Failed to load firmware i915',
143 'Failed to fetch GuC',
144 'Failed to initialize GuC',
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500145 'Failed to load DMC firmware',
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600146 'The driver is built-in, so to load the firmware you need to',
147 ] + x86_common,
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500148 'edgerouter' : [
149 'Fatal server error:',
150 ] + common_errors,
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500151 'jasperforest' : [
152 'Activated service \'org.bluez\' failed:',
153 'Unable to find NFC netlink family',
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500154 ] + common_errors,
155}
156
157log_locations = ["/var/log/","/var/log/dmesg", "/tmp/dmesg_output.log"]
158
159class ParseLogsTest(oeRuntimeTest):
160
161 @classmethod
162 def setUpClass(self):
163 self.errors = errors
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500164
165 # When systemd is enabled we need to notice errors on
166 # circular dependencies in units.
167 if self.hasFeature("systemd"):
168 self.errors.extend([
169 'Found ordering cycle on',
170 'Breaking ordering cycle by deleting job',
171 'deleted to break ordering cycle',
172 'Ordering cycle found, skipping',
173 ])
174
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500175 self.ignore_errors = ignore_errors
176 self.log_locations = log_locations
177 self.msg = ""
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500178 (is_lsb, location) = oeRuntimeTest.tc.target.run("which LSB_Test.sh")
179 if is_lsb == 0:
180 for machine in self.ignore_errors:
181 self.ignore_errors[machine] = self.ignore_errors[machine] + video_related
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500182
183 def getMachine(self):
184 return oeRuntimeTest.tc.d.getVar("MACHINE", True)
185
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600186 def getWorkdir(self):
187 return oeRuntimeTest.tc.d.getVar("WORKDIR", True)
188
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500189 #get some information on the CPU of the machine to display at the beginning of the output. This info might be useful in some cases.
190 def getHardwareInfo(self):
191 hwi = ""
192 (status, cpu_name) = self.target.run("cat /proc/cpuinfo | grep \"model name\" | head -n1 | awk 'BEGIN{FS=\":\"}{print $2}'")
193 (status, cpu_physical_cores) = self.target.run("cat /proc/cpuinfo | grep \"cpu cores\" | head -n1 | awk {'print $4'}")
194 (status, cpu_logical_cores) = self.target.run("cat /proc/cpuinfo | grep \"processor\" | wc -l")
195 (status, cpu_arch) = self.target.run("uname -m")
196 hwi += "Machine information: \n"
197 hwi += "*******************************\n"
198 hwi += "Machine name: "+self.getMachine()+"\n"
199 hwi += "CPU: "+str(cpu_name)+"\n"
200 hwi += "Arch: "+str(cpu_arch)+"\n"
201 hwi += "Physical cores: "+str(cpu_physical_cores)+"\n"
202 hwi += "Logical cores: "+str(cpu_logical_cores)+"\n"
203 hwi += "*******************************\n"
204 return hwi
205
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500206 #go through the log locations provided and if it's a folder create a list with all the .log files in it, if it's a file just add
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500207 #it to that list
208 def getLogList(self, log_locations):
209 logs = []
210 for location in log_locations:
211 (status, output) = self.target.run("test -f "+str(location))
212 if (status == 0):
213 logs.append(str(location))
214 else:
215 (status, output) = self.target.run("test -d "+str(location))
216 if (status == 0):
217 (status, output) = self.target.run("find "+str(location)+"/*.log -maxdepth 1 -type f")
218 if (status == 0):
219 output = output.splitlines()
220 for logfile in output:
221 logs.append(os.path.join(location,str(logfile)))
222 return logs
223
224 #copy the log files to be parsed locally
225 def transfer_logs(self, log_list):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600226 workdir = self.getWorkdir()
227 self.target_logs = workdir + '/' + 'target_logs'
228 target_logs = self.target_logs
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500229 if not os.path.exists(target_logs):
230 os.makedirs(target_logs)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600231 bb.utils.remove(self.target_logs + "/*")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500232 for f in log_list:
233 self.target.copy_from(f, target_logs)
234
235 #get the local list of logs
236 def get_local_log_list(self, log_locations):
237 self.transfer_logs(self.getLogList(log_locations))
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600238 logs = [ os.path.join(self.target_logs, f) for f in os.listdir(self.target_logs) if os.path.isfile(os.path.join(self.target_logs, f)) ]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500239 return logs
240
241 #build the grep command to be used with filters and exclusions
242 def build_grepcmd(self, errors, ignore_errors, log):
243 grepcmd = "grep "
244 grepcmd +="-Ei \""
245 for error in errors:
246 grepcmd += error+"|"
247 grepcmd = grepcmd[:-1]
248 grepcmd += "\" "+str(log)+" | grep -Eiv \'"
249 try:
250 errorlist = ignore_errors[self.getMachine()]
251 except KeyError:
252 self.msg += "No ignore list found for this machine, using default\n"
253 errorlist = ignore_errors['default']
254 for ignore_error in errorlist:
255 ignore_error = ignore_error.replace("(", "\(")
256 ignore_error = ignore_error.replace(")", "\)")
257 ignore_error = ignore_error.replace("'", ".")
258 ignore_error = ignore_error.replace("?", "\?")
259 ignore_error = ignore_error.replace("[", "\[")
260 ignore_error = ignore_error.replace("]", "\]")
261 ignore_error = ignore_error.replace("*", "\*")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500262 ignore_error = ignore_error.replace("0-9", "[0-9]")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500263 grepcmd += ignore_error+"|"
264 grepcmd = grepcmd[:-1]
265 grepcmd += "\'"
266 return grepcmd
267
268 #grep only the errors so that their context could be collected. Default context is 10 lines before and after the error itself
269 def parse_logs(self, errors, ignore_errors, logs, lines_before = 10, lines_after = 10):
270 results = {}
271 rez = []
272 grep_output = ''
273 for log in logs:
274 result = None
275 thegrep = self.build_grepcmd(errors, ignore_errors, log)
276 try:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600277 result = subprocess.check_output(thegrep, shell=True).decode("utf-8")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500278 except:
279 pass
280 if (result is not None):
281 results[log.replace('target_logs/','')] = {}
282 rez = result.splitlines()
283 for xrez in rez:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500284 try:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600285 grep_output = subprocess.check_output(['grep', '-F', xrez, '-B', str(lines_before), '-A', str(lines_after), log]).decode("utf-8")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500286 except:
287 pass
288 results[log.replace('target_logs/','')][xrez]=grep_output
289 return results
290
291 #get the output of dmesg and write it in a file. This file is added to log_locations.
292 def write_dmesg(self):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500293 (status, dmesg) = self.target.run("dmesg > /tmp/dmesg_output.log")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500294
295 @testcase(1059)
296 @skipUnlessPassed('test_ssh')
297 def test_parselogs(self):
298 self.write_dmesg()
299 log_list = self.get_local_log_list(self.log_locations)
300 result = self.parse_logs(self.errors, self.ignore_errors, log_list)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600301 print(self.getHardwareInfo())
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500302 errcount = 0
303 for log in result:
304 self.msg += "Log: "+log+"\n"
305 self.msg += "-----------------------\n"
306 for error in result[log]:
307 errcount += 1
308 self.msg += "Central error: "+str(error)+"\n"
309 self.msg += "***********************\n"
310 self.msg += result[str(log)][str(error)]+"\n"
311 self.msg += "***********************\n"
312 self.msg += "%s errors found in logs." % errcount
313 self.assertEqual(errcount, 0, msg=self.msg)