Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add caching to xwin installation #195

Merged
merged 2 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.xwin-cache/
.xwin-hash/
build/
megalinter-reports/
4 changes: 4 additions & 0 deletions test/CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
76 changes: 62 additions & 14 deletions test/testsuite.bats
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}