Skip to content

Commit 116c931

Browse files
authored
OGSMOD-6769: Run Vulkan unit tests after OpenGL for Viewport Toolbox (#76)
1 parent aca3cc7 commit 116c931

18 files changed

+233
-178
lines changed

test/RenderingFramework/TestFlags.h

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

12+
#include <gtest/gtest.h>
13+
#include <string>
14+
15+
#define HVT_TEST(TestSuiteName, TestName) \
16+
std::string ParamTestName##TestName(const testing::TestParamInfo<std::string>& info) \
17+
{ \
18+
return info.param; \
19+
} \
20+
class TestName : public ::testing::TestWithParam<std::string> \
21+
{ \
22+
public: \
23+
void HVTTest##TestName( \
24+
[[maybe_unused]] const std::string& computedImageName, \
25+
[[maybe_unused]] const std::string& imageFile); \
26+
}; \
27+
/* TODO: Enable "Vulkan" backend when Vulkan support is complete and stable. \
28+
Currently, only "OpenGL" is enabled for testing. */ \
29+
INSTANTIATE_TEST_SUITE_P(TestSuiteName, TestName, ::testing::Values(/*"Vulkan",*/ "OpenGL"), \
30+
ParamTestName##TestName); \
31+
TEST_P(TestName, TestName) \
32+
{ \
33+
TestHelpers::gRunVulkanTests = (GetParam() == "Vulkan"); \
34+
TestHelpers::gTestNames = TestHelpers::getTestNames( \
35+
::testing::UnitTest::GetInstance()->current_test_info()); \
36+
const std::string imageFile = TestHelpers::gTestNames.suiteName + \
37+
std::string("/") + TestHelpers::gTestNames.fixtureName; \
38+
const std::string computedImageName = TestHelpers::appendParamToImageFile(imageFile); \
39+
HVTTest##TestName(computedImageName, imageFile); \
40+
} \
41+
void TestName::HVTTest##TestName( \
42+
[[maybe_unused]] const std::string& computedImageName, \
43+
[[maybe_unused]] const std::string& imageFile)
44+
1245
namespace TestHelpers
1346
{
14-
inline bool gRunVulkanTests = false;
15-
} // namespace TestHelpers
47+
struct TestNames
48+
{
49+
/// @brief The name of the test suite extracted from the test information
50+
std::string suiteName;
51+
/// @brief The name of the test fixture extracted from the test suite name
52+
std::string fixtureName;
53+
/// @brief The parameter name extracted from the test name for parameterized tests
54+
std::string paramName;
55+
};
56+
57+
inline bool gRunVulkanTests = false;
58+
inline TestNames gTestNames = TestNames {};
59+
60+
inline TestNames getTestNames(const ::testing::TestInfo* testInfo)
61+
{
62+
TestNames testNames;
63+
if (testInfo)
64+
{
65+
std::string testSuiteName = testInfo->test_suite_name();
66+
std::string testName = testInfo->name();
67+
68+
size_t pos = testSuiteName.find('/');
69+
if (pos != std::string::npos)
70+
{
71+
testNames.suiteName = testSuiteName.substr(0, pos);
72+
testNames.fixtureName = testSuiteName.substr(pos + 1);
73+
}
74+
75+
pos = testName.find('/');
76+
if (pos != std::string::npos)
77+
{
78+
testNames.paramName = testName.substr(pos + 1);
79+
}
80+
}
81+
return testNames;
82+
}
83+
84+
/// Gets the image file based on the test parameter.
85+
inline std::string getComputedImagePath()
86+
{
87+
return gTestNames.paramName.empty() ? gTestNames.fixtureName
88+
: (gTestNames.fixtureName + "_" + gTestNames.paramName);
89+
}
90+
91+
/// Appends image file based on the test parameter.
92+
inline std::string appendParamToImageFile(const std::string& fileName)
93+
{
94+
return gTestNames.paramName.empty() ? fileName : (fileName + "_" + gTestNames.paramName);
95+
}
96+
97+
} // namespace TestHelpers

test/RenderingFramework/TestHelpers.cpp

