From 548394541b4bbd9ebfe031d9c3a8c57912a535be Mon Sep 17 00:00:00 2001 From: Oneirical Date: Tue, 9 Jul 2024 11:40:02 -0400 Subject: [PATCH 1/2] rewrite dump-ice-to-disk to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/dump-ice-to-disk/Makefile | 10 --- tests/run-make/dump-ice-to-disk/check.sh | 64 ------------------- .../dump-ice-to-disk/{src => }/lib.rs | 0 tests/run-make/dump-ice-to-disk/rmake.rs | 64 +++++++++++++++++++ 5 files changed, 64 insertions(+), 75 deletions(-) delete mode 100644 tests/run-make/dump-ice-to-disk/Makefile delete mode 100644 tests/run-make/dump-ice-to-disk/check.sh rename tests/run-make/dump-ice-to-disk/{src => }/lib.rs (100%) create mode 100644 tests/run-make/dump-ice-to-disk/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 2e26f9344b899..4902656f07384 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -19,7 +19,6 @@ run-make/cross-lang-lto/Makefile run-make/dep-info-doesnt-run-much/Makefile run-make/dep-info-spaces/Makefile run-make/dep-info/Makefile -run-make/dump-ice-to-disk/Makefile run-make/emit-to-stdout/Makefile run-make/export-executable-symbols/Makefile run-make/extern-diff-internal-name/Makefile diff --git a/tests/run-make/dump-ice-to-disk/Makefile b/tests/run-make/dump-ice-to-disk/Makefile deleted file mode 100644 index 23006fc09e2f3..0000000000000 --- a/tests/run-make/dump-ice-to-disk/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/dump-ice-to-disk/check.sh b/tests/run-make/dump-ice-to-disk/check.sh deleted file mode 100644 index ff6e4be35af9d..0000000000000 --- a/tests/run-make/dump-ice-to-disk/check.sh +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/sh - -# Default nightly behavior (write ICE to current directory) -# FIXME(estebank): these are failing on CI, but passing locally. -# $RUSTC src/lib.rs -Z treat-err-as-bug=1 1>$TMPDIR/rust-test-default.log 2>&1 -# default=$(cat ./rustc-ice-*.txt | wc -l) -# rm ./rustc-ice-*.txt - -# Explicit directory set -export RUSTC_ICE=$TMPDIR -$RUSTC src/lib.rs -Z treat-err-as-bug=1 1>$TMPDIR/rust-test-default-set.log 2>&1 -default_set=$(cat $TMPDIR/rustc-ice-*.txt | wc -l) -content=$(cat $TMPDIR/rustc-ice-*.txt) -# Ensure that the ICE dump path doesn't contain `:` because they cause problems on Windows -windows_safe=$(echo rustc-ice-*.txt | grep ':') -if [ ! -z "$windows_safe" ]; then - exit 1 -fi - -rm $TMPDIR/rustc-ice-*.txt -RUST_BACKTRACE=short $RUSTC src/lib.rs -Z treat-err-as-bug=1 1>$TMPDIR/rust-test-short.log 2>&1 -short=$(cat $TMPDIR/rustc-ice-*.txt | wc -l) -rm $TMPDIR/rustc-ice-*.txt -RUST_BACKTRACE=full $RUSTC src/lib.rs -Z treat-err-as-bug=1 1>$TMPDIR/rust-test-full.log 2>&1 -full=$(cat $TMPDIR/rustc-ice-*.txt | wc -l) -rm $TMPDIR/rustc-ice-*.txt - -# Explicitly disabling ICE dump -export RUSTC_ICE=0 -$RUSTC src/lib.rs -Z treat-err-as-bug=1 1>$TMPDIR/rust-test-disabled.log 2>&1 -should_be_empty_tmp=$(ls -l $TMPDIR/rustc-ice-*.txt 2>/dev/null | wc -l) -should_be_empty_dot=$(ls -l ./rustc-ice-*.txt 2>/dev/null | wc -l) - -echo "#### ICE Dump content:" -echo $content -echo "#### default length:" -echo $default -echo "#### short length:" -echo $short -echo "#### default_set length:" -echo $default_set -echo "#### full length:" -echo $full -echo "#### should_be_empty_dot length:" -echo $should_be_empty_dot -echo "#### should_be_empty_tmp length:" -echo $should_be_empty_tmp - -## Verify that a the ICE dump file is created in the appropriate directories, that -## their lengths are the same regardless of other backtrace configuration options, -## that the file is not created when asked to (RUSTC_ICE=0) and that the file -## contains at least part of the expected content. -if [ $short -eq $default_set ] && - #[ $default -eq $short ] && - [ $default_set -eq $full ] && - [[ $content == *"thread 'rustc' panicked at "* ]] && - [[ $content == *"stack backtrace:"* ]] && - #[ $default -gt 0 ] && - [ $should_be_empty_dot -eq 0 ] && - [ $should_be_empty_tmp -eq 0 ]; then - exit 0 -else - exit 1 -fi diff --git a/tests/run-make/dump-ice-to-disk/src/lib.rs b/tests/run-make/dump-ice-to-disk/lib.rs similarity index 100% rename from tests/run-make/dump-ice-to-disk/src/lib.rs rename to tests/run-make/dump-ice-to-disk/lib.rs diff --git a/tests/run-make/dump-ice-to-disk/rmake.rs b/tests/run-make/dump-ice-to-disk/rmake.rs new file mode 100644 index 0000000000000..95f9223452c65 --- /dev/null +++ b/tests/run-make/dump-ice-to-disk/rmake.rs @@ -0,0 +1,64 @@ +// This test checks if internal compilation error (ICE) log files work as expected. +// - Get the number of lines from the log files without any configuration options, +// then check that the line count doesn't change if the backtrace gets configured to be short +// or full. +// - Check that disabling ICE logging results in zero files created. +// - Check that the ICE files contain some of the expected strings. +// See https://github.com/rust-lang/rust/pull/108714 + +// FIXME(Oneirical): try it on Windows! + +use run_make_support::{cwd, fs_wrapper, has_extension, has_prefix, rustc, shallow_find_files}; + +fn main() { + rustc().input("lib.rs").arg("-Ztreat-err-as-bug=1").run_fail(); + let ice_text = get_text_from_ice(); + let default_set = ice_text.lines().count(); + let content = ice_text; + // Ensure that the ICE files don't contain `:` in their filename because + // this causes problems on Windows. + for file in shallow_find_files(cwd(), |path| { + has_prefix(path, "rustc-ice") && has_extension(path, "txt") + }) { + assert!(!file.display().to_string().contains(":")); + } + + clear_ice_files(); + rustc().input("lib.rs").env("RUST_BACKTRACE", "short").arg("-Ztreat-err-as-bug=1").run_fail(); + let short = get_text_from_ice().lines().count(); + clear_ice_files(); + rustc().input("lib.rs").env("RUST_BACKTRACE", "full").arg("-Ztreat-err-as-bug=1").run_fail(); + let full = get_text_from_ice().lines().count(); + clear_ice_files(); + + // The ICE dump is explicitely disabled. Therefore, this should produce no files. + rustc().env("RUSTC_ICE", "0").input("lib.rs").arg("-Ztreat-err-as-bug=1").run_fail(); + assert!(get_text_from_ice().is_empty()); + + // The line count should not change. + assert_eq!(short, default_set); + assert_eq!(full, default_set); + // Some of the expected strings in an ICE file should appear. + assert!(content.contains("thread 'rustc' panicked at")); + assert!(content.contains("stack backtrace:")); +} + +fn clear_ice_files() { + let ice_files = shallow_find_files(cwd(), |path| { + has_prefix(path, "rustc-ice") && has_extension(path, "txt") + }); + for file in ice_files { + fs_wrapper::remove_file(file); + } +} + +fn get_text_from_ice() -> String { + let ice_files = shallow_find_files(cwd(), |path| { + has_prefix(path, "rustc-ice") && has_extension(path, "txt") + }); + let mut output = String::new(); + for file in ice_files { + output.push_str(&fs_wrapper::read_to_string(file)); + } + output +} From f54fa62887b24a9a9d0cae4251b0498fae1dd725 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Tue, 9 Jul 2024 11:55:54 -0400 Subject: [PATCH 2/2] rewrite panic-abort-eh_frame to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/dump-ice-to-disk/rmake.rs | 67 ++++++++++++------- tests/run-make/panic-abort-eh_frame/Makefile | 10 --- tests/run-make/panic-abort-eh_frame/rmake.rs | 20 ++++++ 4 files changed, 62 insertions(+), 36 deletions(-) delete mode 100644 tests/run-make/panic-abort-eh_frame/Makefile create mode 100644 tests/run-make/panic-abort-eh_frame/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 4902656f07384..4313e6472603e 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -81,7 +81,6 @@ run-make/native-link-modifier-whole-archive/Makefile run-make/no-alloc-shim/Makefile run-make/no-builtins-attribute/Makefile run-make/no-duplicate-libs/Makefile -run-make/panic-abort-eh_frame/Makefile run-make/pass-non-c-like-enum-to-c/Makefile run-make/pdb-buildinfo-cl-cmd/Makefile run-make/pgo-gen-lto/Makefile diff --git a/tests/run-make/dump-ice-to-disk/rmake.rs b/tests/run-make/dump-ice-to-disk/rmake.rs index 95f9223452c65..2fb5c825064b0 100644 --- a/tests/run-make/dump-ice-to-disk/rmake.rs +++ b/tests/run-make/dump-ice-to-disk/rmake.rs @@ -6,38 +6,56 @@ // - Check that the ICE files contain some of the expected strings. // See https://github.com/rust-lang/rust/pull/108714 -// FIXME(Oneirical): try it on Windows! - -use run_make_support::{cwd, fs_wrapper, has_extension, has_prefix, rustc, shallow_find_files}; +use run_make_support::{cwd, has_extension, has_prefix, rfs, rustc, shallow_find_files}; fn main() { rustc().input("lib.rs").arg("-Ztreat-err-as-bug=1").run_fail(); - let ice_text = get_text_from_ice(); + let default = get_text_from_ice(".").lines().count(); + clear_ice_files(); + + rustc().env("RUSTC_ICE", cwd()).input("lib.rs").arg("-Ztreat-err-as-bug=1").run_fail(); + let ice_text = get_text_from_ice(cwd()); let default_set = ice_text.lines().count(); let content = ice_text; - // Ensure that the ICE files don't contain `:` in their filename because - // this causes problems on Windows. - for file in shallow_find_files(cwd(), |path| { + let ice_files = shallow_find_files(cwd(), |path| { has_prefix(path, "rustc-ice") && has_extension(path, "txt") - }) { - assert!(!file.display().to_string().contains(":")); - } + }); + assert_eq!(ice_files.len(), 1); // There should only be 1 ICE file. + let ice_file_name = + ice_files.first().and_then(|f| f.file_name()).and_then(|n| n.to_str()).unwrap(); + // Ensure that the ICE dump path doesn't contain `:`, because they cause problems on Windows. + assert!(!ice_file_name.contains(":"), "{ice_file_name}"); clear_ice_files(); - rustc().input("lib.rs").env("RUST_BACKTRACE", "short").arg("-Ztreat-err-as-bug=1").run_fail(); - let short = get_text_from_ice().lines().count(); + rustc() + .env("RUSTC_ICE", cwd()) + .input("lib.rs") + .env("RUST_BACKTRACE", "short") + .arg("-Ztreat-err-as-bug=1") + .run_fail(); + let short = get_text_from_ice(cwd()).lines().count(); clear_ice_files(); - rustc().input("lib.rs").env("RUST_BACKTRACE", "full").arg("-Ztreat-err-as-bug=1").run_fail(); - let full = get_text_from_ice().lines().count(); + rustc() + .env("RUSTC_ICE", cwd()) + .input("lib.rs") + .env("RUST_BACKTRACE", "full") + .arg("-Ztreat-err-as-bug=1") + .run_fail(); + let full = get_text_from_ice(cwd()).lines().count(); clear_ice_files(); - // The ICE dump is explicitely disabled. Therefore, this should produce no files. + // The ICE dump is explicitly disabled. Therefore, this should produce no files. rustc().env("RUSTC_ICE", "0").input("lib.rs").arg("-Ztreat-err-as-bug=1").run_fail(); - assert!(get_text_from_ice().is_empty()); + let ice_files = shallow_find_files(cwd(), |path| { + has_prefix(path, "rustc-ice") && has_extension(path, "txt") + }); + assert!(ice_files.is_empty()); // There should be 0 ICE files. // The line count should not change. assert_eq!(short, default_set); + assert_eq!(short, default); assert_eq!(full, default_set); + assert!(default > 0); // Some of the expected strings in an ICE file should appear. assert!(content.contains("thread 'rustc' panicked at")); assert!(content.contains("stack backtrace:")); @@ -48,17 +66,16 @@ fn clear_ice_files() { has_prefix(path, "rustc-ice") && has_extension(path, "txt") }); for file in ice_files { - fs_wrapper::remove_file(file); + rfs::remove_file(file); } } -fn get_text_from_ice() -> String { - let ice_files = shallow_find_files(cwd(), |path| { - has_prefix(path, "rustc-ice") && has_extension(path, "txt") - }); - let mut output = String::new(); - for file in ice_files { - output.push_str(&fs_wrapper::read_to_string(file)); - } +#[track_caller] +fn get_text_from_ice(dir: impl AsRef) -> String { + let ice_files = + shallow_find_files(dir, |path| has_prefix(path, "rustc-ice") && has_extension(path, "txt")); + assert_eq!(ice_files.len(), 1); // There should only be 1 ICE file. + let ice_file = ice_files.get(0).unwrap(); + let output = rfs::read_to_string(ice_file); output } diff --git a/tests/run-make/panic-abort-eh_frame/Makefile b/tests/run-make/panic-abort-eh_frame/Makefile deleted file mode 100644 index 7020455b742d0..0000000000000 --- a/tests/run-make/panic-abort-eh_frame/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -# only-linux -# -# This test ensures that `panic=abort` code (without `C-unwind`, that is) should not have any -# unwinding related `.eh_frame` sections emitted. - -include ../tools.mk - -all: - $(RUSTC) foo.rs --crate-type=lib --emit=obj=$(TMPDIR)/foo.o -Cpanic=abort --edition 2021 -Z validate-mir - objdump --dwarf=frames $(TMPDIR)/foo.o | $(CGREP) -v 'DW_CFA' diff --git a/tests/run-make/panic-abort-eh_frame/rmake.rs b/tests/run-make/panic-abort-eh_frame/rmake.rs new file mode 100644 index 0000000000000..6bcf718235675 --- /dev/null +++ b/tests/run-make/panic-abort-eh_frame/rmake.rs @@ -0,0 +1,20 @@ +// An `.eh_frame` section in an object file is a symptom of an UnwindAction::Terminate +// being inserted, useful for determining whether or not unwinding is necessary. +// This is useless when panics would NEVER unwind due to -C panic=abort. This section should +// therefore never appear in the emit file of a -C panic=abort compilation, and this test +// checks that this is respected. +// See https://github.com/rust-lang/rust/pull/112403 + +use run_make_support::{llvm_objdump, rustc}; + +fn main() { + rustc() + .input("foo.rs") + .crate_type("lib") + .emit("obj=foo.o") + .panic("abort") + .edition("2021") + .arg("-Zvalidate-mir") + .run(); + llvm_objdump().arg("--dwarf=frames").input("foo.o").run().assert_stdout_not_contains("DW_CFA"); +}