From 3191811858b2d23d098262f6a75a242573444e4b Mon Sep 17 00:00:00 2001 From: Ron <45816308+rjaegers@users.noreply.github.com> Date: Wed, 8 Nov 2023 08:40:43 +0100 Subject: [PATCH] test: add caching to xwin installation (#195) --- .github/workflows/ci.yml | 8 +++++ .gitignore | 1 + test/CMakePresets.json | 4 +++ test/testsuite.bats | 76 ++++++++++++++++++++++++++++++++-------- 4 files changed, 75 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e83ca680..6431c057 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,10 +31,18 @@ jobs: tags: ${{ github.repository }}:test cache-from: type=gha cache-to: type=gha,mode=max + - uses: actions/cache/restore@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3.3.2 + with: + path: test/.xwin-cache + key: xwin-cache - name: Run Tests run: | set -Eeuo pipefail docker run --rm --mount type=bind,src="$(pwd)/test",dst=/ws -w /ws ${{ github.repository }}:test bats --formatter junit testsuite.bats | tee test-report.xml + - uses: actions/cache/save@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3.3.2 + with: + path: test/.xwin-cache + key: xwin-cache - uses: EnricoMi/publish-unit-test-result-action@ca89ad036b5fcd524c1017287fb01b5139908408 # v2.11.0 if: always() with: diff --git a/.gitignore b/.gitignore index 89beb1f2..4b42b9ff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .xwin-cache/ +.xwin-hash/ build/ megalinter-reports/ diff --git a/test/CMakePresets.json b/test/CMakePresets.json index 10b9c9bf..f038d058 100644 --- a/test/CMakePresets.json +++ b/test/CMakePresets.json @@ -23,6 +23,10 @@ "name": "clang-cl", "inherits": "defaults", "toolchainFile": "${sourceDir}/clang-cl/toolchain.cmake", + "environment": { + "CCACHE_DEPEND": "true", + "CCACHE_COMPILERTYPE": "clang-cl" + }, "cacheVariables": { "CMAKE_BUILD_TYPE": "Release" } diff --git a/test/testsuite.bats b/test/testsuite.bats index fcdb6016..6e6d67b1 100644 --- a/test/testsuite.bats +++ b/test/testsuite.bats @@ -1,12 +1,35 @@ #!/usr/bin/env bats +setup_file() { + # Installing the Windows SDK/CRT takes a long time. + # When still valid, use the installation from cache. + + xwin --accept-license --cache-dir .xwin-hash list + HASH_LIST_MANIFEST=$(sha256sum .xwin-hash/dl/manifest*.json | awk '{ print $1 }') + HASH_CACHED_MANIFEST= + + if [[ -d .xwin-cache/dl ]]; then + HASH_CACHED_MANIFEST=$(sha256sum .xwin-cache/dl/manifest*.json | awk '{ print $1 }') + fi + + if [[ $HASH_LIST_MANIFEST != $HASH_CACHED_MANIFEST ]]; then + xwin --accept-license splat --preserve-ms-arch-notation + fi + + cp -r .xwin-cache/splat/ /winsdk +} + +teardown_file() { + rm -rf .xwin-hash/ /winsdk +} + setup() { load '/usr/local/bats-support/load' load '/usr/local/bats-assert/load' } teardown() { - rm -rf build crash-* .xwin-cache + rm -rf build crash-* } # bats test_tags=tc:1 @@ -35,6 +58,15 @@ teardown() { assert_output --partial "Machine: ARM" } +# bats test_tags=tc:3 +@test "valid code input should result in working Windows executable using clang-cl compiler" { + run cmake --preset clang-cl + assert_success + + run cmake --build --preset clang-cl + assert_success +} + # bats test_tags=tc:4 @test "invalid code input should result in failing build" { run cmake --preset gcc @@ -45,7 +77,7 @@ teardown() { } # bats test_tags=tc:5 -@test "using ccache as a compiler launcher should result in cached build" { +@test "using ccache as a compiler launcher should result in cached build using gcc compiler" { run ccache --clear --zero-stats run cmake --preset gcc -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache @@ -72,6 +104,34 @@ teardown() { assert_output --partial "Misses: 0" } +# bats test_tags=tc:17 +@test "using ccache as a compiler launcher should result in cached build using clang-cl compiler" { + run ccache --clear --zero-stats + + run cmake --preset clang-cl -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache + assert_success + + run cmake --build --preset clang-cl + assert_success + + run ccache -s + assert_output --partial "Hits: 0" + assert_output --partial "Misses: 1" + + run rm -rf build + run ccache --zero-stats + + run cmake --preset clang-cl -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache + assert_success + + run cmake --build --preset clang-cl + assert_success + + run ccache -s + assert_output --partial "Hits: 1" + assert_output --partial "Misses: 0" +} + # bats test_tags=tc:6 @test "running clang-tidy as part of the build should result in warning diagnostics" { run cmake --preset clang @@ -175,15 +235,3 @@ teardown() { assert_success assert_output "Hello World!" } - -# bats test_tags=tc:16 -@test "using xwin to install Windows SDK/CRT should result in working environment" { - run xwin --accept-license splat --preserve-ms-arch-notation && mv .xwin-cache/splat/ /winsdk - assert_success - - run cmake --preset clang-cl - assert_success - - run cmake --build --preset clang-cl - assert_success -}