Skip to content

Commit

Permalink
add basic utility code testing for cpp, cpp11, and c (#461)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bashbaug authored Nov 6, 2024
1 parent cb6b2c3 commit 996c728
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 14 additions & 7 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
Expand Down
37 changes: 37 additions & 0 deletions tests/example.c
Original file line number Diff line number Diff line change
@@ -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 <spirv/unified1/GLSL.std.450.h>
#include <spirv/unified1/OpenCL.std.h>
#include <spirv/unified1/spirv.h>

const enum GLSLstd450 kSin = GLSLstd450Sin;
const enum OpenCLstd_Entrypoints kNative_cos = OpenCLstd_Native_cos;
const SpvOp kNop = SpvOpNop;

int main() {
return 0;
}
4 changes: 4 additions & 0 deletions tests/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ const OpenCLLIB::Entrypoints kNative_cos = OpenCLLIB::Native_cos;
const spv::Op kNop = spv::OpNop;

} // anonymous namespace

int main() {
return 0;
}
41 changes: 41 additions & 0 deletions tests/example11.cpp
Original file line number Diff line number Diff line change
@@ -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 <spirv/unified1/GLSL.std.450.h>
#include <spirv/unified1/OpenCL.std.h>
#include <spirv/unified1/spirv.hpp11>

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;
}

0 comments on commit 996c728

Please sign in to comment.