Chromium Code Reviews| Index: chrome/test/perf/frame_rate/frame_rate_tests.cc |
| diff --git a/chrome/test/perf/frame_rate/frame_rate_tests.cc b/chrome/test/perf/frame_rate/frame_rate_tests.cc |
| index 41f8bd84ebf875b84b80af89b7887e4488a67a47..bfd0c92c5de9d41f787cda659b9c008220339803 100644 |
| --- a/chrome/test/perf/frame_rate/frame_rate_tests.cc |
| +++ b/chrome/test/perf/frame_rate/frame_rate_tests.cc |
| @@ -9,35 +9,41 @@ |
| #include "base/path_service.h" |
| #include "base/string_number_conversions.h" |
| #include "base/test/test_timeouts.h" |
| +#include "base/test/trace_event_analyzer.h" |
| #include "base/utf_string_conversions.h" |
| #include "chrome/common/chrome_paths.h" |
| #include "chrome/common/chrome_switches.h" |
| +#include "chrome/test/automation/automation_proxy.h" |
| #include "chrome/test/automation/tab_proxy.h" |
| #include "chrome/test/ui/javascript_test_util.h" |
| #include "chrome/test/ui/ui_perf_test.h" |
| #include "net/base/net_util.h" |
| +#include "ui/gfx/gl/gl_implementation.h" |
| #include "ui/gfx/gl/gl_switches.h" |
| namespace { |
| enum FrameRateTestFlags { |
| - kRequiresGpu = 1 << 0, // only execute test if --enable-gpu |
| - kDisableGpu = 1 << 1, // run test without gpu acceleration |
| - kMakeBodyComposited = 1 << 2, // force the test to use the compositor |
| - kDisableVsync = 1 << 3, // do not lock animation on vertical refresh |
| - kUseReferenceBuild = 1 << 4, // run test using the reference chrome build |
| - kInternal = 1 << 5, // Test uses internal test data |
| - kHasRedirect = 1 << 6, // Test page contains an HTML redirect |
| + kUseGpu = 1 << 0, // Only execute test if --enable-gpu, and verify |
| + // that test ran on GPU. This is required for |
| + // tests that run on GPU. |
| + kForceGpuComposited = (1 << 1) | kUseGpu, // Force the test to use the |
| + // compositor. |
| + kDisableVsync = 1 << 2, // Do not limit framerate to vertical refresh. |
| + // when on GPU, nor to 60hz when not on GPU. |
| + kUseReferenceBuild = 1 << 3, // Run test using the reference chrome build. |
| + kInternal = 1 << 4, // Test uses internal test data. |
| + kHasRedirect = 1 << 5, // Test page contains an HTML redirect. |
| }; |
| std::string GetSuffixForTestFlags(int flags) { |
| std::string suffix; |
| - if (flags & kMakeBodyComposited) |
| + if (flags & kForceGpuComposited) |
| suffix += "_comp"; |
| + if (flags & kUseGpu) |
| + suffix += "_gpu"; |
| if (flags & kDisableVsync) |
| suffix += "_novsync"; |
| - if (flags & kDisableGpu) |
| - suffix += "_nogpu"; |
| if (flags & kUseReferenceBuild) |
| suffix += "_ref"; |
| return suffix; |
| @@ -52,13 +58,19 @@ class FrameRateTest |
| dom_automation_enabled_ = true; |
| } |
| + bool HasFlag(FrameRateTestFlags flag) const { return (GetParam() & flag); } |
|
Justin Novosad
2011/11/09 15:51:23
This test will not work correctly with multi-bit f
jbates
2011/11/09 17:57:57
Done.
|
| + |
| + bool IsGpuAvailable() const { |
| + return CommandLine::ForCurrentProcess()->HasSwitch("enable-gpu"); |
| + } |
| + |
| virtual FilePath GetDataPath(const std::string& name) { |
| // Make sure the test data is checked out. |
| FilePath test_path; |
| PathService::Get(chrome::DIR_TEST_DATA, &test_path); |
| test_path = test_path.Append(FILE_PATH_LITERAL("perf")); |
| test_path = test_path.Append(FILE_PATH_LITERAL("frame_rate")); |
| - if (GetParam() & kInternal) { |
| + if (HasFlag(kInternal)) { |
| test_path = test_path.Append(FILE_PATH_LITERAL("private")); |
| } else { |
| test_path = test_path.Append(FILE_PATH_LITERAL("content")); |
| @@ -68,9 +80,8 @@ class FrameRateTest |
| } |
| virtual void SetUp() { |
| - if (GetParam() & kUseReferenceBuild) { |
| + if (HasFlag(kUseReferenceBuild)) |
| UseReferenceBuild(); |
| - } |
| // UI tests boot up render views starting from about:blank. This causes |
| // the renderer to start up thinking it cannot use the GPU. To work |
| @@ -84,7 +95,7 @@ class FrameRateTest |
| // fixes that error. |
| launch_arguments_.AppendSwitch(switches::kAllowFileAccessFromFiles); |
| - if (GetParam() & kDisableGpu) { |
| + if (!HasFlag(kUseGpu)) { |
| launch_arguments_.AppendSwitch(switches::kDisableAcceleratedCompositing); |
| launch_arguments_.AppendSwitch(switches::kDisableExperimentalWebGL); |
| } else { |
| @@ -94,19 +105,39 @@ class FrameRateTest |
| launch_arguments_.AppendSwitch(switches::kEnableAccelerated2dCanvas); |
| } |
| - if (GetParam() & kDisableVsync) { |
| + if (HasFlag(kDisableVsync)) |
| launch_arguments_.AppendSwitch(switches::kDisableGpuVsync); |
| - } |
| UIPerfTest::SetUp(); |
| } |
| + bool DidRunOnGpu(const std::string& json_events) { |
| + using namespace trace_analyzer; |
| + |
| + // Check trace for GPU accleration. |
| + scoped_ptr<TraceAnalyzer> analyzer(TraceAnalyzer::Create(json_events)); |
| + |
| + gfx::GLImplementation gl_impl = gfx::kGLImplementationNone; |
| + const TraceEvent* gpu_event = analyzer->FindOneEvent( |
| + Query(EVENT_NAME) == Query::String("GLES2DecoderImpl::Initialize") && |
| + Query(EVENT_HAS_NUMBER_ARG, "GLImpl")); |
| + if (gpu_event) |
| + gl_impl = static_cast<gfx::GLImplementation>( |
| + gpu_event->GetKnownArgAsInt("GLImpl")); |
| + return (gl_impl == gfx::kGLImplementationDesktopGL || |
| + gl_impl == gfx::kGLImplementationEGLGLES2); |
| + } |
| + |
| void RunTest(const std::string& name) { |
| - if ((GetParam() & kRequiresGpu) && |
| - !CommandLine::ForCurrentProcess()->HasSwitch("enable-gpu")) { |
| + if (HasFlag(kUseGpu) && !IsGpuAvailable()) { |
| printf("Test skipped: requires gpu\n"); |
| return; |
| } |
| + |
| + // Verify flag combinations. |
| + ASSERT_TRUE(HasFlag(kUseGpu) || !HasFlag(kForceGpuComposited)); |
|
Justin Novosad
2011/11/09 15:51:23
With this assertion in place I think it is not nec
jbates
2011/11/09 17:57:57
Done.
|
| + ASSERT_TRUE(!HasFlag(kUseGpu) || IsGpuAvailable()); |
| + |
| FilePath test_path = GetDataPath(name); |
| ASSERT_TRUE(file_util::DirectoryExists(test_path)) |
| << "Missing test directory: " << test_path.value(); |
| @@ -116,7 +147,11 @@ class FrameRateTest |
| scoped_refptr<TabProxy> tab(GetActiveTab()); |
| ASSERT_TRUE(tab.get()); |
| - if (GetParam() & kHasRedirect) { |
| + // TODO(jbates): remove this check when ref builds are updated. |
| + if (!HasFlag(kUseReferenceBuild)) |
| + ASSERT_TRUE(automation()->BeginTracing("test_gpu")); |
| + |
| + if (HasFlag(kHasRedirect)) { |
| // If the test file is known to contain an html redirect, we must block |
| // until the second navigation is complete and reacquire the active tab |
| // in order to avoid a race condition. |
| @@ -141,7 +176,7 @@ class FrameRateTest |
| tab, L"", L"window.domAutomationController.send(__initialized);", |
| TestTimeouts::large_test_timeout_ms())); |
| - if (GetParam() & kMakeBodyComposited) { |
| + if (HasFlag(kForceGpuComposited)) { |
| ASSERT_TRUE(tab->NavigateToURLAsync( |
| GURL("javascript:__make_body_composited();"))); |
| } |
| @@ -154,6 +189,16 @@ class FrameRateTest |
| tab, L"", L"window.domAutomationController.send(!__running_all);", |
| TestTimeouts::large_test_timeout_ms())); |
| + // TODO(jbates): remove this check when ref builds are updated. |
| + std::string json_events; |
| + if (!HasFlag(kUseReferenceBuild)) { |
| + ASSERT_TRUE(automation()->EndTracing(&json_events)); |
| + |
| + bool did_run_on_gpu = DidRunOnGpu(json_events); |
| + bool expect_gpu = HasFlag(kUseGpu); |
| + EXPECT_EQ(expect_gpu, did_run_on_gpu); |
| + } |
| + |
| // Read out the results. |
| std::wstring json; |
| ASSERT_TRUE(tab->ExecuteAndExtractString( |
| @@ -198,9 +243,9 @@ TEST_P(FrameRateCompositingTest, content) { \ |
| INSTANTIATE_TEST_CASE_P(, FrameRateCompositingTest, ::testing::Values( |
| 0, |
| - kMakeBodyComposited, |
| + kForceGpuComposited, |
| kUseReferenceBuild, |
| - kUseReferenceBuild | kMakeBodyComposited)); |
| + kUseReferenceBuild | kForceGpuComposited)); |
| FRAME_RATE_TEST_WITH_AND_WITHOUT_ACCELERATED_COMPOSITING(blank); |
| FRAME_RATE_TEST_WITH_AND_WITHOUT_ACCELERATED_COMPOSITING(googleblog); |
| @@ -211,19 +256,15 @@ typedef FrameRateTest FrameRateNoVsyncCanvasInternalTest; |
| #define INTERNAL_FRAME_RATE_TEST_CANVAS_WITH_AND_WITHOUT_NOVSYNC(content) \ |
| TEST_P(FrameRateNoVsyncCanvasInternalTest, content) { \ |
| RunTest(#content); \ |
| -} \ |
| +} |
| INSTANTIATE_TEST_CASE_P(, FrameRateNoVsyncCanvasInternalTest, ::testing::Values( |
| - kInternal | kHasRedirect | kRequiresGpu, |
| - kInternal | kHasRedirect | kDisableVsync | |
| - kRequiresGpu, |
| - kInternal | kHasRedirect | kDisableGpu, |
| - kInternal | kHasRedirect | kDisableGpu | |
| - kUseReferenceBuild, |
| - kInternal | kHasRedirect | kUseReferenceBuild | |
| - kRequiresGpu, |
| - kInternal | kHasRedirect | kDisableVsync | |
| - kRequiresGpu | kUseReferenceBuild)); |
| + kInternal | kHasRedirect, |
| + kInternal | kHasRedirect | kUseGpu, |
| + kInternal | kHasRedirect | kUseGpu | kDisableVsync, |
| + kUseReferenceBuild | kInternal | kHasRedirect, |
| + kUseReferenceBuild | kInternal | kHasRedirect | kUseGpu, |
| + kUseReferenceBuild | kInternal | kHasRedirect | kUseGpu | kDisableVsync)); |
| INTERNAL_FRAME_RATE_TEST_CANVAS_WITH_AND_WITHOUT_NOVSYNC(fishbowl) |
| @@ -235,16 +276,13 @@ typedef FrameRateTest FrameRateGpuCanvasInternalTest; |
| #define INTERNAL_FRAME_RATE_TEST_CANVAS_GPU(content) \ |
| TEST_P(FrameRateGpuCanvasInternalTest, content) { \ |
| RunTest(#content); \ |
| -} \ |
| +} |
| INSTANTIATE_TEST_CASE_P(, FrameRateGpuCanvasInternalTest, ::testing::Values( |
| - kInternal | kHasRedirect | kRequiresGpu, |
| - kInternal | kHasRedirect | kDisableVsync | |
| - kRequiresGpu, |
| - kInternal | kHasRedirect | kUseReferenceBuild | |
| - kRequiresGpu, |
| - kInternal | kHasRedirect | kDisableVsync | |
| - kRequiresGpu | kUseReferenceBuild)); |
| + kInternal | kHasRedirect | kUseGpu, |
| + kInternal | kHasRedirect | kUseGpu | kDisableVsync, |
| + kUseReferenceBuild | kInternal | kHasRedirect | kUseGpu, |
| + kUseReferenceBuild | kInternal | kHasRedirect | kUseGpu | kDisableVsync)); |
| INTERNAL_FRAME_RATE_TEST_CANVAS_GPU(fireflies) |
| INTERNAL_FRAME_RATE_TEST_CANVAS_GPU(FishIE) |