mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-26 16:38:12 +00:00
fix(tests): fix click tests race condition
This commit is contained in:
parent
a22f1d3760
commit
69770a42f4
@ -163,6 +163,7 @@ class Layout(Generic[T]):
|
|||||||
self.timers: dict[int, loop.Task] = {}
|
self.timers: dict[int, loop.Task] = {}
|
||||||
self.result_box = loop.mailbox()
|
self.result_box = loop.mailbox()
|
||||||
self.button_request_box = loop.mailbox()
|
self.button_request_box = loop.mailbox()
|
||||||
|
self.button_request_ack_pending: bool = False
|
||||||
self.transition_out: AttachType | None = None
|
self.transition_out: AttachType | None = None
|
||||||
self.backlight_level = BacklightLevels.NORMAL
|
self.backlight_level = BacklightLevels.NORMAL
|
||||||
self.context: context.Context | None = None
|
self.context: context.Context | None = None
|
||||||
@ -281,6 +282,7 @@ class Layout(Generic[T]):
|
|||||||
if __debug__ and CURRENT_LAYOUT is not self:
|
if __debug__ and CURRENT_LAYOUT is not self:
|
||||||
raise wire.FirmwareError("layout received an event but it is not running")
|
raise wire.FirmwareError("layout received an event but it is not running")
|
||||||
|
|
||||||
|
first_paint = False
|
||||||
state = event_call(*args)
|
state = event_call(*args)
|
||||||
self.transition_out = self.layout.get_transition_out()
|
self.transition_out = self.layout.get_transition_out()
|
||||||
|
|
||||||
@ -288,19 +290,22 @@ class Layout(Generic[T]):
|
|||||||
self._emit_message(self.layout.return_value())
|
self._emit_message(self.layout.return_value())
|
||||||
|
|
||||||
elif state is LayoutState.ATTACHED:
|
elif state is LayoutState.ATTACHED:
|
||||||
self._button_request()
|
first_paint = True
|
||||||
if __debug__:
|
self.button_request_ack_pending = self._button_request()
|
||||||
|
if self.button_request_ack_pending:
|
||||||
|
state = LayoutState.TRANSITIONING
|
||||||
|
elif __debug__:
|
||||||
self.notify_debuglink(self)
|
self.notify_debuglink(self)
|
||||||
|
|
||||||
if state is not None:
|
if state is not None:
|
||||||
self.state = state
|
self.state = state
|
||||||
|
|
||||||
if state is LayoutState.ATTACHED:
|
if first_paint:
|
||||||
self._first_paint()
|
self._first_paint()
|
||||||
else:
|
else:
|
||||||
self._paint()
|
self._paint()
|
||||||
|
|
||||||
def _button_request(self) -> None:
|
def _button_request(self) -> bool:
|
||||||
"""Process a button request coming out of the Rust layout."""
|
"""Process a button request coming out of the Rust layout."""
|
||||||
if __debug__ and not self.button_request_box.is_empty():
|
if __debug__ and not self.button_request_box.is_empty():
|
||||||
raise wire.FirmwareError(
|
raise wire.FirmwareError(
|
||||||
@ -310,13 +315,14 @@ class Layout(Generic[T]):
|
|||||||
|
|
||||||
res = self.layout.button_request()
|
res = self.layout.button_request()
|
||||||
if res is None:
|
if res is None:
|
||||||
return
|
return False
|
||||||
|
|
||||||
if self.context is None:
|
if self.context is None:
|
||||||
return
|
return False
|
||||||
|
|
||||||
# in production, we don't want this to fail, hence replace=True
|
# in production, we don't want this to fail, hence replace=True
|
||||||
self.button_request_box.put(res, replace=True)
|
self.button_request_box.put(res, replace=True)
|
||||||
|
return True
|
||||||
|
|
||||||
def _paint(self) -> None:
|
def _paint(self) -> None:
|
||||||
"""Paint the layout and ensure that homescreen cache is properly invalidated."""
|
"""Paint the layout and ensure that homescreen cache is properly invalidated."""
|
||||||
|
Loading…
Reference in New Issue
Block a user