Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
Brad Bishop | 40320b1 | 2019-03-26 16:08:25 -0400 | [diff] [blame] | 7 | import os |
| 8 | import sys |
| 9 | basepath = os.path.abspath(os.path.dirname(__file__) + '/../../../../../') |
| 10 | lib_path = basepath + '/scripts/lib' |
| 11 | sys.path = sys.path + [lib_path] |
| 12 | from resulttool.report import ResultsTextReport |
| 13 | from resulttool import regression as regression |
| 14 | from resulttool import resultutils as resultutils |
| 15 | from oeqa.selftest.case import OESelftestTestCase |
| 16 | |
| 17 | class ResultToolTests(OESelftestTestCase): |
| 18 | base_results_data = {'base_result1': {'configuration': {"TEST_TYPE": "runtime", |
| 19 | "TESTSERIES": "series1", |
| 20 | "IMAGE_BASENAME": "image", |
| 21 | "IMAGE_PKGTYPE": "ipk", |
| 22 | "DISTRO": "mydistro", |
| 23 | "MACHINE": "qemux86"}, |
| 24 | 'result': {}}, |
| 25 | 'base_result2': {'configuration': {"TEST_TYPE": "runtime", |
| 26 | "TESTSERIES": "series1", |
| 27 | "IMAGE_BASENAME": "image", |
| 28 | "IMAGE_PKGTYPE": "ipk", |
| 29 | "DISTRO": "mydistro", |
| 30 | "MACHINE": "qemux86-64"}, |
| 31 | 'result': {}}} |
| 32 | target_results_data = {'target_result1': {'configuration': {"TEST_TYPE": "runtime", |
| 33 | "TESTSERIES": "series1", |
| 34 | "IMAGE_BASENAME": "image", |
| 35 | "IMAGE_PKGTYPE": "ipk", |
| 36 | "DISTRO": "mydistro", |
| 37 | "MACHINE": "qemux86"}, |
| 38 | 'result': {}}, |
| 39 | 'target_result2': {'configuration': {"TEST_TYPE": "runtime", |
| 40 | "TESTSERIES": "series1", |
| 41 | "IMAGE_BASENAME": "image", |
| 42 | "IMAGE_PKGTYPE": "ipk", |
| 43 | "DISTRO": "mydistro", |
| 44 | "MACHINE": "qemux86"}, |
| 45 | 'result': {}}, |
| 46 | 'target_result3': {'configuration': {"TEST_TYPE": "runtime", |
| 47 | "TESTSERIES": "series1", |
| 48 | "IMAGE_BASENAME": "image", |
| 49 | "IMAGE_PKGTYPE": "ipk", |
| 50 | "DISTRO": "mydistro", |
| 51 | "MACHINE": "qemux86-64"}, |
| 52 | 'result': {}}} |
| 53 | |
| 54 | def test_report_can_aggregate_test_result(self): |
| 55 | result_data = {'result': {'test1': {'status': 'PASSED'}, |
| 56 | 'test2': {'status': 'PASSED'}, |
| 57 | 'test3': {'status': 'FAILED'}, |
| 58 | 'test4': {'status': 'ERROR'}, |
| 59 | 'test5': {'status': 'SKIPPED'}}} |
| 60 | report = ResultsTextReport() |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 61 | result_report = report.get_aggregated_test_result(None, result_data, 'DummyMachine') |
Brad Bishop | 40320b1 | 2019-03-26 16:08:25 -0400 | [diff] [blame] | 62 | self.assertTrue(result_report['passed'] == 2, msg="Passed count not correct:%s" % result_report['passed']) |
| 63 | self.assertTrue(result_report['failed'] == 2, msg="Failed count not correct:%s" % result_report['failed']) |
| 64 | self.assertTrue(result_report['skipped'] == 1, msg="Skipped count not correct:%s" % result_report['skipped']) |
| 65 | |
| 66 | def test_regression_can_get_regression_base_target_pair(self): |
| 67 | |
| 68 | results = {} |
| 69 | resultutils.append_resultsdata(results, ResultToolTests.base_results_data) |
| 70 | resultutils.append_resultsdata(results, ResultToolTests.target_results_data) |
| 71 | self.assertTrue('target_result1' in results['runtime/mydistro/qemux86/image'], msg="Pair not correct:%s" % results) |
| 72 | self.assertTrue('target_result3' in results['runtime/mydistro/qemux86-64/image'], msg="Pair not correct:%s" % results) |
| 73 | |
| 74 | def test_regrresion_can_get_regression_result(self): |
| 75 | base_result_data = {'result': {'test1': {'status': 'PASSED'}, |
| 76 | 'test2': {'status': 'PASSED'}, |
| 77 | 'test3': {'status': 'FAILED'}, |
| 78 | 'test4': {'status': 'ERROR'}, |
| 79 | 'test5': {'status': 'SKIPPED'}}} |
| 80 | target_result_data = {'result': {'test1': {'status': 'PASSED'}, |
| 81 | 'test2': {'status': 'FAILED'}, |
| 82 | 'test3': {'status': 'PASSED'}, |
| 83 | 'test4': {'status': 'ERROR'}, |
| 84 | 'test5': {'status': 'SKIPPED'}}} |
| 85 | result, text = regression.compare_result(self.logger, "BaseTestRunName", "TargetTestRunName", base_result_data, target_result_data) |
| 86 | self.assertTrue(result['test2']['base'] == 'PASSED', |
| 87 | msg="regression not correct:%s" % result['test2']['base']) |
| 88 | self.assertTrue(result['test2']['target'] == 'FAILED', |
| 89 | msg="regression not correct:%s" % result['test2']['target']) |
| 90 | self.assertTrue(result['test3']['base'] == 'FAILED', |
| 91 | msg="regression not correct:%s" % result['test3']['base']) |
| 92 | self.assertTrue(result['test3']['target'] == 'PASSED', |
| 93 | msg="regression not correct:%s" % result['test3']['target']) |
| 94 | |
| 95 | def test_merge_can_merged_results(self): |
| 96 | results = {} |
| 97 | resultutils.append_resultsdata(results, ResultToolTests.base_results_data, configmap=resultutils.flatten_map) |
| 98 | resultutils.append_resultsdata(results, ResultToolTests.target_results_data, configmap=resultutils.flatten_map) |
| 99 | self.assertEqual(len(results[''].keys()), 5, msg="Flattened results not correct %s" % str(results)) |
| 100 | |