Skip to content

Commit bcbfa85

Browse files
committed
Leverage Cargo's target runner support to execute tests
1 parent ce27617 commit bcbfa85

File tree

13 files changed

+87
-128
lines changed

13 files changed

+87
-128
lines changed

.travis.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,14 @@ matrix:
5050
- env: TARGET=aarch64-unknown-linux-gnu
5151
- os: osx
5252
osx_image: xcode8.2
53-
env: TARGET=i386-apple-ios
53+
env: TARGET=i386-apple-ios CARGO_TARGET_I386_APPLE_IOS_RUNNER=$HOME/runtest
54+
before_install:
55+
rustc ./ci/ios/deploy_and_run_on_ios_simulator.rs -o $HOME/runtest
5456
- os: osx
5557
osx_image: xcode8.2
56-
env: TARGET=x86_64-apple-ios
58+
env: TARGET=x86_64-apple-ios CARGO_TARGET_X86_64_APPLE_IOS_RUNNER=$HOME/runtest
59+
before_install:
60+
rustc ./ci/ios/deploy_and_run_on_ios_simulator.rs -o $HOME/runtest
5761
- env: TARGET=x86_64-rumprun-netbsd
5862
- env: TARGET=powerpc-unknown-linux-gnu
5963
- env: TARGET=powerpc64-unknown-linux-gnu
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM ubuntu:17.10
2-
RUN apt-get update
3-
RUN apt-get install -y --no-install-recommends \
2+
RUN apt-get update && apt-get install -y --no-install-recommends \
43
gcc libc6-dev ca-certificates \
54
gcc-aarch64-linux-gnu libc6-dev-arm64-cross qemu-user
65
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc \
6+
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER="qemu-aarch64 -L /usr/aarch64-linux-gnu" \
77
PATH=$PATH:/rust/bin
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM ubuntu:17.10
2-
RUN apt-get update
3-
RUN apt-get install -y --no-install-recommends \
2+
RUN apt-get update && apt-get install -y --no-install-recommends \
43
gcc libc6-dev ca-certificates \
54
gcc-arm-linux-gnueabihf libc6-dev-armhf-cross qemu-user
65
ENV CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc \
6+
CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_RUNNER="qemu-arm -L /usr/arm-linux-gnueabihf" \
77
PATH=$PATH:/rust/bin
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
FROM ubuntu:17.10
22

3-
RUN apt-get update
4-
RUN apt-get install -y --no-install-recommends \
3+
RUN apt-get update && apt-get install -y --no-install-recommends \
54
gcc libc6-dev qemu-user ca-certificates \
65
gcc-mips-linux-gnu libc6-dev-mips-cross \
76
qemu-system-mips
87

98
ENV CARGO_TARGET_MIPS_UNKNOWN_LINUX_GNU_LINKER=mips-linux-gnu-gcc \
9+
CARGO_TARGET_MIPS_UNKNOWN_LINUX_GNU_RUNNER="qemu-mips -L /usr/mips-linux-gnu" \
1010
PATH=$PATH:/rust/bin

ci/docker/mips-unknown-linux-musl/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
FROM ubuntu:17.10
22

3-
RUN apt-get update
4-
RUN apt-get install -y --no-install-recommends \
3+
RUN apt-get update && apt-get install -y --no-install-recommends \
54
gcc libc6-dev qemu-user ca-certificates qemu-system-mips curl \
65
bzip2
76

@@ -14,4 +13,5 @@ RUN curl -L https://s3.amazonaws.com/rust-lang-ci/libc/OpenWrt-SDK-ar71xx-generi
1413

1514
ENV PATH=$PATH:/rust/bin:/toolchain/staging_dir/toolchain-mips_34kc_gcc-5.3.0_musl-1.1.15/bin \
1615
CC_mips_unknown_linux_musl=mips-openwrt-linux-gcc \
17-
CARGO_TARGET_MIPS_UNKNOWN_LINUX_MUSL_LINKER=mips-openwrt-linux-gcc
16+
CARGO_TARGET_MIPS_UNKNOWN_LINUX_MUSL_LINKER=mips-openwrt-linux-gcc \
17+
CARGO_TARGET_MIPS_UNKNOWN_LINUX_MUSL_RUNNER="qemu-mips -L /toolchain/staging_dir/toolchain-mips_34kc_gcc-5.3.0_musl-1.1.15"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
FROM ubuntu:17.10
22

3-
RUN apt-get update
4-
RUN apt-get install -y --no-install-recommends \
3+
RUN apt-get update && apt-get install -y --no-install-recommends \
54
gcc libc6-dev qemu-user ca-certificates \
65
gcc-mips64-linux-gnuabi64 libc6-dev-mips64-cross \
76
qemu-system-mips64
87

