Skip to content

Commit 8a40854

Browse files
committed
auto merge of #17868 : nick29581/rust/valgrind, r=alexcrichton
r? @alexcrichton
2 parents 96991e9 + 80ff1d1 commit 8a40854

File tree

11 files changed

+110
-36
lines changed

11 files changed

+110
-36
lines changed

configure

Lines changed: 2 additions & 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"
@@ -906,6 +907,7 @@ do
906907
done
907908

908909
make_dir $h/test/run-pass
910+
make_dir $h/test/run-pass-valgrind
909911
make_dir $h/test/run-pass-fulldeps
910912
make_dir $h/test/run-fail
911913
make_dir $h/test/compile-fail
@@ -1235,15 +1237,6 @@ then
12351237
putvar CFG_PANDOC
12361238
fi
12371239

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

mk/main.mk

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

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+
185+
177186
ifdef CFG_ENABLE_VALGRIND
178187
$(info cfg: enabling valgrind (CFG_ENABLE_VALGRIND))
179188
else
180189
CFG_VALGRIND :=
181190
endif
182-
ifdef CFG_BAD_VALGRIND
183-
$(info cfg: disabling valgrind due to its unreliability on this platform)
184-
CFG_VALGRIND :=
185-
endif
186-
187191

188192
######################################################################
189193
# 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: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
# Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
22
# file at the top-level directory of this distribution and at
33
# http://rust-lang.org/COPYRIGHT.
44
#
@@ -184,12 +184,12 @@ check-notidy: cleantmptestlogs cleantestlibs all check-stage2
184184
# A slightly smaller set of tests for smoke testing.
185185
check-lite: cleantestlibs cleantmptestlogs \
186186
$(foreach crate,$(TEST_TARGET_CRATES),check-stage2-$(crate)) \
187-
check-stage2-rpass \
187+
check-stage2-rpass check-stage2-rpass-valgrind \
188188
check-stage2-rfail check-stage2-cfail check-stage2-rmake
189189
$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
190190

191191
# Only check the 'reference' tests: rpass/cfail/rfail/rmake.
192-
check-ref: cleantestlibs cleantmptestlogs check-stage2-rpass \
192+
check-ref: cleantestlibs cleantmptestlogs check-stage2-rpass check-stage2-rpass-valgrind \
193193
check-stage2-rfail check-stage2-cfail check-stage2-rmake
194194
$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
195195

@@ -326,7 +326,8 @@ check-stage$(1)-T-$(2)-H-$(3)-exec: \
326326
check-stage$(1)-T-$(2)-H-$(3)-rpass-exec \
327327
check-stage$(1)-T-$(2)-H-$(3)-rfail-exec \
328328
check-stage$(1)-T-$(2)-H-$(3)-cfail-exec \
329-
check-stage$(1)-T-$(2)-H-$(3)-rpass-full-exec \
329+
check-stage$(1)-T-$(2)-H-$(3)-rpass-valgrind-exec \
330+
check-stage$(1)-T-$(2)-H-$(3)-rpass-full-exec \
330331
check-stage$(1)-T-$(2)-H-$(3)-cfail-full-exec \
331332
check-stage$(1)-T-$(2)-H-$(3)-rmake-exec \
332333
check-stage$(1)-T-$(2)-H-$(3)-crates-exec \
@@ -364,6 +365,7 @@ check-stage$(1)-T-$(2)-H-$(3)-doc-exec: \
364365

