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