-
Notifications
You must be signed in to change notification settings - Fork 0
OGSMOD-6769: Run Vulkan unit tests after OpenGL for Viewport Toolbox #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2a11a88
a03f8ff
98bde86
4e9a16e
d414f15
2ec443a
d02add7
0f86209
f16df9c
5bc25e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,89 @@ | |
// | ||
#pragma once | ||
|
||
#include <gtest/gtest.h> | ||
#include <string> | ||
|
||
#define HVT_TEST(TestSuiteName, TestName) \ | ||
std::string ParamTestName##TestName(const testing::TestParamInfo<std::string>& info) \ | ||
{ \ | ||
return info.param; \ | ||
} \ | ||
class TestName : public ::testing::TestWithParam<std::string> \ | ||
{ \ | ||
public: \ | ||
void HVTTest##TestName( \ | ||
[[maybe_unused]] const std::string& computedImageName, \ | ||
[[maybe_unused]] const std::string& imageFile); \ | ||
}; \ | ||
/* TODO: Enable "Vulkan" backend when Vulkan support is complete and stable. \ | ||
Currently, only "OpenGL" is enabled for testing. */ \ | ||
INSTANTIATE_TEST_SUITE_P(TestSuiteName, TestName, ::testing::Values(/*"Vulkan",*/ "OpenGL"), \ | ||
ParamTestName##TestName); \ | ||
TEST_P(TestName, TestName) \ | ||
{ \ | ||
TestHelpers::gRunVulkanTests = (GetParam() == "Vulkan"); \ | ||
TestHelpers::gTestNames = TestHelpers::getTestNames( \ | ||
::testing::UnitTest::GetInstance()->current_test_info()); \ | ||
const std::string imageFile = TestHelpers::gTestNames.suiteName + \ | ||
std::string("/") + TestHelpers::gTestNames.fixtureName; \ | ||
const std::string computedImageName = TestHelpers::appendParamToImageFile(imageFile); \ | ||
HVTTest##TestName(computedImageName, imageFile); \ | ||
} \ | ||
void TestName::HVTTest##TestName( \ | ||
[[maybe_unused]] const std::string& computedImageName, \ | ||
[[maybe_unused]] const std::string& imageFile) | ||
|
||
namespace TestHelpers | ||
{ | ||
inline bool gRunVulkanTests = false; | ||
} // namespace TestHelpers | ||
struct TestNames | ||
{ | ||
/// @brief The name of the test suite extracted from the test information | ||
std::string suiteName; | ||
/// @brief The name of the test fixture extracted from the test suite name | ||
std::string fixtureName; | ||
/// @brief The parameter name extracted from the test name for parameterized tests | ||
std::string paramName; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add Doxygen comments to explain these three data members. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
}; | ||
|
||
inline bool gRunVulkanTests = false; | ||
inline TestNames gTestNames = TestNames {}; | ||
|
||
inline TestNames getTestNames(const ::testing::TestInfo* testInfo) | ||
{ | ||
TestNames testNames; | ||
if (testInfo) | ||
{ | ||
std::string testSuiteName = testInfo->test_suite_name(); | ||
std::string testName = testInfo->name(); | ||
|
||
size_t pos = testSuiteName.find('/'); | ||
if (pos != std::string::npos) | ||
{ | ||
testNames.suiteName = testSuiteName.substr(0, pos); | ||
testNames.fixtureName = testSuiteName.substr(pos + 1); | ||
} | ||
|
||
pos = testName.find('/'); | ||
if (pos != std::string::npos) | ||
{ | ||
testNames.paramName = testName.substr(pos + 1); | ||
} | ||
} | ||
return testNames; | ||
} | ||
|
||
/// Gets the image file based on the test parameter. | ||
inline std::string getComputedImagePath() | ||
{ | ||
return gTestNames.paramName.empty() ? gTestNames.fixtureName | ||
: (gTestNames.fixtureName + "_" + gTestNames.paramName); | ||
} | ||
|
||
/// Appends image file based on the test parameter. | ||
inline std::string appendParamToImageFile(const std::string& fileName) | ||
{ | ||
return gTestNames.paramName.empty() ? fileName : (fileName + "_" + gTestNames.paramName); | ||
} | ||
|
||
} // namespace TestHelpers |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,6 +153,15 @@ bool HydraRendererContext::compareImages( | |
return compareImages(inFile, outFile, threshold, pixelCountThreshold); | ||
} | ||
|
||
bool HydraRendererContext::compareImage(const std::string& computedFilename, | ||
const std::string& baselineFilename, const uint8_t threshold, const uint8_t pixelCountThreshold) | ||
{ | ||
const auto baselinePath = getBaselineFolder(); | ||
const std::string baseline = getFilename(baselinePath, baselineFilename); | ||
const std::string computed = getFilename(outFullpath, computedFilename + "_computed"); | ||
return compareImages(computed, baseline, threshold, pixelCountThreshold); | ||
} | ||
|
||
bool HydraRendererContext::compareOutputImages(const std::string& fileName1, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this method be removed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is still used in other places. |
||
const std::string& fileName2, const uint8_t threshold, const uint8_t pixelCountThreshold) | ||
{ | ||
|
@@ -353,6 +362,15 @@ void TestContext::run(TestHelpers::TestStage& stage, hvt::Viewport* viewport, si | |
_backend->run(render, viewport->GetLastFramePass()); | ||
} | ||
|
||
bool TestContext::validateImages(const std::string& computedImageName, const std::string& imageFile, | ||
const uint8_t threshold, const uint8_t pixelCountThreshold) | ||
{ | ||
if (!_backend->saveImage(computedImageName)) { | ||
return false; | ||
} | ||
return _backend->compareImage(computedImageName, imageFile, threshold, pixelCountThreshold); | ||
} | ||
|
||
FramePassInstance FramePassInstance::CreateInstance(std::string const& rendererName, | ||
pxr::UsdStageRefPtr& stage, std::shared_ptr<TestHelpers::HydraRendererContext>& backend, | ||
std::string const& uid) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,10 +22,12 @@ | |
|
||
#include <gtest/gtest.h> | ||
|
||
#include <RenderingFramework/TestFlags.h> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Already included in #include There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hodoulp True, but isn't it good practice to include what is used in a cpp? That being said, this file will compile without the include, so you are right about that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In principle yes. In that specific case it adds useless changes everywhere. |
||
|
||
// | ||
// How to create one frame pass using Storm? | ||
// | ||
TEST(howTo, createOneFramePass) | ||
HVT_TEST(howTo, createOneFramePass) | ||
{ | ||
// Helper to create the Hgi implementation. | ||
|
||
|
@@ -97,10 +99,5 @@ TEST(howTo, createOneFramePass) | |
|
||
// Validates the rendering result. | ||
|
||
const std::string imageFile = std::string(test_info_->test_suite_name()) + std::string("/") + | ||
std::string(test_info_->name()); | ||
|
||
ASSERT_TRUE(context->_backend->saveImage(imageFile)); | ||
|
||
ASSERT_TRUE(context->_backend->compareImages(imageFile)); | ||
ASSERT_TRUE(context->validateImages(computedImageName, imageFile)); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Suggestion] We missed perhaps something to limit changes and/or build issues. The parameter names are those used everywhere by default, but in some case some utests customize their content for specific needs. If you rename
computedImageName
->defaultComputedImageName
&imageFile
->defaultImageFile
it could perhaps ease the refactoring work.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, we can do it in a future PR.