From: Vyacheslav Cherkashin Date: Fri, 10 Aug 2018 18:06:12 +0000 (+0300) Subject: Add saving the tests report X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e4381c6ad7034a3aa57c2020038614ea5f6bd937;p=test%2Fswap-test.git Add saving the tests report Save tests report to: - //report.json Change-Id: Ic45c8959917b4405713d060b2c2cd9da9c6d441a Signed-off-by: Vyacheslav Cherkashin --- diff --git a/core/autotest.py b/core/autotest.py index 0880c96..c6c5777 100755 --- a/core/autotest.py +++ b/core/autotest.py @@ -23,6 +23,7 @@ After that they are checked and final result is shown. import os import sys import time +import json import shutil import host @@ -241,25 +242,42 @@ class Autotest(object): return test_result - def __show_tests_result(self, run_result, check_result): - Info.head('##### Tests results #####') - + def __make_tests_report(self, run_result, check_result): + report_list = [] for test_name in self.__tests_list: + report = { + 'name': test_name, + 'result': 'FAIL', + 'error_description': 'Unknown error', + } + ret = run_result.get(test_name) if ret is None: - Info.test_fail('WAS_NOT_STARTED', test_name) - continue + report['error_description'] = 'Test app was not run' elif ret != 0: - Info.test_fail('RUN_FAIL_%d' % ret, test_name) - continue + report['error_description'] = 'Test app finished with error: %d' % ret + else: + result = check_result[test_name] + for check_name, ret in result.iteritems(): + if ret == auxiliary.CheckerAUX.PASS: + report['result'] = 'PASS' + + report['error_description'] = \ + auxiliary.CheckerAUX.description_by_retcode(ret) + + report_list.append(report) - result = check_result[test_name] - for check_name, ret in result.iteritems(): - ret_str = auxiliary.CheckerAUX.code_to_string(ret) - if ret is auxiliary.CheckerAUX.PASS: - Info.test_pass(ret_str, check_name) - else: - Info.test_fail(ret_str, check_name) + # show tests result + Info.head('##### Tests results #####') + for report in report_list: + if report['result'] == 'PASS': + Info.test_pass(report['result'], report['name']) + else: + Info.test_fail(report['result'], report['name']) + + return { + 'tests_list': report_list + } def run(self): Info.head('Autotest START') @@ -270,8 +288,12 @@ class Autotest(object): # check tests check_test_result = self.__check_all_tests(run_test_result) - # show tests result - self.__show_tests_result(run_test_result, check_test_result) + # make tests report + tests_report = self.__make_tests_report(run_test_result, check_test_result) + + # save tests report + with open(self.__host_config.report(), 'w') as file_obj: + json.dump(tests_report, file_obj, indent=2) def main(argv): diff --git a/core/lib/auxiliary.py b/core/lib/auxiliary.py index 11c4d1f..d1b404f 100644 --- a/core/lib/auxiliary.py +++ b/core/lib/auxiliary.py @@ -29,16 +29,16 @@ class CheckerAUX(object): FAIL = 1 @classmethod - def code_to_string(cls, code): - string = { - cls.PASS: 'PASS', - cls.FAIL: 'FAIL', - }.get(code) + def description_by_retcode(cls, retcode): + description = { + cls.PASS: '', + cls.FAIL: 'Test check failed', + }.get(retcode) - if string is None: - return 'ERROR_%d' % code + if description is None: + return 'Test check finished with unknown error: {}'.format(retcode) - return string + return description @staticmethod def get_trace(path): diff --git a/core/lib/host.py b/core/lib/host.py index 97f6da4..a6cf2b5 100644 --- a/core/lib/host.py +++ b/core/lib/host.py @@ -56,6 +56,9 @@ class Config(object): def test_dir(self, test_name): return os.path.join(self.__tests_dir, test_name) + def report(self): + return os.path.join(self.__tests_dir, 'report.json') + def exec_cmd(cmd, timeout=0, show_output=False): """