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

defmt-test: Exit with semihosting exit #786

Merged
merged 3 commits into from
Oct 11, 2023
Merged

Conversation

Urhengulas
Copy link
Member

This PR makes probe-rs detect exit as successfully. Basically the same as knurling-rs/app-template#71.

@jonathanpallant
Copy link
Contributor

LGTM. Can you post a log from a test run?

@Urhengulas
Copy link
Member Author

Urhengulas commented Oct 11, 2023

@jonathanpallant Of course.

Successful run:

$ cargo test --test integration
    Finished test [optimized + debuginfo] target(s) in 0.07s
     Running tests/integration.rs (target/thumbv7em-none-eabihf/debug/deps/integration-1421b1a08557c90d)
     Erasing sectors ✔ [00:00:00] [######################################] 12.00 KiB/12.00 KiB @ 23.35 KiB/s (eta 0s )
 Programming pages   ✔ [00:00:00] [######################################] 12.00 KiB/12.00 KiB @ 26.45 KiB/s (eta 0s )    Finished in 0.993s
(1/4) running `it_works`...
(2/4) running `it_works2`...
(3/4) running `it_works3`...
(4/4) running `it_works4`...
all tests passed!

Panic:

$ cargo test --test integration
   Compiling krate v0.1.0 (/home/urhengulas/Documents/github.com/knurling-rs/krate)
    Finished test [optimized + debuginfo] target(s) in 0.17s
     Running tests/integration.rs (target/thumbv7em-none-eabihf/debug/deps/integration-1421b1a08557c90d)
     Erasing sectors ✔ [00:00:00] [######################################] 12.00 KiB/12.00 KiB @ 27.83 KiB/s (eta 0s )
 Programming pages   ✔ [00:00:00] [######################################] 12.00 KiB/12.00 KiB @ 30.35 KiB/s (eta 0s )    Finished in 0.852s
(1/4) running `it_works`...
(2/4) running `it_works2`...
(3/4) running `it_works3`...
ERROR panicked at 'assertion failed: false'
└─ integration::tests::it_works3 @ tests/integration.rs:24  
Frame 0: exp_u128 @ 0x00001b70
Frame 1: __udf @ 0x00000afe inline
       ./asm/lib.rs:48:1
Frame 2: __udf @ 0x0000000000000afe
       ./asm/lib.rs:51:17
Frame 3: udf @ 0x000002ee inline
       /home/urhengulas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cortex-m-0.7.7/src/asm.rs:43:5
Frame 4: panic @ 0x00000000000002ea
       /home/urhengulas/Documents/github.com/knurling-rs/krate/src/lib.rs:13:5
Frame 5: panic @ 0x000002c8 inline
       /home/urhengulas/.cargo/git/checkouts/defmt-7f5b74b4e6ff55d4/e36e12a/defmt/src/export/mod.rs:133:14
Frame 6: it_works3 @ 0x00000000000002c4 inline
       /home/urhengulas/Documents/github.com/knurling-rs/krate/tests/integration.rs:24:9
Frame 7: __defmt_test_entry @ 0x00000000000002a6
       /home/urhengulas/Documents/github.com/knurling-rs/krate/tests/integration.rs:8:1
Frame 8: fmt @ 0x0000013c
Frame 9: fmt @ 0x0000013c
Error: CPU halted unexpectedly.
error: test failed, to rerun pass `--test integration`

Caused by:
  process didn't exit successfully: `probe-rs run --chip nRF52840_xxAA /home/urhengulas/Documents/github.com/knurling-rs/krate/target/thumbv7em-none-eabihf/debug/deps/integration-1421b1a08557c90d` (exit status: 1)

I think the error case the stack trace should not be printed either, should it? probe-run does print the backtrace as well. And in case the test does not panic explicitly the backtrace is probably also quite useful.

@Urhengulas
Copy link
Member Author

probe-run does print ERROR the program panicked instead of Error: CPU halted unexpectedly.. Which I think is better. But I feel this is a separate topic of "Make probe-rs detect panics".

@Urhengulas
Copy link
Member Author

@jonathanpallant Can I merge?

@Urhengulas
Copy link
Member Author

I have to say that the probe-run backtrace actually looks better.

probe-run:

ERROR panicked at src/lib.rs:25:5:
OMG!!!
└─ panic_probe::print_defmt::print @ /home/urhengulas/.cargo/git/checkouts/defmt-7f5b74b4e6ff55d4/e36e12a/firmware/panic-probe/src/lib.rs:104
────────────────────────────────────────────────────────────────────────────────
stack backtrace:
   0: HardFaultTrampoline
      <exception entry>
   1: lib::inline::__udf
        at ./asm/inline.rs:181:5
   2: __udf
        at ./asm/lib.rs:51:17
   3: cortex_m::asm::udf
        at /home/urhengulas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cortex-m-0.7.7/src/asm.rs:43:5
   4: panic_probe::hard_fault
        at /home/urhengulas/.cargo/git/checkouts/defmt-7f5b74b4e6ff55d4/e36e12a/firmware/panic-probe/src/lib.rs:86:5
   5: rust_begin_unwind
        at /home/urhengulas/.cargo/git/checkouts/defmt-7f5b74b4e6ff55d4/e36e12a/firmware/panic-probe/src/lib.rs:54:9
   6: core::panicking::panic_fmt
        at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/panicking.rs:67:14
   7: krate::abc
        at src/lib.rs:25:5
   8: main
        at tests/integration.rs:8:1
   9: Reset
(HOST) ERROR the program panicked

probe-rs

ERROR panicked at src/lib.rs:25:5:
OMG!!!
└─ panic_probe::print_defmt::print @ /home/urhengulas/.cargo/git/checkouts/defmt-7f5b74b4e6ff55d4/e36e12a/firmware/panic-probe/src/lib.rs:104 
Frame 0: exp_u128 @ 0x00001bfc
Frame 1: __udf @ 0x00000b8c inline
       ./asm/lib.rs:48:1
Frame 2: __udf @ 0x0000000000000b8c
       ./asm/lib.rs:51:17
Frame 3: udf @ 0x00000410 inline
       /home/urhengulas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cortex-m-0.7.7/src/asm.rs:43:5
Frame 4: hard_fault @ 0x000000000000040c
       /home/urhengulas/.cargo/git/checkouts/defmt-7f5b74b4e6ff55d4/e36e12a/firmware/panic-probe/src/lib.rs:86:5
Frame 5: panic @ 0x000003f6
       /home/urhengulas/.cargo/git/checkouts/defmt-7f5b74b4e6ff55d4/e36e12a/firmware/panic-probe/src/lib.rs:54:9
Frame 6: exp_u128 @ 0x00000d1a
       /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/num/bignum.rs:195:17
Frame 7: abc @ 0x00000372
       /home/urhengulas/Documents/github.com/knurling-rs/krate/src/lib.rs:25:5
Frame 8: __defmt_test_entry @ 0x000002ac
       /home/urhengulas/Documents/github.com/knurling-rs/krate/tests/integration.rs:8:1
Frame 9: fmt @ 0x0000013c
Frame 10: fmt @ 0x0000013c
Error: CPU halted unexpectedly.

@Urhengulas
Copy link
Member Author

@jonathanpallant Can I merge?

I will just go ahead.

@Urhengulas Urhengulas added this pull request to the merge queue Oct 11, 2023
Merged via the queue into main with commit df760c6 Oct 11, 2023
14 checks passed
@Urhengulas Urhengulas deleted the defmt-test-semihosting-exit branch October 11, 2023 17:42
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