Skip to content

Commit addc172

Browse files
committed
auto merge of #17868 : nick29581/rust/valgrind, r=alexcrichton
r? @alexcrichton
2 parents 045bc28 + 85ea3fb commit addc172

File tree

10 files changed

+86
-23
lines changed

10 files changed

+86
-23
lines changed

configure

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,7 @@ do
906906
done
907907

908908
make_dir $h/test/run-pass
909+
make_dir $h/test/run-pass-valgrind
909910
make_dir $h/test/run-pass-fulldeps
910911
make_dir $h/test/run-fail
911912
make_dir $h/test/compile-fail
@@ -1238,7 +1239,8 @@ fi
12381239
# Valgrind is only reliable on Linux. On Windows it doesn't work at all, and
12391240
# on the Mac the dynamic linker causes Valgrind to emit a huge stream of
12401241
# errors.
1241-
if [ $CFG_OSTYPE != unknown-linux-gnu ] && [ $CFG_OSTYPE != apple-darwin ]
1242+
if [ $CFG_OSTYPE != unknown-linux-gnu ] &&
1243+
[ ! [ $CFG_OSTYPE == apple-darwin ] && [ $CFG_CPUTYPE == x86_64 ] ]
12421244
then
12431245
CFG_BAD_VALGRIND=1
12441246
putvar CFG_BAD_VALGRIND

mk/main.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ else
167167
CFG_VALGRIND_COMPILE :=
168168
endif
169169

170+
VALGRIND_PATH :=$(CFG_VALGRIND)
171+
170172
ifdef CFG_ENABLE_VALGRIND
171173
$(info cfg: enabling valgrind (CFG_ENABLE_VALGRIND))
172174
else
@@ -175,6 +177,7 @@ endif
175177
ifdef CFG_BAD_VALGRIND
176178
$(info cfg: disabling valgrind due to its unreliability on this platform)
177179
CFG_VALGRIND :=
180+
VALGRIND_PATH :=
178181
endif
179182

180183

mk/tests.mk

Lines changed: 35 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,19 @@ 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+
ifdef VALGRIND_PATH
534+
CTEST_TESTARGS += --valgrind-path "$(VALGRIND_PATH)"
535+
endif
536+
ifndef CFG_BAD_VALGRIND
537+
ifndef CFG_DISABLE_VALGRIND
538+
CTEST_TESTARGS += --force-valgrind
539+
endif
540+
endif
541+
530542
CTEST_SRC_BASE_rpass-full = run-pass-fulldeps
531543
CTEST_BUILD_BASE_rpass-full = run-pass-fulldeps
532544
CTEST_MODE_rpass-full = run-pass
@@ -621,14 +633,15 @@ TEST_SREQ$(1)_T_$(2)_H_$(3) = \
621633
# remove directive, if present, from CFG_RUSTC_FLAGS (issue #7898).
622634
CTEST_RUSTC_FLAGS := $$(subst --cfg ndebug,,$$(CFG_RUSTC_FLAGS))
623635

624-
# The tests can not be optimized while the rest of the compiler is optimized, so
636+
# The tests cannot be optimized while the rest of the compiler is optimized, so
625637
# filter out the optimization (if any) from rustc and then figure out if we need
626638
# to be optimized
627639
CTEST_RUSTC_FLAGS := $$(subst -O,,$$(CTEST_RUSTC_FLAGS))
628640
ifndef CFG_DISABLE_OPTIMIZE_TESTS
629641
CTEST_RUSTC_FLAGS += -O
630642
endif
631643

644+
632645
CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) := \
633646
--compile-lib-path $$(HLIB$(1)_H_$(3)) \
634647
--run-lib-path $$(TLIB$(1)_T_$(2)_H_$(3)) \
@@ -650,6 +663,7 @@ CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) := \
650663
$$(CTEST_TESTARGS)
651664

652665
CTEST_DEPS_rpass_$(1)-T-$(2)-H-$(3) = $$(RPASS_TESTS)
666+
CTEST_DEPS_rpass-valgrind_$(1)-T-$(2)-H-$(3) = $$(RPASS_VALGRIND_TESTS)
653667
CTEST_DEPS_rpass-full_$(1)-T-$(2)-H-$(3) = $$(RPASS_FULL_TESTS) $$(CSREQ$(1)_T_$(3)_H_$(3)) $$(SREQ$(1)_T_$(2)_H_$(3))
654668
CTEST_DEPS_cfail-full_$(1)-T-$(2)-H-$(3) = $$(CFAIL_FULL_TESTS) $$(CSREQ$(1)_T_$(3)_H_$(3)) $$(SREQ$(1)_T_$(2)_H_$(3))
655669
CTEST_DEPS_rfail_$(1)-T-$(2)-H-$(3) = $$(RFAIL_TESTS)
@@ -721,16 +735,17 @@ endif
721735

722736
endef
723737

724-
CTEST_NAMES = rpass rpass-full cfail-full rfail cfail bench perf debuginfo-gdb debuginfo-lldb codegen
738+
CTEST_NAMES = rpass rpass-valgrind rpass-full cfail-full rfail cfail bench perf debuginfo-gdb debuginfo-lldb codegen
725739

726740
$(foreach host,$(CFG_HOST), \
727741
$(eval $(foreach target,$(CFG_TARGET), \
728742
$(eval $(foreach stage,$(STAGES), \
729743
$(eval $(foreach name,$(CTEST_NAMES), \
730744
$(eval $(call DEF_RUN_COMPILETEST,$(stage),$(target),$(host),$(name))))))))))
731745

732-
PRETTY_NAMES = pretty-rpass pretty-rpass-full pretty-rfail pretty-bench pretty-pretty
746+
PRETTY_NAMES = pretty-rpass pretty-rpass-valgrind pretty-rpass-full pretty-rfail pretty-bench pretty-pretty
733747
PRETTY_DEPS_pretty-rpass = $(RPASS_TESTS)
748+
PRETTY_DEPS_pretty-rpass-valgrind = $(RPASS_VALGRIND_TESTS)
734749
PRETTY_DEPS_pretty-rpass-full = $(RPASS_FULL_TESTS)
735750
PRETTY_DEPS_pretty-rfail = $(RFAIL_TESTS)
736751
PRETTY_DEPS_pretty-bench = $(BENCH_TESTS)
@@ -743,6 +758,7 @@ PRETTY_DEPS$(1)_H_$(3)_pretty-rfail =
743758
PRETTY_DEPS$(1)_H_$(3)_pretty-bench =
744759
PRETTY_DEPS$(1)_H_$(3)_pretty-pretty =
745760
PRETTY_DIRNAME_pretty-rpass = run-pass
761+
PRETTY_DIRNAME_pretty-rpass-valgrind = run-pass-valgrind
746762
PRETTY_DIRNAME_pretty-rpass-full = run-pass-fulldeps
747763
PRETTY_DIRNAME_pretty-rfail = run-fail
748764
PRETTY_DIRNAME_pretty-bench = bench
@@ -890,6 +906,7 @@ TEST_GROUPS = \
890906
$(foreach crate,$(TEST_CRATES),$(crate)) \
891907
$(foreach crate,$(TEST_DOC_CRATES),doc-crate-$(crate)) \
892908
rpass \
909+
rpass-valgrind \
893910
rpass-full \
894911
cfail-full \
895912
rfail \
@@ -904,6 +921,7 @@ TEST_GROUPS = \
904921
$(foreach docname,$(DOCS),doc-$(docname)) \
905922
pretty \
906923
pretty-rpass \
924+
pretty-rpass-valgrind \
907925
pretty-rpass-full \
908926
pretty-rfail \
909927
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)