Skip to content

Commit b70c63a

Browse files
committed
seperated hotpatch test types, improved tests
1 parent 2f1ced7 commit b70c63a

File tree

4 files changed

+96
-32
lines changed

4 files changed

+96
-32
lines changed
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// hotpatch has two requirements:
2+
// 1. the first instruction of a functin must be at least two bytes long
3+
// 2. there must not be a jump to the first instruction
4+
5+
// the functions in this file already fulfill the conditions so hotpatch should not affect them
6+
7+
// --------------------------------------------------------------------------------------------
8+
9+
#[no_mangle]
10+
#[inline(never)]
11+
pub fn return_42() -> i32 {
12+
42
13+
}
14+
15+
// --------------------------------------------------------------------------------------------
16+
// This tailcall does not jump to the first instruction so hotpatch should leave it unaffected
17+
18+
#[no_mangle]
19+
pub fn tailcall(a: i32) -> i32 {
20+
if a > 10000 {
21+
return a;
22+
}
23+
24+
if a % 2 == 0 { tailcall(a / 2) } else { tailcall(a * 3 + 1) }
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Check if hotpatch leaves the functions that are already hotpatchable untouched
2+
3+
//@ revisions: x32 x64
4+
//@[x32] only-x86
5+
//@[x64] only-x86_64
6+
// Reason: hotpatch is only implemented for X86
7+
8+
use run_make_support::{assertion_helpers, llvm, rustc};
9+
10+
fn main() {
11+
let disassemble_symbols_arg = "--disassemble-symbols=return_42,tailcall";
12+
13+
rustc().input("lib.rs").crate_name("regular").crate_type("lib").opt_level("3").run();
14+
15+
let regular_dump = llvm::llvm_objdump()
16+
.arg(disassemble_symbols_arg)
17+
.input("libregular.rlib")
18+
.run()
19+
.stdout_utf8();
20+
21+
rustc()
22+
.input("lib.rs")
23+
.crate_name("hotpatch")
24+
.crate_type("lib")
25+
.opt_level("3")
26+
.arg("-Zhotpatch")
27+
.run();
28+
29+
let hotpatch_dump = llvm::llvm_objdump()
30+
.arg(disassemble_symbols_arg)
31+
.input("libhotpatch.rlib")
32+
.run()
33+
.stdout_utf8();
34+
35+
{
36+
let mut lines_regular = regular_dump.lines();
37+
let mut lines_hotpatch = hotpatch_dump.lines();
38+
39+
loop {
40+
match (lines_regular.next(), lines_hotpatch.next()) {
41+
(None, None) => break,
42+
(Some(r), Some(h)) => {
43+
if r.contains("libregular.rlib") {
44+
assertion_helpers::assert_contains(h, "libhotpatch.rlib")
45+
} else {
46+
assertion_helpers::assert_equals(&r, &h)
47+
}
48+
}
49+
_ => panic!("the files should have equal length"),
50+
}
51+
}
52+
}
53+
}

tests/run-make/hotpatch/lib.rs

+8-25
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// so its important to check that those are
99
// unneccessarily affected
1010

11-
// ------------------------------------------------------------------------------------------------
11+
// ----------------------------------------------------------------------------------------------
1212

1313
// regularly this tailcall would jump to the first instruction the function
1414
// CHECK-LABEL: <tailcall_fn>:
@@ -27,38 +27,21 @@ pub fn tailcall_fn() {
2727
}
2828
}
2929

30-
// ------------------------------------------------------------------------------------------------
30+
// ----------------------------------------------------------------------------------------------
3131

32-
// empty_fn just returns. Note that 'ret' is a single byte instruction, but hotpatch requires a two
33-
// or more byte instructions to be at the start of the functions.
32+
// empty_fn just returns. Note that 'ret' is a single byte instruction, but hotpatch requires
33+
// a two or more byte instructions to be at the start of the functions.
3434
// Preferably we would also tests a different single byte instruction,
3535
// but I was not able to make rustc emit anything but 'ret'.
3636

37+
// check that if the first instruction is just a single byte, so our test is valid
3738
// CHECK-LABEL: <empty_fn>:
38-
// CHECK-NEXT: ret
39+
// CHECK-NOT: 0: {{[0-9a-f][0-9a-f]}} {{[0-9a-f][0-9a-f]}} {{.*}}
3940

41+
// check that the first instruction is at least 2 bytes long
4042
// HOTPATCH-LABEL: <empty_fn>:
41-
// HOTPATCH-NOT: ret
42-
// HOTPATCH: ret
43+
// HOTPATCH-NEXT: 0: {{[0-9a-f][0-9a-f]}} {{[0-9a-f][0-9a-f]}} {{.*}}
4344

4445
#[no_mangle]
4546
#[inline(never)]
4647
pub fn empty_fn() {}
47-
48-
// ------------------------------------------------------------------------------------------------
49-
50-
// return_42 should not be affected by hotpatch
51-
52-
// CHECK-LABEL: <return_42>:
53-
// CHECK-NEXT: 0:
54-
// CHECK-NEXT: ret
55-
56-
// HOTPATCH-LABEL: <return_42>:
57-
// HOTPATCH-NEXT: 0:
58-
// HOTPATCH-NEXT: ret
59-
60-
#[no_mangle]
61-
#[inline(never)]
62-
pub fn return_42() -> i32 {
63-
42
64-
}

tests/run-make/hotpatch/rmake.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@
77
//@[x64] only-x86_64
88
// Reason: hotpatch is only implemented for X86
99

10-
use run_make_support::{llvm, rfs, rustc};
10+
use run_make_support::{llvm, rustc};
1111

1212
fn main() {
13+
let disassemble_symbols_arg = "--disassemble-symbols=tailcall_fn,empty_fn";
1314
{
1415
rustc().input("lib.rs").crate_name("regular").crate_type("lib").opt_level("3").run();
1516

1617
let regular_dump = llvm::llvm_objdump()
17-
.arg("--disassemble-symbols=tailcall_fn,empty_fn,return_42")
18+
.arg(disassemble_symbols_arg)
1819
.input("libregular.rlib")
19-
.run();
20+
.run()
21+
.stdout_utf8();
2022

21-
llvm::llvm_filecheck().patterns("lib.rs").stdin_buf(regular_dump.stdout_utf8()).run();
23+
llvm::llvm_filecheck().patterns("lib.rs").stdin_buf(regular_dump).run();
2224
}
2325

2426
{
@@ -31,14 +33,15 @@ fn main() {
3133
.run();
3234

3335
let hotpatch_dump = llvm::llvm_objdump()
34-
.arg("--disassemble-symbols=tailcall_fn,empty_fn,return_42")
36+
.arg(disassemble_symbols_arg)
3537
.input("libhotpatch.rlib")
36-
.run();
38+
.run()
39+
.stdout_utf8();
3740

3841
llvm::llvm_filecheck()
3942
.patterns("lib.rs")
4043
.check_prefix("HOTPATCH")
41-
.stdin_buf(hotpatch_dump.stdout_utf8())
44+
.stdin_buf(hotpatch_dump)
4245
.run();
4346
}
4447
}

0 commit comments

Comments
 (0)