]> git.proxmox.com Git - rustc.git/blob - src/vendor/libc/ci/run.sh
New upstream version 1.25.0+dfsg1
[rustc.git] / src / vendor / libc / ci / run.sh
1 #!/bin/sh
2
3 # Builds and runs tests for a particular target passed as an argument to this
4 # script.
5
6 set -ex
7
8 TARGET=$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.
16 if [ "$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 \
45 --manifest-path libc-test/Cargo.toml \
46 --target $TARGET \
47 --test main
48 rm $CARGO_TARGET_DIR/$TARGET/debug/main-*.d
49 cp $CARGO_TARGET_DIR/$TARGET/debug/main-* $tmpdir/mount/libc-test
50 echo 'exec $1/libc-test' > $tmpdir/mount/run.sh
51
52 du -sh $tmpdir/mount
53 genext2fs \
54 --root $tmpdir/mount \
55 --size-in-blocks 100000 \
56 $tmpdir/libc-test.img
57
58 # Pass -snapshot to prevent tampering with the disk images, this helps when
59 # running this script in development. The two drives are then passed next,
60 # first is the OS and second is the one we just made. Next the network is
61 # configured to work (I'm not entirely sure how), and then finally we turn off
62 # graphics and redirect the serial console output to out.log.
63 qemu-system-x86_64 \
64 -m 1024 \
65 -snapshot \
66 -drive if=virtio,file=$tmpdir/$qemufile \
67 -drive if=virtio,file=$tmpdir/libc-test.img \
68 -net nic,model=virtio \
69 -net user \
70 -nographic \
71 -vga none 2>&1 | tee $CARGO_TARGET_DIR/out.log
72 exec grep "^PASSED .* tests" $CARGO_TARGET_DIR/out.log
73 fi
74
75 # FIXME: x86_64-unknown-linux-gnux32 fail to compile wihout --release
76 # See https://github.com/rust-lang/rust/issues/45417
77 opt=
78 if [ "$TARGET" = "x86_64-unknown-linux-gnux32" ]; then
79 opt="--release"
80 fi
81
82 cargo test $opt --no-default-features --manifest-path libc-test/Cargo.toml --target $TARGET
83 exec cargo test $opt --manifest-path libc-test/Cargo.toml --target $TARGET