From b75400294a6db0e7952cfb4f849a28da3cd51612 Mon Sep 17 00:00:00 2001 From: He Yin Ling Date: Thu, 7 Mar 2019 20:18:32 +0800 Subject: [PATCH] test: collect unit-test performance items and save to report --- tools/tiny-test-fw/IDF/IDFDUT.py | 10 +++++----- tools/unit-test-app/unit_test.py | 13 +++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/tools/tiny-test-fw/IDF/IDFDUT.py b/tools/tiny-test-fw/IDF/IDFDUT.py index 2e75c7ab56..c8ee24f236 100644 --- a/tools/tiny-test-fw/IDF/IDFDUT.py +++ b/tools/tiny-test-fw/IDF/IDFDUT.py @@ -65,14 +65,14 @@ class IDFRecvThread(DUT.RecvThread): def __init__(self, read, dut): super(IDFRecvThread, self).__init__(read, dut) self.exceptions = _queue.Queue() - self.performances = _queue.Queue() + self.performance_items = _queue.Queue() def collect_performance(self, comp_data): matches = self.PERFORMANCE_PATTERN.findall(comp_data) for match in matches: Utility.console_log("[Performance][{}]: {}".format(match[0], match[1]), color="orange") - self.performances.put((match[0], match[1])) + self.performance_items.put((match[0], match[1])) def detect_exception(self, comp_data): for pattern in self.EXCEPTION_PATTERNS: @@ -157,7 +157,7 @@ class IDFDUT(DUT.SerialDUT): super(IDFDUT, self).__init__(name, port, log_file, app, **kwargs) self.allow_dut_exception = allow_dut_exception self.exceptions = _queue.Queue() - self.performances = _queue.Queue() + self.performance_items = _queue.Queue() @classmethod def get_mac(cls, app, port): @@ -365,7 +365,7 @@ class IDFDUT(DUT.SerialDUT): def stop_receive(self): if self.receive_thread: - for name in ["performances", "exceptions"]: + for name in ["performance_items", "exceptions"]: source_queue = getattr(self.receive_thread, name) dest_queue = getattr(self, name) self._queue_copy(source_queue, dest_queue) @@ -382,7 +382,7 @@ class IDFDUT(DUT.SerialDUT): :return: a list of performance items. """ - return self._get_from_queue("performances") + return self._get_from_queue("performance_items") def close(self): super(IDFDUT, self).close() diff --git a/tools/unit-test-app/unit_test.py b/tools/unit-test-app/unit_test.py index 3360942597..330b32ff31 100755 --- a/tools/unit-test-app/unit_test.py +++ b/tools/unit-test-app/unit_test.py @@ -285,16 +285,19 @@ def run_unit_test_cases(env, extra_data): Utility.console_log("Download finished, start running test cases", "O") for one_case in case_config[ut_config]: + performance_items = [] # create junit report test case junit_test_case = TinyFW.JunitReport.create_test_case("[{}] {}".format(ut_config, one_case["name"])) try: run_one_normal_case(dut, one_case, junit_test_case) + performance_items = dut.get_performance_items() except TestCaseFailed: failed_cases.append(one_case["name"]) except Exception as e: junit_test_case.add_failure_info("Unexpected exception: " + str(e)) failed_cases.append(one_case["name"]) finally: + TinyFW.JunitReport.update_performance(performance_items) TinyFW.JunitReport.test_case_finish(junit_test_case) # raise exception if any case fails @@ -445,6 +448,13 @@ def run_one_multiple_devices_case(duts, ut_config, env, one_case, app_bin, junit if not result: junit_test_case.add_failure_info(output) + + # collect performances from DUTs + performance_items = [] + for dut_name in duts: + performance_items.extend(duts[dut_name].get_performance_items()) + TinyFW.JunitReport.update_performance(performance_items) + return result @@ -628,15 +638,18 @@ def run_multiple_stage_cases(env, extra_data): dut.start_app() for one_case in case_config[ut_config]: + performance_items = [] junit_test_case = TinyFW.JunitReport.create_test_case("[{}] {}".format(ut_config, one_case["name"])) try: run_one_multiple_stage_case(dut, one_case, junit_test_case) + performance_items = dut.get_performance_items() except TestCaseFailed: failed_cases.append(one_case["name"]) except Exception as e: junit_test_case.add_failure_info("Unexpected exception: " + str(e)) failed_cases.append(one_case["name"]) finally: + TinyFW.JunitReport.update_performance(performance_items) TinyFW.JunitReport.test_case_finish(junit_test_case) # raise exception if any case fails