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