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