Automatically detect LTO tests to remove when the sysroot is not compiled with LTO

This commit is contained in:
Antoni Boucher 2024-12-14 17:38:11 -05:00
parent 660305dccb
commit e1439ba178
7 changed files with 53 additions and 55 deletions

View File

@ -95,9 +95,6 @@ jobs:
git config --global user.name "User" git config --global user.name "User"
./y.sh prepare ./y.sh prepare
- name: Add more failing tests because the sysroot is not compiled with LTO
run: cat tests/failing-non-lto-tests.txt >> tests/failing-ui-tests.txt
- name: Run tests - name: Run tests
run: | run: |
./y.sh test --release --clean --build-sysroot ${{ matrix.commands }} ./y.sh test --release --clean --build-sysroot ${{ matrix.commands }}

View File

@ -90,9 +90,6 @@ jobs:
if: matrix.libgccjit_version.gcc != 'libgccjit12.so' if: matrix.libgccjit_version.gcc != 'libgccjit12.so'
run: ./y.sh prepare run: ./y.sh prepare
- name: Add more failing tests because the sysroot is not compiled with LTO
run: cat tests/failing-non-lto-tests.txt >> tests/failing-ui-tests.txt
- name: Run tests - name: Run tests
# TODO: re-enable those tests for libgccjit 12. # TODO: re-enable those tests for libgccjit 12.
if: matrix.libgccjit_version.gcc != 'libgccjit12.so' if: matrix.libgccjit_version.gcc != 'libgccjit12.so'

View File

@ -82,9 +82,6 @@ jobs:
#- name: Add more failing tests for GCC 12 #- name: Add more failing tests for GCC 12
#run: cat tests/failing-ui-tests12.txt >> tests/failing-ui-tests.txt #run: cat tests/failing-ui-tests12.txt >> tests/failing-ui-tests.txt
#- name: Add more failing tests because the sysroot is not compiled with LTO
#run: cat tests/failing-non-lto-tests.txt >> tests/failing-ui-tests.txt
#- name: Run tests #- name: Run tests
#run: | #run: |
#./y.sh test --release --clean --build-sysroot ${{ matrix.commands }} --no-default-features #./y.sh test --release --clean --build-sysroot ${{ matrix.commands }} --no-default-features

View File

@ -102,9 +102,6 @@ jobs:
git config --global user.name "User" git config --global user.name "User"
./y.sh prepare --cross ./y.sh prepare --cross
- name: Add more failing tests because the sysroot is not compiled with LTO
run: cat tests/failing-non-lto-tests.txt >> tests/failing-ui-tests.txt
- name: Run tests - name: Run tests
run: | run: |
./y.sh test --release --clean --build-sysroot --sysroot-features compiler_builtins/no-f16-f128 ${{ matrix.commands }} ./y.sh test --release --clean --build-sysroot --sysroot-features compiler_builtins/no-f16-f128 ${{ matrix.commands }}

View File

@ -70,4 +70,4 @@ jobs:
run: | run: |
# FIXME(antoyo): we cannot enable LTO for stdarch tests currently because of some failing LTO tests using proc-macros. # FIXME(antoyo): we cannot enable LTO for stdarch tests currently because of some failing LTO tests using proc-macros.
echo -n 'lto = "fat"' >> build_system/build_sysroot/Cargo.toml echo -n 'lto = "fat"' >> build_system/build_sysroot/Cargo.toml
EMBED_LTO_BITCODE=1 ./y.sh test --release --clean --release-sysroot --build-sysroot ${{ matrix.commands }} EMBED_LTO_BITCODE=1 ./y.sh test --release --clean --release-sysroot --build-sysroot --keep-lto-tests ${{ matrix.commands }}

View File

