Skip to content

Commit a51fb59

Browse files
committed
test: make sure fmt-write-bloat does not vacuously pass
1 parent 0c0f27a commit a51fb59

File tree

1 file changed

+72
-6
lines changed

1 file changed

+72
-6
lines changed

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

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,90 @@
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+
// NOTE: against the GCC codegen backend, the assertion
23+
// `object_contains_any_symbol_substring(&expect_panic_symbols, &panic_syms)` fails.
24+
//@ ignore-backends: gcc
25+
26+
use std::path::Path;
27+
2128
use run_make_support::env::std_debug_assertions_enabled;
22-
use run_make_support::rustc;
29+
use run_make_support::llvm::{llvm_filecheck, llvm_pdbutil};
2330
use run_make_support::symbols::object_contains_any_symbol_substring;
31+
use run_make_support::{bin_name, is_windows_msvc, rfs, rustc};
2432

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

0 commit comments

Comments
 (0)