Lines changed: 18 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, const uint8_t pixelCountThreshold)
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, pixelCountThreshold);
163+
}
164+
156165
bool HydraRendererContext::compareOutputImages(const std::string& fileName1,
157166
const std::string& fileName2, const uint8_t threshold, const uint8_t pixelCountThreshold)
158167
{
@@ -353,6 +362,15 @@ void TestContext::run(TestHelpers::TestStage& stage, hvt::Viewport* viewport, si
353362
_backend->run(render, viewport->GetLastFramePass());
354363
}
355364

365+
bool TestContext::validateImages(const std::string& computedImageName, const std::string& imageFile,
366+
const uint8_t threshold, const uint8_t pixelCountThreshold)
367+
{
368+
if (!_backend->saveImage(computedImageName)) {
369+
return false;
370+
}
371+
return _backend->compareImage(computedImageName, imageFile, threshold, pixelCountThreshold);
372+
}
373+
356374
FramePassInstance FramePassInstance::CreateInstance(std::string const& rendererName,
357375
pxr::UsdStageRefPtr& stage, std::shared_ptr<TestHelpers::HydraRendererContext>& backend,
358376
std::string const& uid)

test/RenderingFramework/TestHelpers.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ 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+
const uint8_t pixelCountThreshold = 1);
130+
125131
/// Compare two "_computed" images and throws if a difference is found within the thresholds
126132
/// defined
127133
virtual bool compareOutputImages(const std::string& fileName1, const std::string& fileName2,
@@ -227,6 +233,9 @@ class TestContext
227233
// Render a viewport i.e., several frame passes.
228234
void run(TestHelpers::TestStage& stage, hvt::Viewport* viewport, size_t frameCount);
229235

236+
bool validateImages(const std::string& computedImageName, const std::string& imageFile,
237+
const uint8_t threshold = 1, const uint8_t pixelCountThreshold = 1);
238+
230239
public:
231240
// The GPU backend used by the unit test.
232241
std::shared_ptr<TestHelpers::HydraRendererContext> _backend;

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+
HVT_TEST(howTo, CreateHgiImplementation)
5656
{
5757
pxr::HgiUniquePtr hgi;
5858
pxr::HdDriver hgiDriver;

test/howTos/howTo02_CreateOneFramePass.cpp

Lines changed: 4 additions & 7 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+
HVT_TEST(howTo, createOneFramePass)
2931
{
3032
// Helper to create the Hgi implementation.
3133

@@ -97,10 +99,5 @@ 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-
103-
ASSERT_TRUE(context->_backend->saveImage(imageFile));
104-
105-
ASSERT_TRUE(context->_backend->compareImages(imageFile));
102+
ASSERT_TRUE(context->validateImages(computedImageName, imageFile));
106103
}

test/howTos/howTo03_CreateTwoFramePasses.cpp

Lines changed: 5 additions & 7 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+
HVT_TEST(howTo, DISABLED_createTwoFramePasses)
3941
#else
40-
TEST(howTo, DISABLED_createTwoFramePasses)
42+
HVT_TEST(howTo, DISABLED_createTwoFramePasses)
4143
#endif
4244
{
4345
// Helper to create the Hgi implementation.
@@ -200,9 +202,5 @@ 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));
206-
207-
ASSERT_TRUE(context->_backend->compareImages(imageFile, 1));
205+
ASSERT_TRUE(context->validateImages(computedImageName, imageFile));
208206
}

test/howTos/howTo04_CreateACustomRenderTask.cpp

Lines changed: 6 additions & 9 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
30-
// Disabled for Android due to baseline inconsistancy between runners. Refer to OGSMOD-8067
32+
// Disabled for Android due to baseline inconsistency between runners. Refer to OGSMOD-8067
3133
#if defined(__APPLE__) || defined(__ANDROID__)
32-
TEST(howTo, DISABLED_createACustomRenderTask)
34+
HVT_TEST(howTo, DISABLED_createACustomRenderTask)
3335
#else
34-
TEST(howTo, createACustomRenderTask)
36+
HVT_TEST(howTo, createACustomRenderTask)
3537
#endif
3638
{
3739
// Helper to create the Hgi implementation.
@@ -137,10 +139,5 @@ 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-
143-
ASSERT_TRUE(context->_backend->saveImage(imageFile));
144-
145-
ASSERT_TRUE(context->_backend->compareImages(imageFile));
142+
ASSERT_TRUE(context->validateImages(computedImageName, imageFile));
146143
}

