2018-11-19 15:49:56 +01:00
|
|
|
#!/usr/bin/env sh
|
2015-09-12 20:22:42 +02:00
|
|
|
|
2015-09-18 02:45:10 +02:00
|
|
|
# Builds and runs tests for a particular target passed as an argument to this
|
|
|
|
# script.
|
|
|
|
|
2015-09-12 20:22:42 +02:00
|
|
|
set -ex
|
|
|
|
|
2019-10-22 13:20:54 +02:00
|
|
|
MIRRORS_URL="https://ci-mirrors.rust-lang.org/libc"
|
2019-08-21 09:20:32 +02:00
|
|
|
|
2018-11-19 15:49:56 +01:00
|
|
|
TARGET="${1}"
|
2016-06-10 14:03:23 +02:00
|
|
|
|
|
|
|
# If we're going to run tests inside of a qemu image, then we don't need any of
|
|
|
|
# the scripts below. Instead, download the image, prepare a filesystem which has
|
|
|
|
# the current state of this repository, and then run the image.
|
|
|
|
#
|
|
|
|
# It's assume that all images, when run with two disks, will run the `run.sh`
|
|
|
|
# script from the second which we place inside.
|
|
|
|
if [ "$QEMU" != "" ]; then
|
|
|
|
tmpdir=/tmp/qemu-img-creation
|
2018-11-19 15:49:56 +01:00
|
|
|
mkdir -p "${tmpdir}"
|
2016-09-08 06:36:05 +02:00
|
|
|
|
|
|
|
if [ -z "${QEMU#*.gz}" ]; then
|
|
|
|
# image is .gz : download and uncompress it
|
2018-11-19 15:49:56 +01:00
|
|
|
qemufile="$(echo "${QEMU%.gz}" | sed 's/\//__/g')"
|
|
|
|
if [ ! -f "${tmpdir}/${qemufile}" ]; then
|
2019-08-21 09:20:32 +02:00
|
|
|
curl --retry 5 "${MIRRORS_URL}/${QEMU}" | \
|
2018-11-19 15:49:56 +01:00
|
|
|
gunzip -d > "${tmpdir}/${qemufile}"
|
2016-09-08 06:36:05 +02:00
|
|
|
fi
|
2018-03-15 22:23:01 +01:00
|
|
|
elif [ -z "${QEMU#*.xz}" ]; then
|
|
|
|
# image is .xz : download and uncompress it
|
2018-11-19 15:49:56 +01:00
|
|
|
qemufile="$(echo "${QEMU%.xz}" | sed 's/\//__/g')"
|
|
|
|
if [ ! -f "${tmpdir}/${qemufile}" ]; then
|
2019-08-21 09:20:32 +02:00
|
|
|
curl --retry 5 "${MIRRORS_URL}/${QEMU}" | \
|
2018-11-19 15:49:56 +01:00
|
|
|
unxz > "${tmpdir}/${qemufile}"
|
2018-03-15 22:23:01 +01:00
|
|
|
fi
|
2016-09-08 06:36:05 +02:00
|
|
|
else
|
|
|
|
# plain qcow2 image: just download it
|
2018-11-19 15:49:56 +01:00
|
|
|
qemufile="$(echo "${QEMU}" | sed 's/\//__/g')"
|
|
|
|
if [ ! -f "${tmpdir}/${qemufile}" ]; then
|
2020-02-29 14:00:36 +01:00
|
|
|
curl --retry 5 "${MIRRORS_URL}/${QEMU}" \
|
2018-11-19 15:49:56 +01:00
|
|
|
> "${tmpdir}/${qemufile}"
|
2016-09-08 06:36:05 +02:00
|
|
|
fi
|
2016-06-10 14:03:23 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Create a mount a fresh new filesystem image that we'll later pass to QEMU.
|
|
|
|
# This will have a `run.sh` script will which use the artifacts inside to run
|
|
|
|
# on the host.
|
2018-11-19 15:49:56 +01:00
|
|
|
rm -f "${tmpdir}/libc-test.img"
|
|
|
|
mkdir "${tmpdir}/mount"
|
2016-06-10 14:03:23 +02:00
|
|
|
|
2017-08-18 18:20:11 +02:00
|
|
|
# Do the standard rigamarole of cross-compiling an executable and then the
|
|
|
|
# script to run just executes the binary.
|
2017-11-25 22:56:29 +01:00
|
|
|
cargo build \
|
|
|
|
--manifest-path libc-test/Cargo.toml \
|
2018-11-19 15:49:56 +01:00
|
|
|
--target "${TARGET}" \
|
2017-11-25 22:56:29 +01:00
|
|
|
--test main
|
2018-11-19 15:49:56 +01:00
|
|
|
rm "${CARGO_TARGET_DIR}/${TARGET}"/debug/main-*.d
|
|
|
|
cp "${CARGO_TARGET_DIR}/${TARGET}"/debug/main-* "${tmpdir}"/mount/libc-test
|
|
|
|
# shellcheck disable=SC2016
|
|
|
|
echo 'exec $1/libc-test' > "${tmpdir}/mount/run.sh"
|
2016-06-10 14:03:23 +02:00
|
|
|
|
2018-11-19 15:49:56 +01:00
|
|
|
du -sh "${tmpdir}/mount"
|
2016-10-08 20:33:09 +02:00
|
|
|
genext2fs \
|
2018-11-19 15:49:56 +01:00
|
|
|
--root "${tmpdir}/mount" \
|
2016-10-08 20:33:09 +02:00
|
|
|
--size-in-blocks 100000 \
|
2018-11-19 15:49:56 +01:00
|
|
|
"${tmpdir}/libc-test.img"
|
2016-06-10 14:03:23 +02:00
|
|
|
|
|
|
|
# Pass -snapshot to prevent tampering with the disk images, this helps when
|
|
|
|
# running this script in development. The two drives are then passed next,
|
|
|
|
# first is the OS and second is the one we just made. Next the network is
|
|
|
|
# configured to work (I'm not entirely sure how), and then finally we turn off
|
|
|
|
# graphics and redirect the serial console output to out.log.
|
2016-10-08 20:33:09 +02:00
|
|
|
qemu-system-x86_64 \
|
2016-06-10 14:03:23 +02:00
|
|
|
-m 1024 \
|
|
|
|
-snapshot \
|
2018-11-19 15:49:56 +01:00
|
|
|
-drive if=virtio,file="${tmpdir}/${qemufile}" \
|
|
|
|
-drive if=virtio,file="${tmpdir}/libc-test.img" \
|
2016-06-10 14:03:23 +02:00
|
|
|
-net nic,model=virtio \
|
|
|
|
-net user \
|
|
|
|
-nographic \
|
2018-11-19 15:49:56 +01:00
|
|
|
-vga none 2>&1 | tee "${CARGO_TARGET_DIR}/out.log"
|
2019-02-01 06:34:17 +01:00
|
|
|
exec egrep "^(PASSED)|(test result: ok)" "${CARGO_TARGET_DIR}/out.log"
|
2016-06-10 14:03:23 +02:00
|
|
|
fi
|
|
|
|
|
2020-10-08 19:15:04 +02:00
|
|
|
if [ "$TARGET" = "s390x-unknown-linux-gnu" ]; then
|
|
|
|
# FIXME: s390x-unknown-linux-gnu often fails to test due to timeout,
|
|
|
|
# so we retry this N times.
|
|
|
|
N=5
|
|
|
|
n=0
|
|
|
|
passed=0
|
|
|
|
until [ $n -ge $N ]
|
|
|
|
do
|
|
|
|
if [ "$passed" = "0" ]; then
|
|
|
|
if cargo test --no-default-features --manifest-path libc-test/Cargo.toml --target "${TARGET}" ; then
|
|
|
|
passed=$((passed+1))
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
elif [ "$passed" = "1" ]; then
|
2021-07-16 02:36:24 +02:00
|
|
|
if cargo test --manifest-path libc-test/Cargo.toml --target "${TARGET}" ; then
|
2020-10-08 19:15:04 +02:00
|
|
|
passed=$((passed+1))
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
elif [ "$passed" = "2" ]; then
|
2021-07-16 02:36:24 +02:00
|
|
|
if cargo test --features extra_traits --manifest-path libc-test/Cargo.toml --target "${TARGET}"; then
|
2020-10-08 19:15:04 +02:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
n=$((n+1))
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
else
|
2021-07-16 02:36:24 +02:00
|
|
|
cargo test --no-default-features --manifest-path libc-test/Cargo.toml \
|
2020-10-08 19:15:04 +02:00
|
|
|
--target "${TARGET}"
|
2019-02-07 11:36:31 +01:00
|
|
|
|
2021-07-16 02:36:24 +02:00
|
|
|
cargo test --manifest-path libc-test/Cargo.toml --target "${TARGET}"
|
2019-02-07 11:36:31 +01:00
|
|
|
|
2021-07-16 02:36:24 +02:00
|
|
|
RUST_BACKTRACE=1 cargo test --features extra_traits --manifest-path libc-test/Cargo.toml \
|
2020-10-08 19:15:04 +02:00
|
|
|
--target "${TARGET}"
|
|
|
|
fi
|