-
-
Notifications
You must be signed in to change notification settings - Fork 654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rust unit test dependency and initialization issues #4189
Comments
this seemed impractical in the past: the istm we can just add
the easiest solution is to expose a more complex solution is replacing the Rust test harness with something that supports global setup, but that doesn't seem that easy |
This issue report addresses two system problem with our Rust unit tests (
make test_rust
):1. Dependency on
make build_unix
:The
make test_rust
target currently relies on build artifacts frommake build_unix
. If the emulator hasn't been built beforehand, the test build will fail. Ideally, these two targets should be independent, so that running tests does not require the emulator to be built first.2. Improper Initialization of C Functions in Rust Tests:
In Rust unit tests, functions from the C world (e.g.,
trezorhal
) can be invoked without proper prior initialization. While tests can call any function defined in theffi
module, there is currently no mechanism to initializetrezorhal
. Normally, this is handled inmain.c
, which isn't included or called during test execution.This problem became evident with the introduction of the system module, specifically with the new
system_init()
function. In the firmware/bootloader/emulator,system_init()
is the first function called inmain()
to initialize system services (e.g., systick). Without this initialization, functions likesystick_ms()
will always return 0. Sincesystick_ms()
is used in othertrezorhal
functions (as well as in storage), these functions do not work correctly without the necessary initialization.We’ve applied a temporary fix for this issue by automatically initializing the
systick
module whenever any of its functions are called. However, similar initialization issues could arise in other parts of the system in the future.To prevent these issues, systematic approach to properly initialize
trezorhal
drivers in the unit test binary before any test is executed should be introduced.The text was updated successfully, but these errors were encountered: