Skip to content

Commit f1f3512

Browse files
committed
test: make sure fmt-write-bloat does not vacuously pass
1 parent a0f398e commit f1f3512

File tree

1 file changed

+66
-12
lines changed

1 file changed

+66
-12
lines changed

tests/run-make/fmt-write-bloat/rmake.rs

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,78 @@
1212
//! present.
1313
//!
1414
//! Some CI jobs try to run faster by disabling debug assertions (through setting
15-
//! `NO_DEBUG_ASSERTIONS=1`). If debug assertions are disabled, then we can check for the absence of
16-
//! additional `usize` formatting and padding related symbols.
15+
//! `NO_DEBUG_ASSERTIONS=1`). If std debug assertions are disabled, then we can check for the
16+
//! absence of additional `usize` formatting and padding related symbols.
17+
18+
// ignore-tidy-linelength
1719

1820
//@ ignore-cross-compile
1921

20-
use run_make_support::artifact_names::bin_name;
22+
use std::path::Path;
23+
2124
use run_make_support::env::std_debug_assertions_enabled;
22-
use run_make_support::rustc;
25+
use run_make_support::llvm::{llvm_filecheck, llvm_pdbutil};
2326
use run_make_support::symbols::object_contains_any_symbol_substring;
27+
use run_make_support::{is_windows_msvc, rfs, rustc};
2428

2529
fn main() {
26-
rustc().input("main.rs").opt().run();
27-
// panic machinery identifiers, these should not appear in the final binary
28-
let mut panic_syms = vec!["panic_bounds_check", "Debug"];
29-
if std_debug_assertions_enabled() {
30-
// if debug assertions are allowed, we need to allow these,
31-
// otherwise, add them to the list of symbols to deny.
32-
panic_syms.extend_from_slice(&["panicking", "panic_fmt", "pad_integral", "Display"]);
30+
let expect_no_panic_symbols = Path::new("expect_no_panic_symbols");
31+
rustc().input("main.rs").output(&expect_no_panic_symbols).opt().run();
32+
33+
let expect_panic_symbols = Path::new("expect_panic_symbols");
34+
rustc().input("main.rs").output(&expect_panic_symbols).run();
35+
36+
if is_windows_msvc() {
37+
// FIXME(#143737): use actual DIA wrappers instead of parsing `llvm-pdbutil` textual output.
38+
39+
let expect_no_filecheck_pattern = r#"
40+
CHECK: main
41+
CHECK-NOT: {{.*}}Display{{.*}}
42+
CHECK-NOT: {{.*}}panic_bounds_check{{.*}}
43+
"#;
44+
let expect_no_filecheck_path = Path::new("expect_no_panic_symbols_filecheck.txt");
45+
rfs::write(&expect_no_filecheck_path, expect_no_filecheck_pattern);
46+
47+
let expect_no_panic_symbols_pdbutil_dump = llvm_pdbutil()
48+
.arg("dump")
49+
.arg("-publics")
50+
.input(expect_no_panic_symbols.with_extension("pdb"))
51+
.run();
52+
llvm_filecheck()
53+
.patterns(expect_no_filecheck_path)
54+
.stdin_buf(expect_no_panic_symbols_pdbutil_dump.stdout_utf8())
55+
.run();
56+
57+
let expect_filecheck_pattern = r#"
58+
CHECK: main
59+
CHECK: {{.*}}core{{.*}}fmt{{.*}}write{{.*}}
60+
CHECK: {{.*}}core{{.*}}panicking{{.*}}panic_fmt{{.*}}
61+
// _ZN4core3fmt3num3imp54_$LT$impl$u20$core..fmt..Display$u20$for$u20$usize...
62+
CHECK: {{.*}}Display{{.*}}
63+
CHECK-NOT: {{.*}}panic_bounds_check{{.*}}
64+
"#;
65+
let expect_filecheck_path = Path::new("expect_panic_symbols_filecheck.txt");
66+
rfs::write(&expect_filecheck_path, expect_filecheck_pattern);
67+
68+
let expect_panic_symbols_pdbutil_dump = llvm_pdbutil()
69+
.arg("dump")
70+
.arg("-publics")
71+
.input(expect_panic_symbols.with_extension("pdb"))
72+
.run();
73+
llvm_filecheck()
74+
.patterns(expect_filecheck_path)
75+
.stdin_buf(expect_panic_symbols_pdbutil_dump.stdout_utf8())
76+
.run();
77+
} else {
78+
// panic machinery identifiers, these should not appear in the final binary
79+
let mut panic_syms = vec!["panic_bounds_check", "Debug"];
80+
if std_debug_assertions_enabled() {
81+
// If std debug assertions are allowed, we need to allow these, otherwise, add them to
82+
// the list of symbols to deny.
83+
panic_syms.extend_from_slice(&["panicking", "panic_fmt", "pad_integral", "Display"]);
84+
}
85+
86+
assert!(!object_contains_any_symbol_substring(&expect_no_panic_symbols, &panic_syms));
87+
assert!(object_contains_any_symbol_substring(&expect_panic_symbols, &panic_syms));
3388
}
34-
assert!(!object_contains_any_symbol_substring(bin_name("main"), &panic_syms));
3589
}

0 commit comments

Comments
 (0)