diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 00000000..35049cbc --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,2 @@ +[alias] +xtask = "run --package xtask --" diff --git a/Cargo.lock b/Cargo.lock index 522983f4..a0fc5cf2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -152,9 +152,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "4.2.7" +version = "4.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34d21f9bf1b425d2968943631ec91202fe5e837264063503708b83013f8fc938" +checksum = "ca8f255e4b8027970e78db75e78831229c9815fdbfa67eb1a1b777a62e24b4a0" dependencies = [ "clap_builder", "clap_derive", @@ -163,9 +163,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.2.7" +version = "4.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "914c8c79fb560f238ef6429439a30023c862f7a28e688c58f7203f12b29970bd" +checksum = "acd4f3c17c83b0ba34ffbc4f8bbd74f079413f747f84a6f89292f138057e36ab" dependencies = [ "anstream", "anstyle", @@ -176,9 +176,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.2.0" +version = "4.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9644cd56d6b87dbe899ef8b053e331c0637664e9e21a33dfcdc36093f5c5c4" +checksum = "b8cd2b2a819ad6eec39e8f1d6b53001af1e5469f8c177579cdaeb313115b825f" dependencies = [ "heck", "proc-macro2", @@ -188,9 +188,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a2dd5a6fe8c6e3502f568a6353e5273bbb15193ad9a89e457b9970798efbea1" +checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" [[package]] name = "colorchoice" @@ -1427,6 +1427,13 @@ dependencies = [ "tap", ] +[[package]] +name = "xtask" +version = "0.1.0" +dependencies = [ + "clap", +] + [[package]] name = "yaml-rust" version = "0.4.5" diff --git a/Cargo.toml b/Cargo.toml index 972ef466..81f91a96 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,3 +40,6 @@ serial_test = { version = "2", default-features = false } [features] ftdi = ["probe-rs/ftdi"] + +[workspace] +members = [".", "xtask"] diff --git a/src/dep/cratesio.rs b/src/dep/cratesio.rs index 0c345b75..687f4eaa 100644 --- a/src/dep/cratesio.rs +++ b/src/dep/cratesio.rs @@ -35,7 +35,9 @@ impl<'p> Path<'p> { registry_prefix.push(src); let github = super::get_component_normal(components.next()?)?.to_str()?; - if !github.starts_with("github.com-") { + // Rust 1.52 uses "github.com" + // Rust 1.70 uses "index.crates.io" + if !(github.starts_with("github.com-") || github.starts_with("index.crates.io-")) { return None; } registry_prefix.push(github); diff --git a/src/dep/mod.rs b/src/dep/mod.rs index 563ff689..5f49e5b8 100644 --- a/src/dep/mod.rs +++ b/src/dep/mod.rs @@ -53,10 +53,9 @@ impl<'p> Path<'p> { } fn get_component_normal(component: Component) -> Option<&OsStr> { - if let Component::Normal(string) = component { - Some(string) - } else { - None + match component { + Component::Normal(string) => Some(string), + _ => None, } } diff --git a/tests/snapshot.rs b/tests/snapshot.rs index 5891565e..e2a8b35e 100644 --- a/tests/snapshot.rs +++ b/tests/snapshot.rs @@ -62,7 +62,7 @@ fn run_and_terminate(args: &str, timeout_s: u64) -> RunResult { fn run_command(args: &str) -> (os_pipe::PipeReader, std::process::Child) { // add prefix to run this repository's version of `probe-run` and // remove user-dependent registry and rustc information from backtrace paths - let cmd = format!("run -- --chip nRF52840_xxAA tests/test_elfs/{args} --shorten-paths"); + let cmd = format!("run -- --chip nRF52840_xxAA tests/test_elfs/cache/{args} --shorten-paths"); let (reader, writer) = pipe().unwrap(); let writer_clone = writer.try_clone().unwrap(); diff --git a/tests/snapshots/snapshot__case_3_successful_run_can_enforce_backtrace.snap b/tests/snapshots/snapshot__case_3_successful_run_can_enforce_backtrace.snap index 3570b3ef..37619e5d 100644 --- a/tests/snapshots/snapshot__case_3_successful_run_can_enforce_backtrace.snap +++ b/tests/snapshots/snapshot__case_3_successful_run_can_enforce_backtrace.snap @@ -1,6 +1,6 @@ --- source: tests/snapshot.rs -assertion_line: 113 +assertion_line: 114 expression: run_result.output --- @@ -14,12 +14,14 @@ stack backtrace: at ./asm/inline.rs:14:5 1: __bkpt at ./asm/lib.rs:51:17 - 2: app::exit - at /tmp/app/src/lib.rs:17:5 - 3: hello::__cortex_m_rt_main - at /tmp/app/src/bin/hello.rs:10:5 - 4: main - at /tmp/app/src/bin/hello.rs:6:1 - 5: Reset + 2: cortex_m::asm::bkpt + at [cortex-m-0.7.7]/src/call_asm.rs:19:21 + 3: test_elfs::exit + at /test_elfs/src/lib.rs:18:9 + 4: hello::__cortex_m_rt_main + at /test_elfs/src/bin/hello.rs:10:5 + 5: main + at /test_elfs/src/bin/hello.rs:6:1 + 6: Reset (HOST) INFO device halted without error diff --git a/tests/snapshots/snapshot__case_4_stack_overflow_is_reported_as_such.snap b/tests/snapshots/snapshot__case_4_stack_overflow_is_reported_as_such.snap index 767d3fcb..3973e04d 100644 --- a/tests/snapshots/snapshot__case_4_stack_overflow_is_reported_as_such.snap +++ b/tests/snapshots/snapshot__case_4_stack_overflow_is_reported_as_such.snap @@ -7,23 +7,24 @@ expression: run_result.output (HOST) INFO flashing program (2 pages / 8.00 KiB) (HOST) INFO success! ──────────────────────────────────────────────────────────────────────────────── -ack(m=10, n=10, SP=2003bb98) -ack(m=10, n=9, SP=20037b78) -ack(m=10, n=8, SP=20033b58) -ack(m=10, n=7, SP=2002fb38) -ack(m=10, n=6, SP=2002bb18) -ack(m=10, n=5, SP=20027af8) -ack(m=10, n=4, SP=20023ad8) -ack(m=10, n=3, SP=2001fab8) -ack(m=10, n=2, SP=2001ba98) -ack(m=10, n=1, SP=20017a78) -ack(m=10, n=0, SP=20013a58) -ack(m=9, n=1, SP=2000fa38) -ack(m=9, n=0, SP=2000ba18) -ack(m=8, n=1, SP=200079f8) -ack(m=8, n=0, SP=200039d8) +ack(m=10, n=10, SP=0x2003bfd4) +ack(m=10, n=9, SP=0x20037fb4) +ack(m=10, n=8, SP=0x20033f94) +ack(m=10, n=7, SP=0x2002ff74) +ack(m=10, n=6, SP=0x2002bf54) +ack(m=10, n=5, SP=0x20027f34) +ack(m=10, n=4, SP=0x20023f14) +ack(m=10, n=3, SP=0x2001fef4) +ack(m=10, n=2, SP=0x2001bed4) +ack(m=10, n=1, SP=0x20017eb4) +ack(m=10, n=0, SP=0x20013e94) +ack(m=9, n=1, SP=0x2000fe74) +ack(m=9, n=0, SP=0x2000be54) +ack(m=8, n=1, SP=0x20007e34) +ack(m=8, n=0, SP=0x20003e14) ──────────────────────────────────────────────────────────────────────────────── (HOST) WARN program has used at least 240.62/254.93 KiB (94.4%) of stack space +(HOST) WARN data segments might be corrupted due to stack overflow stack backtrace: 0: HardFaultTrampoline diff --git a/tests/snapshots/snapshot__case_5_panic_is_reported_as_such.snap b/tests/snapshots/snapshot__case_5_panic_is_reported_as_such.snap index fe659bf4..0bcd8e8c 100644 --- a/tests/snapshots/snapshot__case_5_panic_is_reported_as_such.snap +++ b/tests/snapshots/snapshot__case_5_panic_is_reported_as_such.snap @@ -1,6 +1,6 @@ --- source: tests/snapshot.rs -assertion_line: 113 +assertion_line: 114 expression: run_result.output --- @@ -17,15 +17,15 @@ stack backtrace: 2: __udf at ./asm/lib.rs:51:17 3: cortex_m::asm::udf - at [cortex-m-0.7.7]/src/asm.rs:43:5 + at [cortex-m-0.7.7]/src/call_asm.rs:19:21 4: _defmt_panic - at /tmp/app/src/lib.rs:12:5 + at /test_elfs/src/lib.rs:12:5 5: defmt::export::panic - at [defmt-0.3.2]/src/export/mod.rs:133:14 + at [defmt-0.3.4]/src/export/mod.rs:133:14 6: panic::__cortex_m_rt_main - at /tmp/app/src/bin/panic.rs:8:5 + at /test_elfs/src/bin/panic.rs:8:5 7: main - at /tmp/app/src/bin/panic.rs:6:1 + at /test_elfs/src/bin/panic.rs:6:1 8: Reset (HOST) ERROR the program panicked diff --git a/tests/snapshots/snapshot__case_6_panic_verbose.snap b/tests/snapshots/snapshot__case_6_panic_verbose.snap index 545c83a0..47237df7 100644 --- a/tests/snapshots/snapshot__case_6_panic_verbose.snap +++ b/tests/snapshots/snapshot__case_6_panic_verbose.snap @@ -1,90 +1,84 @@ --- source: tests/snapshot.rs -assertion_line: 113 +assertion_line: 114 expression: run_result.output --- -(HOST) DEBUG vector table: VectorTable { initial_stack_pointer: 2003fbc0, hard_fault: 17d3 } -(HOST) DEBUG RAM region: 0x20000000-0x2003FFFF -(HOST) DEBUG section `.data` is in RAM at 0x2003FBC0..=0x2003FBF7 -(HOST) DEBUG section `.bss` is in RAM at 0x2003FBF8..=0x2003FBFF -(HOST) DEBUG section `.uninit` is in RAM at 0x2003FC00..=0x2003FFFF -(HOST) DEBUG valid SP range: 0x20000000..=0x2003FBBC (HOST) DEBUG found 1 probes (HOST) DEBUG opened probe (HOST) DEBUG started session (HOST) INFO flashing program (2 pages / 8.00 KiB) -(HOST) DEBUG Erased sector of size 4096 bytes in 121 ms -(HOST) DEBUG Erased sector of size 4096 bytes in 99 ms -(HOST) DEBUG Programmed page of size 4096 bytes in 62 ms -(HOST) DEBUG Programmed page of size 4096 bytes in 62 ms +(HOST) DEBUG Erased sector of size 4096 bytes in 120 ms +(HOST) DEBUG Erased sector of size 4096 bytes in 98 ms +(HOST) DEBUG Programmed page of size 4096 bytes in 61 ms +(HOST) DEBUG Programmed page of size 4096 bytes in 63 ms (HOST) INFO success! -(HOST) DEBUG 261052 bytes of stack available (0x20000000 ..= 0x2003FBBC), using 1024 byte canary -(HOST) TRACE setting up canary took 0.020s (51.19 KiB/s) +(HOST) DEBUG vector table: VectorTable { initial_stack_pointer: 2003fbc0, hard_fault: 1771 } +(HOST) DEBUG RAM region: 0x20000000-0x2003FFFF +(HOST) DEBUG section `.data` is in RAM at 0x2003FBC0..=0x2003FBF7 +(HOST) DEBUG section `.bss` is in RAM at 0x2003FBF8..=0x2003FBFF +(HOST) DEBUG section `.uninit` is in RAM at 0x2003FC00..=0x2003FFFF +(HOST) DEBUG valid SP range: 0x20000000..=0x2003FBBC +(HOST) DEBUG 261052 bytes of stack available (0x20000000 ..= 0x2003FBBC), using 26108 byte canary +(HOST) TRACE setting up canary took 0.022s (1162.52 KiB/s) (HOST) DEBUG starting device (HOST) DEBUG Successfully attached RTT ──────────────────────────────────────────────────────────────────────────────── ERROR panicked at 'explicit panic' ──────────────────────────────────────────────────────────────────────────────── -(HOST) TRACE reading canary took 0.024s (41.48 KiB/s) +(HOST) TRACE reading canary took 0.023s (1131.21 KiB/s) (HOST) DEBUG stack canary intact -(HOST) TRACE 0x000017d2: found FDE for 0x000017d2 .. 0x000017ea at offset 5672 -(HOST) TRACE uwt row for pc 0x000017d2: UnwindTableRow { start_address: 6098, end_address: 6122, saved_args_size: 0, cfa: RegisterAndOffset { register: Register(13), offset: 0 }, registers: RegisterRuleMap { rules: [] } } -(HOST) DEBUG LR=0xFFFFFFF9 PC=0x000017D2 -(HOST) TRACE 0x0000025a: found FDE for 0x0000025a .. 0x0000025e at offset 6632 -(HOST) TRACE uwt row for pc 0x0000025a: UnwindTableRow { start_address: 602, end_address: 606, saved_args_size: 0, cfa: RegisterAndOffset { register: Register(13), offset: 0 }, registers: RegisterRuleMap { rules: [] } } -(HOST) DEBUG LR=0x00000195 PC=0x0000025A -(HOST) TRACE 0x00000194: found FDE for 0x0000018c .. 0x00000196 at offset 96 -(HOST) TRACE uwt row for pc 0x00000194: UnwindTableRow { start_address: 400, end_address: 406, saved_args_size: 0, cfa: RegisterAndOffset { register: Register(7), offset: 8 }, registers: RegisterRuleMap { rules: [(Register(14), Offset(-4)), (Register(7), Offset(-8))] } } -(HOST) DEBUG update_cfa: CFA changed Some(2003fb98) -> 2003fba0 -(HOST) TRACE update reg=Register(14), rule=Offset(-4), abs=0x2003fb9c -> value=0x0000019f -(HOST) TRACE update reg=Register(7), rule=Offset(-8), abs=0x2003fb98 -> value=0x2003fba0 -(HOST) DEBUG LR=0x0000019F PC=0x00000194 -(HOST) TRACE 0x0000019e: found FDE for 0x00000196 .. 0x000001a0 at offset 152 -(HOST) TRACE uwt row for pc 0x0000019e: UnwindTableRow { start_address: 410, end_address: 416, saved_args_size: 0, cfa: RegisterAndOffset { register: Register(7), offset: 8 }, registers: RegisterRuleMap { rules: [(Register(14), Offset(-4)), (Register(7), Offset(-8))] } } -(HOST) DEBUG update_cfa: CFA changed Some(2003fba0) -> 2003fba8 -(HOST) TRACE update reg=Register(14), rule=Offset(-4), abs=0x2003fba4 -> value=0x0000018b -(HOST) TRACE update reg=Register(7), rule=Offset(-8), abs=0x2003fba0 -> value=0x2003fbb0 -(HOST) DEBUG LR=0x0000018B PC=0x0000019E -(HOST) TRACE 0x0000018a: found FDE for 0x00000162 .. 0x0000018c at offset 48 -(HOST) TRACE uwt row for pc 0x0000018a: UnwindTableRow { start_address: 358, end_address: 396, saved_args_size: 0, cfa: RegisterAndOffset { register: Register(7), offset: 8 }, registers: RegisterRuleMap { rules: [(Register(14), Offset(-4)), (Register(7), Offset(-8))] } } -(HOST) DEBUG update_cfa: CFA changed Some(2003fba8) -> 2003fbb8 +(HOST) TRACE 0x00001770: found FDE for 0x00001770 .. 0x00001788 at offset 20 +(HOST) TRACE uwt row for pc 0x00001770: UnwindTableRow { start_address: 6000, end_address: 6024, saved_args_size: 0, cfa: RegisterAndOffset { register: Register(13), offset: 0 }, registers: RegisterRuleMap { rules: [] } } +(HOST) DEBUG LR=0xFFFFFFF9 PC=0x00001770 +(HOST) TRACE 0x00001620: found FDE for 0x00001620 .. 0x00001624 at offset 1388 +(HOST) TRACE uwt row for pc 0x00001620: UnwindTableRow { start_address: 5664, end_address: 5668, saved_args_size: 0, cfa: RegisterAndOffset { register: Register(13), offset: 0 }, registers: RegisterRuleMap { rules: [] } } +(HOST) DEBUG LR=0x00001611 PC=0x00001620 +(HOST) TRACE 0x00001610: found FDE for 0x00001608 .. 0x00001612 at offset 1084 +(HOST) TRACE uwt row for pc 0x00001610: UnwindTableRow { start_address: 5644, end_address: 5650, saved_args_size: 0, cfa: RegisterAndOffset { register: Register(7), offset: 8 }, registers: RegisterRuleMap { rules: [(Register(14), Offset(-4)), (Register(7), Offset(-8))] } } +(HOST) DEBUG update_cfa: CFA changed Some(2003fba8) -> 2003fbb0 +(HOST) TRACE update reg=Register(14), rule=Offset(-4), abs=0x2003fbac -> value=0x0000017f +(HOST) TRACE update reg=Register(7), rule=Offset(-8), abs=0x2003fba8 -> value=0x2003fbb0 +(HOST) DEBUG LR=0x0000017F PC=0x00001610 +(HOST) TRACE 0x0000017e: found FDE for 0x00000162 .. 0x00000180 at offset 80 +(HOST) TRACE uwt row for pc 0x0000017e: UnwindTableRow { start_address: 358, end_address: 384, saved_args_size: 0, cfa: RegisterAndOffset { register: Register(7), offset: 8 }, registers: RegisterRuleMap { rules: [(Register(14), Offset(-4)), (Register(7), Offset(-8))] } } +(HOST) DEBUG update_cfa: CFA changed Some(2003fbb0) -> 2003fbb8 (HOST) TRACE update reg=Register(14), rule=Offset(-4), abs=0x2003fbb4 -> value=0x00000161 (HOST) TRACE update reg=Register(7), rule=Offset(-8), abs=0x2003fbb0 -> value=0x2003fbb8 -(HOST) DEBUG LR=0x00000161 PC=0x0000018A -(HOST) TRACE 0x00000160: found FDE for 0x00000158 .. 0x00000162 at offset 20 +(HOST) DEBUG LR=0x00000161 PC=0x0000017E +(HOST) TRACE 0x00000160: found FDE for 0x00000158 .. 0x00000162 at offset 52 (HOST) TRACE uwt row for pc 0x00000160: UnwindTableRow { start_address: 348, end_address: 354, saved_args_size: 0, cfa: RegisterAndOffset { register: Register(7), offset: 8 }, registers: RegisterRuleMap { rules: [(Register(14), Offset(-4)), (Register(7), Offset(-8))] } } (HOST) DEBUG update_cfa: CFA changed Some(2003fbb8) -> 2003fbc0 (HOST) TRACE update reg=Register(14), rule=Offset(-4), abs=0x2003fbbc -> value=0x0000013d (HOST) TRACE update reg=Register(7), rule=Offset(-8), abs=0x2003fbb8 -> value=0x00000000 (HOST) DEBUG LR=0x0000013D PC=0x00000160 -(HOST) TRACE 0x0000013c: found FDE for 0x00000100 .. 0x0000013e at offset 5688 +(HOST) TRACE 0x0000013c: found FDE for 0x00000100 .. 0x0000013e at offset 36 (HOST) TRACE uwt row for pc 0x0000013c: UnwindTableRow { start_address: 256, end_address: 318, saved_args_size: 0, cfa: RegisterAndOffset { register: Register(13), offset: 0 }, registers: RegisterRuleMap { rules: [] } } (HOST) DEBUG LR=0x0000013D PC=0x0000013C (HOST) TRACE demangle Ok("_ZN3lib6inline5__udf17ha5cfb7665e0fe90cE") (language=Some(DwLang(1C))) -> Ok("lib::inline::__udf") (HOST) TRACE demangle Ok("__udf") (language=Some(DwLang(1C))) -> Ok("__udf") -(HOST) TRACE demangle Ok("_ZN8cortex_m3asm3udf17he6ff4eef0237912cE") (language=Some(DwLang(1C))) -> Ok("cortex_m::asm::udf") +(HOST) TRACE demangle Ok("_ZN8cortex_m3asm3udf17hf580bd6f648768cdE") (language=Some(DwLang(1C))) -> Ok("cortex_m::asm::udf") (HOST) TRACE demangle Ok("_defmt_panic") (language=Some(DwLang(1C))) -> Ok("_defmt_panic") -(HOST) TRACE demangle Ok("_ZN5defmt6export5panic17hedd7fcdbb5580196E") (language=Some(DwLang(1C))) -> Ok("defmt::export::panic") -(HOST) TRACE demangle Ok("_ZN5panic18__cortex_m_rt_main17haa1cdf94498fcb9aE") (language=Some(DwLang(1C))) -> Ok("panic::__cortex_m_rt_main") +(HOST) TRACE demangle Ok("_ZN5defmt6export5panic17h35131ca09663314fE") (language=Some(DwLang(1C))) -> Ok("defmt::export::panic") +(HOST) TRACE demangle Ok("_ZN5panic18__cortex_m_rt_main17h987df67efcfbeac1E") (language=Some(DwLang(1C))) -> Ok("panic::__cortex_m_rt_main") (HOST) TRACE demangle Ok("main") (language=Some(DwLang(1C))) -> Ok("main") stack backtrace: - 0: 0x000017d2 @ HardFaultTrampoline + 0: 0x00001770 @ HardFaultTrampoline - 1: 0x0000025a @ lib::inline::__udf + 1: 0x00001620 @ lib::inline::__udf at ./asm/inline.rs:181:5 - 2: 0x0000025a @ __udf + 2: 0x00001620 @ __udf at ./asm/lib.rs:51:17 - 3: 0x00000194 @ cortex_m::asm::udf - at [cortex-m-0.7.7]/src/asm.rs:43:5 - 4: 0x0000019e @ _defmt_panic - at /tmp/app/src/lib.rs:12:5 - 5: 0x0000018a @ defmt::export::panic - at [defmt-0.3.2]/src/export/mod.rs:133:14 - 6: 0x0000018a @ panic::__cortex_m_rt_main - at /tmp/app/src/bin/panic.rs:8:5 + 3: 0x00001610 @ cortex_m::asm::udf + at [cortex-m-0.7.7]/src/call_asm.rs:19:21 + 4: 0x00001610 @ _defmt_panic + at /test_elfs/src/lib.rs:12:5 + 5: 0x0000017e @ defmt::export::panic + at [defmt-0.3.4]/src/export/mod.rs:133:14 + 6: 0x0000017e @ panic::__cortex_m_rt_main + at /test_elfs/src/bin/panic.rs:8:5 7: 0x00000160 @ main - at /tmp/app/src/bin/panic.rs:6:1 + at /test_elfs/src/bin/panic.rs:6:1 8: 0x0000013c @ Reset (HOST) ERROR the program panicked diff --git a/tests/snapshots/snapshot__case_8_stack_overflow_can_suppress_backtrace.snap b/tests/snapshots/snapshot__case_8_stack_overflow_can_suppress_backtrace.snap index c3336f2f..6b350fc9 100644 --- a/tests/snapshots/snapshot__case_8_stack_overflow_can_suppress_backtrace.snap +++ b/tests/snapshots/snapshot__case_8_stack_overflow_can_suppress_backtrace.snap @@ -7,22 +7,23 @@ expression: run_result.output (HOST) INFO flashing program (2 pages / 8.00 KiB) (HOST) INFO success! ──────────────────────────────────────────────────────────────────────────────── -ack(m=10, n=10, SP=2003bb98) -ack(m=10, n=9, SP=20037b78) -ack(m=10, n=8, SP=20033b58) -ack(m=10, n=7, SP=2002fb38) -ack(m=10, n=6, SP=2002bb18) -ack(m=10, n=5, SP=20027af8) -ack(m=10, n=4, SP=20023ad8) -ack(m=10, n=3, SP=2001fab8) -ack(m=10, n=2, SP=2001ba98) -ack(m=10, n=1, SP=20017a78) -ack(m=10, n=0, SP=20013a58) -ack(m=9, n=1, SP=2000fa38) -ack(m=9, n=0, SP=2000ba18) -ack(m=8, n=1, SP=200079f8) -ack(m=8, n=0, SP=200039d8) +ack(m=10, n=10, SP=0x2003bfd4) +ack(m=10, n=9, SP=0x20037fb4) +ack(m=10, n=8, SP=0x20033f94) +ack(m=10, n=7, SP=0x2002ff74) +ack(m=10, n=6, SP=0x2002bf54) +ack(m=10, n=5, SP=0x20027f34) +ack(m=10, n=4, SP=0x20023f14) +ack(m=10, n=3, SP=0x2001fef4) +ack(m=10, n=2, SP=0x2001bed4) +ack(m=10, n=1, SP=0x20017eb4) +ack(m=10, n=0, SP=0x20013e94) +ack(m=9, n=1, SP=0x2000fe74) +ack(m=9, n=0, SP=0x2000be54) +ack(m=8, n=1, SP=0x20007e34) +ack(m=8, n=0, SP=0x20003e14) ──────────────────────────────────────────────────────────────────────────────── (HOST) WARN program has used at least 240.62/254.93 KiB (94.4%) of stack space +(HOST) WARN data segments might be corrupted due to stack overflow (HOST) ERROR the program has overflowed its stack diff --git a/tests/snapshots/snapshot__case_9_canary.snap b/tests/snapshots/snapshot__case_9_canary.snap index 614ebe11..3973e04d 100644 --- a/tests/snapshots/snapshot__case_9_canary.snap +++ b/tests/snapshots/snapshot__case_9_canary.snap @@ -7,21 +7,21 @@ expression: run_result.output (HOST) INFO flashing program (2 pages / 8.00 KiB) (HOST) INFO success! ──────────────────────────────────────────────────────────────────────────────── -ack(m=10, n=10, SP=2003bfd8) -ack(m=10, n=9, SP=20037fb8) -ack(m=10, n=8, SP=20033f98) -ack(m=10, n=7, SP=2002ff78) -ack(m=10, n=6, SP=2002bf58) -ack(m=10, n=5, SP=20027f38) -ack(m=10, n=4, SP=20023f18) -ack(m=10, n=3, SP=2001fef8) -ack(m=10, n=2, SP=2001bed8) -ack(m=10, n=1, SP=20017eb8) -ack(m=10, n=0, SP=20013e98) -ack(m=9, n=1, SP=2000fe78) -ack(m=9, n=0, SP=2000be58) -ack(m=8, n=1, SP=20007e38) -ack(m=8, n=0, SP=20003e18) +ack(m=10, n=10, SP=0x2003bfd4) +ack(m=10, n=9, SP=0x20037fb4) +ack(m=10, n=8, SP=0x20033f94) +ack(m=10, n=7, SP=0x2002ff74) +ack(m=10, n=6, SP=0x2002bf54) +ack(m=10, n=5, SP=0x20027f34) +ack(m=10, n=4, SP=0x20023f14) +ack(m=10, n=3, SP=0x2001fef4) +ack(m=10, n=2, SP=0x2001bed4) +ack(m=10, n=1, SP=0x20017eb4) +ack(m=10, n=0, SP=0x20013e94) +ack(m=9, n=1, SP=0x2000fe74) +ack(m=9, n=0, SP=0x2000be54) +ack(m=8, n=1, SP=0x20007e34) +ack(m=8, n=0, SP=0x20003e14) ──────────────────────────────────────────────────────────────────────────────── (HOST) WARN program has used at least 240.62/254.93 KiB (94.4%) of stack space (HOST) WARN data segments might be corrupted due to stack overflow diff --git a/tests/snapshots/snapshot__ctrl_c_by_user_is_reported_as_such.snap b/tests/snapshots/snapshot__ctrl_c_by_user_is_reported_as_such.snap index 60a6f287..f7f5e8c3 100644 --- a/tests/snapshots/snapshot__ctrl_c_by_user_is_reported_as_such.snap +++ b/tests/snapshots/snapshot__ctrl_c_by_user_is_reported_as_such.snap @@ -1,6 +1,6 @@ --- source: tests/snapshot.rs -assertion_line: 123 +assertion_line: 124 expression: run_result.output --- @@ -10,9 +10,9 @@ expression: run_result.output ──────────────────────────────────────────────────────────────────────────────── stack backtrace: 0: silent_loop::__cortex_m_rt_main - at /tmp/app/src/bin/silent-loop.rs:9:5 + at /test_elfs/src/bin/silent-loop.rs:9:5 1: main - at /tmp/app/src/bin/silent-loop.rs:6:1 + at /test_elfs/src/bin/silent-loop.rs:6:1 2: Reset (HOST) INFO device halted by user diff --git a/tests/test_elfs/.gitignore b/tests/test_elfs/.gitignore new file mode 100644 index 00000000..96ef6c0b --- /dev/null +++ b/tests/test_elfs/.gitignore @@ -0,0 +1,2 @@ +/target +Cargo.lock diff --git a/tests/test_elfs/Cargo.toml b/tests/test_elfs/Cargo.toml new file mode 100644 index 00000000..9c24b576 --- /dev/null +++ b/tests/test_elfs/Cargo.toml @@ -0,0 +1,28 @@ +[package] +authors = ["The Knurling-rs developers"] +name = "test_elfs" +edition = "2021" +version = "0.1.0" + +[lib] +harness = false + +[dependencies] +cortex-m = { version = "0.7", features = ["critical-section-single-core"] } +cortex-m-rt = "0.7" +defmt = "0.3" +defmt-rtt = "0.4" +panic-probe = { version = "0.3", features = ["print-defmt"] } +nrf52840-hal = "0.16" + +[workspace] + +# cargo build/run --release +[profile.release] +codegen-units = 1 +debug = 2 +debug-assertions = false # <- +incremental = false +lto = 'fat' +opt-level = 3 # <- +overflow-checks = false # <- diff --git a/tests/test_elfs/cache/hello-raw b/tests/test_elfs/cache/hello-raw new file mode 100755 index 00000000..9cc97723 Binary files /dev/null and b/tests/test_elfs/cache/hello-raw differ diff --git a/tests/test_elfs/cache/hello-rzcobs b/tests/test_elfs/cache/hello-rzcobs new file mode 100755 index 00000000..9cc97723 Binary files /dev/null and b/tests/test_elfs/cache/hello-rzcobs differ diff --git a/tests/test_elfs/cache/overflow-no-flip-link b/tests/test_elfs/cache/overflow-no-flip-link new file mode 100755 index 00000000..e78c528d Binary files /dev/null and b/tests/test_elfs/cache/overflow-no-flip-link differ diff --git a/tests/test_elfs/cache/overflow-rzcobs b/tests/test_elfs/cache/overflow-rzcobs new file mode 100755 index 00000000..e78c528d Binary files /dev/null and b/tests/test_elfs/cache/overflow-rzcobs differ diff --git a/tests/test_elfs/cache/panic-rzcobs b/tests/test_elfs/cache/panic-rzcobs new file mode 100755 index 00000000..4c8abc4e Binary files /dev/null and b/tests/test_elfs/cache/panic-rzcobs differ diff --git a/tests/test_elfs/cache/silent-loop-rzcobs b/tests/test_elfs/cache/silent-loop-rzcobs new file mode 100755 index 00000000..46b0221d Binary files /dev/null and b/tests/test_elfs/cache/silent-loop-rzcobs differ diff --git a/tests/test_elfs/hello-raw b/tests/test_elfs/hello-raw deleted file mode 100755 index 79de2bf6..00000000 Binary files a/tests/test_elfs/hello-raw and /dev/null differ diff --git a/tests/test_elfs/hello-rzcobs b/tests/test_elfs/hello-rzcobs deleted file mode 100755 index 17a6c923..00000000 Binary files a/tests/test_elfs/hello-rzcobs and /dev/null differ diff --git a/tests/test_elfs/overflow-no-flip-link b/tests/test_elfs/overflow-no-flip-link deleted file mode 100755 index 0148b9cd..00000000 Binary files a/tests/test_elfs/overflow-no-flip-link and /dev/null differ diff --git a/tests/test_elfs/overflow-rzcobs b/tests/test_elfs/overflow-rzcobs deleted file mode 100755 index e7ad9196..00000000 Binary files a/tests/test_elfs/overflow-rzcobs and /dev/null differ diff --git a/tests/test_elfs/panic-rzcobs b/tests/test_elfs/panic-rzcobs deleted file mode 100755 index 636c209a..00000000 Binary files a/tests/test_elfs/panic-rzcobs and /dev/null differ diff --git a/tests/test_elfs/silent-loop-rzcobs b/tests/test_elfs/silent-loop-rzcobs deleted file mode 100755 index d1768c1d..00000000 Binary files a/tests/test_elfs/silent-loop-rzcobs and /dev/null differ diff --git a/tests/test_elfs/hello.rs b/tests/test_elfs/src/bin/hello.rs similarity index 52% rename from tests/test_elfs/hello.rs rename to tests/test_elfs/src/bin/hello.rs index 9f2fe57b..899c8d7a 100644 --- a/tests/test_elfs/hello.rs +++ b/tests/test_elfs/src/bin/hello.rs @@ -1,11 +1,11 @@ #![no_main] #![no_std] -use app as _; +use test_elfs as _; // global logger + panicking-behavior + memory layout #[cortex_m_rt::entry] fn main() -> ! { defmt::println!("Hello, world!"); - app::exit() + test_elfs::exit() } diff --git a/tests/test_elfs/overflow.rs b/tests/test_elfs/src/bin/overflow.rs similarity index 84% rename from tests/test_elfs/overflow.rs rename to tests/test_elfs/src/bin/overflow.rs index dd4e7253..d5a1a045 100644 --- a/tests/test_elfs/overflow.rs +++ b/tests/test_elfs/src/bin/overflow.rs @@ -1,12 +1,12 @@ #![no_main] #![no_std] -use app as _; +use test_elfs as _; // global logger + panicking-behavior + memory layout #[cortex_m_rt::entry] fn main() -> ! { ack(10, 10); - app::exit() + test_elfs::exit() } fn ack(m: u32, n: u32) -> u32 { diff --git a/tests/test_elfs/panic.rs b/tests/test_elfs/src/bin/panic.rs similarity index 53% rename from tests/test_elfs/panic.rs rename to tests/test_elfs/src/bin/panic.rs index 5d5e8225..69cedd23 100644 --- a/tests/test_elfs/panic.rs +++ b/tests/test_elfs/src/bin/panic.rs @@ -1,7 +1,7 @@ #![no_main] #![no_std] -use app as _; +use test_elfs as _; // global logger + panicking-behavior + memory layout #[cortex_m_rt::entry] fn main() -> ! { diff --git a/tests/test_elfs/silent-loop.rs b/tests/test_elfs/src/bin/silent-loop.rs similarity index 88% rename from tests/test_elfs/silent-loop.rs rename to tests/test_elfs/src/bin/silent-loop.rs index 761b9d0b..d254861d 100644 --- a/tests/test_elfs/silent-loop.rs +++ b/tests/test_elfs/src/bin/silent-loop.rs @@ -1,7 +1,7 @@ #![no_main] #![no_std] -use app as _; +use test_elfs as _; #[cortex_m_rt::entry] fn main() -> ! { diff --git a/tests/test_elfs/src/lib.rs b/tests/test_elfs/src/lib.rs new file mode 100644 index 00000000..08f1f844 --- /dev/null +++ b/tests/test_elfs/src/lib.rs @@ -0,0 +1,20 @@ +#![no_main] +#![no_std] + +use defmt_rtt as _; // global logger +use nrf52840_hal as _; // memory layout +use panic_probe as _; + +// same panicking *behavior* as `panic-probe` but doesn't print a panic message +// this prevents the panic message being printed *twice* when `defmt::panic` is invoked +#[defmt::panic_handler] +fn panic() -> ! { + cortex_m::asm::udf() +} + +/// Terminates the application and makes `probe-run` exit with exit-code = 0 +pub fn exit() -> ! { + loop { + cortex_m::asm::bkpt(); + } +} diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml new file mode 100644 index 00000000..32add9c5 --- /dev/null +++ b/xtask/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "xtask" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +clap = { version = "4.3", features = ["derive"] } diff --git a/xtask/src/build_elfs.rs b/xtask/src/build_elfs.rs new file mode 100644 index 00000000..ba5ab79d --- /dev/null +++ b/xtask/src/build_elfs.rs @@ -0,0 +1,86 @@ +use std::{env, fs, process::Command}; + +const PATH: &str = "tests/test_elfs"; + +/// Build the various test elfs and copy them to the cache +pub fn run() { + all_bins_rzcobs(); + hello_raw(); + overflow_no_flip_link(); +} + +fn all_bins_rzcobs() { + cargo_build("--bins", true); + + for name in ["hello", "overflow", "panic", "silent-loop"] { + copy(name, &format!("{name}-rzcobs")) + } +} + +fn hello_raw() { + // save state of Cargo.toml, so we can restore it later + let cargo_toml = format!("{PATH}/Cargo.toml"); + let before = fs::read(&cargo_toml).unwrap(); + + // activate feature `encoding-raw` of `defmt` + run_cmd("cargo add defmt --features encoding-raw", ""); + + // build the binary + cargo_build("--bin hello", true); + + // restore Cargo.toml + fs::write(cargo_toml, before).unwrap(); + + copy("hello", "hello-raw"); +} + +fn overflow_no_flip_link() { + cargo_build("--bin overflow", false); + + copy("overflow", "overflow-no-flip-link"); +} + +fn cargo_build(target: &str, flip_link: bool) { + let mut args = "cargo build --release --target thumbv7em-none-eabihf ".to_string(); + args.push_str(target); + + let mut rustflags = + "-C link-arg=-Tlink.x -C link-arg=-Tdefmt.x -C link-arg=--nmagic".to_string(); + + // remap the path + let repo_dir = env::current_dir().unwrap(); + rustflags += &format!( + " --remap-path-prefix {}/{PATH}=/test_elfs", + repo_dir.display() + ); + + if flip_link { + // set flip-link as linker + rustflags += " -C linker=flip-link"; + } + + run_cmd(&args, &rustflags); +} + +/// Copy the binary from the `target/` dir to the cache +fn copy(old_name: &str, new_name: &str) { + run_cmd( + &format!("cp ../../target/thumbv7em-none-eabihf/release/{old_name} cache/{new_name}"), + "", + ); +} + +fn run_cmd(command: &str, rustflags: &str) { + println!("RUN: {command}"); + let mut cmd = command.split(' '); + let success = Command::new(cmd.next().unwrap()) + .args(cmd) + .current_dir(PATH) + .env("RUSTFLAGS", rustflags) + .status() + .unwrap() + .success(); + if !success { + panic!("command failed: {command}"); + } +} diff --git a/xtask/src/main.rs b/xtask/src/main.rs new file mode 100644 index 00000000..bdd898da --- /dev/null +++ b/xtask/src/main.rs @@ -0,0 +1,20 @@ +//! # xtask +//! +//! cargo xtask build-tests + +mod build_elfs; + +use clap::Parser; + +#[derive(Parser)] +#[command(author, version, about, long_about = None)] +enum Command { + /// Rebuild elfs for on-device testing + BuildElfs, +} + +fn main() { + match Command::parse() { + Command::BuildElfs => build_elfs::run(), + } +}