Skip to content

Commit 97157b4

Browse files
committed
Auto merge of #297 - posborne:docker-cross-test-infrastructure, r=kamalmarhubi
Docker cross test infrastructure These commits contain the first portion of new infrastructure that will allow us to build for and test on a much larger set of platforms. Nix and the tests are *not* compiling on many platforms right now, but I believe at this point that most of those problems are issues with nix (or libc) rather than the test infrastructure. I want to get this out there so we can start filing issues and other people can start doing testing and development to resolve the issues popping up on various platforms. None of this is integrated in with travis at this point -- that will be phase 3. Phase 2 will be getting qemu going to run the tests for non-host platforms (this might be tricky when running in a container as `/dev/kvm` might need to be passed through). This is based on the testing infrastructure in libc but modified quite a bit -- The libc infrastructure doesn't seem to be a great experience for testing locally. If this approach works out, we might want to push this approach toward libc. The Dockerfile/Image that goes along with this is currently here: * https://github.com/posborne/docker-rust-cross * https://hub.docker.com/r/posborne/rust-cross/ I would have no problem moving this into the org if that makes sense down the line.
2 parents cf83362 + d1311ff commit 97157b4

9 files changed

+338
-24
lines changed

.travis.yml

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,57 @@
1-
---
2-
sudo: false
31
language: rust
2+
sudo: required
3+
dist: trusty
4+
services:
5+
- docker
6+
47
rust:
58
- 1.1.0 # Oldest supported version
6-
- 1.2.0
7-
- 1.3.0
8-
- 1.4.0
9-
- 1.5.0
109
- stable
1110
- beta
1211
- nightly
1312

14-
# Failures on nightly shouldn't fail the overall build.
15-
matrix:
16-
allow_failures:
17-
- rust: nightly
13+
script:
14+
- bash ci/run-travis.sh
15+
16+
env:
17+
- ARCH=x86_64
1818

1919
os:
2020
- linux
2121
- osx
2222

23-
env:
24-
- RUST_TEST_THREADS=1 ARCH=x86_64
25-
- RUST_TEST_THREADS=1 ARCH=i686
26-
27-
script:
28-
- curl -sSL https://raw.githubusercontent.com/carllerche/travis-rust-matrix/master/test | RUST_TEST_THREADS=1 bash
29-
- cargo doc --no-deps
30-
31-
addons:
32-
apt:
33-
packages:
34-
- gcc-multilib
23+
# Failures on nightly shouldn't fail the overall build.
24+
matrix:
25+
fast_finish: true
26+
include:
27+
- os: linux
28+
env: ARCH=i686
29+
rust: stable
30+
- os: osx
31+
env: ARCH=i686
32+
rust: stable
33+
- os: linux
34+
env: TARGET=aarch64-unknown-linux-gnu DOCKER_IMAGE=posborne/rust-cross:arm
35+
rust: 1.7.0
36+
- os: linux
37+
env: TARGET=arm-unknown-linux-gnueabihf DOCKER_IMAGE=posborne/rust-cross:arm
38+
rust: 1.7.0
39+
- os: linux
40+
env: TARGET=mips-unknown-linux-gnu DOCKER_IMAGE=posborne/rust-cross:mips
41+
rust: 1.7.0
42+
- os: linux
43+
env: TARGET=mipsel-unknwon-linux-gnu DOCKER_IMAGE=posborne/rust-cross:mips
44+
rust: 1.7.0
45+
- os: linux
46+
env: TARGET=arm-linux-androideabi DOCKER_IMAGE=posborne/rust-cross:android
47+
rust: 1.7.0
48+
allow_failures:
49+
- rust: nightly
50+
- env: TARGET=aarch64-unknown-linux-gnu DOCKER_IMAGE=posborne/rust-cross:arm
51+
- env: TARGET=arm-unknown-linux-gnueabihf DOCKER_IMAGE=posborne/rust-cross:arm
52+
- env: TARGET=mips-unknown-linux-gnu DOCKER_IMAGE=posborne/rust-cross:mips
53+
- env: TARGET=mipsel-unknwon-linux-gnu DOCKER_IMAGE=posborne/rust-cross:mips
54+
- env: TARGET=arm-linux-androideabi DOCKER_IMAGE=posborne/rust-cross:android
3555

