Add vulkan unit tests to Chromium
Notes:
- INSTANTIATE_TEST_CASE_P is now deprecated, so changed it to
INSTANTIATE_TEST_SUITE_P. This requires and update to
third_party/googletest.
- Updated Driver's loadSwiftShader() function to include the
non standalone path, in order to run the tests in Chromium
- Added Vulkan unit tests to swiftshader_tests
- Added a new GN file for Vulkan unit tests. Note that it
relies on Chromium's version of SPIR-V Tools, not on
SwiftShader's version, in order to avoid build conflicts
Change-Id: I87727f6a858a720d0f5fb8f262ac290818945ac4
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/32349
Presubmit-Ready: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Tested-by: Alexis Hétu <sugoi@google.com>
diff --git a/BUILD.gn b/BUILD.gn
index 56c78ce..915825e 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -186,5 +186,6 @@
data_deps = [
"tests/GLESUnitTests:swiftshader_unittests",
+ "tests/VulkanUnitTests:swiftshader_vulkan_unittests",
]
}
diff --git a/src/Reactor/ReactorUnitTests.cpp b/src/Reactor/ReactorUnitTests.cpp
index 29f3793..490433e 100644
--- a/src/Reactor/ReactorUnitTests.cpp
+++ b/src/Reactor/ReactorUnitTests.cpp
@@ -1248,7 +1248,7 @@
std::pair<float, Float>
>;
-TYPED_TEST_CASE(CToReactorCastTest, CToReactorCastTestTypes);
+TYPED_TEST_SUITE(CToReactorCastTest, CToReactorCastTestTypes);
TYPED_TEST(CToReactorCastTest, Casts)
{
@@ -1320,7 +1320,7 @@
std::pair<float[4], Float4>
>;
-TYPED_TEST_CASE(GEPTest, GEPTestTypes);
+TYPED_TEST_SUITE(GEPTest, GEPTestTypes);
TYPED_TEST(GEPTest, PtrOffsets)
{
diff --git a/tests/VulkanUnitTests/BUILD.gn b/tests/VulkanUnitTests/BUILD.gn
new file mode 100644
index 0000000..f33f59e
--- /dev/null
+++ b/tests/VulkanUnitTests/BUILD.gn
@@ -0,0 +1,51 @@
+# Copyright 2019 The SwiftShader Authors. All Rights Reserved.
+#
+# 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.
+
+import("//testing/test.gni")
+
+test("swiftshader_vulkan_unittests") {
+ deps = [
+ "//base",
+ "//base/test:test_support",
+ "//testing/gmock",
+ "//testing/gtest",
+ "//third_party/SPIRV-Tools/src:SPIRV-Tools",
+ "//third_party/swiftshader/src/Vulkan:swiftshader_libvulkan",
+ ]
+
+ sources = [
+ "//gpu/swiftshader_tests_main.cc",
+ "Device.cpp",
+ "Driver.cpp",
+ "unittests.cpp",
+ ]
+
+ include_dirs = [
+ "//third_party/SPIRV-Tools/src/include",
+ "../../include", # Khronos headers
+ ]
+
+ if (is_win) {
+ ldflags = [
+ "/DELAYLOAD:libvulkan.dll",
+ ]
+ } else if (is_mac) {
+ ldflags = [
+ "-rpath",
+ "@executable_path/",
+ ]
+ } else {
+ ldflags = [ "-Wl,-rpath=\$ORIGIN/swiftshader" ]
+ }
+}
diff --git a/tests/VulkanUnitTests/Driver.cpp b/tests/VulkanUnitTests/Driver.cpp
index 440ea8e..a2a0a25 100644
--- a/tests/VulkanUnitTests/Driver.cpp
+++ b/tests/VulkanUnitTests/Driver.cpp
@@ -49,15 +49,29 @@
bool Driver::loadSwiftShader()
{
#if OS_WINDOWS
-# if defined(NDEBUG)
- return load("./build/Release/libvk_swiftshader.dll");
-# else
- return load("./build/Debug/libvk_swiftshader.dll");
-# endif
+ #if !defined(STANDALONE)
+ // The DLL is delay loaded (see BUILD.gn), so we can load
+ // the correct ones from Chrome's swiftshader subdirectory.
+ HMODULE libvulkan = LoadLibraryA("swiftshader\\libvulkan.dll");
+ EXPECT_NE((HMODULE)NULL, libvulkan);
+ return true;
+ #elif defined(NDEBUG)
+ return load("./build/Release/libvk_swiftshader.dll");
+ #else
+ return load("./build/Debug/libvk_swiftshader.dll");
+ #endif
#elif OS_MAC
- return load("./build/Darwin/libvk_swiftshader.dylib");
+ #if defined(STANDALONE)
+ return load("./build/Darwin/libvk_swiftshader.dylib");
+ #else
+ return load("libvulkan.dylib");
+ #endif
#elif OS_LINUX
- return load("./build/Linux/libvk_swiftshader.so");
+ #if defined(STANDALONE)
+ return load("./build/Linux/libvk_swiftshader.so");
+ #else
+ return load("libvulkan.so");
+ #endif
#elif OS_ANDROID
return load("libvk_swiftshader.so");
#else
diff --git a/tests/VulkanUnitTests/unittests.cpp b/tests/VulkanUnitTests/unittests.cpp
index 50ab3b4..f7868e4 100644
--- a/tests/VulkanUnitTests/unittests.cpp
+++ b/tests/VulkanUnitTests/unittests.cpp
@@ -374,7 +374,7 @@
driver.vkDestroyInstance(instance, nullptr);
}
-INSTANTIATE_TEST_CASE_P(ComputeParams, SwiftShaderVulkanBufferToBufferComputeTest, testing::Values(
+INSTANTIATE_TEST_SUITE_P(ComputeParams, SwiftShaderVulkanBufferToBufferComputeTest, testing::Values(
ComputeParams{512, 1, 1, 1},
ComputeParams{512, 2, 1, 1},
ComputeParams{512, 4, 1, 1},
diff --git a/third_party/googletest b/third_party/googletest
index 02a8ca8..8ffb7e5 160000
--- a/third_party/googletest
+++ b/third_party/googletest
@@ -1 +1 @@
-Subproject commit 02a8ca87735601466d8c564344f9be493da84708
+Subproject commit 8ffb7e5c88b20a297a2e786c480556467496463b