blob: d8d1e1b344f8a89e85d43a83ebf6f1cdf50e7456 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
2# SPDX-License-Identifier: MIT
3#
4
Brad Bishopf86d0552018-12-04 14:18:15 -08005import unittest
6import pprint
Andrew Geissler99467da2019-02-25 18:54:23 -06007import datetime
Brad Bishopf86d0552018-12-04 14:18:15 -08008
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009from oeqa.runtime.case import OERuntimeTestCase
10from oeqa.core.decorator.depends import OETestDepends
Brad Bishopd7bf8c12018-02-25 22:55:05 -050011from oeqa.core.decorator.data import skipIfNotFeature
Brad Bishop977dc1a2019-02-06 16:01:43 -050012from oeqa.runtime.decorator.package import OEHasPackage
Andrew Geissler99467da2019-02-25 18:54:23 -060013from oeqa.utils.logparser import PtestParser
Brad Bishopd7bf8c12018-02-25 22:55:05 -050014
15class PtestRunnerTest(OERuntimeTestCase):
16
Brad Bishopd7bf8c12018-02-25 22:55:05 -050017 @skipIfNotFeature('ptest', 'Test requires ptest to be in DISTRO_FEATURES')
Brad Bishopd7bf8c12018-02-25 22:55:05 -050018 @OETestDepends(['ssh.SSHTest.test_ssh'])
Brad Bishop977dc1a2019-02-06 16:01:43 -050019 @OEHasPackage(['ptest-runner'])
Brad Bishopf86d0552018-12-04 14:18:15 -080020 @unittest.expectedFailure
Brad Bishopd7bf8c12018-02-25 22:55:05 -050021 def test_ptestrunner(self):
Brad Bishop316dfdd2018-06-25 12:45:53 -040022 status, output = self.target.run('which ptest-runner', 0)
23 if status != 0:
24 self.skipTest("No -ptest packages are installed in the image")
25
Brad Bishopd7bf8c12018-02-25 22:55:05 -050026 test_log_dir = self.td.get('TEST_LOG_DIR', '')
27 # The TEST_LOG_DIR maybe NULL when testimage is added after
28 # testdata.json is generated.
29 if not test_log_dir:
30 test_log_dir = os.path.join(self.td.get('WORKDIR', ''), 'testimage')
31 # Don't use self.td.get('DATETIME'), it's from testdata.json, not
32 # up-to-date, and may cause "File exists" when re-reun.
Andrew Geissler99467da2019-02-25 18:54:23 -060033 timestamp = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
Brad Bishopd7bf8c12018-02-25 22:55:05 -050034 ptest_log_dir_link = os.path.join(test_log_dir, 'ptest_log')
Andrew Geissler99467da2019-02-25 18:54:23 -060035 ptest_log_dir = '%s.%s' % (ptest_log_dir_link, timestamp)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050036 ptest_runner_log = os.path.join(ptest_log_dir, 'ptest-runner.log')
37
38 status, output = self.target.run('ptest-runner', 0)
39 os.makedirs(ptest_log_dir)
40 with open(ptest_runner_log, 'w') as f:
41 f.write(output)
42
43 # status != 0 is OK since some ptest tests may fail
44 self.assertTrue(status != 127, msg="Cannot execute ptest-runner!")
45
Brad Bishopf86d0552018-12-04 14:18:15 -080046 if not hasattr(self.tc, "extraresults"):
47 self.tc.extraresults = {}
48 extras = self.tc.extraresults
49 extras['ptestresult.rawlogs'] = {'log': output}
50
Brad Bishopd7bf8c12018-02-25 22:55:05 -050051 # Parse and save results
Andrew Geissler99467da2019-02-25 18:54:23 -060052 parser = PtestParser()
53 results, sections = parser.parse(ptest_runner_log)
54 parser.results_as_files(ptest_log_dir)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050055 if os.path.exists(ptest_log_dir_link):
56 # Remove the old link to create a new one
57 os.remove(ptest_log_dir_link)
58 os.symlink(os.path.basename(ptest_log_dir), ptest_log_dir_link)
Brad Bishop316dfdd2018-06-25 12:45:53 -040059
Andrew Geissler99467da2019-02-25 18:54:23 -060060 extras['ptestresult.sections'] = sections
61
Brad Bishopf86d0552018-12-04 14:18:15 -080062 trans = str.maketrans("()", "__")
Andrew Geissler99467da2019-02-25 18:54:23 -060063 for section in results:
64 for test in results[section]:
65 result = results[section][test]
66 testname = "ptestresult." + (section or "No-section") + "." + "_".join(test.translate(trans).split())
67 extras[testname] = {'status': result}
Brad Bishopf86d0552018-12-04 14:18:15 -080068
Brad Bishop316dfdd2018-06-25 12:45:53 -040069 failed_tests = {}
Andrew Geissler99467da2019-02-25 18:54:23 -060070 for section in results:
71 failed_testcases = [ "_".join(test.translate(trans).split()) for test in results[section] if results[section][test] == 'fail' ]
Brad Bishop316dfdd2018-06-25 12:45:53 -040072 if failed_testcases:
73 failed_tests[section] = failed_testcases
74
Andrew Geissler99467da2019-02-25 18:54:23 -060075 failmsg = ""
76 status, output = self.target.run('dmesg | grep "Killed process"', 0)
77 if output:
78 failmsg = "ERROR: Processes were killed by the OOM Killer:\n%s\n" % output
79
Brad Bishopf86d0552018-12-04 14:18:15 -080080 if failed_tests:
Andrew Geissler99467da2019-02-25 18:54:23 -060081 failmsg = failmsg + "Failed ptests:\n%s" % pprint.pformat(failed_tests)
82
83 if failmsg:
84 self.fail(failmsg)