Skip to content

Commit 9786129

Browse files
committed
OGSMOD-6769: Run Vulkan unit tests after OpenGL for Viewport Toolbox
1 parent eae14dc commit 9786129

18 files changed

+331
-147
lines changed

test/RenderingFramework/TestFlags.h

Lines changed: 113 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,118 @@
99
//
1010
#pragma once
1111

12+
#include <gtest/gtest.h>
13+
#include <string>
14+
15+
#define AGP_TEST_DEFAULT_BACKEND(TestSuiteName, TestName) \
16+
void AGPTestDefaultBackend##TestName(); \
17+
TEST(TestSuiteName, TestName) \
18+
{ \
19+
TestHelpers::gParameterizedTests = false; \
20+
TestHelpers::gTestNames = \
21+
TestHelpers::getTestNames(::testing::UnitTest::GetInstance()->current_test_info()); \
22+
AGPTestDefaultBackend##TestName(); \
23+
} \
24+
void AGPTestDefaultBackend##TestName()
25+
26+
#if defined(ENABLE_VULKAN) && defined(WIN32)
27+
28+
#define AGP_TEST(TestSuiteName, TestName) \
29+
std::string ParamTestName##TestName(const testing::TestParamInfo<std::string>& info) \
30+
{ \
31+
return info.param; \
32+
} \
33+
class TestName : public ::testing::TestWithParam<std::string> \
34+
{ \
35+
public: \
36+
void AGPTest##TestName(); \
37+
}; \
38+
INSTANTIATE_TEST_SUITE_P(TestSuiteName, TestName, ::testing::Values(/*"Vulkan",*/ "OpenGL"), \
39+
ParamTestName##TestName); \
40+
TEST_P(TestName, TestName) \
41+
{ \
42+
TestHelpers::gRunVulkanTests = (GetParam() == "Vulkan"); \
43+
TestHelpers::gParameterizedTests = true; \
44+
TestHelpers::gTestNames = TestHelpers::getTestNames( \
45+
::testing::UnitTest::GetInstance()->current_test_info()); \
46+
AGPTest##TestName(); \
47+
} \
48+
void TestName::AGPTest##TestName()
49+
50+
#else
51+
52+
#define AGP_TEST(TestSuiteName, TestName) \
53+
void AGPTestDefaultBackend##TestName(); \
54+
TEST(TestSuiteName, TestName) \
55+
{ \
56+
TestHelpers::gParameterizedTests = false; \
57+
TestHelpers::gTestNames = TestHelpers::getTestNames( \
58+
::testing::UnitTest::GetInstance()->current_test_info()); \
59+
AGPTestDefaultBackend##TestName(); \
60+
} \
61+
void AGPTestDefaultBackend##TestName()
62+
63+
#endif
64+
1265
namespace TestHelpers
1366
{
14-
inline bool gRunVulkanTests = false;
15-
} // namespace TestHelpers
67+
struct TestNames
68+
{
69+
std::string suiteName;
70+
std::string fixtureName;
71+
std::string paramName;
72+
};
73+
74+
inline bool gRunVulkanTests = false;
75+
inline bool gParameterizedTests = false;
76+
inline TestNames gTestNames = TestNames {};
77+
78+
inline TestNames getTestNames(const ::testing::TestInfo* testInfo)
79+
{
80+
TestNames testNames;
81+
if (testInfo)
82+
{
83+
std::string testSuiteName = testInfo->test_suite_name();
84+
std::string testName = testInfo->name();
85+
86+
// If parameterized tests are used, test_suite_name and name returns
87+
// SuiteName/TestName/Param. Hence the following filtering is
88+
// needed.
89+
if (TestHelpers::gParameterizedTests == true)
90+
{
91+
size_t pos = testSuiteName.find('/');
92+
if (pos != std::string::npos)
93+
{
94+
testNames.suiteName = testSuiteName.substr(0, pos);
95+
testNames.fixtureName = testSuiteName.substr(pos + 1);
96+
}
97+
98+
pos = testName.find('/');
99+
if (pos != std::string::npos)
100+
{
101+
testNames.paramName = testName.substr(pos + 1);
102+
}
103+
}
104+
else // Otherwise the following is enough
105+
{
106+
testNames.suiteName = testInfo->test_suite_name();
107+
testNames.fixtureName = testInfo->name();
108+
}
109+
}
110+
return testNames;
111+
}
112+
113+
/// Gets the image file based on the test parameter.
114+
inline std::string getComputedImagePath()
115+
{
116+
return gTestNames.paramName.empty() ? gTestNames.fixtureName
117+
: (gTestNames.fixtureName + "_" + gTestNames.paramName);
118+
}
119+
120+
/// Appends image file based on the test parameter.
121+
inline std::string appendParamToImageFile(const std::string& fileName)
122+
{
123+
return gTestNames.paramName.empty() ? fileName : (fileName + "_" + gTestNames.paramName);
124+
}
125+
126+
} // namespace TestHelpers

test/RenderingFramework/TestHelpers.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,15 @@ bool HydraRendererContext::compareImages(
153153
return compareImages(inFile, outFile, threshold, pixelCountThreshold);
154154
}
155155

