Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
| 2 | # SPDX-License-Identifier: MIT |
| 3 | # |
| 4 | |
Brad Bishop | f86d055 | 2018-12-04 14:18:15 -0800 | [diff] [blame] | 5 | import unittest |
| 6 | import pprint |
Andrew Geissler | 99467da | 2019-02-25 18:54:23 -0600 | [diff] [blame] | 7 | import datetime |
Brad Bishop | f86d055 | 2018-12-04 14:18:15 -0800 | [diff] [blame] | 8 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 9 | from oeqa.runtime.case import OERuntimeTestCase |
| 10 | from oeqa.core.decorator.depends import OETestDepends |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 11 | from oeqa.core.decorator.data import skipIfNotFeature |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 12 | from oeqa.runtime.decorator.package import OEHasPackage |
Andrew Geissler | 99467da | 2019-02-25 18:54:23 -0600 | [diff] [blame] | 13 | from oeqa.utils.logparser import PtestParser |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 14 | |
| 15 | class PtestRunnerTest(OERuntimeTestCase): |
| 16 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 17 | @skipIfNotFeature('ptest', 'Test requires ptest to be in DISTRO_FEATURES') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 18 | @OETestDepends(['ssh.SSHTest.test_ssh']) |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 19 | @OEHasPackage(['ptest-runner']) |
Brad Bishop | f86d055 | 2018-12-04 14:18:15 -0800 | [diff] [blame] | 20 | @unittest.expectedFailure |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 21 | def test_ptestrunner(self): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 22 | 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 Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 26 | 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 Geissler | 99467da | 2019-02-25 18:54:23 -0600 | [diff] [blame] | 33 | timestamp = datetime.datetime.now().strftime('%Y%m%d%H%M%S') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 34 | ptest_log_dir_link = os.path.join(test_log_dir, 'ptest_log') |
Andrew Geissler | 99467da | 2019-02-25 18:54:23 -0600 | [diff] [blame] | 35 | ptest_log_dir = '%s.%s' % (ptest_log_dir_link, timestamp) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 36 | 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 Bishop | f86d055 | 2018-12-04 14:18:15 -0800 | [diff] [blame] | 46 | if not hasattr(self.tc, "extraresults"): |
| 47 | self.tc.extraresults = {} |
| 48 | extras = self.tc.extraresults |
| 49 | extras['ptestresult.rawlogs'] = {'log': output} |
| 50 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 51 | # Parse and save results |
Andrew Geissler | 99467da | 2019-02-25 18:54:23 -0600 | [diff] [blame] | 52 | parser = PtestParser() |
| 53 | results, sections = parser.parse(ptest_runner_log) |
| 54 | parser.results_as_files(ptest_log_dir) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 55 | 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 Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 59 | |
Andrew Geissler | 99467da | 2019-02-25 18:54:23 -0600 | [diff] [blame] | 60 | extras['ptestresult.sections'] = sections |
| 61 | |
Brad Bishop | f86d055 | 2018-12-04 14:18:15 -0800 | [diff] [blame] | 62 | trans = str.maketrans("()", "__") |
Andrew Geissler | 99467da | 2019-02-25 18:54:23 -0600 | [diff] [blame] | 63 | 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 Bishop | f86d055 | 2018-12-04 14:18:15 -0800 | [diff] [blame] | 68 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 69 | failed_tests = {} |
Andrew Geissler | 99467da | 2019-02-25 18:54:23 -0600 | [diff] [blame] | 70 | for section in results: |
| 71 | failed_testcases = [ "_".join(test.translate(trans).split()) for test in results[section] if results[section][test] == 'fail' ] |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 72 | if failed_testcases: |
| 73 | failed_tests[section] = failed_testcases |
| 74 | |
Andrew Geissler | 99467da | 2019-02-25 18:54:23 -0600 | [diff] [blame] | 75 | 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 Bishop | f86d055 | 2018-12-04 14:18:15 -0800 | [diff] [blame] | 80 | if failed_tests: |
Andrew Geissler | 99467da | 2019-02-25 18:54:23 -0600 | [diff] [blame] | 81 | failmsg = failmsg + "Failed ptests:\n%s" % pprint.pformat(failed_tests) |
| 82 | |
| 83 | if failmsg: |
| 84 | self.fail(failmsg) |