qemu-s390x
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC] gitlab: introduce s390x wasmtime job


From: Ilya Leoshkevich
Subject: [RFC] gitlab: introduce s390x wasmtime job
Date: Tue, 5 Jul 2022 00:48:44 +0200

wasmtime is a WebAssembly runtime, which includes a large testsuite.
This testsuite uses qemu-user (aarch64 and s390x are supported) in
order to exercise foreign architectures. Over time it found several
regressions in qemu itself, and it would be beneficial to catch the
similar ones earlier.

To this end, this patch introduces a job that runs stable wasmtime
testsuite against qemu-s390x. The job is split into the following
components:

- A script for running the tests. Usable on developers' machines:

    qemu$ mkdir build
    qemu$ cd build
    qemu/build$ ../tests/wasmtime/test s390x

- A script for building the tests (build-toolchain.sh).

- A dockerfile describing an image with the prebuilt testsuite
  (debian-s390x-wasmtime-cross.docker).

- gitlab job definition for building the image.

- gitlab job definition for using the image to run the tests.

It's possible to use this with aarch64 as well, but it segfaults at
the moment, therefore this patch does not provide job definitions for
it. This needs to be investigated separately.

The example of a resulting pipeline can be seen at [1].

The test job runs for about 30 minutes mostly due to unnecessary
rebuilds. They will be gone once [2] is integrated and makes it to a
stable release.

This patch depends on madvise(MADV_DONTNEED) passthrough support [3].

[1] https://gitlab.com/iii-i/qemu/-/pipelines/579677396
[2] https://github.com/bytecodealliance/wasmtime/pull/4377
[3] https://lists.gnu.org/archive/html/qemu-devel/2022-07/msg00112.html

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 .gitlab-ci.d/container-cross.yml              | 10 +++
 .gitlab-ci.d/container-template.yml           |  2 +-
 .gitlab-ci.d/qemu-project.yml                 |  1 +
 .gitlab-ci.d/wasmtime-template.yml            |  6 ++
 .gitlab-ci.d/wasmtime.yml                     |  9 ++
 tests/docker/Makefile.include                 |  6 ++
 .../build-toolchain.sh                        | 83 +++++++++++++++++++
 .../debian-s390x-wasmtime-cross.docker        | 16 ++++
 tests/wasmtime/test                           | 39 +++++++++
 9 files changed, 171 insertions(+), 1 deletion(-)
 create mode 100644 .gitlab-ci.d/wasmtime-template.yml
 create mode 100644 .gitlab-ci.d/wasmtime.yml
 create mode 100755 
tests/docker/dockerfiles/debian-s390x-wasmtime-cross.d/build-toolchain.sh
 create mode 100644 tests/docker/dockerfiles/debian-s390x-wasmtime-cross.docker
 create mode 100755 tests/wasmtime/test

diff --git a/.gitlab-ci.d/container-cross.yml b/.gitlab-ci.d/container-cross.yml
index b7963498a3..b3c4b76a16 100644
--- a/.gitlab-ci.d/container-cross.yml
+++ b/.gitlab-ci.d/container-cross.yml
@@ -138,6 +138,16 @@ s390x-debian-cross-container:
   variables:
     NAME: debian-s390x-cross
 
+s390x-debian-wasmtime-cross-container:
+  extends: .container_job_template
+  stage: containers
+  needs: ['s390x-debian-cross-container']
+  variables:
+    NAME: debian-s390x-wasmtime-cross
+    DOCKER_SCRIPT_ARGS: >
+      --extra-files
+      tests/docker/dockerfiles/debian-s390x-wasmtime-cross.d/build-toolchain.sh
+
 sh4-debian-cross-container:
   extends: .container_job_template
   stage: containers-layer2
diff --git a/.gitlab-ci.d/container-template.yml 
b/.gitlab-ci.d/container-template.yml
index c434b9c8f3..8654f89a15 100644
--- a/.gitlab-ci.d/container-template.yml
+++ b/.gitlab-ci.d/container-template.yml
@@ -15,7 +15,7 @@
     - echo "COMMON_TAG:$COMMON_TAG"
     - ./tests/docker/docker.py --engine docker build
           -t "qemu/$NAME" -f "tests/docker/dockerfiles/$NAME.docker"
-          -r $CI_REGISTRY/qemu-project/qemu
+          -r $CI_REGISTRY/qemu-project/qemu $DOCKER_SCRIPT_ARGS
     - docker tag "qemu/$NAME" "$TAG"
     - docker push "$TAG"
   after_script:
diff --git a/.gitlab-ci.d/qemu-project.yml b/.gitlab-ci.d/qemu-project.yml
index 691d9bf5dc..712a27f7a0 100644
--- a/.gitlab-ci.d/qemu-project.yml
+++ b/.gitlab-ci.d/qemu-project.yml
@@ -13,3 +13,4 @@ include:
   - local: '/.gitlab-ci.d/custom-runners.yml'
   - local: '/.gitlab-ci.d/cirrus.yml'
   - local: '/.gitlab-ci.d/windows.yml'
+  - local: '/.gitlab-ci.d/wasmtime.yml'
diff --git a/.gitlab-ci.d/wasmtime-template.yml 
b/.gitlab-ci.d/wasmtime-template.yml
new file mode 100644
index 0000000000..cbf89c39eb
--- /dev/null
+++ b/.gitlab-ci.d/wasmtime-template.yml
@@ -0,0 +1,6 @@
+.wasmtime_job_template:
+  extends: .base_job_template
+  image: $CI_REGISTRY_IMAGE/qemu/$IMAGE:latest
+  stage: test
+  script:
+    - srcdir=$(pwd) && cd /build && "$srcdir"/tests/wasmtime/test "$ARCH"
diff --git a/.gitlab-ci.d/wasmtime.yml b/.gitlab-ci.d/wasmtime.yml
new file mode 100644
index 0000000000..2647f28bb1
--- /dev/null
+++ b/.gitlab-ci.d/wasmtime.yml
@@ -0,0 +1,9 @@
+include:
+  - local: '/.gitlab-ci.d/wasmtime-template.yml'
+
+wasmtime-s390x:
+  extends: .wasmtime_job_template
+  needs: ['s390x-debian-wasmtime-cross-container']
+  variables:
+    IMAGE: debian-s390x-wasmtime-cross
+    ARCH: s390x
diff --git a/tests/docker/Makefile.include b/tests/docker/Makefile.include
index ef4518d9eb..172ffc35c8 100644
--- a/tests/docker/Makefile.include
+++ b/tests/docker/Makefile.include
@@ -137,6 +137,12 @@ docker-image-debian-nios2-cross: 
$(DOCKER_FILES_DIR)/debian-toolchain.docker \
     $(DOCKER_FILES_DIR)/debian-nios2-cross.d/build-toolchain.sh
        $(call debian-toolchain, $@)
 
+docker-image-debian-s390x-wasmtime-cross: \
+    $(DOCKER_FILES_DIR)/debian-s390x-wasmtime-cross.docker \
+    $(DOCKER_FILES_DIR)/debian-s390x-wasmtime-cross.d/build-toolchain.sh
+       $(call debian-toolchain, $@)
+docker-image-debian-s390x-wasmtime-cross: docker-image-debian-s390x-cross
+
 # Specialist build images, sometimes very limited tools
 docker-image-debian-tricore-cross: docker-image-debian10
 docker-image-debian-all-test-cross: docker-image-debian10
diff --git 
a/tests/docker/dockerfiles/debian-s390x-wasmtime-cross.d/build-toolchain.sh 
b/tests/docker/dockerfiles/debian-s390x-wasmtime-cross.d/build-toolchain.sh
new file mode 100755
index 0000000000..a28d61a353
--- /dev/null
+++ b/tests/docker/dockerfiles/debian-s390x-wasmtime-cross.d/build-toolchain.sh
@@ -0,0 +1,83 @@
+#!/bin/sh
+
+# Build the stable wasmtime testsuite and run it with qemu-user from $PATH.
+# ".rustup", ".cargo" and "wasmtime" subdirectories will be created or updated
+# in the current directory.
+#
+# Based on 
https://github.com/bytecodealliance/wasmtime/blob/v0.37.0/.github/workflows/main.yml#L208.
+#
+# Usage:
+#
+#     ./test TARGET_ARCH [CARGO_ARGS ...]
+#
+# where TARGET_ARCH is the architecture to test (aarch64 or s390x) and
+# CARGO_ARGS are the extra arguments passed to cargo test.
+
+set -e -u -x
+
+# Dependency versions.
+export RUSTUP_TOOLCHAIN=1.62.0
+
+# Bump when https://github.com/bytecodealliance/wasmtime/pull/4377 is
+# integrated. Until this moment there will be some unnecessary rebuilds.
+wasmtime_version=0.37.0
+
+# Script arguments.
+arch=$1
+shift
+arch_upper=$(echo "$arch" | tr '[:lower:]' '[:upper:]')
+
+# Install/update Rust.
+export RUSTUP_HOME="$PWD/.rustup"
+export CARGO_HOME="$PWD/.cargo"
+curl \
+    --proto '=https' \
+    --tlsv1.2 \
+    -sSf \
+    https://sh.rustup.rs \
+    | sh -s -- -y \
+        --default-toolchain="$RUSTUP_TOOLCHAIN" \
+        --target=wasm32-wasi \
+        --target=wasm32-unknown-unknown \
+        --target="$arch"-unknown-linux-gnu
+cat >"$CARGO_HOME/config" <<HERE
+[build]
+# Save space by not generating data to speed-up delta builds.
+incremental = false
+
+[profile.test]
+# Save space by not generating debug information.
+debug = 0
+
+[net]
+# Speed up crates.io index update.
+git-fetch-with-cli = true
+HERE
+. "$PWD/.cargo/env"
+
+# Checkout/update wasmtime.
+if [ -d wasmtime ]; then
+    cd wasmtime
+    git fetch --force --tags
+    git checkout v"$wasmtime_version"
+    git submodule update --init --recursive
+else
+    git clone \
+        --depth=1 \
+        --recurse-submodules \
+        --shallow-submodules \
+        -b v"$wasmtime_version" \
+        https://github.com/bytecodealliance/wasmtime.git
+    cd wasmtime
+fi
+
+# Run wasmtime tests.
+export CARGO_BUILD_TARGET="$arch-unknown-linux-gnu"
+runner_var=CARGO_TARGET_${arch_upper}_UNKNOWN_LINUX_GNU_RUNNER
+linker_var=CARGO_TARGET_${arch_upper}_UNKNOWN_LINUX_GNU_LINKER
+eval "export $runner_var=\"qemu-$arch -L /usr/$arch-linux-gnu\""
+eval "export $linker_var=$arch-linux-gnu-gcc"
+export CARGO_PROFILE_DEV_OPT_LEVEL=2
+export WASMTIME_TEST_NO_HOG_MEMORY=1
+export RUST_BACKTRACE=1
+ci/run-tests.sh --locked "$@"
diff --git a/tests/docker/dockerfiles/debian-s390x-wasmtime-cross.docker 
b/tests/docker/dockerfiles/debian-s390x-wasmtime-cross.docker
new file mode 100644
index 0000000000..d08a66dcc2
--- /dev/null
+++ b/tests/docker/dockerfiles/debian-s390x-wasmtime-cross.docker
@@ -0,0 +1,16 @@
+# Image containing pre-built wasmtime tests for s390x.
+
+FROM registry.gitlab.com/qemu-project/qemu/qemu/debian-s390x-cross:latest
+
+RUN export DEBIAN_FRONTEND=noninteractive && \
+    eatmydata apt-get update && \
+    eatmydata apt-get dist-upgrade -y && \
+    eatmydata apt-get install --no-install-recommends -y \
+            curl \
+            libglib2.0-dev && \
+    eatmydata apt-get autoremove -y && \
+    eatmydata apt-get autoclean -y
+
+RUN mkdir /build
+ADD build-toolchain.sh /build
+RUN cd /build && ./build-toolchain.sh s390x --no-run
diff --git a/tests/wasmtime/test b/tests/wasmtime/test
new file mode 100755
index 0000000000..10e2c3f886
--- /dev/null
+++ b/tests/wasmtime/test
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+# Build qemu-user in the current directory, build the stable wasmtime
+# testsuite, and test them together. ".rustup", ".cargo" and "wasmtime"
+# subdirectories, as well as qemu build files, will be created or updated in
+# the current directory.
+#
+# Based on 
https://github.com/bytecodealliance/wasmtime/blob/v0.37.0/.github/workflows/main.yml#L208.
+#
+# Usage:
+#
+#     ./test TARGET_ARCH [CARGO_ARGS ...]
+#
+# where TARGET_ARCH is the architecture to test (aarch64 or s390x) and
+# CARGO_ARGS are the extra arguments passed to cargo test.
+
+set -e -u -x
+
+# Script arguments.
+arch=$1
+shift
+
+# Build QEMU.
+srcdir=$(cd "$(dirname "$0")" && pwd)/../..
+docker_files_dir="$srcdir"/tests/docker/dockerfiles
+"$srcdir"/configure \
+    --target-list="$arch"-linux-user \
+    --disable-tools \
+    --disable-slirp \
+    --disable-fdt \
+    --disable-capstone \
+    --disable-docs
+make --output-sync -j"$(nproc)"
+export PATH="$PWD:$PATH"
+
+# Run wasmtime tests.
+exec \
+    "$docker_files_dir"/debian-s390x-wasmtime-cross.d/build-toolchain.sh \
+    "$arch" "$@"
-- 
2.35.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]