1
1
use crate :: build;
2
2
use crate :: config:: ConfigInfo ;
3
3
use crate :: utils:: {
4
- get_gcc_path, get_toolchain, run_command, run_command_with_env,
4
+ get_gcc_path, get_toolchain, remove_file , run_command, run_command_with_env,
5
5
run_command_with_output_and_env, rustc_version_info, split_args, walk_dir,
6
- remove_file,
7
6
} ;
8
7
9
8
use std:: collections:: { BTreeSet , HashMap } ;
10
9
use std:: ffi:: OsStr ;
11
- use std:: fs:: { File , remove_dir_all } ;
10
+ use std:: fs:: { remove_dir_all , File } ;
12
11
use std:: io:: { BufRead , BufReader } ;
13
12
use std:: path:: { Path , PathBuf } ;
14
13
use std:: str:: FromStr ;
@@ -213,8 +212,11 @@ impl TestArg {
213
212
match ( test_arg. current_part , test_arg. nb_parts ) {
214
213
( Some ( _) , Some ( _) ) | ( None , None ) => { }
215
214
_ => {
216
- return Err ( "If either `--current-part` or `--nb-parts` is specified, the other one \
217
- needs to be specified as well!". to_string ( ) ) ;
215
+ return Err (
216
+ "If either `--current-part` or `--nb-parts` is specified, the other one \
217
+ needs to be specified as well!"
218
+ . to_string ( ) ,
219
+ ) ;
218
220
}
219
221
}
220
222
Ok ( Some ( test_arg) )
@@ -230,20 +232,19 @@ fn build_if_no_backend(env: &Env, args: &TestArg) -> Result<(), String> {
230
232
return Ok ( ( ) ) ;
231
233
}
232
234
let mut command: Vec < & dyn AsRef < OsStr > > = vec ! [ & "cargo" , & "rustc" ] ;
233
- if args. channel == Channel :: Release {
234
- let mut env = env. clone ( ) ;
235
- env. insert ( "CARGO_INCREMENTAL" . to_string ( ) , "1" . to_string ( ) ) ;
235
+ let mut tmp_env;
236
+ let env = if args. channel == Channel :: Release {
237
+ tmp_env = env. clone ( ) ;
238
+ tmp_env. insert ( "CARGO_INCREMENTAL" . to_string ( ) , "1" . to_string ( ) ) ;
236
239
command. push ( & "--release" ) ;
237
- for flag in args. flags . iter ( ) {
238
- command. push ( flag) ;
239
- }
240
- run_command_with_output_and_env ( & command, None , Some ( & env) )
240
+ & tmp_env
241
241
} else {
242
- for flag in args . flags . iter ( ) {
243
- command . push ( flag ) ;
244
- }
245
- run_command_with_output_and_env ( & command, None , Some ( & env ) )
242
+ & env
243
+ } ;
244
+ for flag in args . flags . iter ( ) {
245
+ command. push ( flag ) ;
246
246
}
247
+ run_command_with_output_and_env ( & command, None , Some ( env) )
247
248
}
248
249
249
250
fn clean ( _env : & Env , args : & TestArg ) -> Result < ( ) , String > {
@@ -403,11 +404,7 @@ fn std_tests(env: &Env, args: &TestArg) -> Result<(), String> {
403
404
& args. config_info . target_triple ,
404
405
] ) ;
405
406
run_command_with_env ( & command, None , Some ( env) ) ?;
406
- maybe_run_command_in_vm (
407
- & [ & cargo_target_dir. join ( "alloc_example" ) ] ,
408
- env,
409
- args,
410
- ) ?;
407
+ maybe_run_command_in_vm ( & [ & cargo_target_dir. join ( "alloc_example" ) ] , env, args) ?;
411
408
}
412
409
413
410
// FIXME: create a function "display_if_not_quiet" or something along the line.
@@ -424,11 +421,7 @@ fn std_tests(env: &Env, args: &TestArg) -> Result<(), String> {
424
421
& args. config_info . target_triple ,
425
422
] ) ;
426
423
run_command_with_env ( & command, None , Some ( env) ) ?;
427
- maybe_run_command_in_vm (
428
- & [ & cargo_target_dir. join ( "dst_field_align" ) ] ,
429
- env,
430
- args,
431
- ) ?;
424
+ maybe_run_command_in_vm ( & [ & cargo_target_dir. join ( "dst_field_align" ) ] , env, args) ?;
432
425
433
426
// FIXME: create a function "display_if_not_quiet" or something along the line.
434
427
println ! ( "[AOT] std_example" ) ;
@@ -525,14 +518,15 @@ fn setup_rustc(env: &mut Env, args: &TestArg) -> Result<(), String> {
525
518
None ,
526
519
Some ( env) ,
527
520
) ;
521
+ run_command ( & [ & "git" , & "checkout" , & "--" , & "tests/" ] , rust_dir) ?;
528
522
run_command_with_output_and_env ( & [ & "git" , & "fetch" ] , rust_dir, Some ( env) ) ?;
529
523
let rustc_commit = match rustc_version_info ( env. get ( "RUSTC" ) . map ( |s| s. as_str ( ) ) ) ?. commit_hash {
530
524
Some ( commit_hash) => commit_hash,
531
525
None => return Err ( "Couldn't retrieve rustc commit hash" . to_string ( ) ) ,
532
526
} ;
533
527
run_command_with_output_and_env ( & [ & "git" , & "checkout" , & rustc_commit] , rust_dir, Some ( env) ) ?;
534
528
// FIXME: Is it really needed to empty `RUSTFLAGS` here?
535
- env. insert ( "RUSTFLAGS" . to_string ( ) , String :: new ( ) ) ;
529
+ // env.insert("RUSTFLAGS".to_string(), String::new());
536
530
let cargo = String :: from_utf8 (
537
531
run_command_with_env ( & [ & "rustup" , & "which" , & "cargo" ] , rust_dir, Some ( env) ) ?. stdout ,
538
532
)
@@ -591,15 +585,6 @@ download-ci-llvm = false
591
585
) ,
592
586
)
593
587
. map_err ( |error| format ! ( "Failed to write into `rust/config.toml`: {:?}" , error) ) ?;
594
-
595
- let rustc_commit = match rustc_version_info ( env. get ( "RUSTC" ) . map ( |s| s. as_str ( ) ) ) ?. commit_hash {
596
- Some ( commit_hash) => commit_hash,
597
- None => return Err ( "Couldn't retrieve rustc commit hash" . to_string ( ) ) ,
598
- } ;
599
- // FIXME: create a function "display_if_not_quiet" or something along the line.
600
- println ! ( "commit: {:?}" , rustc_commit) ;
601
- let command: & [ & dyn AsRef < OsStr > ] = & [ & "git" , & "checkout" , & rustc_commit, & "tests" ] ;
602
- run_command_with_output_and_env ( command, rust_dir, Some ( env) ) ?;
603
588
Ok ( ( ) )
604
589
}
605
590
@@ -834,27 +819,6 @@ fn extended_sysroot_tests(env: &Env, args: &TestArg) -> Result<(), String> {
834
819
Ok ( ( ) )
835
820
}
836
821
837
- fn should_remove_ui_test ( file : File ) -> bool {
838
- for line in BufReader :: new ( file) . lines ( ) {
839
- if let Ok ( line) = line {
840
- if [
841
- "// error-pattern:" ,
842
- "// build-fail" ,
843
- "// run-fail" ,
844
- "-Cllvm-args" ,
845
- "//~" ,
846
- "// ~" ,
847
- ]
848
- . iter ( )
849
- . any ( |check| line. contains ( check) )
850
- {
851
- return true ;
852
- }
853
- }
854
- }
855
- false
856
- }
857
-
858
822
fn should_not_remove_test ( file : & str ) -> bool {
859
823
// contains //~ERROR, but shouldn't be removed
860
824
[
@@ -870,21 +834,40 @@ fn should_not_remove_test(file: &str) -> bool {
870
834
. any ( |to_ignore| file. ends_with ( to_ignore) )
871
835
}
872
836
873
- fn should_remove_test ( path : & Path , path_str : & str ) -> bool {
837
+ fn should_remove_test ( file_path : & Path ) -> Result < bool , String > {
874
838
// Tests generating errors.
875
- path. file_name ( )
876
- . and_then ( |name| name. to_str ( ) )
877
- . map ( |name| name. contains ( "thread" ) )
878
- . unwrap_or ( false )
879
- || [
880
- "consts/issue-miri-1910.rs" ,
881
- // Tests generating errors.
882
- "consts/issue-94675.rs" ,
883
- // this test is oom-killed in the CI.
884
- "mir/mir_heavy/issue-miri-1910.rs" ,
839
+ let file = File :: open ( file_path)
840
+ . map_err ( |error| format ! ( "Failed to read `{}`: {:?}" , file_path. display( ) , error) ) ?;
841
+ for line in BufReader :: new ( file) . lines ( ) . filter_map ( |line| line. ok ( ) ) {
842
+ let line = line. trim ( ) ;
843
+ if line. is_empty ( ) {
844
+ continue ;
845
+ }
846
+ if [
847
+ "// error-pattern:" ,
848
+ "// build-fail" ,
849
+ "// run-fail" ,
850
+ "-Cllvm-args" ,
851
+ "//~" ,
852
+ "thread" ,
885
853
]
886
854
. iter ( )
887
- . any ( |to_ignore| path_str. ends_with ( to_ignore) )
855
+ . any ( |check| line. contains ( check) )
856
+ {
857
+ return Ok ( true ) ;
858
+ }
859
+ if line. contains ( "//[" ) && line. contains ( "]~" ) {
860
+ return Ok ( true ) ;
861
+ }
862
+ }
863
+ if file_path
864
+ . display ( )
865
+ . to_string ( )
866
+ . contains ( "ambiguous-4-extern.rs" )
867
+ {
868
+ eprintln ! ( "nothing found for {file_path:?}" ) ;
869
+ }
870
+ Ok ( false )
888
871
}
889
872
890
873
fn test_rustc_inner < F > ( env : & Env , args : & TestArg , prepare_files_callback : F ) -> Result < ( ) , String >
@@ -896,6 +879,8 @@ where
896
879
let mut env = env. clone ( ) ;
897
880
setup_rustc ( & mut env, args) ?;
898
881
882
+ let rust_path = Path :: new ( "rust" ) ;
883
+
899
884
walk_dir (
900
885
"rust/tests/ui" ,
901
886
|dir| {
@@ -924,32 +909,41 @@ where
924
909
// These two functions are used to remove files that are known to not be working currently
925
910
// with the GCC backend to reduce noise.
926
911
fn dir_handling ( dir : & Path ) -> Result < ( ) , String > {
912
+ if dir
913
+ . file_name ( )
914
+ . map ( |name| name == "auxiliary" )
915
+ . unwrap_or ( true )
916
+ {
917
+ return Ok ( ( ) ) ;
918
+ }
927
919
walk_dir ( dir, dir_handling, file_handling)
928
920
}
929
921
fn file_handling ( file_path : & Path ) -> Result < ( ) , String > {
930
- let path_str = file_path. display ( ) . to_string ( ) . replace ( "\\ " , "/" ) ;
931
- if !path_str. ends_with ( ".rs" ) {
922
+ if !file_path
923
+ . extension ( )
924
+ . map ( |extension| extension == "rs" )
925
+ . unwrap_or ( false )
926
+ {
932
927
return Ok ( ( ) ) ;
933
- } else if should_not_remove_test ( & path_str) {
928
+ }
929
+ let path_str = file_path. display ( ) . to_string ( ) . replace ( "\\ " , "/" ) ;
930
+ if should_not_remove_test ( & path_str) {
934
931
return Ok ( ( ) ) ;
935
- } else if should_remove_test ( file_path, & path_str ) {
932
+ } else if should_remove_test ( file_path) ? {
936
933
return remove_file ( & file_path) ;
937
934
}
938
- let file = File :: open ( file_path)
939
- . map_err ( |error| format ! ( "Failed to read `{}`: {:?}" , file_path. display( ) , error) ) ?;
940
- if should_remove_ui_test ( file) {
941
- remove_file ( & file_path) ?;
942
- }
943
935
Ok ( ( ) )
944
936
}
945
937
946
- let rust_path = Path :: new ( "rust" ) ;
938
+ remove_file ( & rust_path. join ( "tests/ui/consts/const_cmp_type_id.rs" ) ) ?;
939
+ remove_file ( & rust_path. join ( "tests/ui/consts/issue-73976-monomorphic.rs" ) ) ?;
940
+ // this test is oom-killed in the CI.
941
+ remove_file ( & rust_path. join ( "tests/ui/consts/issue-miri-1910.rs" ) ) ?;
942
+ // Tests generating errors.
943
+ remove_file ( & rust_path. join ( "tests/ui/consts/issue-94675.rs" ) ) ?;
944
+ remove_file ( & rust_path. join ( "tests/ui/mir/mir_heavy_promoted.rs" ) ) ?;
947
945
948
946
walk_dir ( rust_path. join ( "tests/ui" ) , dir_handling, file_handling) ?;
949
- let file = rust_path. join ( "tests/ui/consts/const_cmp_type_id.rs" ) ;
950
- remove_file ( & file) ?;
951
- let file = rust_path. join ( "tests/ui/consts/issue-73976-monomorphic.rs" ) ;
952
- remove_file ( & file) ?;
953
947
954
948
if !prepare_files_callback ( ) ? {
955
949
// FIXME: create a function "display_if_not_quiet" or something along the line.
@@ -992,26 +986,30 @@ where
992
986
// We increment the number of tests by one because if this is an odd number, we would skip
993
987
// one test.
994
988
let count = files. len ( ) / nb_parts + 1 ;
995
- let start = nb_parts * count;
996
- let end = start + count;
997
- for ( pos, path) in files. iter ( ) . enumerate ( ) {
998
- if pos >= start && pos <= end {
999
- continue ;
1000
- }
1001
- let test_path = rust_path. join ( path) ;
1002
- remove_file ( & test_path) ?;
989
+ let start = current_part * count;
990
+ let end = current_part * count + count;
991
+ // We remove the files we don't want to test.
992
+ for path in files
993
+ . iter ( )
994
+ . enumerate ( )
995
+ . filter ( |( pos, _) | * pos < start || * pos >= end)
996
+ . map ( |( _, path) | path)
997
+ {
998
+ remove_file ( & rust_path. join ( path) ) ?;
1003
999
}
1004
1000
}
1005
1001
1006
1002
// FIXME: create a function "display_if_not_quiet" or something along the line.
1007
1003
println ! ( "[TEST] rustc test suite" ) ;
1008
1004
env. insert ( "COMPILETEST_FORCE_STAGE0" . to_string ( ) , "1" . to_string ( ) ) ;
1009
1005
let rustc_args = format ! (
1010
- "{} {}" ,
1011
- env. get( "RUSTFLAGS" )
1012
- . expect( "RUSTFLAGS should not be empty at this stage" ) ,
1006
+ "{} -Csymbol-mangling-version=v0 -Zcodegen-backend={} --sysroot {}" ,
1013
1007
env. get( "TEST_FLAGS" ) . unwrap_or( & String :: new( ) ) ,
1008
+ args. config_info. cg_backend_path,
1009
+ args. config_info. sysroot_path,
1014
1010
) ;
1011
+
1012
+ env. get_mut ( "RUSTFLAGS" ) . unwrap ( ) . clear ( ) ;
1015
1013
run_command_with_output_and_env (
1016
1014
& [
1017
1015
& "./x.py" ,
0 commit comments