Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # LTP runtime |
| 2 | # |
| 3 | # Copyright (c) 2019 MontaVista Software, LLC |
| 4 | # |
| 5 | # SPDX-License-Identifier: GPL-2.0-only |
| 6 | # |
| 7 | |
| 8 | import time |
| 9 | import datetime |
| 10 | import pprint |
| 11 | |
| 12 | from oeqa.runtime.case import OERuntimeTestCase |
| 13 | from oeqa.core.decorator.depends import OETestDepends |
| 14 | from oeqa.runtime.decorator.package import OEHasPackage |
| 15 | from oeqa.utils.logparser import LtpParser |
| 16 | |
| 17 | class 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 | |
| 58 | class LtpTest(LtpTestBase): |
| 59 | |
Patrick Williams | 73bd93f | 2024-02-20 08:07:48 -0600 | [diff] [blame] | 60 | ltp_groups = ["math", "syscalls", "dio", "io", "mm", "ipc", "sched", "nptl", "pty", "containers", "controllers", "filecaps", "cap_bounds", "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"] |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 61 | |
Patrick Williams | 73bd93f | 2024-02-20 08:07:48 -0600 | [diff] [blame] | 62 | ltp_fs = ["fs", "fs_bind"] |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 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): |
Andrew Geissler | 8f84068 | 2023-07-21 09:09:43 -0500 | [diff] [blame] | 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 | |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 73 | starttime = time.time() |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 74 | (status, output) = self.target.run(cmd, timeout=1200) |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 75 | endtime = time.time() |
| 76 | |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 77 | # 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 Geissler | 8f84068 | 2023-07-21 09:09:43 -0500 | [diff] [blame] | 82 | # Write the console log to disk for convenience |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 83 | with open(os.path.join(self.ltptest_log_dir, "%s-raw.log" % ltp_group), 'w') as f: |
| 84 | f.write(output) |
| 85 | |
Andrew Geissler | 8f84068 | 2023-07-21 09:09:43 -0500 | [diff] [blame] | 86 | # Also put the console log into the test result JSON |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 87 | self.extras['ltpresult.rawlogs']['log'] = self.extras['ltpresult.rawlogs']['log'] + output |
| 88 | |
Andrew Geissler | 8f84068 | 2023-07-21 09:09:43 -0500 | [diff] [blame] | 89 | # Copy the machine-readable test results locally so we can parse it |
| 90 | dst = os.path.join(self.ltptest_log_dir, ltp_group) |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 91 | remote_src = "/opt/ltp/results/%s" % ltp_group |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 92 | (status, output) = self.target.copyFrom(remote_src, dst, True) |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 93 | if status: |
Andrew Geissler | 8f84068 | 2023-07-21 09:09:43 -0500 | [diff] [blame] | 94 | msg = 'File could not be copied. Output: %s' % output |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 95 | self.target.logger.warning(msg) |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 96 | |
| 97 | parser = LtpParser() |
| 98 | results, sections = parser.parse(dst) |
| 99 | |
Andrew Geissler | 8f84068 | 2023-07-21 09:09:43 -0500 | [diff] [blame] | 100 | sections['duration'] = int(endtime-starttime) |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 101 | 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") |