xref: /rust-libc-0.2.174/ci/run.sh (revision ae81dc8d)
1#!/bin/sh
2
3# Builds and runs tests for a particular target passed as an argument to this
4# script.
5
6set -ex
7
8TARGET=$1
9
10# If we're going to run tests inside of a qemu image, then we don't need any of
11# the scripts below. Instead, download the image, prepare a filesystem which has
12# the current state of this repository, and then run the image.
13#
14# It's assume that all images, when run with two disks, will run the `run.sh`
15# script from the second which we place inside.
16if [ "$QEMU" != "" ]; then
17  tmpdir=/tmp/qemu-img-creation
18  mkdir -p $tmpdir
19
20  if [ -z "${QEMU#*.gz}" ]; then
21    # image is .gz : download and uncompress it
22    qemufile=$(echo ${QEMU%.gz} | sed 's/\//__/g')
23    if [ ! -f $tmpdir/$qemufile ]; then
24      curl https://s3-us-west-1.amazonaws.com/rust-lang-ci2/libc/$QEMU | \
25        gunzip -d > $tmpdir/$qemufile
26    fi
27  else
28    # plain qcow2 image: just download it
29    qemufile=$(echo ${QEMU} | sed 's/\//__/g')
30    if [ ! -f $tmpdir/$qemufile ]; then
31      curl https://s3-us-west-1.amazonaws.com/rust-lang-ci2/libc/$QEMU \
32        > $tmpdir/$qemufile
33    fi
34  fi
35
36  # Create a mount a fresh new filesystem image that we'll later pass to QEMU.
37  # This will have a `run.sh` script will which use the artifacts inside to run
38  # on the host.
39  rm -f $tmpdir/libc-test.img
40  mkdir $tmpdir/mount
41
42  # Do the standard rigamarole of cross-compiling an executable and then the
43  # script to run just executes the binary.
44  cargo build --manifest-path libc-test/Cargo.toml --target $TARGET --tests
45  cp $CARGO_TARGET_DIR/$TARGET/debug/main-* $tmpdir/mount/libc-test
46  echo 'exec $1/libc-test' > $tmpdir/mount/run.sh
47
48  du -sh $tmpdir/mount
49  genext2fs \
50      --root $tmpdir/mount \
51      --size-in-blocks 100000 \
52      $tmpdir/libc-test.img
53
54  # Pass -snapshot to prevent tampering with the disk images, this helps when
55  # running this script in development. The two drives are then passed next,
56  # first is the OS and second is the one we just made. Next the network is
57  # configured to work (I'm not entirely sure how), and then finally we turn off
58  # graphics and redirect the serial console output to out.log.
59  qemu-system-x86_64 \
60    -m 1024 \
61    -snapshot \
62    -drive if=virtio,file=$tmpdir/$qemufile \
63    -drive if=virtio,file=$tmpdir/libc-test.img \
64    -net nic,model=virtio \
65    -net user \
66    -nographic \
67    -vga none 2>&1 | tee $CARGO_TARGET_DIR/out.log
68  exec grep "^PASSED .* tests" $CARGO_TARGET_DIR/out.log
69fi
70
71# FIXME: x86_64-unknown-linux-gnux32 fail to compile wihout --release
72# See https://github.com/rust-lang/rust/issues/45417
73opt=
74if [ "$TARGET" = "x86_64-unknown-linux-gnux32" ]; then
75  opt="--release"
76fi
77
78exec cargo test $opt --manifest-path libc-test/Cargo.toml --target $TARGET
79