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..f44c0020ba5fe160a4e66f482d36c59f86003185 100644 |
--- a/chrome/test/perf/frame_rate/frame_rate_tests.cc |
+++ b/chrome/test/perf/frame_rate/frame_rate_tests.cc |
@@ -9,40 +9,32 @@ |
#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, // 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) |
- suffix += "_comp"; |
- if (flags & kDisableVsync) |
- suffix += "_novsync"; |
- if (flags & kDisableGpu) |
- suffix += "_nogpu"; |
- if (flags & kUseReferenceBuild) |
- suffix += "_ref"; |
- return suffix; |
-} |
- |
class FrameRateTest |
: public UIPerfTest |
, public ::testing::WithParamInterface<int> { |
@@ -52,13 +44,34 @@ class FrameRateTest |
dom_automation_enabled_ = true; |
} |
+ bool HasFlag(FrameRateTestFlags flag) const { |
+ return (GetParam() & flag) == flag; |
+ } |
+ |
+ bool IsGpuAvailable() const { |
+ return CommandLine::ForCurrentProcess()->HasSwitch("enable-gpu"); |
+ } |
+ |
+ std::string GetSuffixForTestFlags() { |
+ std::string suffix; |
+ if (HasFlag(kForceGpuComposited)) |
+ suffix += "_comp"; |
+ if (HasFlag(kUseGpu)) |
+ suffix += "_gpu"; |
+ if (HasFlag(kDisableVsync)) |
+ suffix += "_novsync"; |
+ if (HasFlag(kUseReferenceBuild)) |
+ suffix += "_ref"; |
+ return suffix; |
+ } |
+ |
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 +81,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 +96,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 +106,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)); |
+ 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 +148,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 +177,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 +190,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. |
+ if (!HasFlag(kUseReferenceBuild)) { |
+ std::string json_events; |
+ 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( |
@@ -171,8 +217,7 @@ class FrameRateTest |
ASSERT_TRUE(results.find("means") != results.end()); |
ASSERT_TRUE(results.find("sigmas") != results.end()); |
- std::string trace_name = "fps"; |
- trace_name += GetSuffixForTestFlags(GetParam()); |
+ std::string trace_name = "fps" + GetSuffixForTestFlags(); |
printf("GESTURES %s: %s= [%s] [%s] [%s]\n", name.c_str(), |
trace_name.c_str(), |
results["gestures"].c_str(), |
@@ -198,9 +243,9 @@ TEST_P(FrameRateCompositingTest, content) { \ |
INSTANTIATE_TEST_CASE_P(, FrameRateCompositingTest, ::testing::Values( |
0, |
- kMakeBodyComposited, |
+ kUseGpu | kForceGpuComposited, |
kUseReferenceBuild, |
- kUseReferenceBuild | kMakeBodyComposited)); |
+ kUseReferenceBuild | kUseGpu | 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) |