Commit 7456a5e0 authored by Sean Gilhuly's avatar Sean Gilhuly Committed by Commit Bot

Add names to tuple-parameterized tests

Test names can only contain alphanumeric characters, plus underscores.
testing::PrintToStringParamName() stringifies tuples using characters
that aren't valid for test names.

Add a similar function which joins each element using underscores. This
will generate valid names for test parameterization, provided each
element of the tuple can be written using valid characters.

Bug: 1092945, 1117587
Change-Id: I868b1d4040a93bdbf763dbb45b94ff15f181dd18
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2376882Reviewed-by: default avatarkylechar <kylechar@chromium.org>
Commit-Queue: Sean Gilhuly <sgilhuly@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803182}
parent 3bd3ee29
......@@ -6,9 +6,29 @@
#define CC_TEST_TEST_TYPES_H_
#include <ostream>
#include <string>
#include "base/strings/string_util.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace cc {
// Joins all elements of a testing::tuple using an underscore. Use as the fourth
// parameter of INSTANTIATE_TEST_SUITE_P() instead of
// testing::PrintToStringParamName() to generate a valid parameter label. Each
// element of the tuple must be printable, and each combination of tuple values
// must produce a unique string.
// Underscores shouldn't be used in test suite names due to a risk of name
// collision, but this doesn't apply to parameterization labels.
struct PrintTupleToStringParamName {
template <class ParamType>
std::string operator()(const testing::TestParamInfo<ParamType>& info) const {
return base::JoinString(
testing::internal::UniversalTersePrintTupleFieldsToStrings(info.param),
"_");
}
};
enum class TestRendererType {
kGL,
kSkiaGL,
......@@ -35,9 +55,7 @@ struct RasterTestConfig {
void PrintTo(TestRendererType type, std::ostream* os);
// Joins the |renderer_type| and |raster_type| labels using an underscore
// character, resulting in e.g. "Test/SkiaGL_OOP". Underscores shouldn't be used
// in test suite names due to a risk of name collision, but this doesn't apply
// to parameterization labels.
// character, resulting in e.g. "Test/SkiaGL_OOP".
void PrintTo(const RasterTestConfig& config, std::ostream* os);
} // namespace cc
......
......@@ -21,6 +21,12 @@
#if !defined(OS_ANDROID)
// SkBlendMode is declared in the global namespace, so this function also needs
// to be in the global namespace.
void PrintTo(SkBlendMode mode, std::ostream* os) {
*os << SkBlendMode_Name(mode);
}
namespace cc {
namespace {
......@@ -271,7 +277,8 @@ std::vector<RasterTestConfig> const kTestCases = {
INSTANTIATE_TEST_SUITE_P(B,
LayerTreeHostBlendingPixelTest,
::testing::Combine(::testing::ValuesIn(kTestCases),
::testing::ValuesIn(kBlendModes)));
::testing::ValuesIn(kBlendModes)),
PrintTupleToStringParamName());
TEST_P(LayerTreeHostBlendingPixelTest, BlendingWithRoot) {
const int kRootWidth = 2;
......
......@@ -27,6 +27,14 @@
#include "gpu/GLES2/gl2extchromium.h"
namespace cc {
// CompositorMode is declared in the cc namespace, so this function also needs
// to be in the cc namespace.
void PrintTo(CompositorMode mode, std::ostream* os) {
*os << (mode == CompositorMode::THREADED ? "MultiThreaded"
: "SingleThreaded");
}
namespace {
auto CombineWithCompositorModes(const std::vector<TestRendererType>& types) {
......@@ -169,7 +177,8 @@ INSTANTIATE_TEST_SUITE_P(All,
LayerTreeHostCopyRequestTestMultipleRequests,
CombineWithCompositorModes(
{TestRendererType::kGL, TestRendererType::kSkiaGL,
TestRendererType::kSoftware}));
TestRendererType::kSoftware}),
PrintTupleToStringParamName());
TEST_P(LayerTreeHostCopyRequestTestMultipleRequests, Test) {
RunTest(compositor_mode());
......@@ -204,7 +213,8 @@ INSTANTIATE_TEST_SUITE_P(
All,
LayerTreeHostCopyRequestTestMultipleRequestsOutOfOrder,
CombineWithCompositorModes({TestRendererType::kGL,
TestRendererType::kSkiaGL}));
TestRendererType::kSkiaGL}),
PrintTupleToStringParamName());
TEST_P(LayerTreeHostCopyRequestTestMultipleRequestsOutOfOrder, Test) {
RunTest(compositor_mode());
......@@ -263,7 +273,8 @@ INSTANTIATE_TEST_SUITE_P(
All,
LayerTreeHostCopyRequestCompletionCausesCommit,
CombineWithCompositorModes({TestRendererType::kGL,
TestRendererType::kSkiaGL}));
TestRendererType::kSkiaGL}),
PrintTupleToStringParamName());
TEST_P(LayerTreeHostCopyRequestCompletionCausesCommit, Test) {
RunTest(compositor_mode());
......@@ -370,7 +381,8 @@ INSTANTIATE_TEST_SUITE_P(
All,
LayerTreeHostCopyRequestTestLayerDestroyed,
CombineWithCompositorModes({TestRendererType::kGL,
TestRendererType::kSkiaGL}));
TestRendererType::kSkiaGL}),
PrintTupleToStringParamName());
TEST_P(LayerTreeHostCopyRequestTestLayerDestroyed, Test) {
RunTest(compositor_mode());
......@@ -476,7 +488,8 @@ INSTANTIATE_TEST_SUITE_P(
All,
LayerTreeHostCopyRequestTestInHiddenSubtree,
CombineWithCompositorModes({TestRendererType::kGL,
TestRendererType::kSkiaGL}));
TestRendererType::kSkiaGL}),
PrintTupleToStringParamName());
TEST_P(LayerTreeHostCopyRequestTestInHiddenSubtree, Test) {
RunTest(compositor_mode());
......@@ -597,7 +610,8 @@ INSTANTIATE_TEST_SUITE_P(
All,
LayerTreeHostTestHiddenSurfaceNotAllocatedForSubtreeCopyRequest,
CombineWithCompositorModes({TestRendererType::kGL,
TestRendererType::kSkiaGL}));
TestRendererType::kSkiaGL}),
PrintTupleToStringParamName());
TEST_P(LayerTreeHostTestHiddenSurfaceNotAllocatedForSubtreeCopyRequest, Test) {
RunTest(compositor_mode());
......@@ -653,7 +667,8 @@ INSTANTIATE_TEST_SUITE_P(
All,
LayerTreeHostCopyRequestTestClippedOut,
CombineWithCompositorModes({TestRendererType::kGL,
TestRendererType::kSkiaGL}));
TestRendererType::kSkiaGL}),
PrintTupleToStringParamName());
TEST_P(LayerTreeHostCopyRequestTestClippedOut, Test) {
RunTest(compositor_mode());
......@@ -713,7 +728,8 @@ INSTANTIATE_TEST_SUITE_P(
All,
LayerTreeHostCopyRequestTestScaledLayer,
CombineWithCompositorModes({TestRendererType::kGL,
TestRendererType::kSkiaGL}));
TestRendererType::kSkiaGL}),
PrintTupleToStringParamName());
TEST_P(LayerTreeHostCopyRequestTestScaledLayer, Test) {
RunTest(compositor_mode());
......@@ -808,7 +824,8 @@ INSTANTIATE_TEST_SUITE_P(
All,
LayerTreeHostTestAsyncTwoReadbacksWithoutDraw,
CombineWithCompositorModes({TestRendererType::kGL,
TestRendererType::kSkiaGL}));
TestRendererType::kSkiaGL}),
PrintTupleToStringParamName());
TEST_P(LayerTreeHostTestAsyncTwoReadbacksWithoutDraw, Test) {
RunTest(compositor_mode());
......@@ -951,7 +968,8 @@ INSTANTIATE_TEST_SUITE_P(
All,
LayerTreeHostCopyRequestTestDeleteSharedImage,
CombineWithCompositorModes({TestRendererType::kGL,
TestRendererType::kSkiaGL}));
TestRendererType::kSkiaGL}),
PrintTupleToStringParamName());
TEST_P(LayerTreeHostCopyRequestTestDeleteSharedImage, Test) {
RunTest(compositor_mode());
......@@ -1094,7 +1112,8 @@ INSTANTIATE_TEST_SUITE_P(
All,
LayerTreeHostCopyRequestTestCreatesSharedImage,
CombineWithCompositorModes({TestRendererType::kGL,
TestRendererType::kSkiaGL}));
TestRendererType::kSkiaGL}),
PrintTupleToStringParamName());
TEST_P(LayerTreeHostCopyRequestTestCreatesSharedImage, Test) {
RunTest(compositor_mode());
......@@ -1182,7 +1201,8 @@ INSTANTIATE_TEST_SUITE_P(
All,
LayerTreeHostCopyRequestTestDestroyBeforeCopy,
CombineWithCompositorModes({TestRendererType::kGL,
TestRendererType::kSkiaGL}));
TestRendererType::kSkiaGL}),
PrintTupleToStringParamName());
TEST_P(LayerTreeHostCopyRequestTestDestroyBeforeCopy, Test) {
RunTest(compositor_mode());
......@@ -1265,7 +1285,8 @@ INSTANTIATE_TEST_SUITE_P(
All,
LayerTreeHostCopyRequestTestShutdownBeforeCopy,
CombineWithCompositorModes({TestRendererType::kGL,
TestRendererType::kSkiaGL}));
TestRendererType::kSkiaGL}),
PrintTupleToStringParamName());
TEST_P(LayerTreeHostCopyRequestTestShutdownBeforeCopy, Test) {
RunTest(compositor_mode());
......@@ -1397,7 +1418,8 @@ INSTANTIATE_TEST_SUITE_P(
All,
LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest,
CombineWithCompositorModes({TestRendererType::kGL,
TestRendererType::kSkiaGL}));
TestRendererType::kSkiaGL}),
PrintTupleToStringParamName());
TEST_P(LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest, Test) {
RunTest(compositor_mode());
......
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