From e6fff3a43a122a64d04f738e3ff40b8f4ca7c50d Mon Sep 17 00:00:00 2001 From: Paul Osborne Date: Sat, 5 Mar 2016 23:33:17 -0600 Subject: [PATCH 01/20] testing: add ci scripts to aid testing on more architectures/versions These scripts represent a rough first cust at adding support for locally building nix and its tests for a large number of rust versions and architectures. Currently, this mostly helps with testing that nix compiles for various architectures (to the point that there are a mound of problems that need to be addressed). Once these are sorted, the code for actually running the tests for various architectures will be approached (this will require qemu and will still not target all architectures). Signed-off-by: Paul Osborne --- ci/run-all.sh | 48 +++++++++++++++++++++++++ ci/run.sh | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+) create mode 100755 ci/run-all.sh create mode 100755 ci/run.sh diff --git a/ci/run-all.sh b/ci/run-all.sh new file mode 100755 index 0000000000..e20f7735e6 --- /dev/null +++ b/ci/run-all.sh @@ -0,0 +1,48 @@ +#!/bin/bash +# +# This is **not** meant to be run on CI, but rather locally instead. If you're +# on a Linux machine you'll be able to run most of these, but otherwise this'll +# just attempt to run as many platforms as possible! + +set -e + +RUST_VERSIONS=${RUST_VERSIONS:-"\ + 1.6.0 \ + 1.7.0 \ + stable \ + beta \ + nightly"} + +RUST_TARGETS=${RUST_TARGETS:-"\ + aarch64-unknown-linux-gnu \ + arm-linux-androideabi \ + arm-unknown-linux-gnueabi \ + arm-unknown-linux-gnueabihf \ + i686-apple-darwin \ + i686-unknown-linux-gnu \ + mips-unknown-linux-gnu \ + mipsel-unknown-linux-gnu \ + x86_64-apple-darwin \ + x86_64-unknown-linux-gnu \ + x86_64-unknown-linux-musl"} + +DOCKER_IMAGE="rust-crossbuilder" + +BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" + +test_nix() { + version=$1 + target=$2 + + docker run -i -t \ + -v ${BASE_DIR}:/source \ + -e CARGO_TARGET_DIR=/build \ + ${DOCKER_IMAGE} \ + /source/ci/run.sh ${version} ${target} +} + +for version in ${RUST_VERSIONS}; do + for target in ${RUST_TARGETS}; do + test_nix $version $target + done +done diff --git a/ci/run.sh b/ci/run.sh new file mode 100755 index 0000000000..f6c9f7c5d9 --- /dev/null +++ b/ci/run.sh @@ -0,0 +1,98 @@ +#!/bin/bash + +# Builds and runs tests for a particular target passed as an argument to this +# script. + +set -e +set -x + +BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +MANIFEST_PATH="${BASE_DIR}/Cargo.toml" + +VERSION="$1" +TARGET="$2" + +echo "=======================================================" +echo "TESTING VERSION: ${VERSION}, TARGET: ${TARGET}" +echo "=======================================================" + +cross_compile_tests() { + case "$TARGET" in + *-apple-ios) + cargo test --no-run --manifest-path="${MANIFEST_PATH}" --target "$TARGET" -- \ + -C link-args=-mios-simulator-version-min=7.0 + ;; + + *) + cargo test --no-run --verbose \ + --manifest-path="${MANIFEST_PATH}" \ + --target "$TARGET" + ;; + esac +} + +# This is a hack as we cannot currently +# ask cargo what test files it generated: +# https://github.com/rust-lang/cargo/issues/1924 +find_binaries() { + target_base_dir="target/${TARGET}/debug" + + # find [[test]] sections and print the first line and + # hack it to what we want from there. Also "nix" for + # tests that are implicitly prsent + for test_base in $( awk '/\[\[test\]\]/{getline; print}' Cargo.toml | \ + cut -d '=' -f2 | \ + tr -d '"' | \ + tr '-' '_' | \ + tr -d ' '; echo "nix" ); do + for path in ${target_base_dir}/${test_base}-* ; do + echo "${path} " + done + done +} + +test_binary() { + binary=$1 + + case "$TARGET" in + arm-linux-gnueabi-gcc) + qemu-arm -L /usr/arm-linux-gnueabihf "$binary" + ;; + + arm-unknown-linux-gnueabihf) + qemu-arm -L /usr/arm-linux-gnueabihf "$binary" + ;; + + mips-unknown-linux-gnu) + qemu-mips -L /usr/mips-linux-gnu "$binary" + ;; + + aarch64-unknown-linux-gnu) + qemu-aarch64 -L /usr/aarch64-linux-gnu "$binary" + ;; + + *-rumprun-netbsd) + rumprun-bake hw_virtio /tmp/nix-test.img "${binary}" + qemu-system-x86_64 -nographic -vga none -m 64 \ + -kernel /tmp/nix-test.img 2>&1 | tee /tmp/out & + sleep 5 + grep "^PASSED .* tests" /tmp/out + ;; + + *) + echo "Running binary: ${binary}" + ${binary} + ;; + esac +} + +# select the proper version +multirust override ${VERSION} + +# build the tests +cross_compile_tests + +# and run the tests +for bin in $(find_binaries); do + test_binary "${bin}" +done From 6ffe725c7ae60428c2a92c53e0f8b5c55943425a Mon Sep 17 00:00:00 2001 From: Paul Osborne Date: Sun, 6 Mar 2016 20:05:05 -0600 Subject: [PATCH 02/20] testing: configure linker via .cargo/config Signed-off-by: Paul Osborne --- ci/cargo-config | 13 +++++++++++++ ci/run.sh | 11 +++++++++++ 2 files changed, 24 insertions(+) create mode 100644 ci/cargo-config diff --git a/ci/cargo-config b/ci/cargo-config new file mode 100644 index 0000000000..41e232e546 --- /dev/null +++ b/ci/cargo-config @@ -0,0 +1,13 @@ +# Configuration of which linkers to call on Travis for various architectures + +[target.arm-linux-androideabi] +linker = "arm-linux-androideabi-gcc" + +[target.arm-unknown-linux-gnueabihf] +linker = "arm-linux-gnueabihf-gcc-4.7" + +[target.mips-unknown-linux-gnu] +linker = "mips-linux-gnu-gcc-5" + +[target.aarch64-unknown-linux-gnu] +linker = "aarch64-linux-gnu-gcc" diff --git a/ci/run.sh b/ci/run.sh index f6c9f7c5d9..11a4c14286 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -16,6 +16,15 @@ echo "=======================================================" echo "TESTING VERSION: ${VERSION}, TARGET: ${TARGET}" echo "=======================================================" +# +# Tell cargo what linker to use and whatever else is required +# +configure_cargo() { + rm -rf .cargo + mkdir .cargo + cp "${BASE_DIR}/ci/cargo-config" .cargo/config +} + cross_compile_tests() { case "$TARGET" in *-apple-ios) @@ -86,6 +95,8 @@ test_binary() { esac } +configure_cargo + # select the proper version multirust override ${VERSION} From b5a9227323d521c11fb030576711ebdb54c73909 Mon Sep 17 00:00:00 2001 From: Paul Osborne Date: Sun, 6 Mar 2016 20:05:53 -0600 Subject: [PATCH 03/20] testing: add documentation covering the basics Signed-off-by: Paul Osborne --- ci/README.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 ci/README.md diff --git a/ci/README.md b/ci/README.md new file mode 100644 index 0000000000..5e46fadcff --- /dev/null +++ b/ci/README.md @@ -0,0 +1,42 @@ +Test Infrastructure +=================== + +The ci directory contains scripts that aid in the testing of nix both +in our continuous integration environment (Travis CI) but also for +developers working locally. + +Nix interfaces very directly with the underlying platform (usually via +libc) and changes need to be tested on a large number of platforms to +avoid problems. + +Running Tests For Host Architecture +----------------------------------- + +Running the tests for one's host architecture can be done by simply +doing the following: + + $ cargo test + +Running Tests Against All Architectures/Versions +------------------------------------------------ + +Testing for other architectures is more involved. Currently, +developers may run tests against several architectures and versions of +rust by running the `ci/run-all.sh` script. This scripts requires +that docker be set up. This will take some time: + + $ ci/run-all.sh + +The list of versions and architectures tested by this can be +determined by looking at the contents of the script. The docker image +used is [posborne/rust-cross][posborne/rust-cross]. + +Running Test for Specific Architectures/Versions +------------------------------------------------ + +Suppose we have a failing test with Rust 1.6/1.7 on the raspberry pi. In +that case, we can run the following: + + $ RUST_VERSIONS="1.6.0 1.7.0" RUST_TARGETS="arm-unknown-linux-gnueabihf" ci/run-all.sh + +[posborne/rust-cross]: https://github.com/posborne/docker-rust-cross From 22b182029c64f8396ab19f095c539551a73978e6 Mon Sep 17 00:00:00 2001 From: Paul Osborne Date: Sun, 6 Mar 2016 20:07:05 -0600 Subject: [PATCH 04/20] testing: switch to posborne/rust-cross There is now a published docker image (if a bit large) making it possible for others to start using the new test ingfrastructure. There seems to be no shortage of compile problems right now. Signed-off-by: Paul Osborne --- ci/run-all.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ci/run-all.sh b/ci/run-all.sh index e20f7735e6..fd1f600c2a 100755 --- a/ci/run-all.sh +++ b/ci/run-all.sh @@ -1,8 +1,8 @@ #!/bin/bash # -# This is **not** meant to be run on CI, but rather locally instead. If you're -# on a Linux machine you'll be able to run most of these, but otherwise this'll -# just attempt to run as many platforms as possible! +# Build nix and all tests for as many versions and platforms as can be +# managed. This requires docker. +# set -e @@ -26,7 +26,7 @@ RUST_TARGETS=${RUST_TARGETS:-"\ x86_64-unknown-linux-gnu \ x86_64-unknown-linux-musl"} -DOCKER_IMAGE="rust-crossbuilder" +DOCKER_IMAGE="posborne/rust-cross" BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" @@ -41,6 +41,10 @@ test_nix() { /source/ci/run.sh ${version} ${target} } +# Ensure up to date (short compared to everything else) +docker pull ${DOCKER_IMAGE} + +# Run tests for each version/target combination for version in ${RUST_VERSIONS}; do for target in ${RUST_TARGETS}; do test_nix $version $target From 3f2b70af27254f9cb2936e3be402bc39ab448b5f Mon Sep 17 00:00:00 2001 From: Paul Osborne Date: Sun, 6 Mar 2016 23:15:52 -0600 Subject: [PATCH 05/20] testing: allow the docker image to be overriden This is handy for trying out changes to the docker image for testing things out. Signed-off-by: Paul Osborne --- ci/run-all.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/run-all.sh b/ci/run-all.sh index fd1f600c2a..67bf7c8351 100755 --- a/ci/run-all.sh +++ b/ci/run-all.sh @@ -26,7 +26,7 @@ RUST_TARGETS=${RUST_TARGETS:-"\ x86_64-unknown-linux-gnu \ x86_64-unknown-linux-musl"} -DOCKER_IMAGE="posborne/rust-cross" +DOCKER_IMAGE=${DOCKER_IMAGE:-"posborne/rust-cross"} BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" From 806e0a7833afee3de2044eb6392a5b8331064b98 Mon Sep 17 00:00:00 2001 From: Paul Osborne Date: Sun, 6 Mar 2016 23:16:22 -0600 Subject: [PATCH 06/20] testing: remove `set -x` from ci/run.sh Signed-off-by: Paul Osborne --- ci/run.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/ci/run.sh b/ci/run.sh index 11a4c14286..aa734be679 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -4,7 +4,6 @@ # script. set -e -set -x BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" MANIFEST_PATH="${BASE_DIR}/Cargo.toml" From d95f4d55cfec20d0ba162cdf2bd5b411c2de83d7 Mon Sep 17 00:00:00 2001 From: Paul Osborne Date: Sun, 6 Mar 2016 23:32:29 -0600 Subject: [PATCH 07/20] testing: disable some targets and continue running on failure Later on, it will probably make sense to stop on failure -- given that most targets currently fail, however, this works a bit better for the time being. Signed-off-by: Paul Osborne --- ci/run-all.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ci/run-all.sh b/ci/run-all.sh index 67bf7c8351..363244e929 100755 --- a/ci/run-all.sh +++ b/ci/run-all.sh @@ -9,20 +9,22 @@ set -e RUST_VERSIONS=${RUST_VERSIONS:-"\ 1.6.0 \ 1.7.0 \ - stable \ beta \ nightly"} +# Disabled (not working presently) but with some support in the target +# image: +# - i686-apple-darwin +# - x86_64-apple-darwin + RUST_TARGETS=${RUST_TARGETS:-"\ aarch64-unknown-linux-gnu \ arm-linux-androideabi \ arm-unknown-linux-gnueabi \ arm-unknown-linux-gnueabihf \ - i686-apple-darwin \ i686-unknown-linux-gnu \ mips-unknown-linux-gnu \ mipsel-unknown-linux-gnu \ - x86_64-apple-darwin \ x86_64-unknown-linux-gnu \ x86_64-unknown-linux-musl"} @@ -47,6 +49,6 @@ docker pull ${DOCKER_IMAGE} # Run tests for each version/target combination for version in ${RUST_VERSIONS}; do for target in ${RUST_TARGETS}; do - test_nix $version $target + test_nix $version $target || true done done From b5b7042e80e3b45d018f190af88bdf4a39115c02 Mon Sep 17 00:00:00 2001 From: Paul Osborne Date: Sun, 6 Mar 2016 23:42:46 -0600 Subject: [PATCH 08/20] testing: fix test exeuction paths with move to docker container Signed-off-by: Paul Osborne --- ci/run.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ci/run.sh b/ci/run.sh index aa734be679..c83b6b8e6f 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -7,6 +7,7 @@ set -e BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" MANIFEST_PATH="${BASE_DIR}/Cargo.toml" +BUILD_DIR="." VERSION="$1" TARGET="$2" @@ -43,12 +44,12 @@ cross_compile_tests() { # ask cargo what test files it generated: # https://github.com/rust-lang/cargo/issues/1924 find_binaries() { - target_base_dir="target/${TARGET}/debug" + target_base_dir="${BUILD_DIR}/${TARGET}/debug" # find [[test]] sections and print the first line and # hack it to what we want from there. Also "nix" for # tests that are implicitly prsent - for test_base in $( awk '/\[\[test\]\]/{getline; print}' Cargo.toml | \ + for test_base in $( awk '/\[\[test\]\]/{getline; print}' "${MANIFEST_PATH}" | \ cut -d '=' -f2 | \ tr -d '"' | \ tr '-' '_' | \ From 5ddd8b2e22f8b1f530975ce06614eabb491f28a2 Mon Sep 17 00:00:00 2001 From: Paul Osborne Date: Sun, 6 Mar 2016 23:47:50 -0600 Subject: [PATCH 09/20] testing: disable thread parallelization in docker testing Signed-off-by: Paul Osborne --- ci/run.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ci/run.sh b/ci/run.sh index c83b6b8e6f..e39cc44b21 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -12,6 +12,8 @@ BUILD_DIR="." VERSION="$1" TARGET="$2" +export RUST_TEST_THREADS=1 + echo "=======================================================" echo "TESTING VERSION: ${VERSION}, TARGET: ${TARGET}" echo "=======================================================" From 14e2f766fea3fa74cf5070b1c4c4825a57bf2c0a Mon Sep 17 00:00:00 2001 From: Paul Osborne Date: Mon, 7 Mar 2016 00:22:03 -0600 Subject: [PATCH 10/20] testing: export CC based on .cargo/config contents We already need to test cargo about gcc locations so it can perfom linking -- we just parse this information out to tell rust where gcc is for complation (nix-test compiles some C code for testing). Signed-off-by: Paul Osborne --- ci/cargo-config | 16 ++++++++++++++-- ci/run.sh | 13 +++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/ci/cargo-config b/ci/cargo-config index 41e232e546..bb10f3974c 100644 --- a/ci/cargo-config +++ b/ci/cargo-config @@ -1,13 +1,25 @@ # Configuration of which linkers to call on Travis for various architectures +[target.x86_64-unknown-linux-gnu] +linker = "gcc" + +[target.x86_64-unknown-linux-musl] +linker = "gcc" + +[target.i686-unknown-linux-gnu] +linker = "gcc" + +[target.i686-unknown-linux-musl] +linker = "gcc" + [target.arm-linux-androideabi] linker = "arm-linux-androideabi-gcc" [target.arm-unknown-linux-gnueabihf] -linker = "arm-linux-gnueabihf-gcc-4.7" +linker = "arm-linux-gnueabihf-gcc" [target.mips-unknown-linux-gnu] -linker = "mips-linux-gnu-gcc-5" +linker = "mips-linux-gnu-gcc" [target.aarch64-unknown-linux-gnu] linker = "aarch64-linux-gnu-gcc" diff --git a/ci/run.sh b/ci/run.sh index e39cc44b21..d1ac5ad90e 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -27,6 +27,17 @@ configure_cargo() { cp "${BASE_DIR}/ci/cargo-config" .cargo/config } +# +# We need to export CC for the tests to build properly (some C code is +# compiled) to work. We already tell Cargo about the compiler in the +# cargo config, so we just parse that info out of the cargo config +# +cc_for_target() { + awk "/\[target\.${TARGET}\]/{getline; print}" .cargo/config | + cut -d '=' -f2 | \ + tr -d '"' | tr -d ' ' +} + cross_compile_tests() { case "$TARGET" in *-apple-ios) @@ -99,6 +110,8 @@ test_binary() { configure_cargo +export CC="$(cc_for_target)" + # select the proper version multirust override ${VERSION} From b69558cd8290dd63340d0a679cf63db317fd8dac Mon Sep 17 00:00:00 2001 From: Paul Osborne Date: Sun, 13 Mar 2016 00:40:36 -0600 Subject: [PATCH 11/20] testing: fix gcc/linker paths for several targets There are also changes in the upstream docker images to support more targets (android on ARM, etc). --- ci/cargo-config | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ci/cargo-config b/ci/cargo-config index bb10f3974c..2e0505979c 100644 --- a/ci/cargo-config +++ b/ci/cargo-config @@ -16,10 +16,16 @@ linker = "gcc" linker = "arm-linux-androideabi-gcc" [target.arm-unknown-linux-gnueabihf] -linker = "arm-linux-gnueabihf-gcc" +linker = "arm-linux-gnueabihf-gcc-4.7" [target.mips-unknown-linux-gnu] -linker = "mips-linux-gnu-gcc" +linker = "mips-linux-gnu-gcc-5" + +[target.mipsel-unknown-linux-gnu] +linker = "mipsel-linux-gnu-gcc-5" [target.aarch64-unknown-linux-gnu] -linker = "aarch64-linux-gnu-gcc" +linker = "aarch64-linux-gnu-gcc-4.8" + +[target.powerpc-unknown-linux-gnu] +linker = "powerpc-linux-gnu-gcc-4.8" From cd3fdaf9918f5f14b9f818f5f5b616446f28260b Mon Sep 17 00:00:00 2001 From: Paul Osborne Date: Sun, 13 Mar 2016 15:04:46 -0500 Subject: [PATCH 12/20] testing: move to new posborne/rust-cross images The rust-cross image is no longer all-in-one but broken out by architecture class (or platform in the case of android). Signed-off-by: Paul Osborne --- Cargo.toml | 2 +- ci/run-all.sh | 56 +++++++++++++----------------------------------- ci/run-docker.sh | 15 +++++++++++++ 3 files changed, 31 insertions(+), 42 deletions(-) create mode 100755 ci/run-docker.sh diff --git a/Cargo.toml b/Cargo.toml index 9db0c1df48..1089828b81 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ preadv_pwritev = [] signalfd = [] [dependencies] -libc = "0.2.8" +libc = { git = "https://github.com/rust-lang/libc.git" } bitflags = "0.4" cfg-if = "0.1.0" diff --git a/ci/run-all.sh b/ci/run-all.sh index 363244e929..5c38ca7f76 100755 --- a/ci/run-all.sh +++ b/ci/run-all.sh @@ -6,49 +6,23 @@ set -e -RUST_VERSIONS=${RUST_VERSIONS:-"\ - 1.6.0 \ - 1.7.0 \ - beta \ - nightly"} - -# Disabled (not working presently) but with some support in the target -# image: -# - i686-apple-darwin -# - x86_64-apple-darwin - -RUST_TARGETS=${RUST_TARGETS:-"\ - aarch64-unknown-linux-gnu \ - arm-linux-androideabi \ - arm-unknown-linux-gnueabi \ - arm-unknown-linux-gnueabihf \ - i686-unknown-linux-gnu \ - mips-unknown-linux-gnu \ - mipsel-unknown-linux-gnu \ - x86_64-unknown-linux-gnu \ - x86_64-unknown-linux-musl"} - -DOCKER_IMAGE=${DOCKER_IMAGE:-"posborne/rust-cross"} - BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +RUN_DOCKER="${BASE_DIR}/ci/run-docker.sh" + +export RUST_VERSION=1.7.0 -test_nix() { - version=$1 - target=$2 +export DOCKER_IMAGE=posborne/rust-cross:base +RUST_TARGET=x86_64-unknown-linux-gnu ${RUN_DOCKER} +RUST_TARGET=x86_64-unknown-linux-musl ${RUN_DOCKER} - docker run -i -t \ - -v ${BASE_DIR}:/source \ - -e CARGO_TARGET_DIR=/build \ - ${DOCKER_IMAGE} \ - /source/ci/run.sh ${version} ${target} -} +export DOCKER_IMAGE=posborne/rust-cross:arm +RUST_TARGET=aarch64-unknown-linux-gnu ${RUN_DOCKER} +RUST_TARGET=arm-linux-gnueabi test_nix ${RUN_DOCKER} +RUST_TARGET=arm-linux-gnueabihf test_nix ${RUN_DOCKER} -# Ensure up to date (short compared to everything else) -docker pull ${DOCKER_IMAGE} +export DOCKER_IMAGE=posborne/rust-cross:mips +RUST_TARGET=mips-unknown-linux-gnu test_nix ${RUN_DOCKER} +RUST_TARGET=mipsel-unknown-linux-gnu test_nix ${RUN_DOCKER} -# Run tests for each version/target combination -for version in ${RUST_VERSIONS}; do - for target in ${RUST_TARGETS}; do - test_nix $version $target || true - done -done +export DOCKER_IMAGE=posborne/rust-cross:android ${RUN_DOCKER} +RUST_TARGET=arm-linux-androideabi test_nix ${RUN_DOCKER} diff --git a/ci/run-docker.sh b/ci/run-docker.sh new file mode 100755 index 0000000000..3ef831c32c --- /dev/null +++ b/ci/run-docker.sh @@ -0,0 +1,15 @@ +#!/bin/bash +# +# Run the nix tests in a docker container. This script expects the following +# environment variables to be set: +# - DOCKER_IMAGE : Docker image to use for testing (e.g. posborne/rust-cross:arm) +# - RUST_VERSION : Rust Version to test against (e.g. 1.7.0) +# - RUST_TARGET : Target Triple to test + +BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" + +docker run -i -t \ + -v ${BASE_DIR}:/source \ + -e CARGO_TARGET_DIR=/build \ + ${DOCKER_IMAGE} \ + /source/ci/run.sh ${RUST_VERSION} ${RUST_TARGET} From 6ad81d1ce34979253395aa39918899b3134a09c0 Mon Sep 17 00:00:00 2001 From: Paul Osborne Date: Sun, 13 Mar 2016 15:16:03 -0500 Subject: [PATCH 13/20] testing: first shot at testing with travis for arm, mips, android, ... This is based on libc and the new docker-based testing infrastructure via posborne/rust-cross. Signed-off-by: Paul Osborne --- .travis.yml | 50 +++++++++++++++++++++++++++++++++--------------- ci/run-travis.sh | 37 +++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 15 deletions(-) create mode 100644 ci/run-travis.sh diff --git a/.travis.yml b/.travis.yml index c0fd80ab64..640de1335e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,7 @@ --- -sudo: false +sudo: required +services: + - docker language: rust rust: - 1.1.0 # Oldest supported version @@ -7,31 +9,49 @@ rust: - 1.3.0 - 1.4.0 - 1.5.0 + - 1.6.0 + - 1.7.0 - stable - beta - nightly -# Failures on nightly shouldn't fail the overall build. -matrix: - allow_failures: - - rust: nightly +script: + - sh ci/run-travis.sh os: - linux - osx env: - - RUST_TEST_THREADS=1 ARCH=x86_64 - - RUST_TEST_THREADS=1 ARCH=i686 + - ARCH=x86_64 + - ARCH=i686 -script: - - curl -sSL https://raw.githubusercontent.com/carllerche/travis-rust-matrix/master/test | RUST_TEST_THREADS=1 bash - - cargo doc --no-deps - -addons: - apt: - packages: - - gcc-multilib +# Failures on nightly shouldn't fail the overall build. +matrix: + fast_finish: true + include: + - os: linux + env: TARGET=aarch64-unknown-linux-gnu DOCKER_IMAGE=posborne/rust-cross:arm + rust: 1.7.0 + - os: linux + env: TARGET=arm-unknown-linux-gnueabihf DOCKER_IMAGE=posborne/rust-cross:arm + rust: 1.7.0 + - os: linux + env: TARGET=mips-unknown-linux-gnu DOCKER_IMAGE=posborne/rust-cross:mips + rust: 1.7.0 + - os: linux + env: TARGET=mipsel-unknwon-linux-gnu DOCKER_IMAGE=posborne/rust-cross:mips + rust: 1.7.0 + - os: linux + env: TARGET=arm-linux-androideabi DOCKER_IMAGE=posborne/rust-cross:android + rust: 1.7.0 + allow_failures: + - rust: nightly + - env: TARGET=aarch64-unknown-linux-gnu DOCKER_IMAGE=posborne/rust-cross:arm + - env: TARGET=arm-unknown-linux-gnueabihf DOCKER_IMAGE=posborne/rust-cross:arm + - env: TARGET=mips-unknown-linux-gnu DOCKER_IMAGE=posborne/rust-cross:mips + - env: TARGET=mipsel-unknwon-linux-gnu DOCKER_IMAGE=posborne/rust-cross:mips + - env: TARGET=arm-linux-androideabi DOCKER_IMAGE=posborne/rust-cross:android # Deploy documentation to S3 for specific branches. At some # point, it would be nice to also support building docs for diff --git a/ci/run-travis.sh b/ci/run-travis.sh new file mode 100644 index 0000000000..76e3dff5d6 --- /dev/null +++ b/ci/run-travis.sh @@ -0,0 +1,37 @@ +#!/bin/bash +# +# Entry point for all travis builds, this will set up the Travis environment by +# downloading any dependencies. It will then execute the `run.sh` script to +# build and execute all tests. +# +# Much of this script was liberally stolen from rust-lang/libc +# +# Key variables that may be set from Travis: +# - TRAVIS_RUST_VERSION: 1.1.0 ... stable/nightly/beta +# - TRAVIS_OS_NAME: linux/osx +# - DOCKER_IMAGE: posborne/rust-cross:arm +# - TARGET: e.g. arm-unknown-linux-gnueabihf + +set -ex + +BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" + +if [ "$TRAVIS_OS_NAME" = "linux" ]; then + OS=unknown-linux-gnu +else + OS=apple-darwin +fi + +export HOST=$ARCH-$OS +if [ "$TARGET" = "" ]; then + TARGET=$HOST +fi + +if [ "$DOCKER_IMAGE" = "" ]; then + RUST_TEST_THREADS=1 cargo test +else + export RUST_VERSION=${TRAVIS_RUST_VERSION} + export RUST_TARGET=${TARGET} + export DOCKER_IMAGE=${DOCKER_IMAGE} + ${BASE_DIR}/ci/run-docker.sh +fi From 3b7b15d0a7a29c97e0293f8324ca49e15dcf9840 Mon Sep 17 00:00:00 2001 From: Paul Osborne Date: Sun, 13 Mar 2016 15:33:04 -0500 Subject: [PATCH 14/20] testing: docker tests now work on travis All of the platforms tested currently fail in some way currently, but the infrastructure itself appears to be working. As we have moved to the legacy infrastructure (required in order to use docker), the tests do run slower now. To compensate for that, i686 builds are only done on stable and we do not test every version between the current stable and the oldest version we support. Signed-off-by: Paul Osborne --- .travis.yml | 26 +++++++++++++------------- ci/run-travis.sh | 9 ++++++++- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index 640de1335e..67668a1d89 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,35 +1,35 @@ ---- +language: rust sudo: required +dist: trusty services: - docker -language: rust + rust: - 1.1.0 # Oldest supported version - - 1.2.0 - - 1.3.0 - - 1.4.0 - - 1.5.0 - - 1.6.0 - - 1.7.0 - stable - beta - nightly script: - - sh ci/run-travis.sh + - bash ci/run-travis.sh + +env: + - ARCH=x86_64 os: - linux - osx -env: - - ARCH=x86_64 - - ARCH=i686 - # Failures on nightly shouldn't fail the overall build. matrix: fast_finish: true include: + - os: linux + env: ARCH=i686 + rust: stable + - os: osx + env: ARCH=i686 + rust: stable - os: linux env: TARGET=aarch64-unknown-linux-gnu DOCKER_IMAGE=posborne/rust-cross:arm rust: 1.7.0 diff --git a/ci/run-travis.sh b/ci/run-travis.sh index 76e3dff5d6..aeaa4783b7 100644 --- a/ci/run-travis.sh +++ b/ci/run-travis.sh @@ -27,8 +27,15 @@ if [ "$TARGET" = "" ]; then TARGET=$HOST fi +if [ "$TARGET" = "i686-unknown-linux-gnu" ]; then + sudo apt-get -y update + sudo apt-get install -y gcc-multilib +fi + if [ "$DOCKER_IMAGE" = "" ]; then - RUST_TEST_THREADS=1 cargo test + export RUST_TEST_THREADS=1 + curl -sSL "https://raw.githubusercontent.com/carllerche/travis-rust-matrix/master/test" | bash + cargo doc --no-deps else export RUST_VERSION=${TRAVIS_RUST_VERSION} export RUST_TARGET=${TARGET} From ef8f643a4465e91eeb6928b0f5213b421d00274e Mon Sep 17 00:00:00 2001 From: Paul Osborne Date: Mon, 14 Mar 2016 12:45:14 -0500 Subject: [PATCH 15/20] libc: revert change to libc version Signed-off-by: Paul Osborne --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 1089828b81..9db0c1df48 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ preadv_pwritev = [] signalfd = [] [dependencies] -libc = { git = "https://github.com/rust-lang/libc.git" } +libc = "0.2.8" bitflags = "0.4" cfg-if = "0.1.0" From 02af9251786dfb22249151f6be2bb5a4b13d4c2f Mon Sep 17 00:00:00 2001 From: Paul Osborne Date: Mon, 14 Mar 2016 12:52:33 -0500 Subject: [PATCH 16/20] testing: move echo statement within docker run script Based on code review feedback. Signed-off-by: Paul Osborne --- ci/run.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ci/run.sh b/ci/run.sh index d1ac5ad90e..b26c68bc61 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -14,10 +14,6 @@ TARGET="$2" export RUST_TEST_THREADS=1 -echo "=======================================================" -echo "TESTING VERSION: ${VERSION}, TARGET: ${TARGET}" -echo "=======================================================" - # # Tell cargo what linker to use and whatever else is required # @@ -108,8 +104,11 @@ test_binary() { esac } -configure_cargo +echo "=======================================================" +echo "TESTING VERSION: ${VERSION}, TARGET: ${TARGET}" +echo "=======================================================" +configure_cargo export CC="$(cc_for_target)" # select the proper version From 5eb1fa6dcd6696df19c6f1ec24d9e51cf68b4cfd Mon Sep 17 00:00:00 2001 From: Paul Osborne Date: Mon, 14 Mar 2016 12:54:08 -0500 Subject: [PATCH 17/20] testing: use default linker for appropriate platforms For platforms where the host ${CC} is appropriate, use the default implicitly rather than matching it explictly. This will allow for the llvm linker to be used if/when that happens. Signed-off-by: Paul Osborne --- ci/cargo-config | 13 ------------- ci/run.sh | 3 +++ 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/ci/cargo-config b/ci/cargo-config index 2e0505979c..6fee5be7a8 100644 --- a/ci/cargo-config +++ b/ci/cargo-config @@ -1,17 +1,4 @@ # Configuration of which linkers to call on Travis for various architectures - -[target.x86_64-unknown-linux-gnu] -linker = "gcc" - -[target.x86_64-unknown-linux-musl] -linker = "gcc" - -[target.i686-unknown-linux-gnu] -linker = "gcc" - -[target.i686-unknown-linux-musl] -linker = "gcc" - [target.arm-linux-androideabi] linker = "arm-linux-androideabi-gcc" diff --git a/ci/run.sh b/ci/run.sh index b26c68bc61..0a7039f6dd 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -110,6 +110,9 @@ echo "=======================================================" configure_cargo export CC="$(cc_for_target)" +if [ "${CC}" = "" ]; then + unset CC +fi # select the proper version multirust override ${VERSION} From 4e245f48cef1d406bf44da9cda5567091b71f25e Mon Sep 17 00:00:00 2001 From: Paul Osborne Date: Mon, 14 Mar 2016 13:03:51 -0500 Subject: [PATCH 18/20] testing: update documentation related to testing Signed-off-by: Paul Osborne --- CONTRIBUTING.md | 5 ++++- README.md | 2 +- ci/README.md | 12 +++++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3224ad2a29..80c2f04c46 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -72,8 +72,11 @@ environment. We also have [continuous integration set up on Travis-CI][travis-ci], which might find some issues on other platforms. The CI will run once you open a pull request. -[travis-ci]: https://travis-ci.org/nix-rust/nix +There is also infrastructure for running tests for other targets +locally. More information is available in the [CI Readme][ci-readme]. +[travis-ci]: https://travis-ci.org/nix-rust/nix +[ci-readme]: ci/README.md ## Homu, the bot who merges all the PRs diff --git a/README.md b/README.md index da81ed19ce..d10bc0eea0 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ To use `nix`, first add this to your `Cargo.toml`: ```toml [dependencies] -nix = "*" +nix = "0.5.0" ``` Then, add this to your crate root: diff --git a/ci/README.md b/ci/README.md index 5e46fadcff..c86fd7157d 100644 --- a/ci/README.md +++ b/ci/README.md @@ -31,12 +31,18 @@ The list of versions and architectures tested by this can be determined by looking at the contents of the script. The docker image used is [posborne/rust-cross][posborne/rust-cross]. +[posborne/rust-cross]: https://github.com/rust-embedded/docker-rust-cross + Running Test for Specific Architectures/Versions ------------------------------------------------ -Suppose we have a failing test with Rust 1.6/1.7 on the raspberry pi. In +Suppose we have a failing test with Rust 1.7 on the raspberry pi. In that case, we can run the following: - $ RUST_VERSIONS="1.6.0 1.7.0" RUST_TARGETS="arm-unknown-linux-gnueabihf" ci/run-all.sh + $ DOCKER_IMAGE=posborne/rust-cross:arm \ + RUST_VERSION=1.7.0 \ + RUST_TARGET=arm-unknown-linux-gnueabihf ci/run-docker.sh -[posborne/rust-cross]: https://github.com/posborne/docker-rust-cross +Currently, the docker images only support Rust 1.7. To get a better +idea of combinations that might work, look at the contents of the +[travis configuration](../.travis.yml) or [run-all.sh](run-all.sh). From 72f675427568a192266a4828005a6c64252e65d8 Mon Sep 17 00:00:00 2001 From: Paul Osborne Date: Mon, 14 Mar 2016 14:10:38 -0500 Subject: [PATCH 19/20] testing: explicitly check TRAVIS_OS_NAME is osx Signed-off-by: Paul Osborne --- ci/run-travis.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ci/run-travis.sh b/ci/run-travis.sh index aeaa4783b7..195881fe3f 100644 --- a/ci/run-travis.sh +++ b/ci/run-travis.sh @@ -18,8 +18,11 @@ BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" if [ "$TRAVIS_OS_NAME" = "linux" ]; then OS=unknown-linux-gnu -else +elif [ "$TRAVIS_OS_NAME" = "osx" ]; then OS=apple-darwin +else + echo "Unexpected TRAVIS_OS_NAME: $TRAVIS_OS_NAME" + exit 1 fi export HOST=$ARCH-$OS From d1311ffbeb48b8951d4bab9f26aeaa9ab56fa8ae Mon Sep 17 00:00:00 2001 From: Paul Osborne Date: Mon, 14 Mar 2016 14:34:05 -0500 Subject: [PATCH 20/20] testing: ensure run.sh is executing in docker container On the host, some undesired things could end up happening if this is executed, so we now exit and log if that is attempted. In addition, we now backup the previous cargo config if present. This will never be the case in the current build setup, but that could change if we decide to do builds in a data volume in the future. Signed-off-by: Paul Osborne --- ci/run.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/ci/run.sh b/ci/run.sh index 0a7039f6dd..71c91cd9d6 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -5,6 +5,16 @@ set -e +# This should only be run in a docker container, so verify that +if [ ! -f /.dockerinit ]; then + echo "run.sh should only be executed in a docker container" + echo "and that does not appear to be the case. Maybe you meant" + echo "to execute the tests via run-all.sh or run-docker.sh." + echo "" + echo "For more instructions, please refer to ci/README.md" + exit 1 +fi + BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" MANIFEST_PATH="${BASE_DIR}/Cargo.toml" BUILD_DIR="." @@ -18,9 +28,8 @@ export RUST_TEST_THREADS=1 # Tell cargo what linker to use and whatever else is required # configure_cargo() { - rm -rf .cargo - mkdir .cargo - cp "${BASE_DIR}/ci/cargo-config" .cargo/config + mkdir -p .cargo + cp -b "${BASE_DIR}/ci/cargo-config" .cargo/config } #