xref: /rust-libc-0.2.174/ci/run.sh (revision aa41265f)
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  elif [ -z "${QEMU#*.xz}" ]; then
28    # image is .xz : download and uncompress it
29    qemufile=$(echo ${QEMU%.xz} | sed 's/\//__/g')
30    if [ ! -f $tmpdir/$qemufile ]; then
31      curl https://s3-us-west-1.amazonaws.com/rust-lang-ci2/libc/$QEMU | \
32        unxz > $tmpdir/$qemufile
33    fi
34  else
35    # plain qcow2 image: just download it
36    qemufile=$(echo ${QEMU} | sed 's/\//__/g')
37    if [ ! -f $tmpdir/$qemufile ]; then
38      curl https://s3-us-west-1.amazonaws.com/rust-lang-ci2/libc/$QEMU \
39        > $tmpdir/$qemufile
40    fi
41  fi
42
43  # Create a mount a fresh new filesystem image that we'll later pass to QEMU.
44  # This will have a `run.sh` script will which use the artifacts inside to run
45  # on the host.
46  rm -f $tmpdir/libc-test.img
47  mkdir $tmpdir/mount
48
49  # Do the standard rigamarole of cross-compiling an executable and then the
50  # script to run just executes the binary.
51  cargo build \
52    --manifest-path libc-test/Cargo.toml \
53    --target $TARGET \
54    --test main
55  rm $CARGO_TARGET_DIR/$TARGET/debug/main-*.d
56  cp $CARGO_TARGET_DIR/$TARGET/debug/main-* $tmpdir/mount/libc-test
57  echo 'exec $1/libc-test' > $tmpdir/mount/run.sh
58
59  du -sh $tmpdir/mount
60  genext2fs \
61      --root $tmpdir/mount \
62      --size-in-blocks 100000 \
63      $tmpdir/libc-test.img
64
65  # Pass -snapshot to prevent tampering with the disk images, this helps when
66  # running this script in development. The two drives are then passed next,
67  # first is the OS and second is the one we just made. Next the network is
68  # configured to work (I'm not entirely sure how), and then finally we turn off
69  # graphics and redirect the serial console output to out.log.
70  qemu-system-x86_64 \
71    -m 1024 \
72    -snapshot \
73    -drive if=virtio,file=$tmpdir/$qemufile \
74    -drive if=virtio,file=$tmpdir/libc-test.img \
75    -net nic,model=virtio \
76    -net user \
77    -nographic \
78    -vga none 2>&1 | tee $CARGO_TARGET_DIR/out.log
79  exec grep "^PASSED .* tests" $CARGO_TARGET_DIR/out.log
80fi
81
82# FIXME: x86_64-unknown-linux-gnux32 fail to compile wihout --release
83# See https://github.com/rust-lang/rust/issues/45417
84opt=
85if [ "$TARGET" = "x86_64-unknown-linux-gnux32" ]; then
86  opt="--release"
87fi
88
89# Building with --no-default-features is currently broken on rumprun because we
90# need cfg(target_vendor), which is currently unstable.
91if [ "$TARGET" != "x86_64-rumprun-netbsd" ]; then
92  cargo test $opt --no-default-features --manifest-path libc-test/Cargo.toml --target $TARGET
93fi
94exec cargo test $opt --manifest-path libc-test/Cargo.toml --target $TARGET
95