Skip to content

Commit 80ff1d1

Browse files
committed
Error if we should be able to Valgrind but can't
1 parent 1285d4f commit 80ff1d1

File tree

7 files changed

+50
-22
lines changed

7 files changed

+50
-22
lines changed

configure

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ VAL_OPTIONS=""
411411

412412
opt valgrind 0 "run tests with valgrind (memcheck by default)"
413413
opt helgrind 0 "run tests with helgrind instead of memcheck"
414+
opt valgrind-rpass 1 "run rpass-valgrind tests with valgrind"
414415
opt docs 1 "build documentation"
415416
opt optimize 1 "build optimized rust code"
416417
opt optimize-cxx 1 "build optimized C++ code"
@@ -1236,15 +1237,6 @@ then
12361237
putvar CFG_PANDOC
12371238
fi
12381239

1239-
# Valgrind is only reliable on Linux. On Windows it doesn't work at all, and
1240-
# on the Mac the dynamic linker causes Valgrind to emit a huge stream of
1241-
# errors.
1242-
if [ $CFG_OSTYPE != unknown-linux-gnu ] && [ $CFG_OSTYPE != apple-darwin ]
1243-
then
1244-
CFG_BAD_VALGRIND=1
1245-
putvar CFG_BAD_VALGRIND
1246-
fi
1247-
12481240
putvar CFG_LLVM_ROOT
12491241
putvar CFG_LLVM_SRC_DIR
12501242

mk/main.mk

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,19 +174,20 @@ else
174174
CFG_VALGRIND_COMPILE :=
175175
endif
176176

177-
VALGRIND_PATH :=$(CFG_VALGRIND)
177+
178+
ifndef CFG_DISABLE_VALGRIND_RPASS
179+
$(info cfg: enabling valgrind run-pass tests (CFG_ENABLE_VALGRIND_RPASS))
180+
CFG_VALGRIND_RPASS :=$(CFG_VALGRIND)
181+
else
182+
CFG_VALGRIND_RPASS :=
183+
endif
184+
178185

179186
ifdef CFG_ENABLE_VALGRIND
180187
$(info cfg: enabling valgrind (CFG_ENABLE_VALGRIND))
181188
else
182189
CFG_VALGRIND :=
183190
endif
184-
ifdef CFG_BAD_VALGRIND
185-
$(info cfg: disabling valgrind due to its unreliability on this platform)
186-
CFG_VALGRIND :=
187-
VALGRIND_PATH :=
188-
endif
189-
190191

191192
######################################################################
192193
# Target-and-rule "utility variables"

mk/platform.mk

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,20 @@ ifdef CFG_VALGRIND
5858
endif
5959
endif
6060

61+
# If we actually want to run Valgrind on a given platform, set this variable
62+
define DEF_GOOD_VALGRIND
63+
ifeq ($(OSTYPE_$(1)),unknown-linux-gnu)
64+
GOOD_VALGRIND_$(1) = 1
65+
endif
66+
ifneq (,$(filter $(OSTYPE_$(1)),darwin freebsd))
67+
ifeq (HOST_$(1),x86_64)
68+
GOOD_VALGRIND_$(1) = 1
69+
endif
70+
endif
71+
endef
72+
$(foreach t,$(CFG_TARGET),$(eval $(call DEF_GOOD_VALGRIND,$(t))))
73+
$(foreach t,$(CFG_TARGET),$(info cfg: good valgrind for $(t) is $(GOOD_VALGRIND_$(t))))
74+
6175
ifneq ($(findstring linux,$(CFG_OSTYPE)),)
6276
ifdef CFG_PERF
6377
ifneq ($(CFG_PERF_WITH_LOGFD),)

mk/tests.mk

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,9 +530,6 @@ CTEST_SRC_BASE_rpass-valgrind = run-pass-valgrind
530530
CTEST_BUILD_BASE_rpass-valgrind = run-pass-valgrind
531531
CTEST_MODE_rpass-valgrind = run-pass-valgrind
532532
CTEST_RUNTOOL_rpass-valgrind = $(CTEST_RUNTOOL)
533-
ifdef VALGRIND_PATH
534-
CTEST_TESTARGS += --valgrind-path "$(VALGRIND_PATH)"
535-
endif
536533

537534
CTEST_SRC_BASE_rpass-full = run-pass-fulldeps
538535
CTEST_BUILD_BASE_rpass-full = run-pass-fulldeps
@@ -662,6 +659,19 @@ CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) := \
662659
--target-rustcflags "$(RUSTC_FLAGS_$(2)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(2))" \
663660
$$(CTEST_TESTARGS)
664661

662+
ifdef CFG_VALGRIND_RPASS
663+
ifdef GOOD_VALGRIND_$(2)
664+
$(info cfg: valgrind-path set to $(CFG_VALGRIND_RPASS))
665+
CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) += --valgrind-path "$(CFG_VALGRIND_RPASS)"
666+
endif
667+
endif
668+
669+
ifndef CFG_DISABLE_VALGRIND_RPASS
670+
ifdef GOOD_VALGRIND_$(2)
671+
CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) += --force-valgrind
672+
endif
673+
endif
674+
665675
CTEST_DEPS_rpass_$(1)-T-$(2)-H-$(3) = $$(RPASS_TESTS)
666676
CTEST_DEPS_rpass-valgrind_$(1)-T-$(2)-H-$(3) = $$(RPASS_VALGRIND_TESTS)
667677
CTEST_DEPS_rpass-full_$(1)-T-$(2)-H-$(3) = $$(RPASS_FULL_TESTS) $$(CSREQ$(1)_T_$(3)_H_$(3)) $$(SREQ$(1)_T_$(2)_H_$(3))

src/compiletest/common.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ pub struct Config {
7676
// The valgrind path
7777
pub valgrind_path: Option<String>,
7878

79+
// Whether to fail if we can't run run-pass-valgrind tests under valgrind
80+
// (or, alternatively, to silently run them like regular run-pass tests).
81+
pub force_valgrind: bool,
82+
7983
// The directory containing the tests to run
8084
pub src_base: Path,
8185

src/compiletest/compiletest.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ pub mod errors;
3939
pub fn main() {
4040
let args = os::args();
4141
let config = parse_config(args);
42+
43+
if config.valgrind_path.is_none() && config.force_valgrind {
44+
fail!("Can't find Valgrind to run Valgrind tests");
45+
}
46+
4247
log_config(&config);
4348
run_tests(&config);
4449
}
@@ -50,7 +55,8 @@ pub fn parse_config(args: Vec<String> ) -> Config {
5055
reqopt("", "run-lib-path", "path to target shared libraries", "PATH"),
5156
reqopt("", "rustc-path", "path to rustc to use for compiling", "PATH"),
5257
optopt("", "clang-path", "path to executable for codegen tests", "PATH"),
53-
optopt("", "valgrind-path", "path to valgrind executable for valgrind tests", "PROGRAM"),
58+
optopt("", "valgrind-path", "path to Valgrind executable for Valgrind tests", "PROGRAM"),
59+
optflag("", "force-valgrind", "fail if Valgrind tests cannot be run under Valgrind"),
5460
optopt("", "llvm-bin-path", "path to directory holding llvm binaries", "DIR"),
5561
reqopt("", "src-base", "directory to scan for test files", "PATH"),
5662
reqopt("", "build-base", "directory to deposit test outputs", "PATH"),
@@ -127,6 +133,7 @@ pub fn parse_config(args: Vec<String> ) -> Config {
127133
rustc_path: opt_path(matches, "rustc-path"),
128134
clang_path: matches.opt_str("clang-path").map(|s| Path::new(s)),
129135
valgrind_path: matches.opt_str("valgrind-path"),
136+
force_valgrind: matches.opt_present("force-valgrind"),
130137
llvm_bin_path: matches.opt_str("llvm-bin-path").map(|s| Path::new(s)),
131138
src_base: opt_path(matches, "src-base"),
132139
build_base: opt_path(matches, "build-base"),
@@ -164,7 +171,7 @@ pub fn parse_config(args: Vec<String> ) -> Config {
164171
!opt_str2(matches.opt_str("adb-test-dir")).is_empty(),
165172
lldb_python_dir: matches.opt_str("lldb-python-dir"),
166173
test_shard: test::opt_shard(matches.opt_str("test-shard")),
167-
verbose: matches.opt_present("verbose")
174+
verbose: matches.opt_present("verbose"),
168175
}
169176
}
170177

src/compiletest/runtest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ fn run_rpass_test(config: &Config, props: &TestProps, testfile: &Path) {
166166

167167
fn run_valgrind_test(config: &Config, props: &TestProps, testfile: &Path) {
168168
if config.valgrind_path.is_none() {
169+
assert!(!config.force_valgrind);
169170
return run_rpass_test(config, props, testfile);
170171
}
171172

@@ -175,7 +176,6 @@ fn run_valgrind_test(config: &Config, props: &TestProps, testfile: &Path) {
175176
fatal_proc_rec("compilation failed!", &proc_res);
176177
}
177178

178-
println!("running valgrind");
179179
let mut new_config = config.clone();
180180
new_config.runtool = new_config.valgrind_path.clone();
181181
proc_res = exec_compiled_test(&new_config, props, testfile);

0 commit comments

Comments
 (0)