From 11c51c62d4cc91258b01a1d64bdb4702f55b28e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Sat, 19 Apr 2025 11:50:14 +0300 Subject: [PATCH] run-tests: Rewrite detection of what tests we can try to execute Autodetect whether we can run tests in Wine on unix. --- .github/workflows/build.yml | 8 ++--- Dockerfile.system-clang | 2 +- run-tests.sh | 71 +++++++++++++++++++++++++++++++------ 3 files changed, 66 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dd4cd87..1b69944 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -86,7 +86,7 @@ jobs: LLVM_CMAKEFLAGS="-DLLVM_ENABLE_LIBXML2=OFF -DLLDB_ENABLE_PYTHON=OFF" ./build-all.sh $(pwd)/install/llvm-mingw .github/workflows/store-version.sh install/llvm-mingw/versions.txt ./test-libcxx-module.sh $(pwd)/install/llvm-mingw - RUN_I686=false RUN_X86_64=false ./run-tests.sh $(pwd)/install/llvm-mingw + ./run-tests.sh $(pwd)/install/llvm-mingw cd install DISTRO=ubuntu-$(grep DISTRIB_RELEASE /etc/lsb-release | cut -f 2 -d =)-$(uname -m) NAME=llvm-mingw-$TAG-ucrt-$DISTRO @@ -131,7 +131,7 @@ jobs: run: | sudo apt-get update && sudo apt-get install qemu-user-static libc6-arm64-cross libstdc++6-arm64-cross QEMU_LD_PREFIX=/usr/aarch64-linux-gnu ./test-libcxx-module.sh $(pwd)/install/llvm-mingw - QEMU_LD_PREFIX=/usr/aarch64-linux-gnu RUN_I686=false RUN_X86_64=false ./run-tests.sh $(pwd)/install/llvm-mingw + QEMU_LD_PREFIX=/usr/aarch64-linux-gnu ./run-tests.sh $(pwd)/install/llvm-mingw - name: Package the toolchain env: TAG: ${{needs.prepare.outputs.TAG}} @@ -175,7 +175,7 @@ jobs: # llvm-mingw). LLVM_CMAKEFLAGS="-DLLVM_ENABLE_LIBXML2=OFF" ./build-all.sh $(pwd)/install/llvm-mingw --disable-clang-tools-extra --disable-lldb --enable-asserts .github/workflows/store-version.sh install/llvm-mingw/versions.txt - RUN_I686=false RUN_X86_64=false ./run-tests.sh $(pwd)/install/llvm-mingw + ./run-tests.sh $(pwd)/install/llvm-mingw cd install tar -Jcf ../llvm-mingw-linux.tar.xz --format=ustar --numeric-owner --owner=0 --group=0 --sort=name --mtime="$BUILD_DATE" llvm-mingw - uses: actions/upload-artifact@v4 @@ -209,7 +209,7 @@ jobs: MACOS_REDIST=1 LLVM_CMAKEFLAGS="-DLLVM_ENABLE_ZSTD=OFF -DLLDB_ENABLE_PYTHON=OFF" ./build-all.sh $(pwd)/install/llvm-mingw .github/workflows/store-version.sh install/llvm-mingw/versions.txt ./test-libcxx-module.sh $(pwd)/install/llvm-mingw - RUN_I686=false RUN_X86_64=false ./run-tests.sh $(pwd)/install/llvm-mingw + ./run-tests.sh $(pwd)/install/llvm-mingw cd install NAME=llvm-mingw-$TAG-ucrt-macos-universal mv llvm-mingw $NAME diff --git a/Dockerfile.system-clang b/Dockerfile.system-clang index 8125441..98f3abb 100644 --- a/Dockerfile.system-clang +++ b/Dockerfile.system-clang @@ -38,4 +38,4 @@ ENV PATH=$TOOLCHAIN_PREFIX/bin:$PATH # Test the installation COPY test/*.c test/*.cpp test/*.h test/*.idl test/*.rc test/Makefile ./test/ COPY run-tests.sh ./ -RUN RUN_I686=false RUN_X86_64=false ./run-tests.sh $TOOLCHAIN_PREFIX +RUN ./run-tests.sh $TOOLCHAIN_PREFIX diff --git a/run-tests.sh b/run-tests.sh index cf08571..eb53efa 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -76,21 +76,72 @@ fi : ${TARGET_OSES:=${TOOLCHAIN_TARGET_OSES-$DEFAULT_OSES}} -if [ -z "$RUN_X86_64" ] && [ -z "$RUN_I686" ]; then +# This script can be run in a number of configurations: +# - On Linux, where one possibly can run tests on the local machine with wine +# (if available), and possibly also remotely running tests on a different +# machine with suitable COPY_*/RUN_* variables (wrapping scp/ssh). +# - In WSL, running a native Windows toolchain. (We don't detect this case +# automatically, but require the caller to set the suitable RUN_ variables.) +# - In an msys2 shell. + +if [ -z "$RUN_X86_64" ] && [ -z "$RUN_I686" ] && [ -z "$RUN_ARMV7" ] && [ -z "$RUN_AARCH64" ]; then case $(uname) in MINGW*|MSYS*) - NATIVE_X86=1 - RUN_X86_64=true - RUN_I686=true - ;; - *) - case $(uname -m) in - x86_64) - : ${RUN_X86_64:=wine} - : ${RUN_I686:=wine} + # On Windows/arm64, we may be running x86_64 msys2 emulated, so we + # can't rely on "uname -m" here. Inspect the default target architecture + # of the native toolchain instead; we can be sure that we can execute + # the kind of binary that the toolchain consists of. + case $(clang -dumpmachine | sed 's/-.*//') in + i686|x86_64) + # For i686, we could in theory be running on an i686-only machine, + # but let's assume that we can execute x86_64 binaries too + # (for wider test coverage). + NATIVE_X86=1 + RUN_X86_64=true + RUN_I686=true + ;; + armv7) + # This is most probably running on aarch64 so those probably + # could be executed too, but let's skip that for now. + NATIVE_ARMV7=1 + RUN_ARMV7=true + ;; + aarch64) + # Windows/ARM64 can run i686 binaries (and also x86_64 since + # Windows 11). Not setting NATIVE_X86 - the asan tests don't run + # correctly when emulated on ARM64. + # Since Windows 11 24H2 (10.0.26100) armv7 binaries can no longer + # be executed, so out of future precaution, don't automatically + # try to execute them. + NATIVE_AARCH64=1 + RUN_I686=true + RUN_X86_64=true + RUN_AARCH64=true ;; esac ;; + Linux) + if command -v wine >/dev/null; then + # On Linux, use Wine if available. (On macOS, it's less clear + # what Wine can execute; it's most likely an x86_64 version + # emulated with Rosetta. Thus don't automatically use Wine on + # macOS.) + case $(uname -m) in + x86_64) + # Assume that Wine, if installed, supports both 32 and 64 bit + # binaries. + : ${RUN_X86_64:=wine} + : ${RUN_I686:=wine} + ;; + aarch64) + # Don't assume that the installed Wine can run armv7 binaries + # too. (Versions since Wine 10.2 can, if both an armv7 and + # aarch64 version is installed together.) + : ${RUN_AARCH64:=wine} + ;; + esac + fi + ;; esac fi