From e25a3aede047111f023bfef2ccd8ff84814b5fe5 Mon Sep 17 00:00:00 2001 From: Brian Ho Date: Tue, 27 Aug 2019 01:44:29 +0000 Subject: [PATCH] Overload stream insertion for DawnTestParam Passing "--gtest_list_tests" as an argument to the gtest binary lists the tests in the binary. However, when the test suite is parameterized (like in the case of dawn_end2end_tests), the output will list the string name of the parameter along with the test name. Since there is no stream insertion overload for DawnTestParam, we get this output: ./dawn_end2end_tests --gtest_list_tests BasicTests. BufferSetSubData/OpenGL # GetParam() = 56-byte object <03-00 00-00 19... BufferSetSubData/Vulkan # GetParam() = 56-byte object <04-00 00-00 19... ... This CL adds an implementation to display the string name of the param instead. BUG=chromium:993457 TEST=run ./dawn_end2end_test --gtest_list_tests Change-Id: Ifae65a9eaf96448341e6ed1894f116f1af1154b7 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/10240 Commit-Queue: Brian Ho Reviewed-by: Austin Eng Reviewed-by: Kai Ninomiya --- src/tests/DawnTest.cpp | 22 +++++++++++----------- src/tests/DawnTest.h | 5 +++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/tests/DawnTest.cpp b/src/tests/DawnTest.cpp index 938c943469..41902a40f5 100644 --- a/src/tests/DawnTest.cpp +++ b/src/tests/DawnTest.cpp @@ -93,6 +93,17 @@ DawnTestParam ForceWorkarounds(const DawnTestParam& originParam, return newTestParam; } +std::ostream& operator<<(std::ostream& os, const DawnTestParam& param) { + os << ParamName(param.backendType); + for (const char* forceEnabledWorkaround : param.forceEnabledWorkarounds) { + os << "__e_" << forceEnabledWorkaround; + } + for (const char* forceDisabledWorkaround : param.forceDisabledWorkarounds) { + os << "__d_" << forceDisabledWorkaround; + } + return os; +} + // Implementation of DawnTestEnvironment void InitDawnEnd2EndTestEnvironment(int argc, char** argv) { @@ -710,17 +721,6 @@ namespace detail { return backends; } - std::string GetParamName(const testing::TestParamInfo& info) { - std::ostringstream ostream; - ostream << ParamName(info.param.backendType); - - for (const char* forceEnabledWorkaround : info.param.forceEnabledWorkarounds) { - ostream << "_" << forceEnabledWorkaround; - } - - return ostream.str(); - } - // Helper classes to set expectations template diff --git a/src/tests/DawnTest.h b/src/tests/DawnTest.h index 34a066946f..46337167dc 100644 --- a/src/tests/DawnTest.h +++ b/src/tests/DawnTest.h @@ -83,6 +83,8 @@ struct DawnTestParam { std::vector forceDisabledWorkarounds; }; +std::ostream& operator<<(std::ostream& os, const DawnTestParam& param); + // Shorthands for backend types used in the DAWN_INSTANTIATE_TEST extern const DawnTestParam D3D12Backend; extern const DawnTestParam MetalBackend; @@ -269,7 +271,7 @@ class DawnTest : public ::testing::TestWithParam { , testName, \ testing::ValuesIn(::detail::FilterBackends( \ testName##params, sizeof(testName##params) / sizeof(firstParam))), \ - ::detail::GetParamName) + testing::PrintToStringParamName()) // Skip a test when the given condition is satisfied. #define DAWN_SKIP_TEST_IF(condition) \ @@ -282,7 +284,6 @@ namespace detail { // Helper functions used for DAWN_INSTANTIATE_TEST bool IsBackendAvailable(dawn_native::BackendType type); std::vector FilterBackends(const DawnTestParam* params, size_t numParams); - std::string GetParamName(const testing::TestParamInfo& info); // All classes used to implement the deferred expectations should inherit from this. class Expectation {