blob: 2a28ca59a8e50739fbe9bd3219263ac1e9b86adb [file] [log] [blame]
Brad Bishopf86d0552018-12-04 14:18:15 -08001import unittest
2import pprint
Andrew Geissler99467da2019-02-25 18:54:23 -06003import datetime
Brad Bishopf86d0552018-12-04 14:18:15 -08004
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005from oeqa.runtime.case import OERuntimeTestCase
6from oeqa.core.decorator.depends import OETestDepends
7from oeqa.core.decorator.oeid import OETestID
8from oeqa.core.decorator.data import skipIfNotFeature
Brad Bishop977dc1a2019-02-06 16:01:43 -05009from oeqa.runtime.decorator.package import OEHasPackage
Andrew Geissler99467da2019-02-25 18:54:23 -060010from oeqa.utils.logparser import PtestParser
Brad Bishopd7bf8c12018-02-25 22:55:05 -050011
12class PtestRunnerTest(OERuntimeTestCase):
13
Brad Bishopd7bf8c12018-02-25 22:55:05 -050014 @OETestID(1600)
15 @skipIfNotFeature('ptest', 'Test requires ptest to be in DISTRO_FEATURES')
Brad Bishopd7bf8c12018-02-25 22:55:05 -050016 @OETestDepends(['ssh.SSHTest.test_ssh'])
Brad Bishop977dc1a2019-02-06 16:01:43 -050017 @OEHasPackage(['ptest-runner'])
Brad Bishopf86d0552018-12-04 14:18:15 -080018 @unittest.expectedFailure
Brad Bishopd7bf8c12018-02-25 22:55:05 -050019 def test_ptestrunner(self):
Brad Bishop316dfdd2018-06-25 12:45:53 -040020 status, output = self.target.run('which ptest-runner', 0)
21 if status != 0:
22 self.skipTest("No -ptest packages are installed in the image")
23
Brad Bishopd7bf8c12018-02-25 22:55:05 -050024 test_log_dir = self.td.get('TEST_LOG_DIR', '')
25 # The TEST_LOG_DIR maybe NULL when testimage is added after
26 # testdata.json is generated.
27 if not test_log_dir:
28 test_log_dir = os.path.join(self.td.get('WORKDIR', ''), 'testimage')
29 # Don't use self.td.get('DATETIME'), it's from testdata.json, not
30 # up-to-date, and may cause "File exists" when re-reun.
Andrew Geissler99467da2019-02-25 18:54:23 -060031 timestamp = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
Brad Bishopd7bf8c12018-02-25 22:55:05 -050032 ptest_log_dir_link = os.path.join(test_log_dir, 'ptest_log')
Andrew Geissler99467da2019-02-25 18:54:23 -060033 ptest_log_dir = '%s.%s' % (ptest_log_dir_link, timestamp)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050034 ptest_runner_log = os.path.join(ptest_log_dir, 'ptest-runner.log')
35
36 status, output = self.target.run('ptest-runner', 0)
37 os.makedirs(ptest_log_dir)
38 with open(ptest_runner_log, 'w') as f:
39 f.write(output)
40
41 # status != 0 is OK since some ptest tests may fail
42 self.assertTrue(status != 127, msg="Cannot execute ptest-runner!")
43
Brad Bishopf86d0552018-12-04 14:18:15 -080044 if not hasattr(self.tc, "extraresults"):
45 self.tc.extraresults = {}
46 extras = self.tc.extraresults
47 extras['ptestresult.rawlogs'] = {'log': output}
48
Brad Bishopd7bf8c12018-02-25 22:55:05 -050049 # Parse and save results
Andrew Geissler99467da2019-02-25 18:54:23 -060050 parser = PtestParser()
51 results, sections = parser.parse(ptest_runner_log)
52 parser.results_as_files(ptest_log_dir)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050053 if os.path.exists(ptest_log_dir_link):
54 # Remove the old link to create a new one
55 os.remove(ptest_log_dir_link)
56 os.symlink(os.path.basename(ptest_log_dir), ptest_log_dir_link)
Brad Bishop316dfdd2018-06-25 12:45:53 -040057
Andrew Geissler99467da2019-02-25 18:54:23 -060058 extras['ptestresult.sections'] = sections
59
Brad Bishopf86d0552018-12-04 14:18:15 -080060 trans = str.maketrans("()", "__")
Andrew Geissler99467da2019-02-25 18:54:23 -060061 for section in results:
62 for test in results[section]:
63 result = results[section][test]
64 testname = "ptestresult." + (section or "No-section") + "." + "_".join(test.translate(trans).split())
65 extras[testname] = {'status': result}
Brad Bishopf86d0552018-12-04 14:18:15 -080066
Brad Bishop316dfdd2018-06-25 12:45:53 -040067 failed_tests = {}
Andrew Geissler99467da2019-02-25 18:54:23 -060068 for section in results:
69 failed_testcases = [ "_".join(test.translate(trans).split()) for test in results[section] if results[section][test] == 'fail' ]
Brad Bishop316dfdd2018-06-25 12:45:53 -040070 if failed_testcases:
71 failed_tests[section] = failed_testcases
72
Andrew Geissler99467da2019-02-25 18:54:23 -060073 failmsg = ""
74 status, output = self.target.run('dmesg | grep "Killed process"', 0)
75 if output:
76 failmsg = "ERROR: Processes were killed by the OOM Killer:\n%s\n" % output
77
Brad Bishopf86d0552018-12-04 14:18:15 -080078 if failed_tests:
Andrew Geissler99467da2019-02-25 18:54:23 -060079 failmsg = failmsg + "Failed ptests:\n%s" % pprint.pformat(failed_tests)
80
81 if failmsg:
82 self.fail(failmsg)