Skip to content

Commit bb8db13

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 ab00841 commit bb8db13

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

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

+3-16
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
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
#![allow(internal_features)]
99

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

1712
#[no_mangle]
@@ -23,18 +18,10 @@ pub fn main() -> ! {
2318
// sions did place it after the first loop instruction, causing unsoundness)
2419
loop {
2520
unsafe { ptr::write_volatile(port_b, 1) };
26-
delay(500_0000);
2721
unsafe { ptr::write_volatile(port_b, 2) };
28-
delay(500_0000);
2922
}
3023
}
3124

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

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

+28-5
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,32 @@ fn main() {
2020
.output("compiled")
2121
.run();
2222

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

0 commit comments

Comments
 (0)