Skip to content

Commit 070e838

Browse files
committed
Simplify test and make it more reliable
The new `rmake`-content asserts the exact assembly sequence for the loop preventing false-negatives if some instructions would change and thus the label offset might need to change.
1 parent bf794c0 commit 070e838

File tree

2 files changed

+30
-21
lines changed

2 files changed

+30
-21
lines changed

tests/run-make/avr-rjmp-offset/avr-rjmp-offsets.rs

+3-16
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
//! This test case is a `#![no_core]`-version of the MVCE presented in #129301.
22
//!
3-
//! The function [`delay()`] is minimized and does not actually contain a loop
4-
//! in order to remove the need for additional lang items.
5-
#![feature(no_core, lang_items, intrinsics, rustc_attrs, asm_experimental_arch)]
3+
//! The function [`delay()`] is removed, as it is not necessary to trigger the
4+
//! wrong behavior and would require some additional lang items.
5+
#![feature(no_core, lang_items, intrinsics, rustc_attrs)]
66
#![no_core]
77
#![no_main]
88

9-
#[rustc_builtin_macro]
10-
macro_rules! asm {
11-
() => {};
12-
}
13-
149
use minicore::ptr;
1510

1611
#[no_mangle]
@@ -22,18 +17,10 @@ pub fn main() -> ! {
2217
// sions did place it after the first loop instruction, causing unsoundness)
2318
loop {
2419
unsafe { ptr::write_volatile(port_b, 1) };
25-
delay(500_0000);
2620
unsafe { ptr::write_volatile(port_b, 2) };
27-
delay(500_0000);
2821
}
2922
}
3023

31-
#[inline(never)]
32-
#[no_mangle]
33-
fn delay(_: u32) {
34-
unsafe { asm!("nop") };
35-
}
36-
3724
// FIXME: replace with proper minicore once available (#130693)
3825
mod minicore {
3926
#[lang = "sized"]

tests/run-make/avr-rjmp-offset/rmake.rs

+27-5
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,31 @@ fn main() {
1919
.output("compiled")
2020
.run();
2121

22-
llvm_objdump()
23-
.disassemble()
24-
.input("compiled")
25-
.run()
26-
.assert_stdout_contains_regex(r"rjmp.*\.-14");
22+
let disassembly = llvm_objdump().disassemble().input("compiled").run().stdout_utf8();
23+
24+
// search for the following instruction sequence:
25+
// ```disassembly
26+
// 00000080 <main>:
27+
// 80: 81 e0 ldi r24, 0x1
28+
// 82: 92 e0 ldi r25, 0x2
29+
// 84: 85 b9 out 0x5, r24
30+
// 86: 95 b9 out 0x5, r25
31+
// 88: fd cf rjmp .-6
32+
// ```
33+
// This matches on all instructions, since the size of the instructions be-
34+
// fore the relative jump has an impact on the label offset. Old versions
35+
// of the Rust compiler did produce a label `rjmp .-4` (misses the first
36+
// instruction in the loop).
37+
disassembly
38+
.trim()
39+
.lines()
40+
.skip_while(|&line| !line.contains("<main>"))
41+
.skip(1)
42+
.zip(["ldi\t", "ldi\t", "out\t", "out\t", "rjmp\t.-6"])
43+
.for_each(|(line, expected_instruction)| {
44+
assert!(
45+
line.contains(expected_instruction),
46+
"expected instruction `{expected_instruction}`, got `{line}`"
47+
);
48+
});
2749
}

0 commit comments

Comments
 (0)