98
ENV CARGO_TARGET_MIPS64_UNKNOWN_LINUX_GNUABI64_LINKER=mips64-linux-gnuabi64-gcc \
9+
CARGO_TARGET_MIPS64_UNKNOWN_LINUX_GNUABI64_RUNNER="qemu-mips64 -L /usr/mips64-linux-gnuabi64" \
1010
CC_mips64_unknown_linux_gnuabi64=mips64-linux-gnuabi64-gcc \
1111
PATH=$PATH:/rust/bin

ci/docker/mipsel-unknown-linux-musl/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
FROM ubuntu:17.10
22

3-
RUN apt-get update
4-
RUN apt-get install -y --no-install-recommends \
3+
RUN apt-get update && apt-get install -y --no-install-recommends \
54
gcc libc6-dev qemu-user ca-certificates qemu-system-mips curl \
65
bzip2
76

@@ -14,4 +13,5 @@ RUN curl -L https://s3.amazonaws.com/rust-lang-ci/libc/OpenWrt-Toolchain-malta-l
1413

1514
ENV PATH=$PATH:/rust/bin:/toolchain/bin \
1615
CC_mipsel_unknown_linux_musl=mipsel-openwrt-linux-gcc \
17-
CARGO_TARGET_MIPSEL_UNKNOWN_LINUX_MUSL_LINKER=mipsel-openwrt-linux-gcc
16+
CARGO_TARGET_MIPSEL_UNKNOWN_LINUX_MUSL_LINKER=mipsel-openwrt-linux-gcc \
17+
CARGO_TARGET_MIPSEL_UNKNOWN_LINUX_MUSL_RUNNER="qemu-mipsel -L /toolchain"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
FROM ubuntu:17.10
22

3-
RUN apt-get update
4-
RUN apt-get install -y --no-install-recommends \
3+
RUN apt-get update && apt-get install -y --no-install-recommends \
54
gcc libc6-dev qemu-user ca-certificates \
65
gcc-powerpc-linux-gnu libc6-dev-powerpc-cross \
76
qemu-system-ppc
87

98
ENV CARGO_TARGET_POWERPC_UNKNOWN_LINUX_GNU_LINKER=powerpc-linux-gnu-gcc \
9+
CARGO_TARGET_POWERPC_UNKNOWN_LINUX_GNU_RUNNER="qemu-ppc -L /usr/powerpc-linux-gnu" \
1010
PATH=$PATH:/rust/bin
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
FROM ubuntu:17.10
22

3-
RUN apt-get update
4-
RUN apt-get install -y --no-install-recommends \
3+
RUN apt-get update && apt-get install -y --no-install-recommends \
54
gcc libc6-dev qemu-user ca-certificates \
65
gcc-powerpc64-linux-gnu libc6-dev-ppc64-cross \
76
qemu-system-ppc
87

98
ENV CARGO_TARGET_POWERPC64_UNKNOWN_LINUX_GNU_LINKER=powerpc64-linux-gnu-gcc \
9+
CARGO_TARGET_POWERPC64_UNKNOWN_LINUX_GNU_RUNNER="qemu-ppc64 -L /usr/powerpc64-linux-gnu" \
1010
CC=powerpc64-linux-gnu-gcc \
1111
PATH=$PATH:/rust/bin

ci/docker/s390x-unknown-linux-gnu/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
55
gcc-s390x-linux-gnu libc6-dev-s390x-cross
66

77
ENV CARGO_TARGET_S390X_UNKNOWN_LINUX_GNU_LINKER=s390x-linux-gnu-gcc \
8+
# TODO: in theory we should execute this, but qemu segfaults immediately :(
9+
# CARGO_TARGET_S390X_UNKNOWN_LINUX_GNU_RUNNER="qemu-s390x -L /usr/s390x-linux-gnu" \
10+
CARGO_TARGET_S390X_UNKNOWN_LINUX_GNU_RUNNER=true \
811
CC_s390x_unknown_linux_gnu=s390x-linux-gnu-gcc \
912
PATH=$PATH:/rust/bin

