Skip to content

Commit 996c728

Browse files
authored
add basic utility code testing for cpp, cpp11, and c (KhronosGroup#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
1 parent cb6b2c3 commit 996c728

File tree

5 files changed

+97
-8
lines changed

5 files changed

+97
-8
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
2525
# MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
2626
cmake_minimum_required(VERSION 3.14)
27-
project(SPIRV-Headers LANGUAGES CXX VERSION 1.5.5)
27+
project(SPIRV-Headers LANGUAGES C CXX VERSION 1.5.5)
2828

2929
if (CMAKE_VERSION VERSION_LESS "3.21")
3030
# https://cmake.org/cmake/help/latest/variable/PROJECT_IS_TOP_LEVEL.html

tests/CMakeLists.txt

+14-7
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,22 @@
2424
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
2525
# MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
2626

27-
add_library(spirv_headers_simple_test STATIC)
27+
add_executable(spirv_headers_simple_test example.cpp)
28+
target_compile_definitions(spirv_headers_simple_test PRIVATE SPV_ENABLE_UTILITY_CODE)
29+
target_link_libraries(spirv_headers_simple_test PRIVATE SPIRV-Headers::SPIRV-Headers)
30+
add_test(NAME spirv_headers_simple_test COMMAND spirv_headers_simple_test)
2831

29-
target_sources(spirv_headers_simple_test PRIVATE
30-
example.cpp
31-
)
32+
add_executable(spirv_headers_simple_test_cpp11 example11.cpp)
33+
target_compile_definitions(spirv_headers_simple_test_cpp11 PRIVATE SPV_ENABLE_UTILITY_CODE)
34+
target_link_libraries(spirv_headers_simple_test_cpp11 PRIVATE SPIRV-Headers::SPIRV-Headers)
35+
set_target_properties(spirv_headers_simple_test_cpp11 PROPERTIES CXX_STANDARD 11)
36+
add_test(NAME spirv_headers_simple_test_cpp11 COMMAND spirv_headers_simple_test_cpp11)
3237

33-
target_link_libraries(spirv_headers_simple_test PRIVATE
34-
SPIRV-Headers::SPIRV-Headers
35-
)
38+
add_executable(spirv_headers_simple_test_c example.c)
39+
target_compile_definitions(spirv_headers_simple_test_c PRIVATE SPV_ENABLE_UTILITY_CODE)
40+
target_link_libraries(spirv_headers_simple_test_c PRIVATE SPIRV-Headers::SPIRV-Headers)
41+
set_target_properties(spirv_headers_simple_test_c PROPERTIES C_STANDARD 99 LINKER_LANGUAGE C)
42+
add_test(NAME spirv_headers_simple_test_c COMMAND spirv_headers_simple_test_c)
3643

3744
if (NOT TARGET SPIRV-Headers)
3845
message(FATAL_ERROR "SPIRV-Headers target not defined!")

tests/example.c

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) 2016-2024 The Khronos Group Inc.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a
4+
// copy of this software and/or associated documentation files (the
5+
// "Materials"), to deal in the Materials without restriction, including
6+
// without limitation the rights to use, copy, modify, merge, publish,
7+
// distribute, sublicense, and/or sell copies of the Materials, and to
8+
// permit persons to whom the Materials are furnished to do so, subject to
9+
// the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included
12+
// in all copies or substantial portions of the Materials.
13+
//
14+
// MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS
15+
// KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS
16+
// SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT
17+
// https://www.khronos.org/registry/
18+
//
19+
// THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22+
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23+
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24+
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25+
// MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
26+
27+
#include <spirv/unified1/GLSL.std.450.h>
28+
#include <spirv/unified1/OpenCL.std.h>
29+
#include <spirv/unified1/spirv.h>
30+
31+
const enum GLSLstd450 kSin = GLSLstd450Sin;
32+
const enum OpenCLstd_Entrypoints kNative_cos = OpenCLstd_Native_cos;
33+
const SpvOp kNop = SpvOpNop;
34+
35+
int main() {
36+
return 0;
37+
}

tests/example.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,7 @@ const OpenCLLIB::Entrypoints kNative_cos = OpenCLLIB::Native_cos;
3535
const spv::Op kNop = spv::OpNop;
3636

3737
} // anonymous namespace
38+
39+
int main() {
40+
return 0;
41+
}

tests/example11.cpp

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) 2016-2024 The Khronos Group Inc.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a
4+
// copy of this software and/or associated documentation files (the
5+
// "Materials"), to deal in the Materials without restriction, including
6+
// without limitation the rights to use, copy, modify, merge, publish,
7+
// distribute, sublicense, and/or sell copies of the Materials, and to
8+
// permit persons to whom the Materials are furnished to do so, subject to
9+
// the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included
12+
// in all copies or substantial portions of the Materials.
13+
//
14+
// MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS
15+
// KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS
16+
// SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT
17+
// https://www.khronos.org/registry/
18+
//
19+
// THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22+
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23+
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24+
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25+
// MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
26+
27+
#include <spirv/unified1/GLSL.std.450.h>
28+
#include <spirv/unified1/OpenCL.std.h>
29+
#include <spirv/unified1/spirv.hpp11>
30+
31+
namespace {
32+
33+
const GLSLstd450 kSin = GLSLstd450Sin;
34+
const OpenCLLIB::Entrypoints kNative_cos = OpenCLLIB::Native_cos;
35+
const spv::Op kNop = spv::Op::OpNop;
36+
37+
} // anonymous namespace
38+
39+
int main() {
40+
return 0;
41+
}

0 commit comments

Comments
 (0)