Skip to content

Conversation

sm-adsk
Copy link
Contributor

@sm-adsk sm-adsk commented Sep 25, 2025

The Vulkan tests are currently disabled. This PR introduces the HVT_TEST macro that will allow to parameterize which backends (OpenGL, Vulkan, etc...) are to be tested in a future PR.
Currently only OpenGL is tested.

@sm-adsk sm-adsk force-pushed the manars/OGSMOD-6769/parameterize-unit-tests branch 7 times, most recently from 9786129 to ed8c718 Compare September 29, 2025 13:20
@sm-adsk sm-adsk marked this pull request as ready for review September 29, 2025 13:25
@hodoulp
Copy link
Contributor

hodoulp commented Sep 29, 2025

Global comments:

  • The title does explain the content of the pull request i.e., the utest does not run after OpenGL.
  • put a description of the pull request.

return fullFilepath;
};

bool HydraRendererContext::compareImages(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this method be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is still used by other functions.

return compareImages(computed, baseLine, threshold, 1);
}

bool HydraRendererContext::compareOutputImages(const std::string& fileName1,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this method be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is still used in other places.

#include <gtest/gtest.h>

TEST(TestViewportToolbox, framePassUID)
#include <RenderingFramework/TestFlags.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This include is already in RenderingFramework/TestContextCreator.h (at line 25)


#include <gtest/gtest.h>

#include <RenderingFramework/TestFlags.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already included in #include <RenderingFramework/TestContextCreator.h>

Copy link
Contributor

Choose a reason for hiding this comment

The 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?
This makes the code of this file more robust to future changes in TestContextCreator.h, and it is also clearer, in my opinion.

That being said, this file will compile without the include, so you are right about that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In principle yes. In that specific case it adds useless changes everywhere.
Anyway, that's really minor.

TestHelpers::getTestNames(::testing::UnitTest::GetInstance()->current_test_info()); \
AGPTestDefaultBackend##TestName(); \
} \
void AGPTestDefaultBackend##TestName()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a method is created the name must be unique but TestName could not be unique.
To be safe it should be:
void HVTTestDefaultBackend##TestSuiteName##TestName();

