aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Giessen <charles@lunarg.com>2023-06-15 14:05:59 -0600
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>2023-06-16 15:06:03 -0600
commit7879c955b9a8705576d975a9d1bbd280ca40ade8 (patch)
treec7501d7daac6507fd6163e288dc53d16737e1022
parent0d43b2471174e5bb6d5d8061e5f69c609c84ad5d (diff)
downloadusermoji-7879c955b9a8705576d975a9d1bbd280ca40ade8.tar.xz
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.
-rw-r--r--BUILD.md29
-rw-r--r--CMakeLists.txt6
-rw-r--r--tests/CMakeLists.txt34
-rw-r--r--tests/icd/mock_icd_tests.cpp25
-rw-r--r--tests/main.cpp46
5 files changed, 126 insertions, 14 deletions
diff --git a/BUILD.md b/BUILD.md
index 017361f8..81bda3fb 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 8407a4ce..95a7d198 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 00000000..4367354d
--- /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 00000000..18025dfa
--- /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 00000000..a14e8e99
--- /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 <crtdbg.h>
+#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;
+}