1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/command_line.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/string_util.h"
#include "base/test/test_timeouts.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/common/chrome_paths.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 "content/common/json_value_serializer.h"
#include "googleurl/src/gurl.h"
#include "net/base/net_util.h"
namespace {
static const FilePath::CharType kStartFile[] =
FILE_PATH_LITERAL("run.html");
const char kRunV8Benchmark[] = "run-v8-benchmark";
class V8BenchmarkTest : public UIPerfTest {
public:
typedef std::map<std::string, std::string> ResultsMap;
V8BenchmarkTest() : reference_(false) {
dom_automation_enabled_ = true;
show_window_ = true;
}
void RunTest() {
FilePath::StringType start_file(kStartFile);
FilePath test_path = GetV8BenchmarkDir();
test_path = test_path.Append(start_file);
GURL test_url(net::FilePathToFileURL(test_path));
scoped_refptr<TabProxy> tab(GetActiveTab());
ASSERT_TRUE(tab.get());
ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(test_url));
// Wait for the test to finish.
ASSERT_TRUE(WaitUntilTestCompletes(tab.get(), test_url));
PrintResults(tab.get());
}
protected:
bool reference_; // True if this is a reference build.
private:
// Return the path to the V8 benchmark directory on the local filesystem.
FilePath GetV8BenchmarkDir() {
FilePath test_dir;
PathService::Get(chrome::DIR_TEST_DATA, &test_dir);
return test_dir.AppendASCII("v8_benchmark");
}
bool WaitUntilTestCompletes(TabProxy* tab, const GURL& test_url) {
return WaitUntilCookieValue(tab, test_url, "__done",
TestTimeouts::huge_test_timeout_ms(), "1");
}
bool GetScore(TabProxy* tab, std::string* score) {
std::wstring score_wide;
bool succeeded = tab->ExecuteAndExtractString(L"",
L"window.domAutomationController.send(automation.GetScore());",
&score_wide);
// Note that we don't use ASSERT_TRUE here (and in some other places) as it
// doesn't work inside a function with a return type other than void.
EXPECT_TRUE(succeeded);
if (!succeeded)
return false;
score->assign(WideToUTF8(score_wide));
return true;
}
bool GetResults(TabProxy* tab, ResultsMap* results) {
std::wstring json_wide;
bool succeeded = tab->ExecuteAndExtractString(L"",
L"window.domAutomationController.send("
L" JSON.stringify(automation.GetResults()));",
&json_wide);
EXPECT_TRUE(succeeded);
if (!succeeded)
return false;
std::string json = WideToUTF8(json_wide);
return JsonDictionaryToMap(json, results);
}
void PrintResults(TabProxy* tab) {
std::string score;
ASSERT_TRUE(GetScore(tab, &score));
ResultsMap results;
ASSERT_TRUE(GetResults(tab, &results));
std::string trace_name = reference_ ? "score_ref" : "score";
std::string unit_name = "score (bigger is better)";
PrintResult("score", "", trace_name, score, unit_name, true);
ResultsMap::const_iterator it = results.begin();
for (; it != results.end(); ++it)
PrintResult(it->first, "", trace_name, it->second, unit_name, false);
}
DISALLOW_COPY_AND_ASSIGN(V8BenchmarkTest);
};
class V8BenchmarkReferenceTest : public V8BenchmarkTest {
public:
V8BenchmarkReferenceTest() : V8BenchmarkTest() {
reference_ = true;
}
void SetUp() {
UseReferenceBuild();
V8BenchmarkTest::SetUp();
}
};
TEST_F(V8BenchmarkTest, Perf) {
if (!CommandLine::ForCurrentProcess()->HasSwitch(kRunV8Benchmark))
return;
RunTest();
}
// Bug 87162: Disable Perf for ChromeOS
#if defined(OS_CHROMEOS)
#define MAYBE_Perf DISABLED_Perf
#else
#define MAYBE_Perf Perf
#endif
TEST_F(V8BenchmarkReferenceTest, MAYBE_Perf) {
if (!CommandLine::ForCurrentProcess()->HasSwitch(kRunV8Benchmark))
return;
RunTest();
}
} // namespace
|