xref: /rust-libc-0.2.174/ci/run.sh (revision b46b6e2e)
1#!/usr/bin/env 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 --retry 5 "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 --retry 5 "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 --retry 5 "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  # shellcheck disable=SC2016
58  echo 'exec $1/libc-test' > "${tmpdir}/mount/run.sh"
59
60  du -sh "${tmpdir}/mount"
61  genext2fs \
62      --root "${tmpdir}/mount" \
63      --size-in-blocks 100000 \
64      "${tmpdir}/libc-test.img"
65
66  # Pass -snapshot to prevent tampering with the disk images, this helps when
67  # running this script in development. The two drives are then passed next,
68  # first is the OS and second is the one we just made. Next the network is
69  # configured to work (I'm not entirely sure how), and then finally we turn off
70  # graphics and redirect the serial console output to out.log.
71  qemu-system-x86_64 \
72    -m 1024 \
73    -snapshot \
74    -drive if=virtio,file="${tmpdir}/${qemufile}" \
75    -drive if=virtio,file="${tmpdir}/libc-test.img" \
76    -net nic,model=virtio \
77    -net user \
78    -nographic \
79    -vga none 2>&1 | tee "${CARGO_TARGET_DIR}/out.log"
80  exec grep "^PASSED .* tests" "${CARGO_TARGET_DIR}/out.log"
81fi
82
83# FIXME: x86_64-unknown-linux-gnux32 fail to compile without --release
84# See https://github.com/rust-lang/rust/issues/45417
85opt=
86if [ "$TARGET" = "x86_64-unknown-linux-gnux32" ]; then
87  opt="--release"
88fi
89
90# Building with --no-default-features is currently broken on rumprun because we
91# need cfg(target_vendor), which is currently unstable.
92if [ "$TARGET" != "x86_64-rumprun-netbsd" ]; then
93  cargo test $opt --no-default-features --manifest-path libc-test/Cargo.toml --target "${TARGET}"
94fi
95# Test the #[repr(align(x))] feature if this is building on Rust >= 1.25
96if [ "$(rustc --version | sed -E 's/^rustc 1\.([0-9]*)\..*/\1/')" -ge 25 ]; then
97  cargo test $opt --features align --manifest-path libc-test/Cargo.toml --target "${TARGET}"
98fi
99exec cargo test $opt --manifest-path libc-test/Cargo.toml --target "${TARGET}"
100