From 996c728cf7dcfb29845cfa15222822318f047810 Mon Sep 17 00:00:00 2001 From: Ben Ashbaugh Date: Wed, 6 Nov 2024 08:40:19 -0800 Subject: [PATCH] add basic utility code testing for cpp, cpp11, and c (#461) * add basic utility code testing for cpp, cpp11, and c * switch from building libraries to building executables for tests * try adding a specific GitHub action to build with tests * fix syntax for enabling tests * remove commented out line so hpp11 tests should fail now --- CMakeLists.txt | 2 +- tests/CMakeLists.txt | 21 ++++++++++++++------- tests/example.c | 37 +++++++++++++++++++++++++++++++++++++ tests/example.cpp | 4 ++++ tests/example11.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 97 insertions(+), 8 deletions(-) create mode 100644 tests/example.c create mode 100644 tests/example11.cpp 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 ebf7e1244..88a956c4e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -24,15 +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) +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) -target_sources(spirv_headers_simple_test PRIVATE - example.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) -target_link_libraries(spirv_headers_simple_test PRIVATE - SPIRV-Headers::SPIRV-Headers -) +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 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 new file mode 100644 index 000000000..9b5045e76 --- /dev/null +++ b/tests/example.c @@ -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 + +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 new file mode 100644 index 000000000..9adc5b813 --- /dev/null +++ b/tests/example11.cpp @@ -0,0 +1,41 @@ +// 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 + +int main() { + return 0; +}