blob: 51a2c68714ccfbc8868119d24ccf3416de3b67ac [file] [log] [blame]
# Builds and runs tests for a particular target passed as an argument to this
# script.
set -ex
# 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 ``
# script from the second which we place inside.
if [ "$QEMU" != "" ]; then
mkdir -p $tmpdir
if [ -z "${QEMU#*.gz}" ]; then
# image is .gz : download and uncompress it
qemufile=$(echo ${QEMU%.gz} | sed 's/\//__/g')
if [ ! -f $tmpdir/$qemufile ]; then
curl$QEMU | \
gunzip -d > $tmpdir/$qemufile
# plain qcow2 image: just download it
qemufile=$(echo ${QEMU} | sed 's/\//__/g')
if [ ! -f $tmpdir/$qemufile ]; then
curl$QEMU \
> $tmpdir/$qemufile
# Create a mount a fresh new filesystem image that we'll later pass to QEMU.
# This will have a `` script will which use the artifacts inside to run
# on the host.
rm -f $tmpdir/libc-test.img
mkdir $tmpdir/mount
# Do the standard rigamarole of cross-compiling an executable and then the
# script to run just executes the binary.
cargo build --manifest-path libc-test/Cargo.toml --target $TARGET --tests
cp $CARGO_TARGET_DIR/$TARGET/debug/main-* $tmpdir/mount/libc-test
echo 'exec $1/libc-test' > $tmpdir/mount/
du -sh $tmpdir/mount
genext2fs \
--root $tmpdir/mount \
--size-in-blocks 100000 \
# 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.
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
exec cargo test --manifest-path libc-test/Cargo.toml --target $TARGET