Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1 | from oeqa.runtime.case import OERuntimeTestCase |
| 2 | from oeqa.core.decorator.depends import OETestDepends |
| 3 | from oeqa.core.decorator.oeid import OETestID |
| 4 | from oeqa.core.decorator.data import skipIfNotFeature |
| 5 | from oeqa.utils.logparser import Lparser, Result |
| 6 | |
| 7 | class PtestRunnerTest(OERuntimeTestCase): |
| 8 | |
| 9 | # a ptest log parser |
| 10 | def parse_ptest(self, logfile): |
| 11 | parser = Lparser(test_0_pass_regex="^PASS:(.+)", |
| 12 | test_0_fail_regex="^FAIL:(.+)", |
| 13 | test_0_skip_regex="^SKIP:(.+)", |
| 14 | section_0_begin_regex="^BEGIN: .*/(.+)/ptest", |
| 15 | section_0_end_regex="^END: .*/(.+)/ptest") |
| 16 | parser.init() |
| 17 | result = Result() |
| 18 | |
| 19 | with open(logfile, errors='replace') as f: |
| 20 | for line in f: |
| 21 | result_tuple = parser.parse_line(line) |
| 22 | if not result_tuple: |
| 23 | continue |
| 24 | result_tuple = line_type, category, status, name = parser.parse_line(line) |
| 25 | |
| 26 | if line_type == 'section' and status == 'begin': |
| 27 | current_section = name |
| 28 | continue |
| 29 | |
| 30 | if line_type == 'section' and status == 'end': |
| 31 | current_section = None |
| 32 | continue |
| 33 | |
| 34 | if line_type == 'test' and status == 'pass': |
| 35 | result.store(current_section, name, status) |
| 36 | continue |
| 37 | |
| 38 | if line_type == 'test' and status == 'fail': |
| 39 | result.store(current_section, name, status) |
| 40 | continue |
| 41 | |
| 42 | if line_type == 'test' and status == 'skip': |
| 43 | result.store(current_section, name, status) |
| 44 | continue |
| 45 | |
| 46 | result.sort_tests() |
| 47 | return result |
| 48 | |
| 49 | @OETestID(1600) |
| 50 | @skipIfNotFeature('ptest', 'Test requires ptest to be in DISTRO_FEATURES') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 51 | @OETestDepends(['ssh.SSHTest.test_ssh']) |
| 52 | def test_ptestrunner(self): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 53 | status, output = self.target.run('which ptest-runner', 0) |
| 54 | if status != 0: |
| 55 | self.skipTest("No -ptest packages are installed in the image") |
| 56 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 57 | import datetime |
| 58 | |
| 59 | test_log_dir = self.td.get('TEST_LOG_DIR', '') |
| 60 | # The TEST_LOG_DIR maybe NULL when testimage is added after |
| 61 | # testdata.json is generated. |
| 62 | if not test_log_dir: |
| 63 | test_log_dir = os.path.join(self.td.get('WORKDIR', ''), 'testimage') |
| 64 | # Don't use self.td.get('DATETIME'), it's from testdata.json, not |
| 65 | # up-to-date, and may cause "File exists" when re-reun. |
| 66 | datetime = datetime.datetime.now().strftime('%Y%m%d%H%M%S') |
| 67 | ptest_log_dir_link = os.path.join(test_log_dir, 'ptest_log') |
| 68 | ptest_log_dir = '%s.%s' % (ptest_log_dir_link, datetime) |
| 69 | ptest_runner_log = os.path.join(ptest_log_dir, 'ptest-runner.log') |
| 70 | |
| 71 | status, output = self.target.run('ptest-runner', 0) |
| 72 | os.makedirs(ptest_log_dir) |
| 73 | with open(ptest_runner_log, 'w') as f: |
| 74 | f.write(output) |
| 75 | |
| 76 | # status != 0 is OK since some ptest tests may fail |
| 77 | self.assertTrue(status != 127, msg="Cannot execute ptest-runner!") |
| 78 | |
| 79 | # Parse and save results |
| 80 | parse_result = self.parse_ptest(ptest_runner_log) |
| 81 | parse_result.log_as_files(ptest_log_dir, test_status = ['pass','fail', 'skip']) |
| 82 | if os.path.exists(ptest_log_dir_link): |
| 83 | # Remove the old link to create a new one |
| 84 | os.remove(ptest_log_dir_link) |
| 85 | os.symlink(os.path.basename(ptest_log_dir), ptest_log_dir_link) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 86 | |
| 87 | failed_tests = {} |
| 88 | for section in parse_result.result_dict: |
| 89 | failed_testcases = [ test for test, result in parse_result.result_dict[section] if result == 'fail' ] |
| 90 | if failed_testcases: |
| 91 | failed_tests[section] = failed_testcases |
| 92 | |
| 93 | self.assertFalse(failed_tests, msg = "Failed ptests: %s" %(str(failed_tests))) |