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 if [ ! -f $tmpdir/$QEMU ]; then 20 curl https://people.mozilla.org/~acrichton/libc-test/qemu/$QEMU.gz | \ 21 gunzip -d > $tmpdir/$QEMU 22 fi 23 24 # Create a mount a fresh new filesystem image that we'll later pass to QEMU. 25 # This will have a `run.sh` script will which use the artifacts inside to run 26 # on the host. 27 rm -f $tmpdir/libc-test.img 28 dd if=/dev/null of=$tmpdir/libc-test.img bs=1M seek=50 29 mkfs.ext2 -F $tmpdir/libc-test.img 30 rm -rf $tmpdir/mount 31 mkdir $tmpdir/mount 32 mount -t ext2 -o loop $tmpdir/libc-test.img $tmpdir/mount 33 34 # If we have a cross compiler, then we just do the standard rigamarole of 35 # cross-compiling an executable and then the script to run just executes the 36 # binary. 37 # 38 # If we don't have a cross-compiler, however, then we need to do some crazy 39 # acrobatics to get this to work. Generate all.{c,rs} on the host which will 40 # be compiled inside QEMU. Do this here because compiling syntex_syntax in 41 # QEMU would time out basically everywhere. 42 if [ "$CAN_CROSS" = "1" ]; then 43 cargo build --manifest-path libc-test/Cargo.toml --target $TARGET 44 cp $CARGO_TARGET_DIR/$TARGET/debug/libc-test $tmpdir/mount/ 45 echo 'exec $1/libc-test' > $tmpdir/mount/run.sh 46 else 47 rm -rf $tmpdir/generated 48 mkdir -p $tmpdir/generated 49 cargo build --manifest-path libc-test/generate-files/Cargo.toml 50 (cd libc-test && TARGET=$TARGET OUT_DIR=$tmpdir/generated SKIP_COMPILE=1 \ 51 $CARGO_TARGET_DIR/debug/generate-files) 52 53 # Copy this folder into the mounted image, the `run.sh` entry point, and 54 # overwrite the standard libc-test Cargo.toml with the overlay one which will 55 # assume the all.{c,rs} test files have already been generated 56 mkdir $tmpdir/mount/libc 57 cp -r Cargo.* libc-test src ci $tmpdir/mount/libc/ 58 ln -s libc-test/target $tmpdir/mount/libc/target 59 cp ci/run-qemu.sh $tmpdir/mount/run.sh 60 echo $TARGET | tee -a $tmpdir/mount/TARGET 61 cp $tmpdir/generated/* $tmpdir/mount/libc/libc-test 62 cp libc-test/run-generated-Cargo.toml $tmpdir/mount/libc/libc-test/Cargo.toml 63 fi 64 65 umount $tmpdir/mount 66 67 # If we can use kvm, prefer that, otherwise just fall back to user-space 68 # emulation. 69 if kvm-ok; then 70 program=kvm 71 else 72 program=qemu-system-x86_64 73 fi 74 75 # Pass -snapshot to prevent tampering with the disk images, this helps when 76 # running this script in development. The two drives are then passed next, 77 # first is the OS and second is the one we just made. Next the network is 78 # configured to work (I'm not entirely sure how), and then finally we turn off 79 # graphics and redirect the serial console output to out.log. 80 $program \ 81 -m 1024 \ 82 -snapshot \ 83 -drive if=virtio,file=$tmpdir/$QEMU \ 84 -drive if=virtio,file=$tmpdir/libc-test.img \ 85 -net nic,model=virtio \ 86 -net user \ 87 -nographic \ 88 -vga none 2>&1 | tee $CARGO_TARGET_DIR/out.log 89 exec grep "^PASSED .* tests" $CARGO_TARGET_DIR/out.log 90fi 91 92case "$TARGET" in 93 *-apple-ios) 94 cargo rustc --manifest-path libc-test/Cargo.toml --target $TARGET -- \ 95 -C link-args=-mios-simulator-version-min=7.0 96 ;; 97 98 *) 99 cargo build --manifest-path libc-test/Cargo.toml --target $TARGET 100 ;; 101esac 102 103case "$TARGET" in 104 arm-linux-androideabi) 105 emulator @arm-21 -no-window & 106 adb wait-for-device 107 adb push $CARGO_TARGET_DIR/$TARGET/debug/libc-test /data/libc-test 108 adb shell /data/libc-test 2>&1 | tee /tmp/out 109 grep "^PASSED .* tests" /tmp/out 110 ;; 111 112 arm-unknown-linux-gnueabihf) 113 qemu-arm -L /usr/arm-linux-gnueabihf $CARGO_TARGET_DIR/$TARGET/debug/libc-test 114 ;; 115 116 mips-unknown-linux-gnu) 117 qemu-mips -L /usr/mips-linux-gnu $CARGO_TARGET_DIR/$TARGET/debug/libc-test 118 ;; 119 120 aarch64-unknown-linux-gnu) 121 qemu-aarch64 -L /usr/aarch64-linux-gnu/ $CARGO_TARGET_DIR/$TARGET/debug/libc-test 122 ;; 123 124 *-rumprun-netbsd) 125 rumprun-bake hw_virtio /tmp/libc-test.img $CARGO_TARGET_DIR/$TARGET/debug/libc-test 126 qemu-system-x86_64 -nographic -vga none -m 64 \ 127 -kernel /tmp/libc-test.img 2>&1 | tee /tmp/out & 128 sleep 5 129 grep "^PASSED .* tests" /tmp/out 130 ;; 131 132 *) 133 $CARGO_TARGET_DIR/$TARGET/debug/libc-test 134 ;; 135esac 136