Commit b6eb3412 by Shahbaz Youssefi Committed by Commit Bot

Allow testing::Combine in ANGLE_INSTANTIATE_TEST

In most tests, ANGLE_INSTANTIATE_TEST is sufficient. This macro takes a a variable number of angle::PlatformParameters and instantiates that many tests. angle::PlatformParameters already aggregates multiple configurations. In a number of cases, however, it would be useful to have even more configurations in conjunction with angle::PlatformParameters. gl_tests/MultiviewDrawTest.cpp solves this by creating a custom class that combines angle::PlatformParameters with test-specific configurations. gl_tests/CopyTextureTest.cpp included numerous tests with hardcoded values for its configurations. This change introduces ANGLE_INSTANTIATE_TEST_COMBINE_N. These macros take N testing::* parameter generators followed by the list of angle::PlatformParameters as per ANGLE_INSTANTIATE_TEST. They then testing::Combine these generators, placing the angle::PlatformParameters list first. Tests that use this functionality would inherit from ANGLETestWithParams<std::tuple<angle::PlatformParameters, ...>> instead of ANGLETest, and instantiate their tests as such: ANGLE_INSTANTIATE_TEST_COMBINE_3(TestName, PrettyPrintFunction, testing::ValuesIn(listOfParameters), testing::Values(some, other, parameters), testing::Bool(), ES2_D3D9(), ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES(), ES2_VULKAN()); The name of the test, as used by --gtest_filter, will be suffixed with the output of the PrettyPrintFunction. Assuming the tuple type given to ANGLETestWithParams is Params, this function takes a ::testing::TestParamInfo<Params> input to pretty-print the name of the test variation. It is recommended to output the platform first for consistency with other tests. gl_tests/CopyTextureTest.cpp is modified to use this macro. Bug: angleproject:3125 Change-Id: I0311b84659578bf3c7b5e9673b41cc3a3adfc50d Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1506236 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarYuly Novikov <ynovikov@chromium.org>
parent c9bc33cf
......@@ -1161,18 +1161,6 @@ void ANGLETestBase::SetWindowVisible(bool isVisible)
mOSWindow->setVisible(isVisible);
}
ANGLETest::ANGLETest() : ANGLETestBase(GetParam()) {}
void ANGLETest::SetUp()
{
ANGLETestBase::ANGLETestSetUp();
}
void ANGLETest::TearDown()
{
ANGLETestBase::ANGLETestTearDown();
}
bool IsIntel()
{
std::string rendererString(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
......
......@@ -434,16 +434,32 @@ class ANGLETestBase
static Optional<EGLint> mLastRendererType;
};
class ANGLETest : public ANGLETestBase, public ::testing::TestWithParam<angle::PlatformParameters>
template <typename Params = angle::PlatformParameters>
class ANGLETestWithParam : public ANGLETestBase, public ::testing::TestWithParam<Params>
{
protected:
ANGLETest();
ANGLETestWithParam();
public:
void SetUp() override;
void TearDown() override;
void SetUp() override { ANGLETestBase::ANGLETestSetUp(); }
void TearDown() override { ANGLETestBase::ANGLETestTearDown(); }
};
template <typename Params>
ANGLETestWithParam<Params>::ANGLETestWithParam()
: ANGLETestBase(std::get<angle::PlatformParameters>(this->GetParam()))
{}
template <>
inline ANGLETestWithParam<angle::PlatformParameters>::ANGLETestWithParam()
: ANGLETestBase(this->GetParam())
{}
// Note: this hack is not necessary in C++17. Once we switch to C++17, we can just rename
// ANGLETestWithParam to ANGLETest.
using ANGLETest = ANGLETestWithParam<>;
class ANGLETestEnvironment : public testing::Environment
{
public:
......
......@@ -51,15 +51,50 @@ std::vector<T> FilterTestParams(const std::vector<T> &params)
return FilterTestParams(params.data(), params.size());
}
// Used to generate valid test names out of testing::PrintToStringParamName used in combined tests.
struct CombinedPrintToStringParamName
{
template <class ParamType>
std::string operator()(const testing::TestParamInfo<ParamType> &info) const
{
std::string name = testing::PrintToStringParamName()(info);
std::string sanitized;
for (const char c : name)
{
if (c == ',')
{
sanitized += '_';
}
else if (isalnum(c) || c == '_')
{
sanitized += c;
}
}
return sanitized;
}
};
#define ANGLE_INSTANTIATE_TEST_PLATFORMS(testName) \
testing::ValuesIn(::angle::FilterTestParams(testName##params, ArraySize(testName##params)))
// Instantiate the test once for each extra argument. The types of all the
// arguments must match, and getRenderer must be implemented for that type.
#define ANGLE_INSTANTIATE_TEST(testName, firstParam, ...) \
const decltype(firstParam) testName##params[] = {firstParam, ##__VA_ARGS__}; \
INSTANTIATE_TEST_SUITE_P(, testName, \
testing::ValuesIn(::angle::FilterTestParams( \
testName##params, ArraySize(testName##params))), \
#define ANGLE_INSTANTIATE_TEST(testName, first, ...) \
const decltype(first) testName##params[] = {first, ##__VA_ARGS__}; \
INSTANTIATE_TEST_SUITE_P(, testName, ANGLE_INSTANTIATE_TEST_PLATFORMS(testName), \
testing::PrintToStringParamName())
// Instantiate the test for a combination of N parameters and the enumeration of platforms in the
// extra args, similar to ANGLE_INSTANTIATE_TEST. The macros are defined only for the Ns currently
// in use, and can be expanded as necessary.
#define ANGLE_INSTANTIATE_TEST_COMBINE_5(testName, print, combine1, combine2, combine3, combine4, \
combine5, first, ...) \
const decltype(first) testName##params[] = {first, ##__VA_ARGS__}; \
INSTANTIATE_TEST_SUITE_P(, testName, \
testing::Combine(ANGLE_INSTANTIATE_TEST_PLATFORMS(testName), \
combine1, combine2, combine3, combine4, combine5), \
print)
// Checks if a config is expected to be supported by checking a system-based white list.
bool IsConfigWhitelisted(const SystemInfo &systemInfo, const PlatformParameters &param);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment