diff options
| author | David Lönnhager <david.l@mullvad.net> | 2024-04-29 13:47:02 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2024-04-29 13:47:02 +0200 |
| commit | 72be78c59d4ca9b2960ed69345300af16df81be8 (patch) | |
| tree | 1f8856aa84e0f9cf4c2aba81d772baaa7c9014bb | |
| parent | f173d8cc7039c71f0e5306ff88b019d69cf02b1f (diff) | |
| parent | d3bc638002e45b018ada611443da2055e4eec833 (diff) | |
| download | mullvadvpn-72be78c59d4ca9b2960ed69345300af16df81be8.tar.xz mullvadvpn-72be78c59d4ca9b2960ed69345300af16df81be8.zip | |
Merge branch 'test-share-registry'
| -rw-r--r-- | test/Dockerfile | 4 | ||||
| -rw-r--r-- | test/README.md | 19 | ||||
| -rwxr-xr-x | test/build-runner.sh | 38 | ||||
| -rwxr-xr-x | test/build.sh | 31 | ||||
| -rwxr-xr-x | test/ci-runtests.sh | 8 | ||||
| -rwxr-xr-x | test/container-run.sh | 32 |
6 files changed, 84 insertions, 48 deletions
diff --git a/test/Dockerfile b/test/Dockerfile index f2e28244ba..9e6fe20f80 100644 --- a/test/Dockerfile +++ b/test/Dockerfile @@ -1,5 +1,7 @@ ARG IMAGE=ghcr.io/mullvad/mullvadvpn-app-build:latest FROM $IMAGE +RUN rustup target add x86_64-pc-windows-gnu + RUN apt-get update && apt-get install -y \ - pkg-config libssl-dev libpcap-dev + mtools pkg-config libssl-dev libpcap-dev diff --git a/test/README.md b/test/README.md index c29cb51c94..7bbdbd901e 100644 --- a/test/README.md +++ b/test/README.md @@ -53,44 +53,41 @@ For running tests on Linux and Windows guests, you will need these tools and lib ```bash dnf install git gcc protobuf-devel libpcap-devel qemu \ - podman mingw64-gcc mingw64-winpthreads-static mtools \ - golang-github-rootless-containers-rootlesskit slirp4netns dnsmasq \ + podman golang-github-rootless-containers-rootlesskit slirp4netns dnsmasq \ dbus-devel pkgconf-pkg-config swtpm edk2-ovmf \ wireguard-tools - -rustup target add x86_64-pc-windows-gnu ``` # Building the test runner -Building the `test-runner` binary is done with the `build.sh` script. +Building the `test-runner` binary is done with the `build-runner.sh` script. Currently, only `x86_64` platforms are supported for Windows/Linux and `ARM64` (Apple Silicon) for macOS. -The `build.sh` requires the `$TARGET` environment variable to be set. +The `build-runner.sh` requires the `$TARGET` environment variable to be set. For example, building `test-runner` for Linux would look like this: ``` bash -TARGET=x86_64-unknown-linux-gnu ./build.sh +./container-run.sh ./build-runner.sh windows ``` ## Linux -For a Linux target `podman` is required to build the `test-runner`. See the [Linux section under Prerequisities](#Prerequisities) for more details. +Using `podman` is the recommended way to build the `test-runner`. See the [Linux section under Prerequisities](#Prerequisities) for more details. ``` bash -TARGET=x86_64-unknown-linux-gnu ./build.sh +./container-run.sh ./build-runner.sh linux ``` ## macOS ``` bash -TARGET=aarch64-apple-darwin ./build.sh +./build-runner.sh macos ``` ## Windows The `test-runner` binary for Windows may be cross-compiled from a Linux host. ``` bash -TARGET=x86_64-pc-windows-gnu ./build.sh +./container-run.sh ./build-runner.sh windows ``` # Building base images diff --git a/test/build-runner.sh b/test/build-runner.sh new file mode 100755 index 0000000000..ef25d001c3 --- /dev/null +++ b/test/build-runner.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +set -eu + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +REPO_DIR="$SCRIPT_DIR/.." +cd "$SCRIPT_DIR" + +source "$REPO_DIR/scripts/utils/log" + +case ${1-:""} in + linux) + TARGET=x86_64-unknown-linux-gnu + shift + ;; + windows) + TARGET=x86_64-pc-windows-gnu + shift + ;; + macos) + # TODO: x86 + TARGET=aarch64-apple-darwin + shift + ;; + *) + log_error "Invalid platform. Specify a valid platform as first argument" + exit 1 +esac + +cargo build \ + --bin test-runner \ + --bin connection-checker \ + --release --target "${TARGET}" + +# Only build runner image for Windows +if [[ $TARGET == x86_64-pc-windows-gnu ]]; then + TARGET="$TARGET" ./scripts/build-runner-image.sh +fi diff --git a/test/build.sh b/test/build.sh deleted file mode 100755 index d3a3c17470..0000000000 --- a/test/build.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash - -set -eu - -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -APP_DIR="$SCRIPT_DIR/.." -cd "$SCRIPT_DIR" - -if [[ $TARGET == x86_64-unknown-linux-gnu ]]; then - mkdir -p .container/cargo-registry - container_image=$(cat "$APP_DIR/building/linux-container-image.txt") - podman build -t mullvadvpn-app-tests --build-arg IMAGE="${container_image}" . - - podman run --rm -it \ - -v "${SCRIPT_DIR}/.container/cargo-registry":/root/.cargo/registry \ - -v "${APP_DIR}":/src:Z \ - -e CARGO_HOME=/root/.cargo/registry \ - -e CARGO_TARGET_DIR=/src/test/target \ - mullvadvpn-app-tests \ - /bin/bash -c "cd /src/test/; cargo build --bin test-runner --bin connection-checker --release --target ${TARGET}" -else - cargo build \ - --bin test-runner \ - --bin connection-checker \ - --release --target "${TARGET}" -fi - -# Only build runner image for Windows -if [[ $TARGET == x86_64-pc-windows-gnu ]]; then - ./scripts/build-runner-image.sh -fi diff --git a/test/ci-runtests.sh b/test/ci-runtests.sh index b4ea11246f..2ff5ef7304 100755 --- a/test/ci-runtests.sh +++ b/test/ci-runtests.sh @@ -220,15 +220,13 @@ echo "**********************************" find "$PACKAGES_DIR/" -type f ! \( -name "*${OLD_APP_VERSION}_*" -o -name "*${OLD_APP_VERSION}.*" -o -name "*${commit}*" \) -delete || true function build_test_runner { - local target="" if [[ "${TEST_OS}" =~ "debian"|"ubuntu"|"fedora" ]]; then - target="x86_64-unknown-linux-gnu" + ./container-run.sh ./build-runner.sh linux elif [[ "${TEST_OS}" =~ "windows" ]]; then - target="x86_64-pc-windows-gnu" + ./container-run.sh ./build-runner.sh windows elif [[ "${TEST_OS}" =~ "macos" ]]; then - target="aarch64-apple-darwin" + ./build-runner.sh macos fi - TARGET=$target ./build.sh } nice_time build_test_runner diff --git a/test/container-run.sh b/test/container-run.sh new file mode 100755 index 0000000000..58425b2a4d --- /dev/null +++ b/test/container-run.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +set -eu + +CARGO_REGISTRY_VOLUME_NAME=${CARGO_REGISTRY_VOLUME_NAME:-"cargo-registry"} +CONTAINER_RUNNER=${CONTAINER_RUNNER:-"podman"} +PACKAGES_DIR=${PACKAGES_DIR:-"$HOME/.cache/mullvad-test/packages"} + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +REPO_DIR="$SCRIPT_DIR/.." +cd "$SCRIPT_DIR" + +source "$REPO_DIR/scripts/utils/log" + +if [[ "$(uname -s)" != "Linux" ]]; then + log_error "$0 only works on Linux" + exit 1 +fi + +container_image=$(cat "$REPO_DIR/building/linux-container-image.txt") +podman build -t mullvadvpn-app-tests --build-arg IMAGE="${container_image}" . + +set -x +exec "$CONTAINER_RUNNER" run --rm -it \ + -v "${CARGO_REGISTRY_VOLUME_NAME}":/root/.cargo/registry:Z \ + -v "${REPO_DIR}":/build:z \ + -w "/build/test" \ + -e CARGO_TARGET_DIR=/build/test/target \ + -v "${PACKAGES_DIR}":/packages:Z \ + -e PACKAGES_DIR=/packages \ + mullvadvpn-app-tests \ + /bin/bash -c "$*" |
