]> git.proxmox.com Git - rustc.git/blob - src/vendor/libc/ci/run.sh
New upstream version 1.20.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.amazonaws.com/rust-lang-ci/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.amazonaws.com/rust-lang-ci/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 # 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 # Android emulator for x86_64 does not work on travis (missing hardware
109 # acceleration). Tests are run on case *). See ci/android-sysimage.sh for
110 # informations about how tests are run.
111 arm-linux-androideabi | aarch64-linux-android | i686-linux-android)
112 # set SHELL so android can detect a 64bits system, see
113 # http://stackoverflow.com/a/41789144
114 # https://issues.jenkins-ci.org/browse/JENKINS-26930?focusedCommentId=230791&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-230791
115 export SHELL=/bin/dash
116 arch=$(echo $TARGET | cut -d- -f1)
117 accel="-no-accel"
118 if emulator -accel-check; then
119 accel=""
120 fi
121 emulator @$arch -no-window $accel &
122 adb wait-for-device
123 adb push $CARGO_TARGET_DIR/$TARGET/debug/libc-test /data/local/tmp/libc-test
124 adb shell /data/local/tmp/libc-test 2>&1 | tee /tmp/out
125 grep "^PASSED .* tests" /tmp/out
126 ;;
127
128 i386-apple-ios)
129 rustc -O ./ci/ios/deploy_and_run_on_ios_simulator.rs
130 ./deploy_and_run_on_ios_simulator $CARGO_TARGET_DIR/$TARGET/debug/libc-test
131 ;;
132
133 x86_64-apple-ios)
134 rustc -O ./ci/ios/deploy_and_run_on_ios_simulator.rs
135 ./deploy_and_run_on_ios_simulator $CARGO_TARGET_DIR/$TARGET/debug/libc-test
136 ;;
137
138 arm-unknown-linux-gnueabihf)
139 qemu-arm -L /usr/arm-linux-gnueabihf $CARGO_TARGET_DIR/$TARGET/debug/libc-test
140 ;;
141
142 mips-unknown-linux-gnu)
143 qemu-mips -L /usr/mips-linux-gnu $CARGO_TARGET_DIR/$TARGET/debug/libc-test
144 ;;
145
146 mips64-unknown-linux-gnuabi64)
147 qemu-mips64 -L /usr/mips64-linux-gnuabi64 $CARGO_TARGET_DIR/$TARGET/debug/libc-test
148 ;;
149
150 mips-unknown-linux-musl)
151 qemu-mips -L /toolchain/staging_dir/toolchain-mips_34kc_gcc-5.3.0_musl-1.1.15 \
152 $CARGO_TARGET_DIR/$TARGET/debug/libc-test
153 ;;
154
155 mipsel-unknown-linux-musl)
156 qemu-mipsel -L /toolchain $CARGO_TARGET_DIR/$TARGET/debug/libc-test
157 ;;
158
159 powerpc-unknown-linux-gnu)
160 qemu-ppc -L /usr/powerpc-linux-gnu $CARGO_TARGET_DIR/$TARGET/debug/libc-test
161 ;;
162
163 powerpc64-unknown-linux-gnu)
164 qemu-ppc64 -L /usr/powerpc64-linux-gnu $CARGO_TARGET_DIR/$TARGET/debug/libc-test
165 ;;
166
167 aarch64-unknown-linux-gnu)
168 qemu-aarch64 -L /usr/aarch64-linux-gnu/ $CARGO_TARGET_DIR/$TARGET/debug/libc-test
169 ;;
170
171 s390x-unknown-linux-gnu)
172 # TODO: in theory we should execute this, but qemu segfaults immediately :(
173 # qemu-s390x -L /usr/s390x-linux-gnu/ $CARGO_TARGET_DIR/$TARGET/debug/libc-test
174 ;;
175
176 *-rumprun-netbsd)
177 rumprun-bake hw_virtio /tmp/libc-test.img $CARGO_TARGET_DIR/$TARGET/debug/libc-test
178 qemu-system-x86_64 -nographic -vga none -m 64 \
179 -kernel /tmp/libc-test.img 2>&1 | tee /tmp/out &
180 sleep 5
181 grep "^PASSED .* tests" /tmp/out
182 ;;
183
184 *)
185 $CARGO_TARGET_DIR/$TARGET/debug/libc-test
186 ;;
187 esac