3656
# Deploy documentation to S3 for specific branches. At some
3757
# point, it would be nice to also support building docs for

CONTRIBUTING.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,11 @@ environment. We also have [continuous integration set up on
7272
Travis-CI][travis-ci], which might find some issues on other platforms. The CI
7373
will run once you open a pull request.
7474

75-
[travis-ci]: https://travis-ci.org/nix-rust/nix
75+
There is also infrastructure for running tests for other targets
76+
locally. More information is available in the [CI Readme][ci-readme].
7677

78+
[travis-ci]: https://travis-ci.org/nix-rust/nix
79+
[ci-readme]: ci/README.md
7780

7881
## Homu, the bot who merges all the PRs
7982

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ To use `nix`, first add this to your `Cargo.toml`:
2020

2121
```toml
2222
[dependencies]
23-
nix = "*"
23+
nix = "0.5.0"
2424
```
2525

2626
Then, add this to your crate root:

ci/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
Test Infrastructure
2+
===================
3+
4+
The ci directory contains scripts that aid in the testing of nix both
5+
in our continuous integration environment (Travis CI) but also for
6+
developers working locally.
7+
8+
Nix interfaces very directly with the underlying platform (usually via
9+
libc) and changes need to be tested on a large number of platforms to
10+
avoid problems.
11+
12+
Running Tests For Host Architecture
13+
-----------------------------------
14+
15+
Running the tests for one's host architecture can be done by simply
16+
doing the following:
17+
18+
$ cargo test
19+
20+
Running Tests Against All Architectures/Versions
21+
------------------------------------------------
22+
23+
Testing for other architectures is more involved. Currently,
24+
developers may run tests against several architectures and versions of
25+
rust by running the `ci/run-all.sh` script. This scripts requires
26+
that docker be set up. This will take some time:
27+
28+
$ ci/run-all.sh
29+
30+
The list of versions and architectures tested by this can be
31+
determined by looking at the contents of the script. The docker image
32+
used is [posborne/rust-cross][posborne/rust-cross].
33+
34+
[posborne/rust-cross]: https://github.com/rust-embedded/docker-rust-cross
35+
36+
Running Test for Specific Architectures/Versions
37+
------------------------------------------------
38+
39+
Suppose we have a failing test with Rust 1.7 on the raspberry pi. In
40+
that case, we can run the following:
41+
42+
$ DOCKER_IMAGE=posborne/rust-cross:arm \
43+
RUST_VERSION=1.7.0 \
44+
RUST_TARGET=arm-unknown-linux-gnueabihf ci/run-docker.sh
45+
46+
Currently, the docker images only support Rust 1.7. To get a better
47+
idea of combinations that might work, look at the contents of the
48+
[travis configuration](../.travis.yml) or [run-all.sh](run-all.sh).

ci/cargo-config

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Configuration of which linkers to call on Travis for various architectures
2+
[target.arm-linux-androideabi]
3+
linker = "arm-linux-androideabi-gcc"
4+
5+
[target.arm-unknown-linux-gnueabihf]
6+
linker = "arm-linux-gnueabihf-gcc-4.7"
7+
8+
[target.mips-unknown-linux-gnu]
9+
linker = "mips-linux-gnu-gcc-5"
10+
11+
[target.mipsel-unknown-linux-gnu]
12+
linker = "mipsel-linux-gnu-gcc-5"
13+
14+
[target.aarch64-unknown-linux-gnu]
15+
linker = "aarch64-linux-gnu-gcc-4.8"
16+
17+
[target.powerpc-unknown-linux-gnu]
18+
linker = "powerpc-linux-gnu-gcc-4.8"

