bugfix:fix the multi device stop thread bug
This commit is contained in:
parent
88d40e01b4
commit
df83323ee3
1 changed files with 8 additions and 8 deletions
|
@ -254,6 +254,7 @@ def run_unit_test_cases(env, extra_data):
|
||||||
raise AssertionError("Unit Test Failed")
|
raise AssertionError("Unit Test Failed")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Handler(threading.Thread):
|
class Handler(threading.Thread):
|
||||||
|
|
||||||
WAIT_SIGNAL_PATTERN = re.compile(r'Waiting for signal: \[(.+)\]!')
|
WAIT_SIGNAL_PATTERN = re.compile(r'Waiting for signal: \[(.+)\]!')
|
||||||
|
@ -271,6 +272,7 @@ class Handler(threading.Thread):
|
||||||
self.result = False
|
self.result = False
|
||||||
self.fail_name = None
|
self.fail_name = None
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
|
self.force_stop = threading.Event() # it show the running status
|
||||||
threading.Thread.__init__(self, name="{} Handler".format(dut))
|
threading.Thread.__init__(self, name="{} Handler".format(dut))
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
@ -289,7 +291,7 @@ class Handler(threading.Thread):
|
||||||
def device_wait_action(data):
|
def device_wait_action(data):
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
expected_signal = data[0]
|
expected_signal = data[0]
|
||||||
while not THREAD_TERMINATE_FLAG:
|
while 1:
|
||||||
if time.time() > start_time + self.timeout:
|
if time.time() > start_time + self.timeout:
|
||||||
Utility.console_log("Timeout in device for function: %s"%self.child_case_name, color="orange")
|
Utility.console_log("Timeout in device for function: %s"%self.child_case_name, color="orange")
|
||||||
break
|
break
|
||||||
|
@ -321,9 +323,7 @@ class Handler(threading.Thread):
|
||||||
self.dut.expect("Running " + self.parent_case_name + "...")
|
self.dut.expect("Running " + self.parent_case_name + "...")
|
||||||
except ExpectTimeout:
|
except ExpectTimeout:
|
||||||
Utility.console_log("No case detected!", color="orange")
|
Utility.console_log("No case detected!", color="orange")
|
||||||
THREAD_TERMINATE_FLAG = True
|
while not self.finish and not self.force_stop.isSet():
|
||||||
|
|
||||||
while not self.finish and not THREAD_TERMINATE_FLAG:
|
|
||||||
try:
|
try:
|
||||||
self.dut.expect_any((re.compile('\(' + str(self.child_case_index) + '\)\s"(\w+)"'), get_child_case_name),
|
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
|
(self.WAIT_SIGNAL_PATTERN, device_wait_action), # wait signal pattern
|
||||||
|
@ -335,6 +335,9 @@ class Handler(threading.Thread):
|
||||||
one_device_case_finish(False)
|
one_device_case_finish(False)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
self.force_stop.set()
|
||||||
|
|
||||||
|
|
||||||
def get_case_info(one_case):
|
def get_case_info(one_case):
|
||||||
parent_case = one_case["name"]
|
parent_case = one_case["name"]
|
||||||
|
@ -360,9 +363,6 @@ def case_run(duts, ut_config, env, one_case, failed_cases, app_bin):
|
||||||
result = True
|
result = True
|
||||||
parent_case, case_num = get_case_info(one_case)
|
parent_case, case_num = get_case_info(one_case)
|
||||||
|
|
||||||
global THREAD_TERMINATE_FLAG
|
|
||||||
THREAD_TERMINATE_FLAG = False
|
|
||||||
|
|
||||||
for i in range(case_num):
|
for i in range(case_num):
|
||||||
dut = get_dut(duts, env, "dut%d" % i, ut_config, app_bin)
|
dut = get_dut(duts, env, "dut%d" % i, ut_config, app_bin)
|
||||||
threads.append(Handler(dut, send_signal_list, lock,
|
threads.append(Handler(dut, send_signal_list, lock,
|
||||||
|
@ -374,7 +374,7 @@ def case_run(duts, ut_config, env, one_case, failed_cases, app_bin):
|
||||||
thread.join()
|
thread.join()
|
||||||
result = result and thread.result
|
result = result and thread.result
|
||||||
if not thread.result:
|
if not thread.result:
|
||||||
THREAD_TERMINATE_FLAG = True
|
[thd.stop() for thd in threads]
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
Utility.console_log("Success: " + one_case["name"], color="green")
|
Utility.console_log("Success: " + one_case["name"], color="green")
|
||||||
|
|
Loading…
Reference in a new issue