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