From d49a7c8f76e86bfc4d4df4d6cb750a3746a8c921 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Wed, 5 Jun 2024 12:07:27 -0400 Subject: [PATCH] rewrite `short-ice` in `rmake` format --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/short-ice/Makefile | 10 ----- tests/run-make/short-ice/check.sh | 36 ---------------- tests/run-make/short-ice/rmake.rs | 41 +++++++++++++++++++ 4 files changed, 41 insertions(+), 47 deletions(-) delete mode 100644 tests/run-make/short-ice/Makefile delete mode 100644 tests/run-make/short-ice/check.sh create mode 100644 tests/run-make/short-ice/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 96a27610500b5..9cb8c3fd5d2fd 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -224,7 +224,6 @@ run-make/sepcomp-cci-copies/Makefile run-make/sepcomp-inlining/Makefile run-make/sepcomp-separate/Makefile run-make/share-generics-dylib/Makefile -run-make/short-ice/Makefile run-make/silly-file-names/Makefile run-make/simd-ffi/Makefile run-make/split-debuginfo/Makefile diff --git a/tests/run-make/short-ice/Makefile b/tests/run-make/short-ice/Makefile deleted file mode 100644 index 23006fc09e2f3..0000000000000 --- a/tests/run-make/short-ice/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -include ../tools.mk - -# ignore-windows - -export RUSTC := $(RUSTC_ORIGINAL) -export LD_LIBRARY_PATH := $(HOST_RPATH_DIR) -export TMPDIR := $(TMPDIR) - -all: - bash check.sh diff --git a/tests/run-make/short-ice/check.sh b/tests/run-make/short-ice/check.sh deleted file mode 100644 index 56babd2142f8c..0000000000000 --- a/tests/run-make/short-ice/check.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh -export RUSTC_ICE=0 -RUST_BACKTRACE=1 $RUSTC src/lib.rs -Z treat-err-as-bug=1 1>$TMPDIR/rust-test-1.log 2>&1 -RUST_BACKTRACE=full $RUSTC src/lib.rs -Z treat-err-as-bug=1 1>$TMPDIR/rust-test-2.log 2>&1 - -short=$(cat $TMPDIR/rust-test-1.log | wc -l) -full=$(cat $TMPDIR/rust-test-2.log | wc -l) -rustc_query_count=$(cat $TMPDIR/rust-test-1.log | grep rustc_query_ | wc -l) -rustc_query_count_full=$(cat $TMPDIR/rust-test-2.log | grep rustc_query_ | wc -l) - -begin_count=$(cat $TMPDIR/rust-test-2.log | grep __rust_begin_short_backtrace | wc -l) -end_count=$(cat $TMPDIR/rust-test-2.log | grep __rust_end_short_backtrace | wc -l) - -cat $TMPDIR/rust-test-1.log -echo "=====================" -cat $TMPDIR/rust-test-2.log -echo "=====================" - -echo "short backtrace: $short" -echo "full backtrace: $full" -echo "begin_count: $begin_count" -echo "end_count : $end_count" -echo "rustc_query_count: $rustc_query_count" -echo "rustc_query_count_full: $rustc_query_count_full" - -## backtraces to vary a bit depending on platform and configuration options, -## here we make sure that the short backtrace of rustc_query is shorter than the full, -## and marks are in pairs. -if [ $short -lt $full ] && - [ $begin_count -eq $end_count ] && - [ $(($rustc_query_count + 5)) -lt $rustc_query_count_full ] && - [ $rustc_query_count_full -gt 5 ]; then - exit 0 -else - exit 1 -fi diff --git a/tests/run-make/short-ice/rmake.rs b/tests/run-make/short-ice/rmake.rs new file mode 100644 index 0000000000000..8c7ced0993028 --- /dev/null +++ b/tests/run-make/short-ice/rmake.rs @@ -0,0 +1,41 @@ +// Backtraces in internal compiler errors used to be unbearably long, spanning +// multiple hundreds of lines. A fix was pushed in #108938, and this test gathers +// varied metrics on level 1 and full-level backtraces to check that the output +// was shortened down to an appropriate length. +// See https://github.com/rust-lang/rust/issues/107910 + +use run_make_support::rustc; +use std::env; + +fn main() { + env::set_var("RUST_BACKTRACE", "1"); + let mut rust_test_1 = rustc().input("src/lib.rs").arg("-Ztreat-err-as-bug=1").run(); + env::set_var("RUST_BACKTRACE", "full"); + let mut rust_test_2 = rustc().input("src/lib.rs").arg("-Ztreat-err-as-bug=1").run(); + let mut log_1 = rust_test_1.stdout; + log_1.append(&mut rust_test_1.stderr); + let mut log_2 = rust_test_2.stdout; + log_2.append(&mut rust_test_2.stderr); + let rust_test_log_1 = &std::str::from_utf8(&log_1).unwrap(); + let rust_test_log_2 = &std::str::from_utf8(&log_2).unwrap(); + + let rustc_query_count_full = count_lines_with(rust_test_log_2, "rustc_query_"); + + assert!( + rust_test_log_1.lines().count() < rust_test_log_2.lines().count() + && count_lines_with(rust_test_log_2, "__rust_begin_short_backtrace") + == count_lines_with(rust_test_log_2, "__rust_end_short_backtrace") + && count_lines_with(rust_test_log_1, "rustc_query_") + 5 < rustc_query_count_full + && rustc_query_count_full > 5 + ); +} + +fn count_lines_with(s: &str, search: &str) -> usize { + let mut count = 0; + for line in s.lines() { + if line.contains(search) { + count += 1; + } + } + count +}