@@ -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,10 @@ 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
+
80
+ compiler. args ( san_flags) ;
81
+
68
82
compiler. args ( & [
69
83
"--edition=2018" ,
70
84
"-o" ,
@@ -78,7 +92,25 @@ fn main() {
78
92
lib_arg. as_str ( ) ,
79
93
] ) ;
80
94
81
- let runtime = Command :: new ( exe) ;
95
+ assert ! (
96
+ !( valgrind && !sanitizers. is_empty( ) ) ,
97
+ "Valgrind can't be used on code compiled with sanitizers"
98
+ ) ;
99
+
100
+ let mut runtime;
101
+ if valgrind {
102
+ let suppr_file = PathBuf :: from ( "gc_tests/valgrind.supp" ) ;
103
+ let suppressions = [ "--suppressions=" , suppr_file. to_str ( ) . unwrap ( ) ] . concat ( ) ;
104
+ runtime = Command :: new ( "valgrind" ) ;
105
+ runtime. args ( & [
106
+ "--error-exitcode=1" ,
107
+ suppressions. as_str ( ) ,
108
+ exe. to_str ( ) . unwrap ( ) ,
109
+ ] ) ;
110
+ } else {
111
+ runtime = Command :: new ( exe) ;
112
+ } ;
113
+
82
114
vec ! [ ( "Compiler" , compiler) , ( "Run-time" , runtime) ]
83
115
} )
84
116
. run ( ) ;
0 commit comments