156+
bool HydraRendererContext::compareImage(const std::string& computedFilename,
157+
const std::string& baseLineFilename, const uint8_t threshold)
158+
{
159+
const auto baselinePath = getBaselineFolder();
160+
const std::string baseLine = getFilename(baselinePath, baseLineFilename);
161+
const std::string computed = getFilename(outFullpath, computedFilename + "_computed");
162+
return compareImages(computed, baseLine, threshold, 1);
163+
}
164+
156165
bool HydraRendererContext::compareOutputImages(const std::string& fileName1,
157166
const std::string& fileName2, const uint8_t threshold, const uint8_t pixelCountThreshold)
158167
{

test/RenderingFramework/TestHelpers.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ class HydraRendererContext
122122
virtual bool compareImages(const std::string& fileName, const uint8_t threshold = 1,
123123
const uint8_t pixelCountThreshold = 0);
124124

125+
/// Compare image against stored "_computed" image and throws if a difference is found within
126+
/// the threshold defined.
127+
virtual bool compareImage(const std::string& computedFilename,
128+
const std::string& baseLineFilename, const uint8_t threshold = 1);
129+
125130
/// Compare two "_computed" images and throws if a difference is found within the thresholds
126131
/// defined
127132
virtual bool compareOutputImages(const std::string& fileName1, const std::string& fileName2,

test/howTos/howTo01_CreateHgiImplementation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
//
5353
// How to create an Hgi implementation?
5454
//
55-
TEST(howTo, createHgiImplementation)
55+
AGP_TEST(howTo, CreateHgiImplementation)
5656
{
5757
pxr::HgiUniquePtr hgi;
5858
pxr::HdDriver hgiDriver;

test/howTos/howTo02_CreateOneFramePass.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222

2323
#include <gtest/gtest.h>
2424

25+
#include <RenderingFramework/TestFlags.h>
26+
2527
//
2628
// How to create one frame pass using Storm?
2729
//
28-
TEST(howTo, createOneFramePass)
30+
AGP_TEST(howTo, createOneFramePass)
2931
{
3032
// Helper to create the Hgi implementation.
3133

@@ -97,10 +99,12 @@ TEST(howTo, createOneFramePass)
9799

98100
// Validates the rendering result.
99101

100-
const std::string imageFile = std::string(test_info_->test_suite_name()) + std::string("/") +
101-
std::string(test_info_->name());
102+
const std::string imageFile =
103+
TestHelpers::gTestNames.suiteName + std::string("/") + TestHelpers::gTestNames.fixtureName;
104+
105+
const std::string computedImageName = TestHelpers::appendParamToImageFile(imageFile);
102106

103-
ASSERT_TRUE(context->_backend->saveImage(imageFile));
107+
ASSERT_TRUE(context->_backend->saveImage(computedImageName));
104108

105-
ASSERT_TRUE(context->_backend->compareImages(imageFile));
109+
ASSERT_TRUE(context->_backend->compareImage(computedImageName, imageFile));
106110
}

test/howTos/howTo03_CreateTwoFramePasses.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
#include <gtest/gtest.h>
2727

28+
#include <RenderingFramework/TestFlags.h>
29+
2830
//
2931
// How to create two frame passes?
3032
//
@@ -35,9 +37,9 @@
3537
// NOTE: It turns out "axisTripod.usda" has coplanar geometry and it can create random
3638
// inconsistencies on all platforms. Refer to OGSMOD-6304.
3739
#if (TARGET_OS_IPHONE == 1) || (defined(_WIN32) && defined(ENABLE_VULKAN)) || defined(__linux__) || !defined(ADSK_OPENUSD_PENDING)
38-
TEST(howTo, DISABLED_createTwoFramePasses)
40+
AGP_TEST(howTo, DISABLED_createTwoFramePasses)
3941
#else
40-
TEST(howTo, DISABLED_createTwoFramePasses)
42+
AGP_TEST(howTo, DISABLED_createTwoFramePasses)
4143
#endif
4244
{
4345
// Helper to create the Hgi implementation.
@@ -200,9 +202,12 @@ TEST(howTo, DISABLED_createTwoFramePasses)
200202

201203
// Validates the rendering result.
202204

203-
const std::string imageFile = std::string(test_info_->test_suite_name()) + std::string("/") +
204-
std::string(test_info_->name());
205-
ASSERT_TRUE(context->_backend->saveImage(imageFile));
205+
const std::string imageFile =
206+
TestHelpers::gTestNames.suiteName + std::string("/") + TestHelpers::gTestNames.fixtureName;
207+
208+
const std::string computedImageName = TestHelpers::appendParamToImageFile(imageFile);
209+
210+
ASSERT_TRUE(context->_backend->saveImage(computedImageName));
206211

207-
ASSERT_TRUE(context->_backend->compareImages(imageFile, 1));
212+
ASSERT_TRUE(context->_backend->compareImage(computedImageName, imageFile, 1));
208213
}

test/howTos/howTo04_CreateACustomRenderTask.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@
2323

2424
#include <gtest/gtest.h>
2525

26+
#include <RenderingFramework/TestFlags.h>
27+
2628
//
2729
// How to create a custom render task?
2830
//
2931
// TODO: The result image is not stable between runs on macOS, skip on that platform for now
3032
// Disabled for Android due to baseline inconsistancy between runners. Refer to OGSMOD-8067
3133
#if defined(__APPLE__) || defined(__ANDROID__)
32-
TEST(howTo, DISABLED_createACustomRenderTask)
34+
AGP_TEST(howTo, DISABLED_createACustomRenderTask)
3335
#else
34-
TEST(howTo, createACustomRenderTask)
36+
AGP_TEST(howTo, createACustomRenderTask)
3537
#endif
3638
{
3739
// Helper to create the Hgi implementation.
@@ -137,10 +139,12 @@ TEST(howTo, createACustomRenderTask)
137139

138140
// Validates the rendering result.
139141

140-
const std::string imageFile = std::string(test_info_->test_suite_name()) + std::string("/") +
141-
std::string(test_info_->name());
142+
const std::string imageFile =
143+
TestHelpers::gTestNames.suiteName + std::string("/") + TestHelpers::gTestNames.fixtureName;
144+
145+
const std::string computedImageName = TestHelpers::appendParamToImageFile(imageFile);
142146

143-
ASSERT_TRUE(context->_backend->saveImage(imageFile));
147+
ASSERT_TRUE(context->_backend->saveImage(computedImageName));
144148

145-
ASSERT_TRUE(context->_backend->compareImages(imageFile));
149+
ASSERT_TRUE(context->_backend->compareImage(computedImageName, imageFile));
146150
}

test/howTos/howTo05_UseSSAORenderTask.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,17 @@ PXR_NAMESPACE_USING_DIRECTIVE
2626

2727
#include <gtest/gtest.h>
2828

29+
#include <RenderingFramework/TestFlags.h>
30+
2931
//
3032
// How to use the SSAO render task?
3133
//
3234
// FIXME: The result image is not stable between runs on macOS. Refer to OGSMOD-4820.
3335
// Note: As Android is now built on macOS platform, the same challenge exists!
3436
#if defined(__APPLE__) || defined(__ANDROID__)
35-
TEST(howTo, DISABLED_useSSAORenderTask)
37+
AGP_TEST(howTo, DISABLED_useSSAORenderTask)
3638
#else
37-
TEST(howTo, useSSAORenderTask)
39+
AGP_TEST(howTo, useSSAORenderTask)
3840
#endif
3941
{
4042
// Helper to create the Hgi implementation.
@@ -149,10 +151,12 @@ TEST(howTo, useSSAORenderTask)
149151

150152
// Validates the rendering result.
151153

152-
const std::string imageFile = std::string(test_info_->test_suite_name()) + std::string("/") +
153-
std::string(test_info_->name());
154+
const std::string imageFile =
155+
TestHelpers::gTestNames.suiteName + std::string("/") + TestHelpers::gTestNames.fixtureName;
156+
157+
const std::string computedImageName = TestHelpers::appendParamToImageFile(imageFile);
154158

155-
ASSERT_TRUE(context->_backend->saveImage(imageFile));
159+
ASSERT_TRUE(context->_backend->saveImage(computedImageName));
156160

157-
ASSERT_TRUE(context->_backend->compareImages(imageFile));
161+
ASSERT_TRUE(context->_backend->compareImage(computedImageName, imageFile));
158162
}

test/howTos/howTo06_UseFXAARenderTask.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,16 @@ PXR_NAMESPACE_USING_DIRECTIVE
2626

2727
#include <gtest/gtest.h>
2828

29+
#include <RenderingFramework/TestFlags.h>
30+
2931
//
3032
// How to use the FXAA render task?
3133
//
3234
// FIXME: OGSMOD-7891 - Produce weird image & unstable images between runs on Android.
3335
#if defined(__APPLE__) || defined(__ANDROID__)
34-
TEST(howTo, DISABLED_useFXAARenderTask)
36+
AGP_TEST(howTo, DISABLED_useFXAARenderTask)
3537
#else
36-
TEST(howTo, useFXAARenderTask)
38+
AGP_TEST(howTo, useFXAARenderTask)
3739
#endif
3840
{
3941
// Helper to create the Hgi implementation.
@@ -134,10 +136,12 @@ TEST(howTo, useFXAARenderTask)
134136

135137
// Validates the rendering result.
136138

137-
const std::string imageFile = std::string(test_info_->test_suite_name()) + std::string("/") +
138-
std::string(test_info_->name());
139+
const std::string imageFile =
140+
TestHelpers::gTestNames.suiteName + std::string("/") + TestHelpers::gTestNames.fixtureName;
141+
142+
const std::string computedImageName = TestHelpers::appendParamToImageFile(imageFile);
139143

140-
ASSERT_TRUE(context->_backend->saveImage(imageFile));
144+
ASSERT_TRUE(context->_backend->saveImage(computedImageName));
141145

142-
ASSERT_TRUE(context->_backend->compareImages(imageFile));
146+
ASSERT_TRUE(context->_backend->compareImage(computedImageName, imageFile));
143147
}

0 commit comments

Comments
 (0)