diff --git a/.gitignore b/.gitignore index d5693c8450..afa204c2cc 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,6 @@ bin # Emacs *~ \#*\# + +# ARM tests +qemu-arm-static diff --git a/buildscripts/grpc-java-linux-arm64-tests/Dockerfile b/buildscripts/grpc-java-linux-arm64-tests/Dockerfile new file mode 100644 index 0000000000..47cbd18ebc --- /dev/null +++ b/buildscripts/grpc-java-linux-arm64-tests/Dockerfile @@ -0,0 +1,10 @@ +# This docker image uses magic to seamlessly run its contents using qemu ARM emulator on x86 host. +# See https://ownyourbits.com/2018/06/27/running-and-building-arm-docker-containers-in-x86/ + +# We want to test on arm64v8 +FROM arm64v8/debian:buster + +# Make the host's qemu-arm-static emulator available from inside the docker container. +COPY qemu-arm-static /usr/bin + +RUN apt-get update && apt-get install -y --no-install-recommends openjdk-11-jdk-headless && apt-get clean diff --git a/buildscripts/run_arm64_tests_in_docker.sh b/buildscripts/run_arm64_tests_in_docker.sh new file mode 100755 index 0000000000..f6f8c14cbb --- /dev/null +++ b/buildscripts/run_arm64_tests_in_docker.sh @@ -0,0 +1,26 @@ +#!/bin/bash +set -ex + +readonly grpc_java_dir="$(dirname "$(readlink -f "$0")")/.." + +# Build magic docker image that can run on x86 host, but looks like an ARM machine +# from the inside (qemu-user-static is used for emulation) +# Run "sudo apt install qemu-user-static binfmt-support" install the emulator +# on the host machine. +# Also see https://ownyourbits.com/2018/06/27/running-and-building-arm-docker-containers-in-x86/ +cp /usr/bin/qemu-arm-static "${grpc_java_dir}/buildscripts/grpc-java-linux-arm64-tests" +docker build -t grpc-java-linux-arm64-tests "${grpc_java_dir}/buildscripts/grpc-java-linux-arm64-tests" + +if [[ -t 0 ]]; then + DOCKER_ARGS="-it" +else + # The input device on kokoro is not a TTY, so -it does not work. + DOCKER_ARGS= +fi + +# - run docker container under current user's UID to avoid polluting the workspace +# - set the user.home property to avoid creating a "?" directory under grpc-java +exec docker run $DOCKER_ARGS --rm=true -v "${grpc_java_dir}":/grpc-java -w /grpc-java \ + --user "$(id -u):$(id -g)" -e "JAVA_OPTS=-Duser.home=/grpc-java/.current-user-home" \ + grpc-java-linux-arm64-tests \ + bash -c "./gradlew build -PskipAndroid=true -PskipCodegen=true"