365366
check-stage$(1)-T-$(2)-H-$(3)-pretty-exec: \
366367
check-stage$(1)-T-$(2)-H-$(3)-pretty-rpass-exec \
368+
check-stage$(1)-T-$(2)-H-$(3)-pretty-rpass-valgrind-exec \
367369
check-stage$(1)-T-$(2)-H-$(3)-pretty-rpass-full-exec \
368370
check-stage$(1)-T-$(2)-H-$(3)-pretty-rfail-exec \
369371
check-stage$(1)-T-$(2)-H-$(3)-pretty-bench-exec \
@@ -489,15 +491,11 @@ $(foreach host,$(CFG_HOST), \
489491
# Rules for the compiletest tests (rpass, rfail, etc.)
490492
######################################################################
491493

492-
RPASS_RC := $(wildcard $(S)src/test/run-pass/*.rc)
493494
RPASS_RS := $(wildcard $(S)src/test/run-pass/*.rs)
494-
RPASS_FULL_RC := $(wildcard $(S)src/test/run-pass-fulldeps/*.rc)
495+
RPASS_VALGRIND_RS := $(wildcard $(S)src/test/run-pass-valgrind/*.rs)
495496
RPASS_FULL_RS := $(wildcard $(S)src/test/run-pass-fulldeps/*.rs)
496-
CFAIL_FULL_RC := $(wildcard $(S)src/test/compile-fail-fulldeps/*.rc)
497497
CFAIL_FULL_RS := $(wildcard $(S)src/test/compile-fail-fulldeps/*.rs)
498-
RFAIL_RC := $(wildcard $(S)src/test/run-fail/*.rc)
499498
RFAIL_RS := $(wildcard $(S)src/test/run-fail/*.rs)
500-
CFAIL_RC := $(wildcard $(S)src/test/compile-fail/*.rc)
501499
CFAIL_RS := $(wildcard $(S)src/test/compile-fail/*.rs)
502500
BENCH_RS := $(wildcard $(S)src/test/bench/*.rs)
503501
PRETTY_RS := $(wildcard $(S)src/test/pretty/*.rs)
@@ -510,11 +508,12 @@ CODEGEN_CC := $(wildcard $(S)src/test/codegen/*.cc)
510508
# a performance monitor.
511509
PERF_RS := $(wildcard $(S)src/test/bench/*.rs)
512510

513-
RPASS_TESTS := $(RPASS_RC) $(RPASS_RS)
514-
RPASS_FULL_TESTS := $(RPASS_FULL_RC) $(RPASS_FULL_RS)
515-
CFAIL_FULL_TESTS := $(CFAIL_FULL_RC) $(CFAIL_FULL_RS)
516-
RFAIL_TESTS := $(RFAIL_RC) $(RFAIL_RS)
517-
CFAIL_TESTS := $(CFAIL_RC) $(CFAIL_RS)
511+
RPASS_TESTS := $(RPASS_RS)
512+
RPASS_VALGRIND_TESTS := $(RPASS_VALGRIND_RS)
513+
RPASS_FULL_TESTS := $(RPASS_FULL_RS)
514+
CFAIL_FULL_TESTS := $(CFAIL_FULL_RS)
515+
RFAIL_TESTS := $(RFAIL_RS)
516+
CFAIL_TESTS := $(CFAIL_RS)
518517
BENCH_TESTS := $(BENCH_RS)
519518
PERF_TESTS := $(PERF_RS)
520519
PRETTY_TESTS := $(PRETTY_RS)
@@ -527,6 +526,11 @@ CTEST_BUILD_BASE_rpass = run-pass
527526
CTEST_MODE_rpass = run-pass
528527
CTEST_RUNTOOL_rpass = $(CTEST_RUNTOOL)
529528

529+
CTEST_SRC_BASE_rpass-valgrind = run-pass-valgrind
530+
CTEST_BUILD_BASE_rpass-valgrind = run-pass-valgrind
531+
CTEST_MODE_rpass-valgrind = run-pass-valgrind
532+
CTEST_RUNTOOL_rpass-valgrind = $(CTEST_RUNTOOL)
533+
530534
CTEST_SRC_BASE_rpass-full = run-pass-fulldeps
531535
CTEST_BUILD_BASE_rpass-full = run-pass-fulldeps
532536
CTEST_MODE_rpass-full = run-pass
@@ -622,7 +626,7 @@ TEST_SREQ$(1)_T_$(2)_H_$(3) = \
622626
# remove directive, if present, from CFG_RUSTC_FLAGS (issue #7898).
623627
CTEST_RUSTC_FLAGS := $$(subst --cfg ndebug,,$$(CFG_RUSTC_FLAGS))
624628

625-
# The tests can not be optimized while the rest of the compiler is optimized, so
629+
# The tests cannot be optimized while the rest of the compiler is optimized, so
626630
# filter out the optimization (if any) from rustc and then figure out if we need
627631
# to be optimized
628632
CTEST_RUSTC_FLAGS := $$(subst -O,,$$(CTEST_RUSTC_FLAGS))
@@ -634,6 +638,7 @@ endif
634638
# slow things down.
635639
CTEST_RUSTC_FLAGS += -C codegen-units=1
636640

641+
637642
CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) := \
638643
--compile-lib-path $$(HLIB$(1)_H_$(3)) \
639644
--run-lib-path $$(TLIB$(1)_T_$(2)_H_$(3)) \
@@ -654,7 +659,21 @@ CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) := \
654659
--target-rustcflags "$(RUSTC_FLAGS_$(2)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(2))" \
655660
$$(CTEST_TESTARGS)
656661

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+
657675
CTEST_DEPS_rpass_$(1)-T-$(2)-H-$(3) = $$(RPASS_TESTS)
676+
CTEST_DEPS_rpass-valgrind_$(1)-T-$(2)-H-$(3) = $$(RPASS_VALGRIND_TESTS)
658677
CTEST_DEPS_rpass-full_$(1)-T-$(2)-H-$(3) = $$(RPASS_FULL_TESTS) $$(CSREQ$(1)_T_$(3)_H_$(3)) $$(SREQ$(1)_T_$(2)_H_$(3))
659678
CTEST_DEPS_cfail-full_$(1)-T-$(2)-H-$(3) = $$(CFAIL_FULL_TESTS) $$(CSREQ$(1)_T_$(3)_H_$(3)) $$(SREQ$(1)_T_$(2)_H_$(3))
660679
CTEST_DEPS_rfail_$(1)-T-$(2)-H-$(3) = $$(RFAIL_TESTS)
@@ -726,16 +745,17 @@ endif
726745

727746
endef
728747

729-
CTEST_NAMES = rpass rpass-full cfail-full rfail cfail bench perf debuginfo-gdb debuginfo-lldb codegen
748+
CTEST_NAMES = rpass rpass-valgrind rpass-full cfail-full rfail cfail bench perf debuginfo-gdb debuginfo-lldb codegen
730749

731750
$(foreach host,$(CFG_HOST), \
732751
$(eval $(foreach target,$(CFG_TARGET), \
733752
$(eval $(foreach stage,$(STAGES), \
734753
$(eval $(foreach name,$(CTEST_NAMES), \
735754
$(eval $(call DEF_RUN_COMPILETEST,$(stage),$(target),$(host),$(name))))))))))
736755

737-
PRETTY_NAMES = pretty-rpass pretty-rpass-full pretty-rfail pretty-bench pretty-pretty
756+
PRETTY_NAMES = pretty-rpass pretty-rpass-valgrind pretty-rpass-full pretty-rfail pretty-bench pretty-pretty
738757
PRETTY_DEPS_pretty-rpass = $(RPASS_TESTS)
758+
PRETTY_DEPS_pretty-rpass-valgrind = $(RPASS_VALGRIND_TESTS)
739759
PRETTY_DEPS_pretty-rpass-full = $(RPASS_FULL_TESTS)
740760
PRETTY_DEPS_pretty-rfail = $(RFAIL_TESTS)
741761
PRETTY_DEPS_pretty-bench = $(BENCH_TESTS)
@@ -748,6 +768,7 @@ PRETTY_DEPS$(1)_H_$(3)_pretty-rfail =
748768
PRETTY_DEPS$(1)_H_$(3)_pretty-bench =
749769
PRETTY_DEPS$(1)_H_$(3)_pretty-pretty =
750770
PRETTY_DIRNAME_pretty-rpass = run-pass
771+
PRETTY_DIRNAME_pretty-rpass-valgrind = run-pass-valgrind
751772
PRETTY_DIRNAME_pretty-rpass-full = run-pass-fulldeps
752773
PRETTY_DIRNAME_pretty-rfail = run-fail
753774
PRETTY_DIRNAME_pretty-bench = bench
@@ -895,6 +916,7 @@ TEST_GROUPS = \
895916
$(foreach crate,$(TEST_CRATES),$(crate)) \
896917
$(foreach crate,$(TEST_DOC_CRATES),doc-crate-$(crate)) \
897918
rpass \
919+
rpass-valgrind \
898920
rpass-full \
899921
cfail-full \
900922
rfail \
@@ -909,6 +931,7 @@ TEST_GROUPS = \
909931
$(foreach docname,$(DOCS),doc-$(docname)) \
910932
pretty \
911933
pretty-rpass \
934+
pretty-rpass-valgrind \
912935
pretty-rpass-full \
913936
pretty-rfail \
914937
pretty-bench \

src/compiletest/common.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub enum Mode {
1717
CompileFail,
1818
RunFail,
1919
RunPass,
20+
RunPassValgrind,
2021
Pretty,
2122
DebugInfoGdb,
2223
DebugInfoLldb,
@@ -29,6 +30,7 @@ impl FromStr for Mode {
2930
"compile-fail" => Some(CompileFail),
3031
"run-fail" => Some(RunFail),
3132
"run-pass" => Some(RunPass),
33+
"run-pass-valgrind" => Some(RunPassValgrind),
3234
"pretty" => Some(Pretty),
3335
"debuginfo-lldb" => Some(DebugInfoLldb),
3436
"debuginfo-gdb" => Some(DebugInfoGdb),
@@ -44,6 +46,7 @@ impl fmt::Show for Mode {
4446
CompileFail => "compile-fail",
4547
RunFail => "run-fail",
4648
RunPass => "run-pass",
49+
RunPassValgrind => "run-pass-valgrind",
4750
Pretty => "pretty",
4851
DebugInfoGdb => "debuginfo-gdb",
4952
DebugInfoLldb => "debuginfo-lldb",
@@ -70,6 +73,13 @@ pub struct Config {
7073
// The llvm binaries path
7174
pub llvm_bin_path: Option<Path>,
7275

76+
// The valgrind path
77+
pub valgrind_path: Option<String>,
78+
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+
7383
// The directory containing the tests to run
7484
pub src_base: Path,
7585

src/compiletest/compiletest.rs

Lines changed: 11 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,13 +55,15 @@ 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"),
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"),
5360
optopt("", "llvm-bin-path", "path to directory holding llvm binaries", "DIR"),
5461
reqopt("", "src-base", "directory to scan for test files", "PATH"),
5562
reqopt("", "build-base", "directory to deposit test outputs", "PATH"),
5663
reqopt("", "aux-base", "directory to find auxiliary test files", "PATH"),
5764
reqopt("", "stage-id", "the target-stage identifier", "stageN-TARGET"),
5865
reqopt("", "mode", "which sort of compile tests to run",
59-
"(compile-fail|run-fail|run-pass|pretty|debug-info)"),
66+
"(compile-fail|run-fail|run-pass|run-pass-valgrind|pretty|debug-info)"),
6067
optflag("", "ignored", "run tests marked as ignored"),
6168
optopt("", "runtool", "supervisor program to run tests under \
6269
(eg. emulator, valgrind)", "PROGRAM"),
@@ -125,6 +132,8 @@ pub fn parse_config(args: Vec<String> ) -> Config {
125132
run_lib_path: matches.opt_str("run-lib-path").unwrap(),
126133
rustc_path: opt_path(matches, "rustc-path"),
127134
clang_path: matches.opt_str("clang-path").map(|s| Path::new(s)),
135+
valgrind_path: matches.opt_str("valgrind-path"),
136+
force_valgrind: matches.opt_present("force-valgrind"),
128137
llvm_bin_path: matches.opt_str("llvm-bin-path").map(|s| Path::new(s)),
129138
src_base: opt_path(matches, "src-base"),
130139
build_base: opt_path(matches, "build-base"),
@@ -162,7 +171,7 @@ pub fn parse_config(args: Vec<String> ) -> Config {
162171
!opt_str2(matches.opt_str("adb-test-dir")).is_empty(),
163172
lldb_python_dir: matches.opt_str("lldb-python-dir"),
164173
test_shard: test::opt_shard(matches.opt_str("test-shard")),
165-
verbose: matches.opt_present("verbose")
174+
verbose: matches.opt_present("verbose"),
166175
}
167176
}
168177

src/compiletest/runtest.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use common::Config;
12-
use common::{CompileFail, Pretty, RunFail, RunPass, DebugInfoGdb};
12+
use common::{CompileFail, Pretty, RunFail, RunPass, RunPassValgrind, DebugInfoGdb};
1313
use common::{Codegen, DebugInfoLldb};
1414
use errors;
1515
use header::TestProps;
@@ -35,7 +35,6 @@ use std::time::Duration;
3535
use test::MetricMap;
3636

3737
pub fn run(config: Config, testfile: String) {
38-
3938
match config.target.as_slice() {
4039

4140
"arm-linux-androideabi" => {
@@ -64,6 +63,7 @@ pub fn run_metrics(config: Config, testfile: String, mm: &mut MetricMap) {
6463
CompileFail => run_cfail_test(&config, &props, &testfile),
6564
RunFail => run_rfail_test(&config, &props, &testfile),
6665
RunPass => run_rpass_test(&config, &props, &testfile),
66+
RunPassValgrind => run_valgrind_test(&config, &props, &testfile),
6767
Pretty => run_pretty_test(&config, &props, &testfile),
6868
DebugInfoGdb => run_debuginfo_gdb_test(&config, &props, &testfile),
6969
DebugInfoLldb => run_debuginfo_lldb_test(&config, &props, &testfile),
@@ -164,6 +164,27 @@ fn run_rpass_test(config: &Config, props: &TestProps, testfile: &Path) {
164164
}
165165
}
166166

167+
fn run_valgrind_test(config: &Config, props: &TestProps, testfile: &Path) {
168+
if config.valgrind_path.is_none() {
169+
assert!(!config.force_valgrind);
170+
return run_rpass_test(config, props, testfile);
171+
}
172+
173+
let mut proc_res = compile_test(config, props, testfile);
174+
175+
if !proc_res.status.success() {
176+
fatal_proc_rec("compilation failed!", &proc_res);
177+
}
178+
179+
let mut new_config = config.clone();
180+
new_config.runtool = new_config.valgrind_path.clone();
181+
proc_res = exec_compiled_test(&new_config, props, testfile);
182+
183+
if !proc_res.status.success() {
184+
fatal_proc_rec("test run failed!", &proc_res);
185+
}
186+
}
187+
167188
fn run_pretty_test(config: &Config, props: &TestProps, testfile: &Path) {
168189
if props.pp_exact.is_some() {
169190
logv(config, "testing for exact pretty-printing".to_string());

src/libgetopts/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ pub fn short_usage(program_name: &str, opts: &[OptGroup]) -> String {
804804
/// whitespace removed, and are only cut at whitespace boundaries.
805805
///
806806
/// Note: Function was moved here from `std::str` because this module is the only place that
807-
/// uses it, and because it was to specific for a general string function.
807+
/// uses it, and because it was too specific for a general string function.
808808
///
809809
/// #Failure:
810810
///

0 commit comments

Comments
 (0)