From ac62b8437d3cf61cc3570f3b46fb05188152b2f6 Mon Sep 17 00:00:00 2001 From: houchenyao Date: Mon, 20 Aug 2018 19:21:10 +0800 Subject: [PATCH] bugfix:fix the multi device stop thread bug --- tools/unit-test-app/unit_test.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/tools/unit-test-app/unit_test.py b/tools/unit-test-app/unit_test.py index f7ea874e70..7e916c1ef0 100644 --- a/tools/unit-test-app/unit_test.py +++ b/tools/unit-test-app/unit_test.py @@ -257,6 +257,7 @@ def run_unit_test_cases(env, extra_data): raise AssertionError("Unit Test Failed") + class Handler(threading.Thread): WAIT_SIGNAL_PATTERN = re.compile(r'Waiting for signal: \[(.+)\]!') @@ -275,6 +276,7 @@ class Handler(threading.Thread): self.output = "" self.fail_name = None self.timeout = timeout + self.force_stop = threading.Event() # it show the running status threading.Thread.__init__(self, name="{} Handler".format(dut)) def run(self): @@ -323,12 +325,14 @@ class Handler(threading.Thread): self.dut.reset() self.dut.write("-", flush=False) - self.dut.expect_any(UT_APP_BOOT_UP_DONE, "0 Tests 0 Failures 0 Ignored") - time.sleep(1) - self.dut.write("\"{}\"".format(self.parent_case_name)) - self.dut.expect("Running " + self.parent_case_name + "...") - - while not self.finish: + try: + self.dut.expect_any(UT_APP_BOOT_UP_DONE, "0 Tests 0 Failures 0 Ignored") + time.sleep(1) + self.dut.write("\"{}\"".format(self.parent_case_name)) + self.dut.expect("Running " + self.parent_case_name + "...") + except ExpectTimeout: + Utility.console_log("No case detected!", color="orange") + while not self.finish and not self.force_stop.isSet(): try: self.dut.expect_any((re.compile('\(' + str(self.child_case_index) + '\)\s"(\w+)"'), get_child_case_name), (self.WAIT_SIGNAL_PATTERN, device_wait_action), # wait signal pattern @@ -340,6 +344,9 @@ class Handler(threading.Thread): one_device_case_finish(False) break + def stop(self): + self.force_stop.set() + def get_case_info(one_case): parent_case = one_case["name"] @@ -364,6 +371,7 @@ def run_one_multiple_devices_case(duts, ut_config, env, one_case, failed_cases, failed_device = [] result = True parent_case, case_num = get_case_info(one_case) + for i in range(case_num): dut = get_dut(duts, env, "dut%d" % i, ut_config) threads.append(Handler(dut, send_signal_list, lock, @@ -377,7 +385,8 @@ def run_one_multiple_devices_case(duts, ut_config, env, one_case, failed_cases, result = result and thread.result output += thread.output if not thread.result: - failed_device.append(thread.fail_name) + [thd.stop() for thd in threads] + if result: Utility.console_log("Success: " + one_case["name"], color="green") else: