Skip to content

Commit 82d9758

Browse files
committed
test: make sure fmt-write-bloat does not vacuously pass
1 parent e2c96cc commit 82d9758

File tree

1 file changed

+68
-6
lines changed

1 file changed

+68
-6
lines changed

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

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,86 @@
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::{bin_name, is_windows_msvc, rfs, rustc};
2428

2529
fn main() {
26-
rustc().input("main.rs").opt().run();
2730
// panic machinery identifiers, these should not appear in the final binary
2831
let mut panic_syms = vec!["panic_bounds_check", "Debug"];
2932
if std_debug_assertions_enabled() {
3033
// if debug assertions are allowed, we need to allow these,
3134
// otherwise, add them to the list of symbols to deny.
3235
panic_syms.extend_from_slice(&["panicking", "panic_fmt", "pad_integral", "Display"]);
3336
}
34-
assert!(!object_contains_any_symbol_substring(bin_name("main"), &panic_syms));
37+
38+
let expect_no_panic_symbols = bin_name("expect_no_panic_symbols");
39+
let expect_no_panic_symbols = Path::new(&expect_no_panic_symbols);
40+
rustc().input("main.rs").output(&expect_no_panic_symbols).opt().run();
41+
42+
let expect_panic_symbols = bin_name("expect_panic_symbols");
43+
let expect_panic_symbols = Path::new(&expect_panic_symbols);
44+
rustc().input("main.rs").output(&expect_panic_symbols).run();
45+
46+
if is_windows_msvc() {
47+
// FIXME(#143737): use actual DIA wrappers instead of parsing `llvm-pdbutil` textual output.
48+
49+
let expect_no_filecheck_pattern = r#"
50+
CHECK: main
51+
CHECK-NOT: {{.*}}Display{{.*}}
52+
CHECK-NOT: {{.*}}panic_bounds_check{{.*}}
53+
"#;
54+
let expect_no_filecheck_path = Path::new("expect_no_panic_symbols_filecheck.txt");
55+
rfs::write(&expect_no_filecheck_path, expect_no_filecheck_pattern);
56+
57+
let expect_no_panic_symbols_pdbutil_dump = llvm_pdbutil()
58+
.arg("dump")
59+
.arg("-publics")
60+
.input(expect_no_panic_symbols.with_extension("pdb"))
61+
.run();
62+
llvm_filecheck()
63+
.patterns(expect_no_filecheck_path)
64+
.stdin_buf(expect_no_panic_symbols_pdbutil_dump.stdout_utf8())
65+
.run();
66+
67+
// NOTE: on different platforms, they may not go through the same code path. E.g. on
68+
// `i686-msvc`, we do not go through `panic_fmt` (only `panic`). So for the check here we
69+
// only try to match for mangled `core::panicking` module path.
70+
let expect_filecheck_pattern = r#"
71+
CHECK: main
72+
CHECK: {{.*}}core{{.*}}panicking{{.*}}
73+
// _ZN4core3fmt3num3imp54_$LT$impl$u20$core..fmt..Display$u20$for$u20$usize...
74+
CHECK: {{.*}}Display{{.*}}
75+
CHECK-NOT: {{.*}}panic_bounds_check{{.*}}
76+
"#;
77+
let expect_filecheck_path = Path::new("expect_panic_symbols_filecheck.txt");
78+
rfs::write(&expect_filecheck_path, expect_filecheck_pattern);
79+
80+
let expect_panic_symbols_pdbutil_dump = llvm_pdbutil()
81+
.arg("dump")
82+
.arg("-publics")
83+
.input(expect_panic_symbols.with_extension("pdb"))
84+
.run();
85+
llvm_filecheck()
86+
.patterns(expect_filecheck_path)
87+
.stdin_buf(expect_panic_symbols_pdbutil_dump.stdout_utf8())
88+
.run();
89+
} else {
90+
// At least the `main` symbol (or `_main`) should be present.
91+
assert!(object_contains_any_symbol_substring(&expect_no_panic_symbols, &["main"]));
92+
assert!(object_contains_any_symbol_substring(&expect_panic_symbols, &["main"]));
93+
94+
assert!(!object_contains_any_symbol_substring(&expect_no_panic_symbols, &panic_syms));
95+
assert!(object_contains_any_symbol_substring(&expect_panic_symbols, &panic_syms));
96+
}
3597
}

0 commit comments

Comments
 (0)