]> git.proxmox.com Git - rustc.git/blob - src/liblibc/ci/run.sh
New upstream version 1.14.0+dfsg1
[rustc.git] / src / liblibc / 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://people.mozilla.org/~acrichton/libc-test/qemu/$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://people.mozilla.org/~acrichton/libc-test/qemu/$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 # If we have a cross compiler, then we just do the standard rigamarole of
43 # cross-compiling an executable and then the script to run just executes the
44 # binary.
45 #
46 # If we don't have a cross-compiler, however, then we need to do some crazy
47 # acrobatics to get this to work. Generate all.{c,rs} on the host which will
48 # be compiled inside QEMU. Do this here because compiling syntex_syntax in
49 # QEMU would time out basically everywhere.
50 if [ "$CAN_CROSS" = "1" ]; then
51 cargo build --manifest-path libc-test/Cargo.toml --target $TARGET
52 cp $CARGO_TARGET_DIR/$TARGET/debug/libc-test $tmpdir/mount/
53 echo 'exec $1/libc-test' > $tmpdir/mount/run.sh
54 else
55 rm -rf $tmpdir/generated
56 mkdir -p $tmpdir/generated
57 cargo build --manifest-path libc-test/generate-files/Cargo.toml
58 (cd libc-test && TARGET=$TARGET OUT_DIR=$tmpdir/generated SKIP_COMPILE=1 \
59 $CARGO_TARGET_DIR/debug/generate-files)
60
61 # Copy this folder into the mounted image, the `run.sh` entry point, and
62 # overwrite the standard libc-test Cargo.toml with the overlay one which will
63 # assume the all.{c,rs} test files have already been generated
64 mkdir $tmpdir/mount/libc
65 cp -r Cargo.* libc-test src ci $tmpdir/mount/libc/
66 ln -s libc-test/target $tmpdir/mount/libc/target
67 cp ci/run-qemu.sh $tmpdir/mount/run.sh
68 echo $TARGET | tee -a $tmpdir/mount/TARGET
69 cp $tmpdir/generated/* $tmpdir/mount/libc/libc-test
70 cp libc-test/run-generated-Cargo.toml $tmpdir/mount/libc/libc-test/Cargo.toml
71 fi
72
73 du -sh $tmpdir/mount
74 genext2fs \
75 --root $tmpdir/mount \
76 --size-in-blocks 100000 \
77 $tmpdir/libc-test.img
78
79 # Pass -snapshot to prevent tampering with the disk images, this helps when
80 # running this script in development. The two drives are then passed next,
81 # first is the OS and second is the one we just made. Next the network is
82 # configured to work (I'm not entirely sure how), and then finally we turn off
83 # graphics and redirect the serial console output to out.log.
84 qemu-system-x86_64 \
85 -m 1024 \
86 -snapshot \
87 -drive if=virtio,file=$tmpdir/$qemufile \
88 -drive if=virtio,file=$tmpdir/libc-test.img \
89 -net nic,model=virtio \
90 -net user \
91 -nographic \
92 -vga none 2>&1 | tee $CARGO_TARGET_DIR/out.log
93 exec grep "^PASSED .* tests" $CARGO_TARGET_DIR/out.log
94 fi
95
96 case "$TARGET" in
97 *-apple-ios)
98 cargo rustc --manifest-path libc-test/Cargo.toml --target $TARGET -- \
99 -C link-args=-mios-simulator-version-min=7.0
100 ;;
101
102 *)
103 cargo build --manifest-path libc-test/Cargo.toml --target $TARGET
104 ;;
105 esac
106
107 case "$TARGET" in
108 arm-linux-androideabi)
109 emulator @arm-21 -no-window &
110 adb wait-for-device
111 adb push $CARGO_TARGET_DIR/$TARGET/debug/libc-test /data/libc-test
112 adb shell /data/libc-test 2>&1 | tee /tmp/out
113 grep "^PASSED .* tests" /tmp/out
114 ;;
115
116 arm-unknown-linux-gnueabihf)
117 qemu-arm -L /usr/arm-linux-gnueabihf $CARGO_TARGET_DIR/$TARGET/debug/libc-test
118 ;;
119
120 mips-unknown-linux-gnu)
121 qemu-mips -L /usr/mips-linux-gnu $CARGO_TARGET_DIR/$TARGET/debug/libc-test
122 ;;
123
124 mips64-unknown-linux-gnuabi64)
125 qemu-mips64 -L /usr/mips64-linux-gnuabi64 $CARGO_TARGET_DIR/$TARGET/debug/libc-test
126 ;;
127
128 mips-unknown-linux-musl)
129 qemu-mips -L /toolchain/staging_dir/toolchain-mips_34kc_gcc-5.3.0_musl-1.1.15 \
130 $CARGO_TARGET_DIR/$TARGET/debug/libc-test
131 ;;
132
133 mipsel-unknown-linux-musl)
134 qemu-mipsel -L /toolchain $CARGO_TARGET_DIR/$TARGET/debug/libc-test
135 ;;
136
137 powerpc-unknown-linux-gnu)
138 qemu-ppc -L /usr/powerpc-linux-gnu $CARGO_TARGET_DIR/$TARGET/debug/libc-test
139 ;;
140
141 powerpc64-unknown-linux-gnu)
142 qemu-ppc64 -L /usr/powerpc64-linux-gnu $CARGO_TARGET_DIR/$TARGET/debug/libc-test
143 ;;
144
145 aarch64-unknown-linux-gnu)
146 qemu-aarch64 -L /usr/aarch64-linux-gnu/ $CARGO_TARGET_DIR/$TARGET/debug/libc-test
147 ;;
148
149 *-rumprun-netbsd)
150 rumprun-bake hw_virtio /tmp/libc-test.img $CARGO_TARGET_DIR/$TARGET/debug/libc-test
151 qemu-system-x86_64 -nographic -vga none -m 64 \
152 -kernel /tmp/libc-test.img 2>&1 | tee /tmp/out &
153 sleep 5
154 grep "^PASSED .* tests" /tmp/out
155 ;;
156
157 *)
158 $CARGO_TARGET_DIR/$TARGET/debug/libc-test
159 ;;
160 esac