ci/docker/x86_64-rumprun-netbsd/Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@ USER root
33
RUN apt-get update
44
RUN apt-get install -y --no-install-recommends \
55
qemu
6-
ENV PATH=$PATH:/rust/bin
6+
ENV PATH=$PATH:/rust/bin \
7+
CARGO_TARGET_X86_64_RUMPRUN_NETBSD_RUNNER=/tmp/runtest
8+
9+
ADD docker/x86_64-rumprun-netbsd/runtest.rs /tmp/
10+
ENTRYPOINT ["sh", "-c", "rustc /tmp/runtest.rs -o /tmp/runtest && exec \"$@\"", "--"]
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
use std::env;
2+
use std::process::{Command, Stdio};
3+
use std::sync::mpsc;
4+
use std::thread;
5+
use std::time::Duration;
6+
use std::io::{BufRead, BufReader, Read};
7+
8+
fn main() {
9+
assert_eq!(env::args().len(), 2);
10+
11+
let status = Command::new("rumprun-bake")
12+
.arg("hw_virtio")
13+
.arg("/tmp/libc-test.img")
14+
.arg(env::args().nth(1).unwrap())
15+
.status()
16+
.expect("failed to run rumprun-bake");
17+
assert!(status.success());
18+
19+
let mut child = Command::new("qemu-system-x86_64")
20+
.arg("-nographic")
21+
.arg("-vga").arg("none")
22+
.arg("-m").arg("64")
23+
.arg("-kernel").arg("/tmp/libc-test.img")
24+
.stdout(Stdio::piped())
25+
.stderr(Stdio::piped())
26+
.spawn()
27+
.expect("failed to spawn qemu");
28+
29+
let mut stdout = child.stdout.take().unwrap();
30+
let mut stderr = child.stderr.take().unwrap();
31+
let (tx, rx) = mpsc::channel();
32+
let tx2 = tx.clone();
33+
let t1 = thread::spawn(move || find_ok(&mut stdout, tx));
34+
let t2 = thread::spawn(move || find_ok(&mut stderr, tx2));
35+
36+
let res = rx.recv_timeout(Duration::new(5, 0));
37+
child.kill().unwrap();
38+
t1.join().unwrap();
39+
t2.join().unwrap();
40+
41+
if res.is_err() {
42+
panic!("didn't find success");
43+
}
44+
}
45+
46+
fn find_ok(input: &mut Read, tx: mpsc::Sender<()>) {
47+
for line in BufReader::new(input).lines() {
48+
let line = line.unwrap();
49+
println!("{}", line);
50+
if line.starts_with("PASSED ") && line.contains(" tests") {
51+
tx.send(()).unwrap();
52+
}
53+
}
54+
}

ci/run.sh

Lines changed: 1 addition & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -68,110 +68,4 @@ if [ "$QEMU" != "" ]; then
6868
exec grep "^PASSED .* tests" $CARGO_TARGET_DIR/out.log
6969
fi
7070

