@@ -15,6 +15,16 @@ use tempdir::TempDir;
15
15
static CRATE_NAME : & ' static str = "gcmalloc" ;
16
16
17
17
fn main ( ) {
18
+ let sanitizers: Vec < String > = match env:: var ( "SANITIZERS" ) {
19
+ Ok ( ref s) => s. split ( ';' ) . map ( |s| s. to_string ( ) ) . collect ( ) ,
20
+ Err ( _) => Vec :: new ( ) ,
21
+ } ;
22
+
23
+ let valgrind: bool = match env:: var ( "VALGRIND" ) {
24
+ Ok ( ref s) => s == "true" ,
25
+ Err ( _) => false ,
26
+ } ;
27
+
18
28
// We grab the rlibs from `target/<debug | release>/` but in order
19
29
// for them to exist here, they must have been moved from `deps/`.
20
30
// Simply running `cargo test` will not do this, instead, we must
@@ -65,6 +75,9 @@ fn main() {
65
75
let lib_arg = [ CRATE_NAME , "=" , lib_path. to_str ( ) . unwrap ( ) ] . concat ( ) ;
66
76
let deps_arg = [ "dependency=" , deps_path. to_str ( ) . unwrap ( ) ] . concat ( ) ;
67
77
78
+ let san_flags = sanitizers. iter ( ) . map ( |x| format ! ( "-Zsanitizer={}" , x) ) ;
79
+ compiler. args ( san_flags) ;
80
+
68
81
compiler. args ( & [
69
82
"--edition=2018" ,
70
83
"-o" ,
@@ -78,7 +91,25 @@ fn main() {
78
91
lib_arg. as_str ( ) ,
79
92
] ) ;
80
93
81
- let runtime = Command :: new ( exe) ;
94
+ assert ! (
95
+ !( valgrind && !sanitizers. is_empty( ) ) ,
96
+ "Valgrind can't be used on code compiled with sanitizers"
97
+ ) ;
98
+
99
+ let mut runtime;
100
+ if valgrind {
101
+ let suppr_file = PathBuf :: from ( "gc_tests/valgrind.supp" ) ;
102
+ let suppressions = [ "--suppressions=" , suppr_file. to_str ( ) . unwrap ( ) ] . concat ( ) ;
103
+ runtime = Command :: new ( "valgrind" ) ;
104
+ runtime. args ( & [
105
+ "--error-exitcode=1" ,
106
+ suppressions. as_str ( ) ,
107
+ exe. to_str ( ) . unwrap ( ) ,
108
+ ] ) ;
109
+ } else {
110
+ runtime = Command :: new ( exe) ;
111
+ } ;
112
+
82
113
vec ! [ ( "Compiler" , compiler) , ( "Run-time" , runtime) ]
83
114
} )
84
115
. run ( ) ;
0 commit comments