set -ex
TARGET=$1
if [ "$QEMU" != "" ]; then
tmpdir=/tmp/qemu-img-creation
mkdir -p $tmpdir
if [ -z "${QEMU#*.gz}" ]; then
qemufile=$(echo ${QEMU%.gz} | sed 's/\//__/g')
if [ ! -f $tmpdir/$qemufile ]; then
curl https://s3-us-west-1.amazonaws.com/rust-lang-ci2/libc/$QEMU | \
gunzip -d > $tmpdir/$qemufile
fi
elif [ -z "${QEMU#*.xz}" ]; then
qemufile=$(echo ${QEMU%.xz} | sed 's/\//__/g')
if [ ! -f $tmpdir/$qemufile ]; then
curl https://s3-us-west-1.amazonaws.com/rust-lang-ci2/libc/$QEMU | \
unxz > $tmpdir/$qemufile
fi
else
qemufile=$(echo ${QEMU} | sed 's/\//__/g')
if [ ! -f $tmpdir/$qemufile ]; then
curl https://s3-us-west-1.amazonaws.com/rust-lang-ci2/libc/$QEMU \
> $tmpdir/$qemufile
fi
fi
rm -f $tmpdir/libc-test.img
mkdir $tmpdir/mount
cargo build \
--manifest-path libc-test/Cargo.toml \
--target $TARGET \
--test main
rm $CARGO_TARGET_DIR/$TARGET/debug/main-*.d
cp $CARGO_TARGET_DIR/$TARGET/debug/main-* $tmpdir/mount/libc-test
echo 'exec $1/libc-test' > $tmpdir/mount/run.sh
du -sh $tmpdir/mount
genext2fs \
--root $tmpdir/mount \
--size-in-blocks 100000 \
$tmpdir/libc-test.img
qemu-system-x86_64 \
-m 1024 \
-snapshot \
-drive if=virtio,file=$tmpdir/$qemufile \
-drive if=virtio,file=$tmpdir/libc-test.img \
-net nic,model=virtio \
-net user \
-nographic \
-vga none 2>&1 | tee $CARGO_TARGET_DIR/out.log
exec grep "^PASSED .* tests" $CARGO_TARGET_DIR/out.log
fi
opt=
if [ "$TARGET" = "x86_64-unknown-linux-gnux32" ]; then
opt="--release"
fi
cargo test $opt --no-default-features --manifest-path libc-test/Cargo.toml --target $TARGET
exec cargo test $opt --manifest-path libc-test/Cargo.toml --target $TARGET