Skip to content

Commit 1b005eb

Browse files
authored
Merge pull request rust-lang#660 from bjorn3/libtest
Libtest support
2 parents e7a5078 + 82e31e2 commit 1b005eb

7 files changed

+114
-5
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ perf.data.old
77
/build_sysroot/sysroot
88
/build_sysroot/sysroot_src
99
/build_sysroot/Cargo.lock
10+
/build_sysroot/test_target/Cargo.lock
1011
/rust
1112
/regex

build_sysroot/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ version = "0.0.0"
77
core = { path = "./sysroot_src/src/libcore" }
88
compiler_builtins = "0.1"
99
alloc = { path = "./sysroot_src/src/liballoc" }
10-
std = { path = "./sysroot_src/src/libstd" }
10+
std = { path = "./sysroot_src/src/libstd", features = ["panic_unwind"] }
1111

1212
alloc_system = { path = "./alloc_system" }
1313

build_sysroot/build_sysroot.sh

+13-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ popd >/dev/null
1212
# Cleanup for previous run
1313
# v Clean target dir except for build scripts and incremental cache
1414
rm -r target/*/{debug,release}/{build,deps,examples,libsysroot*,native} || true
15-
rm Cargo.lock 2>/dev/null || true
15+
rm -r sysroot_src/src/{libcore,libtest}/target/$TARGET_TRIPLE/$sysroot_channel/ || true
16+
rm Cargo.lock test_target/Cargo.lock 2>/dev/null || true
1617
rm -r sysroot 2>/dev/null || true
1718

1819
# Build libs
@@ -28,3 +29,14 @@ fi
2829
# Copy files to sysroot
2930
mkdir -p sysroot/lib/rustlib/$TARGET_TRIPLE/lib/
3031
cp target/$TARGET_TRIPLE/$sysroot_channel/deps/*.rlib sysroot/lib/rustlib/$TARGET_TRIPLE/lib/
32+
33+
if [[ "$1" == "--release" ]]; then
34+
channel='release'
35+
RUSTFLAGS="$RUSTFLAGS -Zmir-opt-level=3" cargo build --target $TARGET_TRIPLE --release --manifest-path ./sysroot_src/src/libtest/Cargo.toml
36+
else
37+
channel='debug'
38+
cargo build --target $TARGET_TRIPLE --manifest-path ./sysroot_src/src/libtest/Cargo.toml
39+
fi
40+
41+
# Copy files to sysroot
42+
cp sysroot_src/src/libtest/target/$TARGET_TRIPLE/$sysroot_channel/deps/*.rlib sysroot/lib/rustlib/$TARGET_TRIPLE/lib/
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
From a25405f1fc4a168c9c370524be48aff8c8ebc529 Mon Sep 17 00:00:00 2001
2+
From: bjorn3 <bjorn3@users.noreply.github.com>
3+
Date: Wed, 12 Jun 2019 18:07:23 +0200
4+
Subject: [PATCH] Fix libtest compilation
5+
6+
---
7+
src/libtest/lib.rs | 11 +++++------
8+
1 file changed, 5 insertions(+), 6 deletions(-)
9+
10+
diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs
11+
index 810a98e..4fdde0e 100644
12+
--- a/src/libtest/lib.rs
13+
+++ b/src/libtest/lib.rs
14+
@@ -1441,11 +1441,11 @@ pub fn run_test(
15+
return;
16+
}
17+
18+
- fn run_test_inner(
19+
+ fn run_test_inner<F: FnOnce() + Send + 'static>(
20+
desc: TestDesc,
21+
monitor_ch: Sender<MonitorMsg>,
22+
nocapture: bool,
23+
- testfn: Box<dyn FnOnce() + Send>,
24+
+ testfn: F,
25+
concurrency: Concurrent,
26+
) {
27+
// Buffer for capturing standard I/O
28+
@@ -1500,15 +1500,14 @@ pub fn run_test(
29+
(benchfn.clone())(harness)
30+
});
31+
}
32+
- DynTestFn(f) => {
33+
- let cb = move || __rust_begin_short_backtrace(f);
34+
- run_test_inner(desc, monitor_ch, opts.nocapture, Box::new(cb), concurrency)
35+
+ DynTestFn(_f) => {
36+
+ unimplemented!();
37+
}
38+
StaticTestFn(f) => run_test_inner(
39+
desc,
40+
monitor_ch,
41+
opts.nocapture,
42+
- Box::new(move || __rust_begin_short_backtrace(f)),
43+
+ move || __rust_begin_short_backtrace(f),
44+
concurrency,
45+
),
46+
}
47+
--
48+
2.11.0
49+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
From e275a6ac96bedda2d57296914f2bb736e1e4154c Mon Sep 17 00:00:00 2001
2+
From: bjorn3 <bjorn3@users.noreply.github.com>
3+
Date: Fri, 9 Aug 2019 13:16:55 +0200
4+
Subject: [PATCH] [test] Force single thread mode
5+
6+
---
7+
src/libtest/lib.rs | 11 +----------
8+
1 file changed, 1 insertion(+), 10 deletions(-)
9+
10+
diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs
11+
index 8d74d9a..c7a3c23 100644
12+
--- a/src/libtest/lib.rs
13+
+++ b/src/libtest/lib.rs
14+
@@ -1419,16 +1419,7 @@ pub fn run_test(
15+
.unwrap();
16+
};
17+
18+
- // If the platform is single-threaded we're just going to run
19+
- // the test synchronously, regardless of the concurrency
20+
- // level.
21+
- let supports_threads = !cfg!(target_os = "emscripten") && !cfg!(target_arch = "wasm32");
22+
- if concurrency == Concurrent::Yes && supports_threads {
23+
- let cfg = thread::Builder::new().name(name.as_slice().to_owned());
24+
- cfg.spawn(runtest).unwrap();
25+
- } else {
26+
- runtest();
27+
- }
28+
+ runtest();
29+
}
30+
31+
match testfn {
32+
--
33+
2.20.1
34+

src/intrinsics.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,20 @@ pub fn codegen_intrinsic_call<'a, 'tcx: 'a>(
10111011
simd_fmax, (c x, c y) {
10121012
simd_flt_binop!(fx, intrinsic, fmax(x, y) -> ret);
10131013
};
1014+
1015+
try, (v f, v data, v _local_ptr) {
1016+
// FIXME once unwinding is supported, change this to actually catch panics
1017+
let f_sig = fx.bcx.func.import_signature(Signature {
1018+
call_conv: cranelift::codegen::isa::CallConv::SystemV,
1019+
params: vec![AbiParam::new(fx.bcx.func.dfg.value_type(data))],
1020+
returns: vec![],
1021+
});
1022+
1023+
fx.bcx.ins().call_indirect(f_sig, f, &[data]);
1024+
1025+
let ret_val = CValue::const_val(fx, ret.layout().ty, 0);
1026+
ret.write_cvalue(fx, ret_val);
1027+
};
10141028
}
10151029

10161030
if let Some((_, dest)) = destination {

test.sh

+2-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ echo "[TEST] rust-lang/regex example shootout-regex-dna"
5858
cat examples/regexdna-input.txt | ../cargo.sh run --example shootout-regex-dna > res.txt
5959
diff -u res.txt examples/regexdna-output.txt
6060

61-
# FIXME compile libtest
62-
# echo "[TEST] rust-lang/regex standalone tests"
63-
# ../cargo.sh test
61+
echo "[TEST] rust-lang/regex standalone tests"
62+
../cargo.sh test --tests -- --exclude-should-panic --test-threads 1 -Zunstable-options
6463
popd
6564

6665
COMPILE_MOD_BENCH_INLINE="$RUSTC example/mod_bench.rs --crate-type bin -Zmir-opt-level=3 -O --crate-name mod_bench_inline"

0 commit comments

Comments
 (0)