71-
# Build all tests making sure that the iOS builds are handled properly.
72-
if [[ "$TARGET" == *-apple-ios ]]; then
73-
export RUSTFLAGS="-C link-args=-mios-simulator-version-min=7.0"
74-
fi
75-
cargo build --manifest-path libc-test/Cargo.toml --target $TARGET --tests
76-
77-
case "$TARGET" in
78-
# Android emulator for x86_64 does not work on travis (missing hardware
79-
# acceleration). Tests are run on case *). See ci/android-sysimage.sh for
80-
# informations about how tests are run.
81-
arm-linux-androideabi | aarch64-linux-android | i686-linux-android)
82-
# set SHELL so android can detect a 64bits system, see
83-
# http://stackoverflow.com/a/41789144
84-
# https://issues.jenkins-ci.org/browse/JENKINS-26930?focusedCommentId=230791&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-230791
85-
export SHELL=/bin/dash
86-
arch=$(echo $TARGET | cut -d- -f1)
87-
accel="-no-accel"
88-
if emulator -accel-check; then
89-
accel=""
90-
fi
91-
emulator @$arch -no-window $accel &
92-
adb wait-for-device
93-
# TODO: replace these steps with a single program so that it can be used as a runner for cargo test
94-
adb push $CARGO_TARGET_DIR/$TARGET/debug/main-* /data/local/tmp/main
95-
adb shell /data/local/tmp/main 2>&1 | tee /tmp/out
96-
grep "^PASSED .* tests" /tmp/out
97-
adb push $CARGO_TARGET_DIR/$TARGET/debug/linux_fcntl-* /data/local/tmp/linux_fcntl
98-
adb shell /data/local/tmp/linux_fcntl 2>&1 | tee /tmp/out
99-
grep "^PASSED .* tests" /tmp/out
100-
;;
101-
102-
i386-apple-ios)
103-
rustc -O ./ci/ios/deploy_and_run_on_ios_simulator.rs
104-
export CARGO_TARGET_I386_APPLE_IOS_RUNNER="./deploy_and_run_on_ios_simulator"
105-
cargo test --manifest-path libc-test/Cargo.toml --target $TARGET
106-
;;
107-
108-
x86_64-apple-ios)
109-
rustc -O ./ci/ios/deploy_and_run_on_ios_simulator.rs
110-
export CARGO_TARGET_X86_64_APPLE_IOS_RUNNER="./deploy_and_run_on_ios_simulator"
111-
cargo test --manifest-path libc-test/Cargo.toml --target $TARGET
112-
;;
113-
114-
arm-unknown-linux-gnueabihf)
115-
export CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_RUNNER="qemu-arm -L /usr/arm-linux-gnueabihf"
116-
cargo test --manifest-path libc-test/Cargo.toml --target $TARGET
117-
;;
118-
119-
mips-unknown-linux-gnu)
120-
export CARGO_TARGET_MIPS_UNKNOWN_LINUX_GNU_RUNNER="qemu-mips -L /usr/mips-linux-gnu"
121-
cargo test --manifest-path libc-test/Cargo.toml --target $TARGET
122-
;;
123-
124-
mips64-unknown-linux-gnuabi64)
125-
export CARGO_TARGET_MIPS64_UNKNOWN_LINUX_GNUABI64_RUNNER="qemu-mips64 -L /usr/mips64-linux-gnuabi64"
126-
cargo test --manifest-path libc-test/Cargo.toml --target $TARGET
127-
;;
128-
129-
mips-unknown-linux-musl)
130-
export CARGO_TARGET_MIPS_UNKNOWN_LINUX_MUSL_RUNNER="qemu-mips -L /toolchain/staging_dir/toolchain-mips_34kc_gcc-5.3.0_musl-1.1.15"
131-
cargo test --manifest-path libc-test/Cargo.toml --target $TARGET
132-
;;
133-
134-
mipsel-unknown-linux-musl)
135-
export CARGO_TARGET_MIPSEL_UNKNOWN_LINUX_MUSL_RUNNER="qemu-mipsel -L /toolchain"
136-
cargo test --manifest-path libc-test/Cargo.toml --target $TARGET
137-
;;
138-
139-
powerpc-unknown-linux-gnu)
140-
export CARGO_TARGET_POWERPC_UNKNOWN_LINUX_GNU_RUNNER="qemu-ppc -L /usr/powerpc-linux-gnu"
141-
cargo test --manifest-path libc-test/Cargo.toml --target $TARGET
142-
;;
143-
144-
powerpc64-unknown-linux-gnu)
145-
export CARGO_TARGET_POWERPC64_UNKNOWN_LINUX_GNU_RUNNER="qemu-ppc64 -L /usr/powerpc64-linux-gnu"
146-
cargo test --manifest-path libc-test/Cargo.toml --target $TARGET
147-
;;
148-
149-
aarch64-unknown-linux-gnu)
150-
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER="qemu-aarch64 -L /usr/aarch64-linux-gnu"
151-
cargo test --manifest-path libc-test/Cargo.toml --target $TARGET
152-
;;
153-
154-
s390x-unknown-linux-gnu)
155-
# TODO: in theory we should execute this, but qemu segfaults immediately :(
156-
#export CARGO_TARGET_S390X_UNKNOWN_LINUX_GNU_RUNNER="qemu-s390x -L /usr/s390x-linux-gnu"
157-
#cargo test --manifest-path libc-test/Cargo.toml --target $TARGET
158-
;;
159-
160-
*-rumprun-netbsd)
161-
# TODO: replace these steps with a single program so that it can be used as a runner for cargo test
162-
rumprun-bake hw_virtio /tmp/libc-test.img $CARGO_TARGET_DIR/$TARGET/debug/main-*
163-
qemu-system-x86_64 -nographic -vga none -m 64 \
164-
-kernel /tmp/libc-test.img 2>&1 | tee /tmp/out &
165-
sleep 5
166-
grep "^PASSED .* tests" /tmp/out
167-
rumprun-bake hw_virtio /tmp/libc-test.img $CARGO_TARGET_DIR/$TARGET/debug/linux_fcntl-*
168-
qemu-system-x86_64 -nographic -vga none -m 64 \
169-
-kernel /tmp/libc-test.img 2>&1 | tee /tmp/out &
170-
sleep 5
171-
grep "^PASSED .* tests" /tmp/out
172-
;;
173-
174-
*)
175-
cargo test --manifest-path libc-test/Cargo.toml --target $TARGET
176-
;;
177-
esac
71+
cargo test --manifest-path libc-test/Cargo.toml --target $TARGET

0 commit comments

Comments
 (0)