xref: /OK3568_Linux_fs/yocto/poky/meta/lib/oeqa/runtime/cases/ltp_compliance.py (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1# LTP compliance 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 LtpComplianceParser
16
17class LtpPosixBase(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, 'ltpcomp_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['ltpposixresult.rawlogs'] = {'log': ""}
44
45
46    @classmethod
47    def ltp_finishup(cls):
48        cls.extras['ltpposixresult.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
54        os.symlink(os.path.basename(cls.ltptest_log_dir), cls.ltptest_log_dir_link)
55
56        if cls.failmsg:
57            cls.fail(cls.failmsg)
58
59class LtpPosixTest(LtpPosixBase):
60    posix_groups = ["AIO", "MEM", "MSG", "SEM", "SIG",  "THR", "TMR", "TPS"]
61
62    def runltp(self, posix_group):
63            cmd = "/opt/ltp/bin/run-posix-option-group-test.sh %s 2>@1 | tee /opt/ltp/results/%s" % (posix_group, posix_group)
64            starttime = time.time()
65            (status, output) = self.target.run(cmd)
66            endtime = time.time()
67
68            with open(os.path.join(self.ltptest_log_dir, "%s" % posix_group), 'w') as f:
69                f.write(output)
70
71            self.extras['ltpposixresult.rawlogs']['log'] = self.extras['ltpposixresult.rawlogs']['log'] + output
72
73            parser = LtpComplianceParser()
74            results, sections  = parser.parse(os.path.join(self.ltptest_log_dir, "%s" % posix_group))
75
76            runtime = int(endtime-starttime)
77            sections['duration'] = runtime
78            self.sections[posix_group] =  sections
79
80            failed_tests = {}
81            for test in results:
82                result = results[test]
83                testname = ("ltpposixresult." + posix_group + "." + test)
84                self.extras[testname] = {'status': result}
85                if result == 'FAILED':
86                    failed_tests[posix_group] = test
87
88            if failed_tests:
89                self.failmsg = self.failmsg + "Failed ptests:\n%s" % pprint.pformat(failed_tests)
90
91    # LTP Posix compliance runtime tests
92
93    @OETestDepends(['ssh.SSHTest.test_ssh'])
94    @OEHasPackage(["ltp"])
95    def test_posix_groups(self):
96        for posix_group in self.posix_groups:
97            self.runltp(posix_group)
98