test/howTos/howTo05_UseSSAORenderTask.cpp

Lines changed: 5 additions & 8 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+
HVT_TEST(howTo, DISABLED_useSSAORenderTask)
3638
#else
37-
TEST(howTo, useSSAORenderTask)
39+
HVT_TEST(howTo, useSSAORenderTask)
3840
#endif
3941
{
4042
// Helper to create the Hgi implementation.
@@ -149,10 +151,5 @@ 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-
155-
ASSERT_TRUE(context->_backend->saveImage(imageFile));
156-
157-
ASSERT_TRUE(context->_backend->compareImages(imageFile));
154+
ASSERT_TRUE(context->validateImages(computedImageName, imageFile));
158155
}

test/howTos/howTo06_UseFXAARenderTask.cpp

Lines changed: 5 additions & 8 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+
HVT_TEST(howTo, DISABLED_useFXAARenderTask)
3537
#else
36-
TEST(howTo, useFXAARenderTask)
38+
HVT_TEST(howTo, useFXAARenderTask)
3739
#endif
3840
{
3941
// Helper to create the Hgi implementation.
@@ -134,10 +136,5 @@ 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-
140-
ASSERT_TRUE(context->_backend->saveImage(imageFile));
141-
142-
ASSERT_TRUE(context->_backend->compareImages(imageFile));
139+
ASSERT_TRUE(context->validateImages(computedImageName, imageFile));
143140
}

test/howTos/howTo07_UseIncludeExclude.cpp

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

2626
#include <gtest/gtest.h>
2727

28+
#include <RenderingFramework/TestFlags.h>
29+
2830
//
2931
// Include or exclude geometry prims on the fly?
3032
//
@@ -111,9 +113,9 @@ void CreateTest(const std::shared_ptr<TestHelpers::TestContext>& context,
111113
// FIXME: It's sometime failed to render on iOS.Refer to OGSMOD-6933.
112114
// Need to investigate if Android has similar issue too
113115
#if defined(__ANDROID__) || (TARGET_OS_IPHONE == 1)
114-
TEST(howTo, DISABLED_useCollectionToExclude)
116+
HVT_TEST(howTo, DISABLED_useCollectionToExclude)
115117
#else
116-
TEST(howTo, useCollectionToExclude)
118+
HVT_TEST(howTo, useCollectionToExclude)
117119
#endif
118120
{
119121
// Helper to create the Hgi implementation.
@@ -134,20 +136,15 @@ TEST(howTo, useCollectionToExclude)
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-
140-
ASSERT_TRUE(context->_backend->saveImage(imageFile));
141-
142-
ASSERT_TRUE(context->_backend->compareImages(imageFile));
139+
ASSERT_TRUE(context->validateImages(computedImageName, imageFile));
143140
}
144141

145142
// FIXME: It's sometime failed to render on iOS.Refer to OGSMOD-6933.
146143
// Need to investigate if Android has similar issue too
147144
#if defined(__ANDROID__) || (TARGET_OS_IPHONE == 1)
148-
TEST(howTo, DISABLED_useCollectionToInclude)
145+
HVT_TEST(howTo, DISABLED_useCollectionToInclude)
149146
#else
150-
TEST(howTo, useCollectionToInclude)
147+
HVT_TEST(howTo, useCollectionToInclude)
151148
#endif
152149
{
153150
// Helper to create the Hgi implementation.
@@ -168,10 +165,5 @@ TEST(howTo, useCollectionToInclude)
168165

169166
// Validates the rendering result.
170167

171-
const std::string imageFile = std::string(test_info_->test_suite_name()) + std::string("/") +
172-
std::string(test_info_->name());
173-
174-
ASSERT_TRUE(context->_backend->saveImage(imageFile));
175-
176-
ASSERT_TRUE(context->_backend->compareImages(imageFile));
168+
ASSERT_TRUE(context->validateImages(computedImageName, imageFile));
177169
}

0 commit comments

Comments
 (0)