33bats_require_minimum_version 1.5.0
44
55setup_file () {
6- # Installing the Windows SDK/CRT takes a long time.
7- # When still valid, use the installation from cache.
8-
9- xwin --accept-license --manifest-version 16 --cache-dir ${BATS_TEST_DIRNAME} /.xwin-hash list
10- HASH_LIST_MANIFEST=$( sha256sum ${BATS_TEST_DIRNAME} /.xwin-hash/dl/manifest* .json | awk ' { print $1 }' )
11- HASH_CACHED_MANIFEST=
12-
13- if [[ -d ${BATS_TEST_DIRNAME} /.xwin-cache/dl ]]; then
14- HASH_CACHED_MANIFEST=$( sha256sum ${BATS_TEST_DIRNAME} /.xwin-cache/dl/manifest* .json | awk ' { print $1 }' )
15- fi
16-
17- if [[ $HASH_LIST_MANIFEST != $HASH_CACHED_MANIFEST ]]; then
18- xwin --accept-license --manifest-version 16 --cache-dir ${BATS_TEST_DIRNAME} /.xwin-cache splat --preserve-ms-arch-notation
19- fi
20-
21- ln -sf ${BATS_TEST_DIRNAME} /.xwin-cache/splat/ /winsdk
6+ install_win_sdk_when_ci_set
227}
238
249teardown_file () {
@@ -38,6 +23,55 @@ teardown() {
3823 popd
3924}
4025
26+ # # This section contains tests for version correctness and compatibility of the installed tools.
27+ # Comparing the versions of the installed tools with the expected versions and ensuring
28+ # that the tools are compatible with each other. E.g. that the host and embedded toolchains
29+ # are aligned in terms of major and minor versions.
30+
31+ # bats test_tags=Compatibility,Version,Clang
32+ @test " clang toolchain versions should be aligned with expected versions" {
33+ EXPECTED_VERSION=$( get_expected_semver_for clang)
34+
35+ for TOOL in clang clang++ clang-cl clang-format clang-tidy; do
36+ INSTALLED_VERSION=$( $TOOL --version | to_semver)
37+ assert_equal_print $EXPECTED_VERSION $INSTALLED_VERSION " Tool '${TOOL} ' version"
38+ done
39+ }
40+
41+ # bats test_tags=Compatibility,Version,GCC
42+ @test " host gcc toolchain versions and alternatives should be aligned with expected versions" {
43+ EXPECTED_VERSION=$( get_expected_semver_for g++)
44+
45+ for TOOL in cc gcc c++ g++ gcov; do
46+ INSTALLED_VERSION=$( $TOOL --version | to_semver)
47+ assert_equal_print $EXPECTED_VERSION $INSTALLED_VERSION " Tool '${TOOL} ' version"
48+ done
49+ }
50+
51+ # bats test_tags=Compatibility,Version,HostGCCArmGCC
52+ @test " host and embedded gcc toolchain versions should be the same major and minor version" {
53+ EXPECTED_MAJOR_MINOR_VERSION=$( get_expected_semver_for g++ | cut -d. -f1,2)
54+ INSTALLED_MAJOR_MINOR_VERSION=$( arm-none-eabi-gcc -dumpfullversion | cut -d. -f1,2)
55+ assert_equal_print $EXPECTED_MAJOR_MINOR_VERSION $INSTALLED_MAJOR_MINOR_VERSION " Host and ARM GCC major and minor version"
56+ }
57+
58+ # bats test_tags=Compatibility,Version,Tools
59+ @test " supporting tool versions should be aligned with expected versions" {
60+ for TOOL in gdb gdb-multiarch git ninja; do
61+ EXPECTED_VERSION=$( get_expected_semver_for ${TOOL} )
62+ INSTALLED_VERSION=$( ${TOOL} --version | to_semver)
63+
64+ assert_equal_print $EXPECTED_VERSION $INSTALLED_VERSION " Tool '${TOOL} ' version"
65+ done
66+
67+ for TOOL in cmake conan; do
68+ EXPECTED_VERSION=$( cat ${BATS_TEST_DIRNAME} /../../.devcontainer/cpp/requirements.in | grep ${TOOL} | to_semver)
69+ INSTALLED_VERSION=$( ${TOOL} --version | to_semver)
70+
71+ assert_equal_print $EXPECTED_VERSION $INSTALLED_VERSION " Tool '${TOOL} ' version"
72+ done
73+ }
74+
4175@test " valid code input should result in working executable using host compiler" {
4276 cmake --preset gcc
4377 cmake --build --preset gcc
@@ -57,6 +91,8 @@ teardown() {
5791}
5892
5993@test " valid code input should result in Windows executable using clang-cl compiler" {
94+ install_win_sdk_when_ci_unset
95+
6096 cmake --preset clang-cl
6197 cmake --build --preset clang-cl
6298}
@@ -79,6 +115,8 @@ teardown() {
79115}
80116
81117@test " using ccache as a compiler launcher should result in cached build using clang-cl compiler" {
118+ install_win_sdk_when_ci_unset
119+
82120 configure_and_build_with_ccache clang-cl
83121}
84122
@@ -134,14 +172,6 @@ teardown() {
134172 assert_output --partial " [info] Mutation score:"
135173}
136174
137- @test " host gdb should be able to start" {
138- gdb --version
139- }
140-
141- @test " gdb-multiarch should be able to start" {
142- gdb-multiarch --version
143- }
144-
145175@test " clangd should be able to analyze source files" {
146176 run clangd --check=gcc/main.cpp
147177 assert_success
@@ -229,3 +259,67 @@ function build_and_run_with_sanitizers() {
229259 assert_failure
230260 assert_output --partial " ThreadSanitizer: data race"
231261}
262+
263+ function to_semver() {
264+ grep -o ' [0-9]\+\.[0-9]\+\.[0-9]\+' | head -n1
265+ }
266+
267+ function get_expected_version_for() {
268+ local TOOL=${1:? }
269+
270+ jq -sr " .[0] * .[1] | to_entries[] | select(.key | startswith(\" ${TOOL} \" )) | .value | sub(\" -.*\" ; \"\" )" \
271+ ${BATS_TEST_DIRNAME} /../../.devcontainer/cpp/apt-requirements-base.json \
272+ ${BATS_TEST_DIRNAME} /../../.devcontainer/cpp/apt-requirements-clang.json
273+ }
274+
275+ function get_expected_semver_for() {
276+ local TOOL=${1:? }
277+
278+ get_expected_version_for ${TOOL} | to_semver
279+ }
280+
281+ function install_win_sdk() {
282+ # Installing the Windows SDK/CRT takes a long time.
283+ # When still valid, use the installation from cache.
284+
285+ xwin --accept-license --manifest-version 16 --cache-dir ${BATS_TEST_DIRNAME} /.xwin-hash list
286+ local HASH_LIST_MANIFEST=$( sha256sum ${BATS_TEST_DIRNAME} /.xwin-hash/dl/manifest* .json | awk ' { print $1 }' )
287+ local HASH_CACHED_MANIFEST=
288+
289+ if [[ -d ${BATS_TEST_DIRNAME} /.xwin-cache/dl ]]; then
290+ HASH_CACHED_MANIFEST=$( sha256sum ${BATS_TEST_DIRNAME} /.xwin-cache/dl/manifest* .json | awk ' { print $1 }' )
291+ fi
292+
293+ if [[ $HASH_LIST_MANIFEST != $HASH_CACHED_MANIFEST ]]; then
294+ xwin --accept-license --manifest-version 16 --cache-dir ${BATS_TEST_DIRNAME} /.xwin-cache splat --preserve-ms-arch-notation
295+ fi
296+
297+ ln -sf ${BATS_TEST_DIRNAME} /.xwin-cache/splat/ /winsdk
298+ }
299+
300+ function install_win_sdk_when_ci_unset() {
301+ # When running tests locally we typically run them one by one,
302+ # and want to install the Win SDK only for each test that requires it.
303+
304+ if [[ -z " ${CI} " ]]; then
305+ install_win_sdk
306+ fi
307+ }
308+
309+ function install_win_sdk_when_ci_set() {
310+ # When running on a CI environment we run all tests in a single batch,
311+ # and only want to install the Win SKD once.
312+
313+ if [[ -n " ${CI} " ]]; then
314+ install_win_sdk
315+ fi
316+ }
317+
318+ function assert_equal_print() {
319+ local EXPECTED=${1:? }
320+ local ACTUAL=${2:? }
321+ local MESSAGE=${3:- " Expecting values to be equal" }
322+
323+ echo " # ${MESSAGE} expected(${EXPECTED} ) actual(${ACTUAL} )" >&3
324+ assert_equal ${ACTUAL} ${EXPECTED}
325+ }
0 commit comments