ci/run-all.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
#
3+
# Build nix and all tests for as many versions and platforms as can be
4+
# managed. This requires docker.
5+
#
6+
7+
set -e
8+
9+
BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
10+
RUN_DOCKER="${BASE_DIR}/ci/run-docker.sh"
11+
12+
export RUST_VERSION=1.7.0
13+
14+
export DOCKER_IMAGE=posborne/rust-cross:base
15+
RUST_TARGET=x86_64-unknown-linux-gnu ${RUN_DOCKER}
16+
RUST_TARGET=x86_64-unknown-linux-musl ${RUN_DOCKER}
17+
18+
export DOCKER_IMAGE=posborne/rust-cross:arm
19+
RUST_TARGET=aarch64-unknown-linux-gnu ${RUN_DOCKER}
20+
RUST_TARGET=arm-linux-gnueabi test_nix ${RUN_DOCKER}
21+
RUST_TARGET=arm-linux-gnueabihf test_nix ${RUN_DOCKER}
22+
23+
export DOCKER_IMAGE=posborne/rust-cross:mips
24+
RUST_TARGET=mips-unknown-linux-gnu test_nix ${RUN_DOCKER}
25+
RUST_TARGET=mipsel-unknown-linux-gnu test_nix ${RUN_DOCKER}
26+
27+
export DOCKER_IMAGE=posborne/rust-cross:android ${RUN_DOCKER}
28+
RUST_TARGET=arm-linux-androideabi test_nix ${RUN_DOCKER}

ci/run-docker.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
#
3+
# Run the nix tests in a docker container. This script expects the following
4+
# environment variables to be set:
5+
# - DOCKER_IMAGE : Docker image to use for testing (e.g. posborne/rust-cross:arm)
6+
# - RUST_VERSION : Rust Version to test against (e.g. 1.7.0)
7+
# - RUST_TARGET : Target Triple to test
8+
9+
BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
10+
11+
docker run -i -t \
12+
-v ${BASE_DIR}:/source \
13+
-e CARGO_TARGET_DIR=/build \
14+
${DOCKER_IMAGE} \
15+
/source/ci/run.sh ${RUST_VERSION} ${RUST_TARGET}

ci/run-travis.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
#
3+
# Entry point for all travis builds, this will set up the Travis environment by
4+
# downloading any dependencies. It will then execute the `run.sh` script to
5+
# build and execute all tests.
6+
#
7+
# Much of this script was liberally stolen from rust-lang/libc
8+
#
9+
# Key variables that may be set from Travis:
10+
# - TRAVIS_RUST_VERSION: 1.1.0 ... stable/nightly/beta
11+
# - TRAVIS_OS_NAME: linux/osx
12+
# - DOCKER_IMAGE: posborne/rust-cross:arm
13+
# - TARGET: e.g. arm-unknown-linux-gnueabihf
14+
15+
set -ex
16+
17+
BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
18+
19+
if [ "$TRAVIS_OS_NAME" = "linux" ]; then
20+
OS=unknown-linux-gnu
21+
elif [ "$TRAVIS_OS_NAME" = "osx" ]; then
22+
OS=apple-darwin
23+
else
24+
echo "Unexpected TRAVIS_OS_NAME: $TRAVIS_OS_NAME"
25+
exit 1
26+
fi
27+
28+
export HOST=$ARCH-$OS
29+
if [ "$TARGET" = "" ]; then
30+
TARGET=$HOST
31+
fi
32+
33+
if [ "$TARGET" = "i686-unknown-linux-gnu" ]; then
34+
sudo apt-get -y update
35+
sudo apt-get install -y gcc-multilib
36+
fi
37+
38+
if [ "$DOCKER_IMAGE" = "" ]; then
39+
export RUST_TEST_THREADS=1
40+
curl -sSL "https://raw.githubusercontent.com/carllerche/travis-rust-matrix/master/test" | bash
41+
cargo doc --no-deps
42+
else
43+
export RUST_VERSION=${TRAVIS_RUST_VERSION}
44+
export RUST_TARGET=${TARGET}
45+
export DOCKER_IMAGE=${DOCKER_IMAGE}
46+
${BASE_DIR}/ci/run-docker.sh
47+
fi

