From 7879c955b9a8705576d975a9d1bbd280ca40ade8 Mon Sep 17 00:00:00 2001 From: Charles Giessen Date: Thu, 15 Jun 2023 14:05:59 -0600 Subject: [PATCH] test: Add test infrastructure Add necessary CMake code to enable tests to be built and run. Most of the logic is taken from Vulkan-ValidationLayers' and adapted for use here. New build option: BUILD_TESTS - defaults to OFF. Controls whether to build tests. --- BUILD.md | 29 ++++++++++++++-------------- CMakeLists.txt | 6 ++++++ tests/CMakeLists.txt | 34 ++++++++++++++++++++++++++++++++ tests/icd/mock_icd_tests.cpp | 25 ++++++++++++++++++++++++ tests/main.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 126 insertions(+), 14 deletions(-) create mode 100644 tests/CMakeLists.txt create mode 100644 tests/icd/mock_icd_tests.cpp create mode 100644 tests/main.cpp diff --git a/BUILD.md b/BUILD.md index 017361f..81bda3f 100644 --- a/BUILD.md +++ b/BUILD.md @@ -202,22 +202,23 @@ be specified to customize the build. Some of the options are binary on/off options, while others take a string as input. The following is a table of all on/off options currently supported by this repository: -| Option | Platform | Default | Description | -| ------ | -------- | ------- | ----------- | -| BUILD_CUBE | All | `ON` | Controls whether or not the vkcube demo is built. | -| BUILD_VULKANINFO | All | `ON` | Controls whether or not the vulkaninfo utility is built. | -| BUILD_ICD | All | `ON` | Controls whether or not the mock ICD is built. | -| INSTALL_ICD | All | `OFF` | Controls whether or not the mock ICD is installed as part of the install target. | -| BUILD_WSI_XCB_SUPPORT | Linux | `ON` | Build the components with XCB support. | -| BUILD_WSI_XLIB_SUPPORT | Linux | `ON` | Build the components with Xlib support. | -| BUILD_WSI_WAYLAND_SUPPORT | Linux | `ON` | Build the components with Wayland support. | -| BUILD_WSI_DIRECTFB_SUPPORT | Linux | `OFF` | Build the components with DirectFB support. | +| Option | Platform | Default | Description | +| -------------------------- | -------- | ------- | -------------------------------------------------------------------------------- | +| BUILD_TESTS | All | `OFF` | Controls whether the tests are built. | +| BUILD_CUBE | All | `ON` | Controls whether or not the vkcube demo is built. | +| BUILD_VULKANINFO | All | `ON` | Controls whether or not the vulkaninfo utility is built. | +| BUILD_ICD | All | `ON` | Controls whether or not the mock ICD is built. | +| INSTALL_ICD | All | `OFF` | Controls whether or not the mock ICD is installed as part of the install target. | +| BUILD_WSI_XCB_SUPPORT | Linux | `ON` | Build the components with XCB support. | +| BUILD_WSI_XLIB_SUPPORT | Linux | `ON` | Build the components with Xlib support. | +| BUILD_WSI_WAYLAND_SUPPORT | Linux | `ON` | Build the components with Wayland support. | +| BUILD_WSI_DIRECTFB_SUPPORT | Linux | `OFF` | Build the components with DirectFB support. | The following is a table of all string options currently supported by this repository: -| Option | Platform | Default | Description | -| ------ | -------- | ------- | ----------- | -| VULKANINFO_BUILD_DLL_VERSIONINFO | Windows | `""` | Set the Windows specific version information for Vulkaninfo. Format is "major.minor.patch.build". | +| Option | Platform | Default | Description | +| -------------------------------- | -------- | ------- | ------------------------------------------------------------------------------------------------- | +| VULKANINFO_BUILD_DLL_VERSIONINFO | Windows | `""` | Set the Windows specific version information for Vulkaninfo. Format is "major.minor.patch.build". | These variables should be set using the `-D` option when invoking CMake to generate the native platform files. @@ -388,7 +389,7 @@ have installed. Generator strings that correspond to versions of Visual Studio include: | Build Platform | 64-bit Generator | 32-bit Generator | -|------------------------------|-------------------------------|-------------------------| +| ---------------------------- | ----------------------------- | ----------------------- | | Microsoft Visual Studio 2013 | "Visual Studio 12 2013 Win64" | "Visual Studio 12 2013" | | Microsoft Visual Studio 2015 | "Visual Studio 14 2015 Win64" | "Visual Studio 14 2015" | | Microsoft Visual Studio 2017 | "Visual Studio 15 2017 Win64" | "Visual Studio 15 2017" | diff --git a/CMakeLists.txt b/CMakeLists.txt index 8407a4c..95a7d19 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -170,3 +170,9 @@ if(BUILD_ICD) endif() add_subdirectory(windows-runtime-installer) + +option(BUILD_TESTS "Build the tests") +if(BUILD_TESTS) + enable_testing() + add_subdirectory(tests) +endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..4367354 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,34 @@ +# ~~~ +# Copyright (c) 2023 Valve Corporation +# Copyright (c) 2023 LunarG, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ~~~ + +find_package(GTest REQUIRED CONFIG QUIET) + +add_executable(vulkan_tools_tests) +target_sources(vulkan_tools_tests PRIVATE + main.cpp + icd/mock_icd_tests.cpp +) +get_target_property(TEST_SOURCES vulkan_tools_tests SOURCES) +source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES ${TEST_SOURCES}) + +# make sure tests are built after all of the following are built +add_dependencies(vulkan_tools_tests vkcube vkcubepp VkICD_mock_icd vulkaninfo) + +target_link_libraries(vulkan_tools_tests GTest::gtest) + +include(GoogleTest) +gtest_discover_tests(vulkan_tools_tests DISCOVERY_TIMEOUT 100) diff --git a/tests/icd/mock_icd_tests.cpp b/tests/icd/mock_icd_tests.cpp new file mode 100644 index 0000000..18025df --- /dev/null +++ b/tests/icd/mock_icd_tests.cpp @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 The Khronos Group Inc. + * Copyright (c) 2023 Valve Corporation + * Copyright (c) 2023 LunarG, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "gtest/gtest.h" + +TEST(MockICD, Basic) { + // only to make sure tests can be run + ASSERT_TRUE(true); +} diff --git a/tests/main.cpp b/tests/main.cpp new file mode 100644 index 0000000..a14e8e9 --- /dev/null +++ b/tests/main.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2023 The Khronos Group Inc. + * Copyright (c) 2023 Valve Corporation + * Copyright (c) 2023 LunarG, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#if defined(_WIN32) && !defined(NDEBUG) +#include +#endif + +#include "gtest/gtest.h" + +int main(int argc, char **argv) { + int result; + +#if defined(_WIN32) +#if !defined(NDEBUG) + _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); + _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); +#endif + // Avoid "Abort, Retry, Ignore" dialog boxes + _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT); + SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); + _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE); + _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); +#endif + + ::testing::InitGoogleTest(&argc, argv); + + result = RUN_ALL_TESTS(); + + return result; +} -- 2.7.4