{ \
TestHelpers::gParameterizedTests = false; \
TestHelpers::gTestNames = TestHelpers::getTestNames( \
::testing::UnitTest::GetInstance()->current_test_info()); \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few missing spaces.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

// If parameterized tests are used, test_suite_name and name returns
// SuiteName/TestName/Param. Hence the following filtering is
// needed.
if (TestHelpers::gParameterizedTests == true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (TestHelpers::gParameterizedTests == true) -> if (TestHelpers::gParameterizedTests)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces the HVT_TEST macro system to enable parameterized testing for different rendering backends (OpenGL, Vulkan, etc.) in the Viewport Toolbox, laying groundwork for future Vulkan test enablement while currently only testing OpenGL.

  • Replaces standard TEST macros with HVT_TEST and HVT_TEST_DEFAULT_BACKEND macros
  • Updates image comparison logic to use new helper functions for parameterized test naming
  • Adds backend parameterization infrastructure in TestFlags.h

Reviewed Changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/tests/testTaskManager.cpp Converts TEST macros to HVT_TEST variants and updates image comparison calls
test/tests/testSearches.cpp Converts TEST macros to HVT_TEST variants and updates image comparison calls
test/tests/testFramePasses.cpp Converts TEST macros to HVT_TEST variants and updates image comparison calls
test/tests/testFramePass.cpp Converts TEST macros to HVT_TEST variants, adds TestFlags.h include, and updates image comparison calls
test/howTos/*.cpp Converts TEST macros to HVT_TEST variants, adds TestFlags.h includes, and updates image comparison calls
test/RenderingFramework/TestHelpers.h Adds compareImage method declaration
test/RenderingFramework/TestHelpers.cpp Implements compareImage method
test/RenderingFramework/TestFlags.h Adds HVT_TEST macro definitions and test naming helper functions

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

{ \
public: \
void AGPTest##TestName(); \
}; \
Copy link

Copilot AI Sep 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commented out 'Vulkan' parameter suggests incomplete implementation. Consider adding a TODO comment explaining when Vulkan will be enabled or use a more explicit conditional compilation approach.

Suggested change
}; \
}; \
/* TODO: Enable "Vulkan" backend when Vulkan support is complete and stable.
Currently, only "OpenGL" is enabled for testing. */

Copilot uses AI. Check for mistakes.

// Validates the rendering result.

std::string imageFile = std::string(test_info_->name());
const std::string computedFileName = TestHelpers::getComputedImagePath();
Copy link

Copilot AI Sep 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assignment to const variable 'computedFileName' will not compile. The variable should be declared as non-const or the logic should be restructured.

Suggested change
const std::string computedFileName = TestHelpers::getComputedImagePath();
std::string computedFileName = TestHelpers::getComputedImagePath();

Copilot uses AI. Check for mistakes.

public: \
void AGPTest##TestName(); \
}; \
INSTANTIATE_TEST_SUITE_P(TestSuiteName, TestName, ::testing::Values(/*"Vulkan",*/ "OpenGL"), \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am guessing this is the line that will need to be changed to activate Vulkan:
INSTANTIATE_TEST_SUITE_P(TestSuiteName, TestName, ::testing::Values(/*"Vulkan",*/ "OpenGL"),
->
INSTANTIATE_TEST_SUITE_P(TestSuiteName, TestName, ::testing::Values("Vulkan", "OpenGL"),


#include <gtest/gtest.h>

#include <RenderingFramework/TestFlags.h>
Copy link
Contributor

Choose a reason for hiding this comment

The 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?
This makes the code of this file more robust to future changes in TestContextCreator.h, and it is also clearer, in my opinion.

That being said, this file will compile without the include, so you are right about that.

::testing::UnitTest::GetInstance()->current_test_info()); \
AGPTestDefaultBackend##TestName(); \
} \
void AGPTestDefaultBackend##TestName()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: The block is the exact same as, defined above:

#define HVT_TEST_DEFAULT_BACKEND(TestSuiteName, TestName)                                          \
    void AGPTestDefaultBackend##TestName();                                                        \
    TEST(TestSuiteName, TestName)                                                                  \
    {                                                                                              \
        TestHelpers::gParameterizedTests = false;                                                  \
        TestHelpers::gTestNames          = TestHelpers::getTestNames(                              \
            ::testing::UnitTest::GetInstance()->current_test_info());                              \
        AGPTestDefaultBackend##TestName();                                                         \
    }                                                                                              \
    void AGPTestDefaultBackend##TestName()

The only difference is the name.
I am guessing you could define it as follow to prevent repetition:
#define HVT_TEST(TestSuiteName, TestName) HVT_TEST_DEFAULT_BACKEND(TestSuiteName, TestName)

@sm-adsk sm-adsk force-pushed the manars/OGSMOD-6769/parameterize-unit-tests branch from ed8c718 to 9e6bc1d Compare September 29, 2025 20:07
@hodoulp
Copy link
Contributor

hodoulp commented Sep 29, 2025

@sm-adsk do not squash your commits because I cannot see what you changed.
Note: The squash will be done before merging.

@hodoulp
Copy link
Contributor

hodoulp commented Sep 29, 2025

Copy link
Contributor

@hodoulp hodoulp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sebastienberube-adsk
Copy link
Contributor

sebastienberube-adsk commented Sep 29, 2025

@sm-adsk I have approved, but I believe these comments should be addressed, at the minimum:
https://github.com/Autodesk/hydra-viewport-toolbox/pull/76/files#r2388970787
https://github.com/Autodesk/hydra-viewport-toolbox/pull/76/files#r2388713260
https://github.com/Autodesk/hydra-viewport-toolbox/pull/76/files#r2389079932
https://github.com/Autodesk/hydra-viewport-toolbox/pull/76/files#r2388719809

These links do not highlight any code section i.e., seem to be invalid.

The squash commit might have invalidated these links.
For reference, the 4 things I though were most important were:

  • reuse HVT_TEST_DEFAULT_BACKEND() in HVT_TEST() when vulkan is disabled
  • if (TestHelpers::gParameterizedTests == true) -> if (TestHelpers::gParameterizedTests)
  • AGPTestDefaultBackend -> HVTTestDefaultBackend
  • remove const that can break the compilation in test/tests/testSearches.cpp:
    const std::string computedFileName = TestHelpers::getComputedImagePath();
    ->
    std::string computedFileName = TestHelpers::getComputedImagePath();

{ \
return info.param; \
} \
class TestName : public ::testing::TestWithParam<std::string> \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed:
Param##TestSuiteName##TestName -> Param##TestSuiteName##TestName
class TestName -> class UnitTest##TestSuiteName##TestName

Copy link
Contributor

@hodoulp hodoulp Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, the method can be a static method from class UnitTest##TestSuiteName##TestName

class UnitTest##TestSuiteName##TestName : public ::testing::TestWithParam<std::string>  
{
public:
    std::string GetParam(testing::TestParamInfo<std::string> const& info)
    {
        return info.param;
    }
    void execute();
};


inline bool gRunVulkanTests = false;
inline bool gParameterizedTests = false;
inline TestNames gTestNames = TestNames {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These three declarations are 'strange' i.e., inline !?
Does it mean that they will be created every time this file header is included?

My current understand is that they must be static to have only one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replacing inline with static gives the following error on Jenkins:
'TestHelpers::gRunVulkanTests' defined but not used [-Werror=unused-variable]

{
std::string suiteName;
std::string fixtureName;
std::string paramName;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add Doxygen comments to explain these three data members.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

TestHelpers::gTestNames = TestHelpers::getTestNames( \
::testing::UnitTest::GetInstance()->current_test_info()); \
HVTTest##TestName(); \
} \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a global data for gRunVulkanTests & gTestNames when you can change the code to be:

const auto backendIsVulkan = (GetParam() == "Vulkan"); 
const auto testInfo = (::testing::UnitTest::GetInstance()->current_test_info());
HVTTest##TestName(backendIsVulkan, testInfo); 

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, I don't understand gParameterizedTests ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gParameterizedTests has been deprecated and is now removed.

@sm-adsk sm-adsk force-pushed the manars/OGSMOD-6769/parameterize-unit-tests branch 3 times, most recently from 961b6d1 to 86dfd10 Compare October 1, 2025 14:02
public: \
void HVTTest##TestName( \
[[maybe_unused]] const std::string& computedImageName, \
[[maybe_unused]] const std::string& imageFile); \
Copy link
Contributor

@hodoulp hodoulp Oct 1, 2025

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.

Copy link
Contributor Author

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.

@hodoulp hodoulp self-requested a review October 1, 2025 15:00
Copy link
Contributor

@hodoulp hodoulp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The direction is the right one but I understand that it could take some time to finalize HVT & the other dependent repos & I don't want to block you so I approve the pull request to unlock it. But it must still have an explicit @sebastienberube-adsk approval before merging.

@sm-adsk sm-adsk force-pushed the manars/OGSMOD-6769/parameterize-unit-tests branch from 93fad29 to 0f86209 Compare October 3, 2025 01:00
@sm-adsk sm-adsk merged commit 116c931 into main Oct 7, 2025
10 checks passed
@sm-adsk sm-adsk deleted the manars/OGSMOD-6769/parameterize-unit-tests branch October 7, 2025 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants