From 80ff1d1a107bc0b89e26c4179794573738bbb3fc Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Thu, 9 Oct 2014 12:11:37 +1300 Subject: [PATCH] Error if we should be able to Valgrind but can't --- configure | 10 +--------- mk/main.mk | 15 ++++++++------- mk/platform.mk | 14 ++++++++++++++ mk/tests.mk | 16 +++++++++++++--- src/compiletest/common.rs | 4 ++++ src/compiletest/compiletest.rs | 11 +++++++++-- src/compiletest/runtest.rs | 2 +- 7 files changed, 50 insertions(+), 22 deletions(-) diff --git a/configure b/configure index 8604dfeaffc..05bfdb3e9fd 100755 --- a/configure +++ b/configure @@ -411,6 +411,7 @@ VAL_OPTIONS="" opt valgrind 0 "run tests with valgrind (memcheck by default)" opt helgrind 0 "run tests with helgrind instead of memcheck" +opt valgrind-rpass 1 "run rpass-valgrind tests with valgrind" opt docs 1 "build documentation" opt optimize 1 "build optimized rust code" opt optimize-cxx 1 "build optimized C++ code" @@ -1236,15 +1237,6 @@ then putvar CFG_PANDOC fi -# Valgrind is only reliable on Linux. On Windows it doesn't work at all, and -# on the Mac the dynamic linker causes Valgrind to emit a huge stream of -# errors. -if [ $CFG_OSTYPE != unknown-linux-gnu ] && [ $CFG_OSTYPE != apple-darwin ] -then - CFG_BAD_VALGRIND=1 - putvar CFG_BAD_VALGRIND -fi - putvar CFG_LLVM_ROOT putvar CFG_LLVM_SRC_DIR diff --git a/mk/main.mk b/mk/main.mk index 93fdda869c9..e927f6ad468 100644 --- a/mk/main.mk +++ b/mk/main.mk @@ -174,19 +174,20 @@ else CFG_VALGRIND_COMPILE := endif -VALGRIND_PATH :=$(CFG_VALGRIND) + +ifndef CFG_DISABLE_VALGRIND_RPASS + $(info cfg: enabling valgrind run-pass tests (CFG_ENABLE_VALGRIND_RPASS)) + CFG_VALGRIND_RPASS :=$(CFG_VALGRIND) +else + CFG_VALGRIND_RPASS := +endif + ifdef CFG_ENABLE_VALGRIND $(info cfg: enabling valgrind (CFG_ENABLE_VALGRIND)) else CFG_VALGRIND := endif -ifdef CFG_BAD_VALGRIND - $(info cfg: disabling valgrind due to its unreliability on this platform) - CFG_VALGRIND := - VALGRIND_PATH := -endif - ###################################################################### # Target-and-rule "utility variables" diff --git a/mk/platform.mk b/mk/platform.mk index beefefcf5e5..9db9138d5e9 100644 --- a/mk/platform.mk +++ b/mk/platform.mk @@ -58,6 +58,20 @@ ifdef CFG_VALGRIND endif endif +# If we actually want to run Valgrind on a given platform, set this variable +define DEF_GOOD_VALGRIND + ifeq ($(OSTYPE_$(1)),unknown-linux-gnu) + GOOD_VALGRIND_$(1) = 1 + endif + ifneq (,$(filter $(OSTYPE_$(1)),darwin freebsd)) + ifeq (HOST_$(1),x86_64) + GOOD_VALGRIND_$(1) = 1 + endif + endif +endef +$(foreach t,$(CFG_TARGET),$(eval $(call DEF_GOOD_VALGRIND,$(t)))) +$(foreach t,$(CFG_TARGET),$(info cfg: good valgrind for $(t) is $(GOOD_VALGRIND_$(t)))) + ifneq ($(findstring linux,$(CFG_OSTYPE)),) ifdef CFG_PERF ifneq ($(CFG_PERF_WITH_LOGFD),) diff --git a/mk/tests.mk b/mk/tests.mk index 07e13057e36..3bbd871e5be 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -530,9 +530,6 @@ CTEST_SRC_BASE_rpass-valgrind = run-pass-valgrind CTEST_BUILD_BASE_rpass-valgrind = run-pass-valgrind CTEST_MODE_rpass-valgrind = run-pass-valgrind CTEST_RUNTOOL_rpass-valgrind = $(CTEST_RUNTOOL) -ifdef VALGRIND_PATH -CTEST_TESTARGS += --valgrind-path "$(VALGRIND_PATH)" -endif CTEST_SRC_BASE_rpass-full = run-pass-fulldeps CTEST_BUILD_BASE_rpass-full = run-pass-fulldeps @@ -662,6 +659,19 @@ CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) := \ --target-rustcflags "$(RUSTC_FLAGS_$(2)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(2))" \ $$(CTEST_TESTARGS) +ifdef CFG_VALGRIND_RPASS +ifdef GOOD_VALGRIND_$(2) +$(info cfg: valgrind-path set to $(CFG_VALGRIND_RPASS)) +CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) += --valgrind-path "$(CFG_VALGRIND_RPASS)" +endif +endif + +ifndef CFG_DISABLE_VALGRIND_RPASS +ifdef GOOD_VALGRIND_$(2) +CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) += --force-valgrind +endif +endif + CTEST_DEPS_rpass_$(1)-T-$(2)-H-$(3) = $$(RPASS_TESTS) CTEST_DEPS_rpass-valgrind_$(1)-T-$(2)-H-$(3) = $$(RPASS_VALGRIND_TESTS) CTEST_DEPS_rpass-full_$(1)-T-$(2)-H-$(3) = $$(RPASS_FULL_TESTS) $$(CSREQ$(1)_T_$(3)_H_$(3)) $$(SREQ$(1)_T_$(2)_H_$(3)) diff --git a/src/compiletest/common.rs b/src/compiletest/common.rs index d8a0afc38e7..2c917f7aefe 100644 --- a/src/compiletest/common.rs +++ b/src/compiletest/common.rs @@ -76,6 +76,10 @@ pub struct Config { // The valgrind path pub valgrind_path: Option, + // Whether to fail if we can't run run-pass-valgrind tests under valgrind + // (or, alternatively, to silently run them like regular run-pass tests). + pub force_valgrind: bool, + // The directory containing the tests to run pub src_base: Path, diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index 3ac25937b38..7af25de1f6f 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -39,6 +39,11 @@ pub mod errors; pub fn main() { let args = os::args(); let config = parse_config(args); + + if config.valgrind_path.is_none() && config.force_valgrind { + fail!("Can't find Valgrind to run Valgrind tests"); + } + log_config(&config); run_tests(&config); } @@ -50,7 +55,8 @@ pub fn parse_config(args: Vec ) -> Config { reqopt("", "run-lib-path", "path to target shared libraries", "PATH"), reqopt("", "rustc-path", "path to rustc to use for compiling", "PATH"), optopt("", "clang-path", "path to executable for codegen tests", "PATH"), - optopt("", "valgrind-path", "path to valgrind executable for valgrind tests", "PROGRAM"), + optopt("", "valgrind-path", "path to Valgrind executable for Valgrind tests", "PROGRAM"), + optflag("", "force-valgrind", "fail if Valgrind tests cannot be run under Valgrind"), optopt("", "llvm-bin-path", "path to directory holding llvm binaries", "DIR"), reqopt("", "src-base", "directory to scan for test files", "PATH"), reqopt("", "build-base", "directory to deposit test outputs", "PATH"), @@ -127,6 +133,7 @@ pub fn parse_config(args: Vec ) -> Config { rustc_path: opt_path(matches, "rustc-path"), clang_path: matches.opt_str("clang-path").map(|s| Path::new(s)), valgrind_path: matches.opt_str("valgrind-path"), + force_valgrind: matches.opt_present("force-valgrind"), llvm_bin_path: matches.opt_str("llvm-bin-path").map(|s| Path::new(s)), src_base: opt_path(matches, "src-base"), build_base: opt_path(matches, "build-base"), @@ -164,7 +171,7 @@ pub fn parse_config(args: Vec ) -> Config { !opt_str2(matches.opt_str("adb-test-dir")).is_empty(), lldb_python_dir: matches.opt_str("lldb-python-dir"), test_shard: test::opt_shard(matches.opt_str("test-shard")), - verbose: matches.opt_present("verbose") + verbose: matches.opt_present("verbose"), } } diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index 6b542fed68d..34129dedbd8 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -166,6 +166,7 @@ fn run_rpass_test(config: &Config, props: &TestProps, testfile: &Path) { fn run_valgrind_test(config: &Config, props: &TestProps, testfile: &Path) { if config.valgrind_path.is_none() { + assert!(!config.force_valgrind); return run_rpass_test(config, props, testfile); } @@ -175,7 +176,6 @@ fn run_valgrind_test(config: &Config, props: &TestProps, testfile: &Path) { fatal_proc_rec("compilation failed!", &proc_res); } - println!("running valgrind"); let mut new_config = config.clone(); new_config.runtool = new_config.valgrind_path.clone(); proc_res = exec_compiled_test(&new_config, props, testfile);