blob: c7e79438a48fc325b7b0e52e53cea3ab60ef72cb [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001# 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
Andrew Geissler82c905d2020-04-13 13:39:40 -050060 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"]
Brad Bishopc342db32019-05-15 21:57:59 -040061
Andrew Geissler82c905d2020-04-13 13:39:40 -050062 ltp_fs = ["fs", "fsx", "fs_bind"]
Brad Bishopc342db32019-05-15 21:57:59 -040063 # 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):
Andrew Geissler8f840682023-07-21 09:09:43 -050068 # 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
Brad Bishopc342db32019-05-15 21:57:59 -040073 starttime = time.time()
Patrick Williams2a254922023-08-11 09:48:11 -050074 (status, output) = self.target.run(cmd, timeout=1200)
Brad Bishopc342db32019-05-15 21:57:59 -040075 endtime = time.time()
76
Patrick Williams2a254922023-08-11 09:48:11 -050077 # status of 1 is 'just' tests failing. 255 likely was a command output timeout
78 if status and status != 1:
79 msg = 'Command %s returned exit code %s' % (cmd, status)
80 self.target.logger.warning(msg)
81
Andrew Geissler8f840682023-07-21 09:09:43 -050082 # Write the console log to disk for convenience
Brad Bishopc342db32019-05-15 21:57:59 -040083 with open(os.path.join(self.ltptest_log_dir, "%s-raw.log" % ltp_group), 'w') as f:
84 f.write(output)
85
Andrew Geissler8f840682023-07-21 09:09:43 -050086 # Also put the console log into the test result JSON
Brad Bishopc342db32019-05-15 21:57:59 -040087 self.extras['ltpresult.rawlogs']['log'] = self.extras['ltpresult.rawlogs']['log'] + output
88
Andrew Geissler8f840682023-07-21 09:09:43 -050089 # Copy the machine-readable test results locally so we can parse it
90 dst = os.path.join(self.ltptest_log_dir, ltp_group)
Brad Bishopc342db32019-05-15 21:57:59 -040091 remote_src = "/opt/ltp/results/%s" % ltp_group
Andrew Geissler635e0e42020-08-21 15:58:33 -050092 (status, output) = self.target.copyFrom(remote_src, dst, True)
Andrew Geissler635e0e42020-08-21 15:58:33 -050093 if status:
Andrew Geissler8f840682023-07-21 09:09:43 -050094 msg = 'File could not be copied. Output: %s' % output
Andrew Geissler635e0e42020-08-21 15:58:33 -050095 self.target.logger.warning(msg)
Brad Bishopc342db32019-05-15 21:57:59 -040096
97 parser = LtpParser()
98 results, sections = parser.parse(dst)
99
Andrew Geissler8f840682023-07-21 09:09:43 -0500100 sections['duration'] = int(endtime-starttime)
Brad Bishopc342db32019-05-15 21:57:59 -0400101 self.sections[ltp_group] = sections
102
103 failed_tests = {}
104 for test in results:
105 result = results[test]
106 testname = ("ltpresult." + ltp_group + "." + test)
107 self.extras[testname] = {'status': result}
108 if result == 'FAILED':
109 failed_tests[ltp_group] = test
110
111 if failed_tests:
112 self.failmsg = self.failmsg + "Failed ptests:\n%s" % pprint.pformat(failed_tests)
113
114 # LTP runtime tests
115 @OETestDepends(['ssh.SSHTest.test_ssh'])
116 @OEHasPackage(["ltp"])
117 def test_ltp_help(self):
118 (status, output) = self.target.run('/opt/ltp/runltp --help')
119 msg = 'Failed to get ltp help. Output: %s' % output
120 self.assertEqual(status, 0, msg=msg)
121
122 @OETestDepends(['ltp.LtpTest.test_ltp_help'])
123 def test_ltp_groups(self):
124 for ltp_group in self.ltp_groups:
125 self.runltp(ltp_group)
126
127 @OETestDepends(['ltp.LtpTest.test_ltp_groups'])
128 def test_ltp_runltp_cve(self):
129 self.runltp("cve")