Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | import os |
| 2 | import unittest |
| 3 | import subprocess |
| 4 | from oeqa.oetest import oeRuntimeTest |
| 5 | from oeqa.utils.decorators import * |
| 6 | |
| 7 | #in the future these lists could be moved outside of module |
| 8 | errors = ["error", "cannot", "can\'t", "failed"] |
| 9 | |
| 10 | common_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 Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 39 | 'netlink init failed', |
| 40 | 'Fast TSC calibration', |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 41 | "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 Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame^] | 46 | "GPT: Use GNU Parted to correct GPT errors", |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 47 | ] |
| 48 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 49 | video_related = [ |
| 50 | "uvesafb", |
| 51 | ] |
| 52 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 53 | x86_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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 58 | 'pmd_set_huge: Cannot satisfy', |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 59 | 'failed to setup card detect gpio', |
| 60 | 'amd_nb: Cannot enumerate AMD northbridges', |
| 61 | 'failed to retrieve link info, disabling eDP', |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame^] | 62 | 'Direct firmware load for iwlwifi', |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 63 | ] + common_errors |
| 64 | |
| 65 | qemux86_common = [ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 66 | '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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 69 | 'amd_nb: Cannot enumerate AMD northbridges', |
| 70 | 'uvesafb: 5000 ms task timeout, infinitely waiting', |
| 71 | 'tsc: HPET/PMTIMER calibration failed', |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 72 | ] + common_errors |
| 73 | |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame^] | 74 | ignore_errors = { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 75 | 'default' : common_errors, |
| 76 | 'qemux86' : [ |
| 77 | 'Failed to access perfctr msr (MSR', |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 78 | 'pci 0000:00:00.0: [Firmware Bug]: reg 0x..: invalid BAR (can\'t size)', |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 79 | ] + 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 93 | 'can\'t handle BAR above 4GB', |
| 94 | 'Cannot reserve Legacy IO', |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 95 | ] + 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 99 | '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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 109 | ] + common_errors, |
| 110 | 'qemuarm64' : [ |
| 111 | 'Fatal server error:', |
| 112 | '(EE) Server terminated with error (1). Closing log file.', |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 113 | 'dmi: Firmware registration failed.', |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 114 | 'irq: type mismatch, failed to map hwirq-27 for /intc', |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 115 | ] + 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 Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 125 | 'intel-core2-32' : [ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 126 | '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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 134 | 'dmi: Firmware registration failed.', |
| 135 | 'ioremap error for 0x78', |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 136 | ] + x86_common, |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 137 | 'intel-corei7-64' : x86_common, |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 138 | 'crownbay' : x86_common, |
| 139 | 'genericx86' : x86_common, |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 140 | '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 Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame^] | 145 | 'Failed to load DMC firmware', |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 146 | 'The driver is built-in, so to load the firmware you need to', |
| 147 | ] + x86_common, |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 148 | 'edgerouter' : [ |
| 149 | 'Fatal server error:', |
| 150 | ] + common_errors, |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 151 | 'jasperforest' : [ |
| 152 | 'Activated service \'org.bluez\' failed:', |
| 153 | 'Unable to find NFC netlink family', |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 154 | ] + common_errors, |
| 155 | } |
| 156 | |
| 157 | log_locations = ["/var/log/","/var/log/dmesg", "/tmp/dmesg_output.log"] |
| 158 | |
| 159 | class ParseLogsTest(oeRuntimeTest): |
| 160 | |
| 161 | @classmethod |
| 162 | def setUpClass(self): |
| 163 | self.errors = errors |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 164 | |
| 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 175 | self.ignore_errors = ignore_errors |
| 176 | self.log_locations = log_locations |
| 177 | self.msg = "" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 178 | (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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 182 | |
| 183 | def getMachine(self): |
| 184 | return oeRuntimeTest.tc.d.getVar("MACHINE", True) |
| 185 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 186 | def getWorkdir(self): |
| 187 | return oeRuntimeTest.tc.d.getVar("WORKDIR", True) |
| 188 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 189 | #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 Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame^] | 206 | #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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 207 | #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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 226 | workdir = self.getWorkdir() |
| 227 | self.target_logs = workdir + '/' + 'target_logs' |
| 228 | target_logs = self.target_logs |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 229 | if not os.path.exists(target_logs): |
| 230 | os.makedirs(target_logs) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 231 | bb.utils.remove(self.target_logs + "/*") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 232 | 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 238 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 239 | 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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 262 | ignore_error = ignore_error.replace("0-9", "[0-9]") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 263 | 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 277 | result = subprocess.check_output(thegrep, shell=True).decode("utf-8") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 278 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 284 | try: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 285 | grep_output = subprocess.check_output(['grep', '-F', xrez, '-B', str(lines_before), '-A', str(lines_after), log]).decode("utf-8") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 286 | 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 Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 293 | (status, dmesg) = self.target.run("dmesg > /tmp/dmesg_output.log") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 294 | |
| 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 301 | print(self.getHardwareInfo()) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 302 | 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) |