ci/run.sh

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
#!/bin/bash
2+
3+
# Builds and runs tests for a particular target passed as an argument to this
4+
# script.
5+
6+
set -e
7+
8+
# This should only be run in a docker container, so verify that
9+
if [ ! -f /.dockerinit ]; then
10+
echo "run.sh should only be executed in a docker container"
11+
echo "and that does not appear to be the case. Maybe you meant"
12+
echo "to execute the tests via run-all.sh or run-docker.sh."
13+
echo ""
14+
echo "For more instructions, please refer to ci/README.md"
15+
exit 1
16+
fi
17+
18+
BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
19+
MANIFEST_PATH="${BASE_DIR}/Cargo.toml"
20+
BUILD_DIR="."
21+
22+
VERSION="$1"
23+
TARGET="$2"
24+
25+
export RUST_TEST_THREADS=1
26+
27+
#
28+
# Tell cargo what linker to use and whatever else is required
29+
#
30+
configure_cargo() {
31+
mkdir -p .cargo
32+
cp -b "${BASE_DIR}/ci/cargo-config" .cargo/config
33+
}
34+
35+
#
36+
# We need to export CC for the tests to build properly (some C code is
37+
# compiled) to work. We already tell Cargo about the compiler in the
38+
# cargo config, so we just parse that info out of the cargo config
39+
#
40+
cc_for_target() {
41+
awk "/\[target\.${TARGET}\]/{getline; print}" .cargo/config |
42+
cut -d '=' -f2 | \
43+
tr -d '"' | tr -d ' '
44+
}
45+
46+
cross_compile_tests() {
47+
case "$TARGET" in
48+
*-apple-ios)
49+
cargo test --no-run --manifest-path="${MANIFEST_PATH}" --target "$TARGET" -- \
50+
-C link-args=-mios-simulator-version-min=7.0
51+
;;
52+
53+
*)
54+
cargo test --no-run --verbose \
55+
--manifest-path="${MANIFEST_PATH}" \
56+
--target "$TARGET"
57+
;;
58+
esac
59+
}
60+
61+
# This is a hack as we cannot currently
62+
# ask cargo what test files it generated:
63+
# https://github.com/rust-lang/cargo/issues/1924
64+
find_binaries() {
65+
target_base_dir="${BUILD_DIR}/${TARGET}/debug"
66+
67+
# find [[test]] sections and print the first line and
68+
# hack it to what we want from there. Also "nix" for
69+
# tests that are implicitly prsent
70+
for test_base in $( awk '/\[\[test\]\]/{getline; print}' "${MANIFEST_PATH}" | \
71+
cut -d '=' -f2 | \
72+
tr -d '"' | \
73+
tr '-' '_' | \
74+
tr -d ' '; echo "nix" ); do
75+
for path in ${target_base_dir}/${test_base}-* ; do
76+
echo "${path} "
77+
done
78+
done
79+
}
80+
81+
test_binary() {
82+
binary=$1
83+
84+
case "$TARGET" in
85+
arm-linux-gnueabi-gcc)
86+
qemu-arm -L /usr/arm-linux-gnueabihf "$binary"
87+
;;
88+
89+
arm-unknown-linux-gnueabihf)
90+
qemu-arm -L /usr/arm-linux-gnueabihf "$binary"
91+
;;
92+
93+
mips-unknown-linux-gnu)
94+
qemu-mips -L /usr/mips-linux-gnu "$binary"
95+
;;
96+
97+
aarch64-unknown-linux-gnu)
98+
qemu-aarch64 -L /usr/aarch64-linux-gnu "$binary"
99+
;;
100+
101+
*-rumprun-netbsd)
102+
rumprun-bake hw_virtio /tmp/nix-test.img "${binary}"
103+
qemu-system-x86_64 -nographic -vga none -m 64 \
104+
-kernel /tmp/nix-test.img 2>&1 | tee /tmp/out &
105+
sleep 5
106+
grep "^PASSED .* tests" /tmp/out
107+
;;
108+
109+
*)
110+
echo "Running binary: ${binary}"
111+
${binary}
112+
;;
113+
esac
114+
}
115+
116+
echo "======================================================="
117+
echo "TESTING VERSION: ${VERSION}, TARGET: ${TARGET}"
118+
echo "======================================================="
119+
120+
configure_cargo
121+
export CC="$(cc_for_target)"
122+
if [ "${CC}" = "" ]; then
123+
unset CC
124+
fi
125+
126+
# select the proper version
127+
multirust override ${VERSION}
128+
129+
# build the tests
130+
cross_compile_tests
131+
132+
# and run the tests
133+
for bin in $(find_binaries); do
134+
test_binary "${bin}"
135+
done

0 commit comments

Comments
 (0)