Skip to content

Commit a63b83e

Browse files
authored
ui pattern failure tests (#524)
1 parent eccab8b commit a63b83e

File tree

6 files changed

+170
-67
lines changed

6 files changed

+170
-67
lines changed

Diff for: .github/workflows/failures.yml

+9
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,12 @@ jobs:
9898
run: |
9999
${{ matrix.libgccjit_version.env_extra }} ./y.sh test --release --clean --build-sysroot --test-failing-rustc ${{ matrix.libgccjit_version.extra }} | tee output_log
100100
rg --text "test result" output_log >> $GITHUB_STEP_SUMMARY
101+
102+
- name: Run failing ui pattern tests for ICE
103+
id: ui-tests
104+
run: |
105+
${{ matrix.libgccjit_version.env_extra }} ./y.sh test --release --test-failing-ui-pattern-tests ${{ matrix.libgccjit_version.extra }} | tee output_log_ui
106+
if grep -q "the compiler unexpectedly panicked" output_log_ui; then
107+
echo "Error: 'the compiler unexpectedly panicked' found in output logs. CI Error!!"
108+
exit 1
109+
fi

Diff for: build_system/src/build.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn cleanup_sysroot_previous_build(start_dir: &Path) {
6868
// Clean target dir except for build scripts and incremental cache
6969
let _ = walk_dir(
7070
start_dir.join("target"),
71-
|dir: &Path| {
71+
&mut |dir: &Path| {
7272
for top in &["debug", "release"] {
7373
let _ = fs::remove_dir_all(dir.join(top).join("build"));
7474
let _ = fs::remove_dir_all(dir.join(top).join("deps"));
@@ -77,7 +77,7 @@ fn cleanup_sysroot_previous_build(start_dir: &Path) {
7777

7878
let _ = walk_dir(
7979
dir.join(top),
80-
|sub_dir: &Path| {
80+
&mut |sub_dir: &Path| {
8181
if sub_dir
8282
.file_name()
8383
.map(|filename| filename.to_str().unwrap().starts_with("libsysroot"))
@@ -87,7 +87,7 @@ fn cleanup_sysroot_previous_build(start_dir: &Path) {
8787
}
8888
Ok(())
8989
},
90-
|file: &Path| {
90+
&mut |file: &Path| {
9191
if file
9292
.file_name()
9393
.map(|filename| filename.to_str().unwrap().starts_with("libsysroot"))
@@ -97,11 +97,13 @@ fn cleanup_sysroot_previous_build(start_dir: &Path) {
9797
}
9898
Ok(())
9999
},
100+
false,
100101
);
101102
}
102103
Ok(())
103104
},
104-
|_| Ok(()),
105+
&mut |_| Ok(()),
106+
false,
105107
);
106108

107109
let _ = fs::remove_file(start_dir.join("Cargo.lock"));
@@ -166,14 +168,15 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
166168
// Copy files to sysroot
167169
let sysroot_path = start_dir.join(format!("sysroot/lib/rustlib/{}/lib/", config.target_triple));
168170
create_dir(&sysroot_path)?;
169-
let copier = |dir_to_copy: &Path| {
171+
let mut copier = |dir_to_copy: &Path| {
170172
// FIXME: should not use shell command!
171173
run_command(&[&"cp", &"-r", &dir_to_copy, &sysroot_path], None).map(|_| ())
172174
};
173175
walk_dir(
174176
start_dir.join(&format!("target/{}/{}/deps", config.target_triple, channel)),
175-
copier,
176-
copier,
177+
&mut copier.clone(),
178+
&mut copier,
179+
false,
177180
)?;
178181

179182
// Copy the source files to the sysroot (Rust for Linux needs this).

Diff for: build_system/src/prepare.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -72,30 +72,33 @@ fn prepare_libcore(
7272
let mut patches = Vec::new();
7373
walk_dir(
7474
"patches",
75-
|_| Ok(()),
76-
|file_path: &Path| {
75+
&mut |_| Ok(()),
76+
&mut |file_path: &Path| {
7777
patches.push(file_path.to_path_buf());
7878
Ok(())
7979
},
80+
false,
8081
)?;
8182
if cross_compile {
8283
walk_dir(
8384
"patches/cross_patches",
84-
|_| Ok(()),
85-
|file_path: &Path| {
85+
&mut |_| Ok(()),
86+
&mut |file_path: &Path| {
8687
patches.push(file_path.to_path_buf());
8788
Ok(())
8889
},
90+
false,
8991
)?;
9092
}
9193
if libgccjit12_patches {
9294
walk_dir(
9395
"patches/libgccjit12",
94-
|_| Ok(()),
95-
|file_path: &Path| {
96+
&mut |_| Ok(()),
97+
&mut |file_path: &Path| {
9698
patches.push(file_path.to_path_buf());
9799
Ok(())
98100
},
101+
false,
99102
)?;
100103
}
101104
patches.sort();

Diff for: build_system/src/test.rs

+97-53
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ fn get_runners() -> Runners {
2323
runners.insert("--test-rustc", ("Run all rustc tests", test_rustc as Runner));
2424
runners
2525
.insert("--test-successful-rustc", ("Run successful rustc tests", test_successful_rustc));
26+
runners.insert(
27+
"--test-failing-ui-pattern-tests",
28+
("Run failing ui pattern tests", test_failing_ui_pattern_tests),
29+
);
2630
runners.insert("--test-failing-rustc", ("Run failing rustc tests", test_failing_rustc));
2731
runners.insert("--projects", ("Run the tests of popular crates", test_projects));
2832
runners.insert("--test-libcore", ("Run libcore tests", test_libcore));
@@ -808,7 +812,7 @@ fn extended_sysroot_tests(env: &Env, args: &TestArg) -> Result<(), String> {
808812
Ok(())
809813
}
810814

811-
fn should_not_remove_test(file: &str) -> bool {
815+
fn valid_ui_error_pattern_test(file: &str) -> bool {
812816
// contains //~ERROR, but shouldn't be removed
813817
[
814818
"issues/auxiliary/issue-3136-a.rs",
@@ -824,7 +828,7 @@ fn should_not_remove_test(file: &str) -> bool {
824828
}
825829

826830
#[rustfmt::skip]
827-
fn should_remove_test(file_path: &Path) -> Result<bool, String> {
831+
fn contains_ui_error_patterns(file_path: &Path) -> Result<bool, String> {
828832
// Tests generating errors.
829833
let file = File::open(file_path)
830834
.map_err(|error| format!("Failed to read `{}`: {:?}", file_path.display(), error))?;
@@ -856,10 +860,19 @@ fn should_remove_test(file_path: &Path) -> Result<bool, String> {
856860
Ok(false)
857861
}
858862

863+
// # Parameters
864+
//
865+
// * `env`: An environment variable that provides context for the function.
866+
// * `args`: The arguments passed to the test. This could include things like the flags, config etc.
867+
// * `prepare_files_callback`: A callback function that prepares the files needed for the test. Its used to remove/retain tests giving Error to run various rust test suits.
868+
// * `run_error_pattern_test`: A boolean that determines whether to run only error pattern tests.
869+
// * `test_type`: A string that indicates the type of the test being run.
870+
//
859871
fn test_rustc_inner<F>(
860872
env: &Env,
861873
args: &TestArg,
862874
prepare_files_callback: F,
875+
run_error_pattern_test: bool,
863876
test_type: &str,
864877
) -> Result<(), String>
865878
where
@@ -876,54 +889,71 @@ where
876889
}
877890

878891
if test_type == "ui" {
879-
walk_dir(
880-
rust_path.join("tests/ui"),
881-
|dir| {
882-
let dir_name = dir.file_name().and_then(|name| name.to_str()).unwrap_or("");
883-
if [
884-
"abi",
885-
"extern",
886-
"unsized-locals",
887-
"proc-macro",
888-
"threads-sendsync",
889-
"borrowck",
890-
"test-attrs",
891-
]
892-
.iter()
893-
.any(|name| *name == dir_name)
894-
{
895-
std::fs::remove_dir_all(dir).map_err(|error| {
896-
format!("Failed to remove folder `{}`: {:?}", dir.display(), error)
897-
})?;
892+
if run_error_pattern_test {
893+
// After we removed the error tests that are known to panic with rustc_codegen_gcc, we now remove the passing tests since this runs the error tests.
894+
walk_dir(
895+
rust_path.join("tests/ui"),
896+
&mut |_dir| Ok(()),
897+
&mut |file_path| {
898+
if contains_ui_error_patterns(file_path)? {
899+
Ok(())
900+
} else {
901+
remove_file(file_path).map_err(|e| e.to_string())
902+
}
903+
},
904+
true,
905+
)?;
906+
} else {
907+
walk_dir(
908+
rust_path.join("tests/ui"),
909+
&mut |dir| {
910+
let dir_name = dir.file_name().and_then(|name| name.to_str()).unwrap_or("");
911+
if [
912+
"abi",
913+
"extern",
914+
"unsized-locals",
915+
"proc-macro",
916+
"threads-sendsync",
917+
"borrowck",
918+
"test-attrs",
919+
]
920+
.iter()
921+
.any(|name| *name == dir_name)
922+
{
923+
std::fs::remove_dir_all(dir).map_err(|error| {
924+
format!("Failed to remove folder `{}`: {:?}", dir.display(), error)
925+
})?;
926+
}
927+
Ok(())
928+
},
929+
&mut |_| Ok(()),
930+
false,
931+
)?;
932+
933+
// These two functions are used to remove files that are known to not be working currently
934+
// with the GCC backend to reduce noise.
935+
fn dir_handling(dir: &Path) -> Result<(), String> {
936+
if dir.file_name().map(|name| name == "auxiliary").unwrap_or(true) {
937+
return Ok(());
898938
}
899-
Ok(())
900-
},
901-
|_| Ok(()),
902-
)?;
903939

904-
// These two functions are used to remove files that are known to not be working currently
905-
// with the GCC backend to reduce noise.
906-
fn dir_handling(dir: &Path) -> Result<(), String> {
907-
if dir.file_name().map(|name| name == "auxiliary").unwrap_or(true) {
908-
return Ok(());
940+
walk_dir(dir, &mut dir_handling, &mut file_handling, false)
909941
}
910-
walk_dir(dir, dir_handling, file_handling)
911-
}
912-
fn file_handling(file_path: &Path) -> Result<(), String> {
913-
if !file_path.extension().map(|extension| extension == "rs").unwrap_or(false) {
914-
return Ok(());
915-
}
916-
let path_str = file_path.display().to_string().replace("\\", "/");
917-
if should_not_remove_test(&path_str) {
918-
return Ok(());
919-
} else if should_remove_test(file_path)? {
920-
return remove_file(&file_path);
942+
fn file_handling(file_path: &Path) -> Result<(), String> {
943+
if !file_path.extension().map(|extension| extension == "rs").unwrap_or(false) {
944+
return Ok(());
945+
}
946+
let path_str = file_path.display().to_string().replace("\\", "/");
947+
if valid_ui_error_pattern_test(&path_str) {
948+
return Ok(());
949+
} else if contains_ui_error_patterns(file_path)? {
950+
return remove_file(&file_path);
951+
}
952+
Ok(())
921953
}
922-
Ok(())
923-
}
924-
925-
walk_dir(rust_path.join("tests/ui"), dir_handling, file_handling)?;
926954

955+
walk_dir(rust_path.join("tests/ui"), &mut dir_handling, &mut file_handling, false)?;
956+
}
927957
let nb_parts = args.nb_parts.unwrap_or(0);
928958
if nb_parts > 0 {
929959
let current_part = args.current_part.unwrap();
@@ -1004,22 +1034,24 @@ where
10041034
}
10051035

10061036
fn test_rustc(env: &Env, args: &TestArg) -> Result<(), String> {
1007-
test_rustc_inner(env, args, |_| Ok(false), "run-make")?;
1008-
test_rustc_inner(env, args, |_| Ok(false), "ui")
1037+
test_rustc_inner(env, args, |_| Ok(false), false, "run-make")?;
1038+
test_rustc_inner(env, args, |_| Ok(false), false, "ui")
10091039
}
10101040

10111041
fn test_failing_rustc(env: &Env, args: &TestArg) -> Result<(), String> {
10121042
let result1 = test_rustc_inner(
10131043
env,
10141044
args,
1015-
prepare_files_callback_failing("tests/failing-run-make-tests.txt", "run-make"),
1045+
retain_files_callback("tests/failing-run-make-tests.txt", "run-make"),
1046+
false,
10161047
"run-make",
10171048
);
10181049

10191050
let result2 = test_rustc_inner(
10201051
env,
10211052
args,
1022-
prepare_files_callback_failing("tests/failing-ui-tests.txt", "ui"),
1053+
retain_files_callback("tests/failing-ui-tests.txt", "ui"),
1054+
false,
10231055
"ui",
10241056
);
10251057

@@ -1030,18 +1062,30 @@ fn test_successful_rustc(env: &Env, args: &TestArg) -> Result<(), String> {
10301062
test_rustc_inner(
10311063
env,
10321064
args,
1033-
prepare_files_callback_success("tests/failing-ui-tests.txt", "ui"),
1065+
remove_files_callback("tests/failing-ui-tests.txt", "ui"),
1066+
false,
10341067
"ui",
10351068
)?;
10361069
test_rustc_inner(
10371070
env,
10381071
args,
1039-
prepare_files_callback_success("tests/failing-run-make-tests.txt", "run-make"),
1072+
remove_files_callback("tests/failing-run-make-tests.txt", "run-make"),
1073+
false,
10401074
"run-make",
10411075
)
10421076
}
10431077

1044-
fn prepare_files_callback_failing<'a>(
1078+
fn test_failing_ui_pattern_tests(env: &Env, args: &TestArg) -> Result<(), String> {
1079+
test_rustc_inner(
1080+
env,
1081+
args,
1082+
remove_files_callback("tests/failing-ice-tests.txt", "ui"),
1083+
true,
1084+
"ui",
1085+
)
1086+
}
1087+
1088+
fn retain_files_callback<'a>(
10451089
file_path: &'a str,
10461090
test_type: &'a str,
10471091
) -> impl Fn(&Path) -> Result<bool, String> + 'a {
@@ -1104,7 +1148,7 @@ fn prepare_files_callback_failing<'a>(
11041148
}
11051149
}
11061150

1107-
fn prepare_files_callback_success<'a>(
1151+
fn remove_files_callback<'a>(
11081152
file_path: &'a str,
11091153
test_type: &'a str,
11101154
) -> impl Fn(&Path) -> Result<bool, String> + 'a {

Diff for: build_system/src/utils.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,12 @@ pub fn git_clone_root_dir(
343343
git_clone_inner(to_clone, &dest_parent_dir.join(&repo_name), shallow_clone, repo_name)
344344
}
345345

346-
pub fn walk_dir<P, D, F>(dir: P, mut dir_cb: D, mut file_cb: F) -> Result<(), String>
346+
pub fn walk_dir<P, D, F>(
347+
dir: P,
348+
dir_cb: &mut D,
349+
file_cb: &mut F,
350+
recursive: bool,
351+
) -> Result<(), String>
347352
where
348353
P: AsRef<Path>,
349354
D: FnMut(&Path) -> Result<(), String>,
@@ -358,6 +363,9 @@ where
358363
let entry_path = entry.path();
359364
if entry_path.is_dir() {
360365
dir_cb(&entry_path)?;
366+
if recursive {
367+
walk_dir(entry_path, dir_cb, file_cb, recursive)?; // Recursive call
368+
}
361369
} else {
362370
file_cb(&entry_path)?;
363371
}

0 commit comments

Comments
 (0)