Skip to content

Commit 5431404

Browse files
committed
Auto merge of rust-lang#118548 - Enselic:bench-padding, r=thomcc,ChrisDenton
libtest: Fix padding of benchmarks run as tests ### Summary The first commit adds regression tests for libtest padding. The second commit fixes padding for benches run as tests and updates the blessed output of the regression tests to make it clear what effect the fix has on padding. Closes rust-lang#104092 which is **E-help-wanted** and **regression-from-stable-to-stable** ### More details Before this fix we applied padding _before_ manually doing what `convert_benchmarks_to_tests()` does which affects padding calculations. Instead use `convert_benchmarks_to_tests()` first if applicable and then apply padding afterwards so it becomes correct. Benches should only be padded when run as benches to make it easy to compare the benchmark numbers. Not when run as tests. r? `@ghost` until CI passes.
2 parents 6029085 + 12e6bcf commit 5431404

File tree

5 files changed

+58
-14
lines changed

5 files changed

+58
-14
lines changed

library/test/src/lib.rs

+8-14
Original file line numberDiff line numberDiff line change
@@ -298,24 +298,18 @@ where
298298

299299
let mut filtered = FilteredTests { tests: Vec::new(), benches: Vec::new(), next_id: 0 };
300300

301-
for test in filter_tests(opts, tests) {
301+
let mut filtered_tests = filter_tests(opts, tests);
302+
if !opts.bench_benchmarks {
303+
filtered_tests = convert_benchmarks_to_tests(filtered_tests);
304+
}
305+
306+
for test in filtered_tests {
302307
let mut desc = test.desc;
303308
desc.name = desc.name.with_padding(test.testfn.padding());
304309

305310
match test.testfn {
306-
DynBenchFn(benchfn) => {
307-
if opts.bench_benchmarks {
308-
filtered.add_bench(desc, DynBenchFn(benchfn));
309-
} else {
310-
filtered.add_test(desc, DynBenchAsTestFn(benchfn));
311-
}
312-
}
313-
StaticBenchFn(benchfn) => {
314-
if opts.bench_benchmarks {
315-
filtered.add_bench(desc, StaticBenchFn(benchfn));
316-
} else {
317-
filtered.add_test(desc, StaticBenchAsTestFn(benchfn));
318-
}
311+
DynBenchFn(_) | StaticBenchFn(_) => {
312+
filtered.add_bench(desc, test.testfn);
319313
}
320314
testfn => {
321315
filtered.add_test(desc, testfn);
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# ignore-cross-compile because we run the compiled code
2+
# needs-unwind because #[bench] and -Cpanic=abort requires -Zpanic-abort-tests
3+
include ../tools.mk
4+
5+
NORMALIZE=sed 's%[0-9,]\{1,\} ns/iter (+/- [0-9,]\{1,\})%?? ns/iter (+/- ??)%' | sed 's%finished in [0-9\.]\{1,\}%finished in ??%'
6+
7+
all:
8+
$(RUSTC) --test tests.rs
9+
10+
$(call RUN,tests) --test-threads=1 | $(NORMALIZE) > "$(TMPDIR)"/test.stdout
11+
$(RUSTC_TEST_OP) "$(TMPDIR)"/test.stdout test.stdout
12+
13+
$(call RUN,tests) --test-threads=1 --bench | $(NORMALIZE) > "$(TMPDIR)"/bench.stdout
14+
$(RUSTC_TEST_OP) "$(TMPDIR)"/bench.stdout bench.stdout
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
running 4 tests
3+
test short_test_name ... ignored
4+
test this_is_a_really_long_test_name ... ignored
5+
test short_bench_name ... bench: ?? ns/iter (+/- ??)
6+
test this_is_a_really_long_bench_name ... bench: ?? ns/iter (+/- ??)
7+
8+
test result: ok. 0 passed; 0 failed; 2 ignored; 2 measured; 0 filtered out; finished in ??s
9+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
running 4 tests
3+
test short_bench_name ... ok
4+
test short_test_name ... ok
5+
test this_is_a_really_long_bench_name ... ok
6+
test this_is_a_really_long_test_name ... ok
7+
8+
test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in ??s
9+
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![feature(test)]
2+
extern crate test;
3+
4+
#[test]
5+
fn short_test_name() {}
6+
7+
#[test]
8+
fn this_is_a_really_long_test_name() {}
9+
10+
#[bench]
11+
fn short_bench_name(b: &mut test::Bencher) {
12+
b.iter(|| 1);
13+
}
14+
15+
#[bench]
16+
fn this_is_a_really_long_bench_name(b: &mut test::Bencher) {
17+
b.iter(|| 1);
18+
}

0 commit comments

Comments
 (0)