@ -93,6 +93,7 @@ struct TestArg {
sysroot_panic_abort: bool, sysroot_panic_abort: bool,
config_info: ConfigInfo, config_info: ConfigInfo,
sysroot_features: Vec<String>, sysroot_features: Vec<String>,
keep_lto_tests: bool,
} }
impl TestArg { impl TestArg {
@ -128,6 +129,9 @@ impl TestArg {
"--sysroot-panic-abort" => { "--sysroot-panic-abort" => {
test_arg.sysroot_panic_abort = true; test_arg.sysroot_panic_abort = true;
} }
"--keep-lto-tests" => {
test_arg.keep_lto_tests = true;
}
"--sysroot-features" => match args.next() { "--sysroot-features" => match args.next() {
Some(feature) if !feature.is_empty() => { Some(feature) if !feature.is_empty() => {
test_arg.sysroot_features.push(feature); test_arg.sysroot_features.push(feature);
@ -194,7 +198,7 @@ fn build_if_no_backend(env: &Env, args: &TestArg) -> Result<(), String> {
} }
fn clean(_env: &Env, args: &TestArg) -> Result<(), String> { fn clean(_env: &Env, args: &TestArg) -> Result<(), String> {
let _ = std::fs::remove_dir_all(&args.config_info.cargo_target_dir); let _ = remove_dir_all(&args.config_info.cargo_target_dir);
let path = Path::new(&args.config_info.cargo_target_dir).join("gccjit"); let path = Path::new(&args.config_info.cargo_target_dir).join("gccjit");
create_dir(&path) create_dir(&path)
} }
@ -835,8 +839,7 @@ fn valid_ui_error_pattern_test(file: &str) -> bool {
.any(|to_ignore| file.ends_with(to_ignore)) .any(|to_ignore| file.ends_with(to_ignore))
} }
#[rustfmt::skip] fn contains_ui_error_patterns(file_path: &Path, keep_lto_tests: bool) -> Result<bool, String> {
fn contains_ui_error_patterns(file_path: &Path) -> Result<bool, String> {
// Tests generating errors. // Tests generating errors.
let file = File::open(file_path) let file = File::open(file_path)
.map_err(|error| format!("Failed to read `{}`: {:?}", file_path.display(), error))?; .map_err(|error| format!("Failed to read `{}`: {:?}", file_path.display(), error))?;
@ -845,19 +848,22 @@ fn contains_ui_error_patterns(file_path: &Path) -> Result<bool, String> {
if line.is_empty() { if line.is_empty() {
continue; continue;
} }
if [ if ["//@ error-pattern:", "//@ build-fail", "//@ run-fail", "-Cllvm-args", "//~", "thread"]
"//@ error-pattern:",
"//@ build-fail",
"//@ run-fail",
"-Cllvm-args",
"//~",
"thread",
]
.iter() .iter()
.any(|check| line.contains(check)) .any(|check| line.contains(check))
{ {
return Ok(true); return Ok(true);
} }
if !keep_lto_tests
&& (line.contains("-Clto")
|| line.contains("-C lto")
|| line.contains("compile-flags: -Clinker-plugin-lto"))
&& !line.contains("-Clto=thin")
{
return Ok(true);
}
if line.contains("//[") && line.contains("]~") { if line.contains("//[") && line.contains("]~") {
return Ok(true); return Ok(true);
} }
@ -903,7 +909,7 @@ where
rust_path.join("tests/ui"), rust_path.join("tests/ui"),
&mut |_dir| Ok(()), &mut |_dir| Ok(()),
&mut |file_path| { &mut |file_path| {
if contains_ui_error_patterns(file_path)? { if contains_ui_error_patterns(file_path, args.keep_lto_tests)? {
Ok(()) Ok(())
} else { } else {
remove_file(file_path).map_err(|e| e.to_string()) remove_file(file_path).map_err(|e| e.to_string())
@ -928,7 +934,7 @@ where
.iter() .iter()
.any(|name| *name == dir_name) .any(|name| *name == dir_name)
{ {
std::fs::remove_dir_all(dir).map_err(|error| { remove_dir_all(dir).map_err(|error| {
format!("Failed to remove folder `{}`: {:?}", dir.display(), error) format!("Failed to remove folder `{}`: {:?}", dir.display(), error)
})?; })?;
} }
@ -940,27 +946,42 @@ where
// These two functions are used to remove files that are known to not be working currently // These two functions are used to remove files that are known to not be working currently
// with the GCC backend to reduce noise. // with the GCC backend to reduce noise.
fn dir_handling(dir: &Path) -> Result<(), String> { fn dir_handling(keep_lto_tests: bool) -> impl Fn(&Path) -> Result<(), String> {
if dir.file_name().map(|name| name == "auxiliary").unwrap_or(true) { move |dir| {
return Ok(()); if dir.file_name().map(|name| name == "auxiliary").unwrap_or(true) {
} return Ok(());
}
walk_dir(dir, &mut dir_handling, &mut file_handling, false) walk_dir(
} dir,
fn file_handling(file_path: &Path) -> Result<(), String> { &mut dir_handling(keep_lto_tests),
if !file_path.extension().map(|extension| extension == "rs").unwrap_or(false) { &mut file_handling(keep_lto_tests),
return Ok(()); false,
)
} }
let path_str = file_path.display().to_string().replace("\\", "/");
if valid_ui_error_pattern_test(&path_str) {
return Ok(());
} else if contains_ui_error_patterns(file_path)? {
return remove_file(&file_path);
}
Ok(())
} }
walk_dir(rust_path.join("tests/ui"), &mut dir_handling, &mut file_handling, false)?; fn file_handling(keep_lto_tests: bool) -> impl Fn(&Path) -> Result<(), String> {
move |file_path| {
if !file_path.extension().map(|extension| extension == "rs").unwrap_or(false) {
return Ok(());
}
let path_str = file_path.display().to_string().replace("\\", "/");
if valid_ui_error_pattern_test(&path_str) {
return Ok(());
} else if contains_ui_error_patterns(file_path, keep_lto_tests)? {
return remove_file(&file_path);
}
Ok(())
}
}
walk_dir(
rust_path.join("tests/ui"),
&mut dir_handling(args.keep_lto_tests),
&mut file_handling(args.keep_lto_tests),
false,
)?;
} }
let nb_parts = args.nb_parts.unwrap_or(0); let nb_parts = args.nb_parts.unwrap_or(0);
if nb_parts > 0 { if nb_parts > 0 {
@ -1173,7 +1194,7 @@ fn remove_files_callback<'a>(
files.split('\n').map(|line| line.trim()).filter(|line| !line.is_empty()) files.split('\n').map(|line| line.trim()).filter(|line| !line.is_empty())
{ {
let path = rust_path.join(file); let path = rust_path.join(file);
if let Err(e) = std::fs::remove_dir_all(&path) { if let Err(e) = remove_dir_all(&path) {
println!("Failed to remove directory `{}`: {}", path.display(), e); println!("Failed to remove directory `{}`: {}", path.display(), e);
} }
} }

View File

@ -1,11 +0,0 @@
tests/ui/issues/issue-44056.rs
tests/ui/lto/fat-lto.rs
tests/ui/lto/debuginfo-lto.rs
tests/ui/lto/lto-many-codegen-units.rs
tests/ui/lto/issue-100772.rs
tests/ui/lto/lto-rustc-loads-linker-plugin.rs
tests/ui/panic-runtime/lto-unwind.rs
tests/ui/sanitizer/issue-111184-cfi-coroutine-witness.rs
tests/ui/sepcomp/sepcomp-lib-lto.rs
tests/ui/lto/lto-opt-level-s.rs
tests/ui/lto/lto-opt-level-z.rs