1c342db35SBrad Bishop# LTP runtime 2c342db35SBrad Bishop# 3c342db35SBrad Bishop# Copyright (c) 2019 MontaVista Software, LLC 4c342db35SBrad Bishop# 5c342db35SBrad Bishop# SPDX-License-Identifier: GPL-2.0-only 6c342db35SBrad Bishop# 7c342db35SBrad Bishop 8c342db35SBrad Bishopimport time 9c342db35SBrad Bishopimport datetime 10c342db35SBrad Bishopimport pprint 11c342db35SBrad Bishop 12c342db35SBrad Bishopfrom oeqa.runtime.case import OERuntimeTestCase 13c342db35SBrad Bishopfrom oeqa.core.decorator.depends import OETestDepends 14c342db35SBrad Bishopfrom oeqa.runtime.decorator.package import OEHasPackage 15c342db35SBrad Bishopfrom oeqa.utils.logparser import LtpParser 16c342db35SBrad Bishop 17c342db35SBrad Bishopclass LtpTestBase(OERuntimeTestCase): 18c342db35SBrad Bishop 19c342db35SBrad Bishop @classmethod 20c342db35SBrad Bishop def setUpClass(cls): 21c342db35SBrad Bishop cls.ltp_startup() 22c342db35SBrad Bishop 23c342db35SBrad Bishop @classmethod 24c342db35SBrad Bishop def tearDownClass(cls): 25c342db35SBrad Bishop cls.ltp_finishup() 26c342db35SBrad Bishop 27c342db35SBrad Bishop @classmethod 28c342db35SBrad Bishop def ltp_startup(cls): 29c342db35SBrad Bishop cls.sections = {} 30c342db35SBrad Bishop cls.failmsg = "" 31c342db35SBrad Bishop test_log_dir = os.path.join(cls.td.get('WORKDIR', ''), 'testimage') 32c342db35SBrad Bishop timestamp = datetime.datetime.now().strftime('%Y%m%d%H%M%S') 33c342db35SBrad Bishop 34c342db35SBrad Bishop cls.ltptest_log_dir_link = os.path.join(test_log_dir, 'ltp_log') 35c342db35SBrad Bishop cls.ltptest_log_dir = '%s.%s' % (cls.ltptest_log_dir_link, timestamp) 36c342db35SBrad Bishop os.makedirs(cls.ltptest_log_dir) 37c342db35SBrad Bishop 38c342db35SBrad Bishop cls.tc.target.run("mkdir -p /opt/ltp/results") 39c342db35SBrad Bishop 40c342db35SBrad Bishop if not hasattr(cls.tc, "extraresults"): 41c342db35SBrad Bishop cls.tc.extraresults = {} 42c342db35SBrad Bishop cls.extras = cls.tc.extraresults 43c342db35SBrad Bishop cls.extras['ltpresult.rawlogs'] = {'log': ""} 44c342db35SBrad Bishop 45c342db35SBrad Bishop 46c342db35SBrad Bishop @classmethod 47c342db35SBrad Bishop def ltp_finishup(cls): 48c342db35SBrad Bishop cls.extras['ltpresult.sections'] = cls.sections 49c342db35SBrad Bishop 50c342db35SBrad Bishop # update symlink to ltp_log 51c342db35SBrad Bishop if os.path.exists(cls.ltptest_log_dir_link): 52c342db35SBrad Bishop os.remove(cls.ltptest_log_dir_link) 53c342db35SBrad Bishop os.symlink(os.path.basename(cls.ltptest_log_dir), cls.ltptest_log_dir_link) 54c342db35SBrad Bishop 55c342db35SBrad Bishop if cls.failmsg: 56c342db35SBrad Bishop cls.fail(cls.failmsg) 57c342db35SBrad Bishop 58c342db35SBrad Bishopclass LtpTest(LtpTestBase): 59c342db35SBrad Bishop 60*edff4923SAndrew Geissler ltp_groups = ["math", "syscalls", "dio", "mm", "ipc", "sched", "nptl", "pty", "containers", "controllers", "fcntl-locktests", "commands", "net.ipv6_lib", "input","fs_perms_simple", "cve", "crypto", "ima", "net.nfs", "net_stress.ipsec_icmp", "net.ipv6", "numa", "uevent", "ltp-aiodio.part1", "ltp-aiodio.part2", "ltp-aiodio.part3", "ltp-aiodio.part4"] 61c342db35SBrad Bishop 6273bd93f1SPatrick Williams ltp_fs = ["fs", "fs_bind"] 63c342db35SBrad Bishop # skip kernel cpuhotplug 64c342db35SBrad Bishop ltp_kernel = ["power_management_tests", "hyperthreading ", "kernel_misc", "hugetlb"] 65c342db35SBrad Bishop ltp_groups += ltp_fs 66c342db35SBrad Bishop 67c342db35SBrad Bishop def runltp(self, ltp_group): 688f840685SAndrew Geissler # LTP appends to log files, so ensure we start with a clean log 698f840685SAndrew Geissler self.target.deleteFiles("/opt/ltp/results/", ltp_group) 708f840685SAndrew Geissler 718f840685SAndrew Geissler cmd = '/opt/ltp/runltp -f %s -q -r /opt/ltp -l /opt/ltp/results/%s -I 1 -d /opt/ltp' % (ltp_group, ltp_group) 728f840685SAndrew Geissler 73c342db35SBrad Bishop starttime = time.time() 742a25492cSPatrick Williams (status, output) = self.target.run(cmd, timeout=1200) 75c342db35SBrad Bishop endtime = time.time() 76c342db35SBrad Bishop 772a25492cSPatrick Williams # status of 1 is 'just' tests failing. 255 likely was a command output timeout 782a25492cSPatrick Williams if status and status != 1: 792a25492cSPatrick Williams msg = 'Command %s returned exit code %s' % (cmd, status) 802a25492cSPatrick Williams self.target.logger.warning(msg) 812a25492cSPatrick Williams 828f840685SAndrew Geissler # Write the console log to disk for convenience 83c342db35SBrad Bishop with open(os.path.join(self.ltptest_log_dir, "%s-raw.log" % ltp_group), 'w') as f: 84c342db35SBrad Bishop f.write(output) 85c342db35SBrad Bishop 868f840685SAndrew Geissler # Also put the console log into the test result JSON 87c342db35SBrad Bishop self.extras['ltpresult.rawlogs']['log'] = self.extras['ltpresult.rawlogs']['log'] + output 88c342db35SBrad Bishop 898f840685SAndrew Geissler # Copy the machine-readable test results locally so we can parse it 908f840685SAndrew Geissler dst = os.path.join(self.ltptest_log_dir, ltp_group) 91c342db35SBrad Bishop remote_src = "/opt/ltp/results/%s" % ltp_group 92635e0e46SAndrew Geissler (status, output) = self.target.copyFrom(remote_src, dst, True) 93635e0e46SAndrew Geissler if status: 948f840685SAndrew Geissler msg = 'File could not be copied. Output: %s' % output 95635e0e46SAndrew Geissler self.target.logger.warning(msg) 96c342db35SBrad Bishop 97c342db35SBrad Bishop parser = LtpParser() 98c342db35SBrad Bishop results, sections = parser.parse(dst) 99c342db35SBrad Bishop 1008f840685SAndrew Geissler sections['duration'] = int(endtime-starttime) 101c342db35SBrad Bishop self.sections[ltp_group] = sections 102c342db35SBrad Bishop 103c342db35SBrad Bishop failed_tests = {} 104c342db35SBrad Bishop for test in results: 105c342db35SBrad Bishop result = results[test] 106c342db35SBrad Bishop testname = ("ltpresult." + ltp_group + "." + test) 107c342db35SBrad Bishop self.extras[testname] = {'status': result} 108c342db35SBrad Bishop if result == 'FAILED': 109c342db35SBrad Bishop failed_tests[ltp_group] = test 110c342db35SBrad Bishop 111c342db35SBrad Bishop if failed_tests: 112c342db35SBrad Bishop self.failmsg = self.failmsg + "Failed ptests:\n%s" % pprint.pformat(failed_tests) 113c342db35SBrad Bishop 114c342db35SBrad Bishop # LTP runtime tests 115c342db35SBrad Bishop @OETestDepends(['ssh.SSHTest.test_ssh']) 116c342db35SBrad Bishop @OEHasPackage(["ltp"]) 117c342db35SBrad Bishop def test_ltp_help(self): 118c342db35SBrad Bishop (status, output) = self.target.run('/opt/ltp/runltp --help') 119c342db35SBrad Bishop msg = 'Failed to get ltp help. Output: %s' % output 120c342db35SBrad Bishop self.assertEqual(status, 0, msg=msg) 121c342db35SBrad Bishop 122c342db35SBrad Bishop @OETestDepends(['ltp.LtpTest.test_ltp_help']) 123c342db35SBrad Bishop def test_ltp_groups(self): 124c342db35SBrad Bishop for ltp_group in self.ltp_groups: 125c342db35SBrad Bishop self.runltp(ltp_group) 126c342db35SBrad Bishop 127c342db35SBrad Bishop @OETestDepends(['ltp.LtpTest.test_ltp_groups']) 128c342db35SBrad Bishop def test_ltp_runltp_cve(self): 129c342db35SBrad Bishop self.runltp("cve") 130