Skip to content
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: add c-unit-testing feature #1166

Merged
merged 1 commit into from
Jan 24, 2024

Conversation

benma
Copy link
Collaborator

@benma benma commented Jan 24, 2024

The testing feature is enabled for Rust unit tests, but not for the Rust code when compiled to be linked to the C unit tests.

We want to add a simulator in the unit-test directory (as C unit tests are already standalone host binaries that link the full C/Rust firmware code), but need a way to change behavior for the simulator only. The testing flag is not enabled there as mentioned above.

We add a c-unit-testing feature that is active only in Rust code when linked to the C unit tests (including the simulator) for this purpose.

We wanted to simply enable testing there as well, but ran into compilation problems when compiling the Rust unit tests:

/usr/bin/ld:
.../build-build-rust-unit-tests/src/../lib/libbitbox_merged.a(bitbox02_rust_c-06ac99f37ae6bb45.bitbox02_rust_c.ff44fdfedc2996e0-cgu.0.rcgu.o):(.init_array.00099+0x0):
multiple definition of `std::sys::unix::args::imp::ARGV_INIT_ARRAY';
.../build-build-rust-unit-tests/src/rust/target/all-features/release/deps/bitbox02-5ad04c78e548693d.bitbox02.5d97720ccc25f2c4-cgu.0.rcgu.o:(.init_array.00099+0x0):
first defined here

@benma benma requested a review from asi345 January 24, 2024 11:32
The `testing` feature is enabled for *Rust* unit tests, but not for
the Rust code when compiled to be linked to the *C* unit tests.

We want to add a simulator in the unit-test directory (as C unit tests
are already standalone host binaries that link the full C/Rust
firmware code), but need a way to change behavior for the simulator
only. The `testing` flag is not enabled there as mentioned above.

We add a `c-unit-testing` feature that is active only in Rust code
when linked to the C unit tests (including the simulator) for this
purpose.

We wanted to simply enable `testing` there as well, but ran into
compilation problems when compiling the Rust unit tests:

```
/usr/bin/ld:
.../build-build-rust-unit-tests/src/../lib/libbitbox_merged.a(bitbox02_rust_c-06ac99f37ae6bb45.bitbox02_rust_c.ff44fdfedc2996e0-cgu.0.rcgu.o):(.init_array.00099+0x0):
multiple definition of `std::sys::unix::args::imp::ARGV_INIT_ARRAY';
.../build-build-rust-unit-tests/src/rust/target/all-features/release/deps/bitbox02-5ad04c78e548693d.bitbox02.5d97720ccc25f2c4-cgu.0.rcgu.o:(.init_array.00099+0x0):
first defined here
```
@benma benma force-pushed the feature-c-unit-tests branch from 458ef5e to 23be89d Compare January 24, 2024 11:33
Copy link
Collaborator

@asi345 asi345 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@benma benma merged commit 3c0e9ac into BitBoxSwiss:master Jan 24, 2024
1 check passed
@benma benma deleted the feature-c-unit-tests branch January 24, 2024 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants