Skip to content

Commit ef66111

Browse files
Filip Jagodzinskic1728p9
authored andcommitted
Tests: USB: Update endpoint halt test
Wait for a locally created Timer thread to finish before returning.
1 parent a2ad3b7 commit ef66111

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

TESTS/host_tests/pyusb_basic.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,22 +1026,28 @@ def timer_handler():
10261026
delayed_halt.start()
10271027
# Keep transferring data to and from the device until one of the endpoints
10281028
# is halted.
1029-
while delayed_halt.is_alive():
1030-
if ctrl_error.is_set():
1031-
raise_unconditionally(lineno(), 'Halting endpoint {0.bEndpointAddress:#04x} failed'
1032-
.format(ep_to_halt))
1033-
try:
1034-
loopback_ep_test(ep_out, ep_in, ep_out.wMaxPacketSize)
1035-
except usb.core.USBError as err:
1029+
try:
1030+
while delayed_halt.is_alive():
1031+
if ctrl_error.is_set():
1032+
raise_unconditionally(lineno(), 'Halting endpoint {0.bEndpointAddress:#04x} failed'
1033+
.format(ep_to_halt))
10361034
try:
1037-
ep_status = usb.control.get_status(dev, ep_to_halt)
1035+
loopback_ep_test(ep_out, ep_in, ep_out.wMaxPacketSize)
10381036
except usb.core.USBError as err:
1039-
raise_unconditionally(lineno(), 'Unable to get endpoint status ({!r}).'.format(err))
1040-
if ep_status == 1:
1041-
# OK, got USBError because of endpoint halt
1042-
return
1043-
else:
1044-
raise_unconditionally(lineno(), 'Unexpected error ({!r}).'.format(err))
1037+
try:
1038+
ep_status = usb.control.get_status(dev, ep_to_halt)
1039+
except usb.core.USBError as err:
1040+
raise_unconditionally(lineno(), 'Unable to get endpoint status ({!r}).'.format(err))
1041+
if ep_status == 1:
1042+
# OK, got USBError because of endpoint halt
1043+
return
1044+
else:
1045+
raise_unconditionally(lineno(), 'Unexpected error ({!r}).'.format(err))
1046+
except:
1047+
raise
1048+
finally:
1049+
# Always wait for the Timer thread created above.
1050+
delayed_halt.join()
10451051
raise_unconditionally(lineno(), 'Halting endpoint {0.bEndpointAddress:#04x}'
10461052
' during transmission did not raise USBError.'
10471053
.format(ep_to_halt))

0 commit comments

Comments
 (0)