From ee7b15d1f9507eadd4463492a30eb4dbefec380c Mon Sep 17 00:00:00 2001 From: Ben Ashbaugh Date: Fri, 25 Oct 2024 15:12:38 -0700 Subject: [PATCH 1/5] add basic utility code testing for cpp, cpp11, and c --- tests/CMakeLists.txt | 19 +++++++++++++------ tests/example.c | 33 +++++++++++++++++++++++++++++++++ tests/example11.cpp | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 tests/example.c create mode 100644 tests/example11.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ebf7e1244..01def6fce 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -25,14 +25,21 @@ # MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. add_library(spirv_headers_simple_test STATIC) +target_sources(spirv_headers_simple_test PRIVATE example.cpp) +target_compile_definitions(spirv_headers_simple_test PRIVATE SPV_ENABLE_UTILITY_CODE) +target_link_libraries(spirv_headers_simple_test PRIVATE SPIRV-Headers::SPIRV-Headers) -target_sources(spirv_headers_simple_test PRIVATE - example.cpp -) +add_library(spirv_headers_simple_test_cpp11 STATIC) +target_sources(spirv_headers_simple_test_cpp11 PRIVATE example11.cpp) +#target_compile_definitions(spirv_headers_simple_test_cpp11 PRIVATE SPV_ENABLE_UTILITY_CODE) +target_link_libraries(spirv_headers_simple_test_cpp11 PRIVATE SPIRV-Headers::SPIRV-Headers) +set_target_properties(spirv_headers_simple_test_cpp11 PROPERTIES CXX_STANDARD 11) -target_link_libraries(spirv_headers_simple_test PRIVATE - SPIRV-Headers::SPIRV-Headers -) +add_library(spirv_headers_simple_test_c STATIC) +target_sources(spirv_headers_simple_test_c PRIVATE example.c) +target_compile_definitions(spirv_headers_simple_test_c PRIVATE SPV_ENABLE_UTILITY_CODE) +target_link_libraries(spirv_headers_simple_test_c PRIVATE SPIRV-Headers::SPIRV-Headers) +set_target_properties(spirv_headers_simple_test_c PROPERTIES C_STANDARD 99 LINKER_LANGUAGE CXX) if (NOT TARGET SPIRV-Headers) message(FATAL_ERROR "SPIRV-Headers target not defined!") diff --git a/tests/example.c b/tests/example.c new file mode 100644 index 000000000..2deb2c868 --- /dev/null +++ b/tests/example.c @@ -0,0 +1,33 @@ +// Copyright (c) 2016-2024 The Khronos Group Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and/or associated documentation files (the +// "Materials"), to deal in the Materials without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Materials, and to +// permit persons to whom the Materials are furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Materials. +// +// MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS +// KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS +// SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT +// https://www.khronos.org/registry/ +// +// THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +// MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + +#include +#include +#include + +const GLSLstd450 kSin = GLSLstd450Sin; +const OpenCLstd_Entrypoints kNative_cos = OpenCLstd_Native_cos; +const SpvOp kNop = SpvOpNop; diff --git a/tests/example11.cpp b/tests/example11.cpp new file mode 100644 index 000000000..50d8de88d --- /dev/null +++ b/tests/example11.cpp @@ -0,0 +1,37 @@ +// Copyright (c) 2016-2024 The Khronos Group Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and/or associated documentation files (the +// "Materials"), to deal in the Materials without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Materials, and to +// permit persons to whom the Materials are furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Materials. +// +// MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS +// KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS +// SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT +// https://www.khronos.org/registry/ +// +// THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +// MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. + +#include +#include +#include + +namespace { + +const GLSLstd450 kSin = GLSLstd450Sin; +const OpenCLLIB::Entrypoints kNative_cos = OpenCLLIB::Native_cos; +const spv::Op kNop = spv::Op::OpNop; + +} // anonymous namespace From 9118c9386e36017d15c3f09c85f1b92f88ae2db1 Mon Sep 17 00:00:00 2001 From: Ben Ashbaugh Date: Fri, 25 Oct 2024 15:34:22 -0700 Subject: [PATCH 2/5] switch from building libraries to building executables for tests --- CMakeLists.txt | 2 +- tests/CMakeLists.txt | 14 +++++++------- tests/example.c | 8 ++++++-- tests/example.cpp | 4 ++++ tests/example11.cpp | 4 ++++ 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b018b23fa..957b92243 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. cmake_minimum_required(VERSION 3.14) -project(SPIRV-Headers LANGUAGES CXX VERSION 1.5.5) +project(SPIRV-Headers LANGUAGES C CXX VERSION 1.5.5) if (CMAKE_VERSION VERSION_LESS "3.21") # https://cmake.org/cmake/help/latest/variable/PROJECT_IS_TOP_LEVEL.html diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 01def6fce..14e6f756b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -24,22 +24,22 @@ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. -add_library(spirv_headers_simple_test STATIC) -target_sources(spirv_headers_simple_test PRIVATE example.cpp) +add_executable(spirv_headers_simple_test example.cpp) target_compile_definitions(spirv_headers_simple_test PRIVATE SPV_ENABLE_UTILITY_CODE) target_link_libraries(spirv_headers_simple_test PRIVATE SPIRV-Headers::SPIRV-Headers) +add_test(NAME spirv_headers_simple_test COMMAND spirv_headers_simple_test) -add_library(spirv_headers_simple_test_cpp11 STATIC) -target_sources(spirv_headers_simple_test_cpp11 PRIVATE example11.cpp) +add_executable(spirv_headers_simple_test_cpp11 example11.cpp) #target_compile_definitions(spirv_headers_simple_test_cpp11 PRIVATE SPV_ENABLE_UTILITY_CODE) target_link_libraries(spirv_headers_simple_test_cpp11 PRIVATE SPIRV-Headers::SPIRV-Headers) set_target_properties(spirv_headers_simple_test_cpp11 PROPERTIES CXX_STANDARD 11) +add_test(NAME spirv_headers_simple_test_cpp11 COMMAND spirv_headers_simple_test_cpp11) -add_library(spirv_headers_simple_test_c STATIC) -target_sources(spirv_headers_simple_test_c PRIVATE example.c) +add_executable(spirv_headers_simple_test_c example.c) target_compile_definitions(spirv_headers_simple_test_c PRIVATE SPV_ENABLE_UTILITY_CODE) target_link_libraries(spirv_headers_simple_test_c PRIVATE SPIRV-Headers::SPIRV-Headers) -set_target_properties(spirv_headers_simple_test_c PROPERTIES C_STANDARD 99 LINKER_LANGUAGE CXX) +set_target_properties(spirv_headers_simple_test_c PROPERTIES C_STANDARD 99 LINKER_LANGUAGE C) +add_test(NAME spirv_headers_simple_test_c COMMAND spirv_headers_simple_test_c) if (NOT TARGET SPIRV-Headers) message(FATAL_ERROR "SPIRV-Headers target not defined!") diff --git a/tests/example.c b/tests/example.c index 2deb2c868..9b5045e76 100644 --- a/tests/example.c +++ b/tests/example.c @@ -28,6 +28,10 @@ #include #include -const GLSLstd450 kSin = GLSLstd450Sin; -const OpenCLstd_Entrypoints kNative_cos = OpenCLstd_Native_cos; +const enum GLSLstd450 kSin = GLSLstd450Sin; +const enum OpenCLstd_Entrypoints kNative_cos = OpenCLstd_Native_cos; const SpvOp kNop = SpvOpNop; + +int main() { + return 0; +} diff --git a/tests/example.cpp b/tests/example.cpp index 1920e8038..11274f47e 100644 --- a/tests/example.cpp +++ b/tests/example.cpp @@ -35,3 +35,7 @@ const OpenCLLIB::Entrypoints kNative_cos = OpenCLLIB::Native_cos; const spv::Op kNop = spv::OpNop; } // anonymous namespace + +int main() { + return 0; +} diff --git a/tests/example11.cpp b/tests/example11.cpp index 50d8de88d..9adc5b813 100644 --- a/tests/example11.cpp +++ b/tests/example11.cpp @@ -35,3 +35,7 @@ const OpenCLLIB::Entrypoints kNative_cos = OpenCLLIB::Native_cos; const spv::Op kNop = spv::Op::OpNop; } // anonymous namespace + +int main() { + return 0; +} From 5f0ed1319c727f65bfadc59ced8d08ebdfcc0a53 Mon Sep 17 00:00:00 2001 From: Ben Ashbaugh Date: Fri, 25 Oct 2024 15:42:13 -0700 Subject: [PATCH 3/5] try adding a specific GitHub action to build with tests --- .github/workflows/presubmit.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index d7958ca75..5caeaeb70 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -39,6 +39,17 @@ jobs: - name: Check generated headers run: git diff --exit-code + build_with_tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Build + run: | + mkdir build + cd build + cmake -DCMAKE_INSTALL_PREFIX=install -DSPIRV_HEADERS_ENABLE_TESTS .. + cmake --build . --target install + test_cmake_min_required: runs-on: ubuntu-latest steps: From 8bc6df5c8cc3796243652fecef82df699983fc22 Mon Sep 17 00:00:00 2001 From: Ben Ashbaugh Date: Fri, 25 Oct 2024 15:47:54 -0700 Subject: [PATCH 4/5] fix syntax for enabling tests --- .github/workflows/presubmit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index 5caeaeb70..0c3c7db11 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -47,7 +47,7 @@ jobs: run: | mkdir build cd build - cmake -DCMAKE_INSTALL_PREFIX=install -DSPIRV_HEADERS_ENABLE_TESTS .. + cmake -DCMAKE_INSTALL_PREFIX=install -DSPIRV_HEADERS_ENABLE_TESTS=ON .. cmake --build . --target install test_cmake_min_required: From 1f0c59d6285343f72b8ff7478e19e1bbdaf16f8b Mon Sep 17 00:00:00 2001 From: Ben Ashbaugh Date: Fri, 25 Oct 2024 15:50:36 -0700 Subject: [PATCH 5/5] remove commented out line so hpp11 tests should fail now --- .github/workflows/presubmit.yml | 11 ----------- tests/CMakeLists.txt | 2 +- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index 0c3c7db11..d7958ca75 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -39,17 +39,6 @@ jobs: - name: Check generated headers run: git diff --exit-code - build_with_tests: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Build - run: | - mkdir build - cd build - cmake -DCMAKE_INSTALL_PREFIX=install -DSPIRV_HEADERS_ENABLE_TESTS=ON .. - cmake --build . --target install - test_cmake_min_required: runs-on: ubuntu-latest steps: diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 14e6f756b..88a956c4e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -30,7 +30,7 @@ target_link_libraries(spirv_headers_simple_test PRIVATE SPIRV-Headers::SPIRV-Hea add_test(NAME spirv_headers_simple_test COMMAND spirv_headers_simple_test) add_executable(spirv_headers_simple_test_cpp11 example11.cpp) -#target_compile_definitions(spirv_headers_simple_test_cpp11 PRIVATE SPV_ENABLE_UTILITY_CODE) +target_compile_definitions(spirv_headers_simple_test_cpp11 PRIVATE SPV_ENABLE_UTILITY_CODE) target_link_libraries(spirv_headers_simple_test_cpp11 PRIVATE SPIRV-Headers::SPIRV-Headers) set_target_properties(spirv_headers_simple_test_cpp11 PROPERTIES CXX_STANDARD 11) add_test(NAME spirv_headers_simple_test_cpp11 COMMAND spirv_headers_simple_test_cpp11)