1# LTP runtime 2# 3# Copyright (c) 2019 MontaVista Software, LLC 4# 5# SPDX-License-Identifier: GPL-2.0-only 6# 7 8import time 9import datetime 10import pprint 11 12from oeqa.runtime.case import OERuntimeTestCase 13from oeqa.core.decorator.depends import OETestDepends 14from oeqa.runtime.decorator.package import OEHasPackage 15from oeqa.utils.logparser import LtpParser 16 17class LtpTestBase(OERuntimeTestCase): 18 19 @classmethod 20 def setUpClass(cls): 21 cls.ltp_startup() 22 23 @classmethod 24 def tearDownClass(cls): 25 cls.ltp_finishup() 26 27 @classmethod 28 def ltp_startup(cls): 29 cls.sections = {} 30 cls.failmsg = "" 31 test_log_dir = os.path.join(cls.td.get('WORKDIR', ''), 'testimage') 32 timestamp = datetime.datetime.now().strftime('%Y%m%d%H%M%S') 33 34 cls.ltptest_log_dir_link = os.path.join(test_log_dir, 'ltp_log') 35 cls.ltptest_log_dir = '%s.%s' % (cls.ltptest_log_dir_link, timestamp) 36 os.makedirs(cls.ltptest_log_dir) 37 38 cls.tc.target.run("mkdir -p /opt/ltp/results") 39 40 if not hasattr(cls.tc, "extraresults"): 41 cls.tc.extraresults = {} 42 cls.extras = cls.tc.extraresults 43 cls.extras['ltpresult.rawlogs'] = {'log': ""} 44 45 46 @classmethod 47 def ltp_finishup(cls): 48 cls.extras['ltpresult.sections'] = cls.sections 49 50 # update symlink to ltp_log 51 if os.path.exists(cls.ltptest_log_dir_link): 52 os.remove(cls.ltptest_log_dir_link) 53 os.symlink(os.path.basename(cls.ltptest_log_dir), cls.ltptest_log_dir_link) 54 55 if cls.failmsg: 56 cls.fail(cls.failmsg) 57 58class LtpTest(LtpTestBase): 59 60 ltp_groups = ["math", "syscalls", "dio", "io", "mm", "ipc", "sched", "nptl", "pty", "containers", "controllers", "filecaps", "cap_bounds", "fcntl-locktests", "connectors", "commands", "net.ipv6_lib", "input","fs_perms_simple"] 61 62 ltp_fs = ["fs", "fsx", "fs_bind"] 63 # skip kernel cpuhotplug 64 ltp_kernel = ["power_management_tests", "hyperthreading ", "kernel_misc", "hugetlb"] 65 ltp_groups += ltp_fs 66 67 def runltp(self, ltp_group): 68 # LTP appends to log files, so ensure we start with a clean log 69 self.target.deleteFiles("/opt/ltp/results/", ltp_group) 70 71 cmd = '/opt/ltp/runltp -f %s -q -r /opt/ltp -l /opt/ltp/results/%s -I 1 -d /opt/ltp' % (ltp_group, ltp_group) 72 73 starttime = time.time() 74 (status, output) = self.target.run(cmd) 75 endtime = time.time() 76 77 # Write the console log to disk for convenience 78 with open(os.path.join(self.ltptest_log_dir, "%s-raw.log" % ltp_group), 'w') as f: 79 f.write(output) 80 81 # Also put the console log into the test result JSON 82 self.extras['ltpresult.rawlogs']['log'] = self.extras['ltpresult.rawlogs']['log'] + output 83 84 # Copy the machine-readable test results locally so we can parse it 85 dst = os.path.join(self.ltptest_log_dir, ltp_group) 86 remote_src = "/opt/ltp/results/%s" % ltp_group 87 (status, output) = self.target.copyFrom(remote_src, dst, True) 88 if status: 89 msg = 'File could not be copied. Output: %s' % output 90 self.target.logger.warning(msg) 91 92 parser = LtpParser() 93 results, sections = parser.parse(dst) 94 95 sections['duration'] = int(endtime-starttime) 96 self.sections[ltp_group] = sections 97 98 failed_tests = {} 99 for test in results: 100 result = results[test] 101 testname = ("ltpresult." + ltp_group + "." + test) 102 self.extras[testname] = {'status': result} 103 if result == 'FAILED': 104 failed_tests[ltp_group] = test 105 106 if failed_tests: 107 self.failmsg = self.failmsg + "Failed ptests:\n%s" % pprint.pformat(failed_tests) 108 109 # LTP runtime tests 110 @OETestDepends(['ssh.SSHTest.test_ssh']) 111 @OEHasPackage(["ltp"]) 112 def test_ltp_help(self): 113 (status, output) = self.target.run('/opt/ltp/runltp --help') 114 msg = 'Failed to get ltp help. Output: %s' % output 115 self.assertEqual(status, 0, msg=msg) 116 117 @OETestDepends(['ltp.LtpTest.test_ltp_help']) 118 def test_ltp_groups(self): 119 for ltp_group in self.ltp_groups: 120 self.runltp(ltp_group) 121 122 @OETestDepends(['ltp.LtpTest.test_ltp_groups']) 123 def test_ltp_runltp_cve(self): 124 self.runltp("cve") 125