OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 */ | |
30 | |
31 #include "config.h" | |
32 #include "DumpRenderTree.h" | |
33 | |
34 #include "MockPlatform.h" | |
35 #include "TestShell.h" | |
36 #include "webkit/support/webkit_support.h" | |
37 #include "public/platform/WebCompositorSupport.h" | |
38 #include <v8/include/v8-testing.h> | |
39 #include <v8/include/v8.h> | |
40 #include <wtf/OwnPtr.h> | |
41 #include <wtf/Vector.h> | |
42 | |
43 using namespace std; | |
44 | |
45 static const char optionComplexText[] = "--complex-text"; | |
46 static const char optionDumpPixels[] = "--pixel-tests"; | |
47 static const char optionDumpPixelsShortForm[] = "-p"; | |
48 static const char optionNotree[] = "--notree"; | |
49 static const char optionThreaded[] = "--threaded"; | |
50 static const char optionDebugRenderTree[] = "--debug-render-tree"; | |
51 static const char optionDebugLayerTree[] = "--debug-layer-tree"; | |
52 | |
53 static const char optionAllowExternalPages[] = "--allow-external-pages"; | |
54 static const char optionStartupDialog[] = "--testshell-startup-dialog"; | |
55 static const char optionCheckLayoutTestSystemDeps[] = "--check-layout-test-sys-d
eps"; | |
56 | |
57 static const char optionHardwareAcceleratedGL[] = "--enable-hardware-gpu"; | |
58 static const char optionEnableSoftwareCompositing[] = "--enable-software-composi
ting"; | |
59 static const char optionEnableThreadedCompositing[] = "--enable-threaded-composi
ting"; | |
60 static const char optionForceCompositingMode[] = "--force-compositing-mode"; | |
61 static const char optionEnableAccelerated2DCanvas[] = "--enable-accelerated-2d-c
anvas"; | |
62 static const char optionEnableAcceleratedCompositingForVideo[] = "--enable-accel
erated-video"; | |
63 static const char optionEnableAcceleratedFixedPosition[] = "--enable-accelerated
-fixed-position"; | |
64 static const char optionEnableAcceleratedOverflowScroll[] = "--enable-accelerate
d-overflow-scroll"; | |
65 static const char optionEnableAcceleratedTransition[] = "--enable-accelerated-tr
ansition"; | |
66 static const char optionEnablePerTilePainting[] = "--enable-per-tile-painting"; | |
67 static const char optionEnableDeferredImageDecoding[] = "--enable-deferred-image
-decoding"; | |
68 static const char optionDisableThreadedHTMLParser[] = "--disable-threaded-html-p
arser"; | |
69 | |
70 static const char optionStressOpt[] = "--stress-opt"; | |
71 static const char optionStressDeopt[] = "--stress-deopt"; | |
72 static const char optionJavaScriptFlags[] = "--js-flags="; | |
73 static const char optionEncodeBinary[] = "--encode-binary"; | |
74 static const char optionNoTimeout[] = "--no-timeout"; | |
75 static const char optionWebCoreLogChannels[] = "--webcore-log-channels="; | |
76 | |
77 class WebKitSupportTestEnvironment { | |
78 public: | |
79 WebKitSupportTestEnvironment() | |
80 { | |
81 m_mockPlatform = MockPlatform::create(); | |
82 webkit_support::SetUpTestEnvironment(m_mockPlatform.get()); | |
83 } | |
84 ~WebKitSupportTestEnvironment() | |
85 { | |
86 webkit_support::TearDownTestEnvironment(); | |
87 } | |
88 | |
89 MockPlatform* mockPlatform() { return m_mockPlatform.get(); } | |
90 | |
91 private: | |
92 OwnPtr<MockPlatform> m_mockPlatform; | |
93 }; | |
94 | |
95 static void runTest(TestShell& shell, TestParams& params, const string& inputLin
e, const bool forceDumpPixels) | |
96 { | |
97 int oldTimeoutMsec = shell.layoutTestTimeout(); | |
98 TestCommand command = parseInputLine(inputLine); | |
99 params.testUrl = webkit_support::CreateURLForPathOrURL(command.pathOrURL); | |
100 params.pixelHash = command.shouldDumpPixels; | |
101 webkit_support::SetCurrentDirectoryForFileURL(params.testUrl); | |
102 v8::V8::SetFlagsFromString(shell.javaScriptFlags().c_str(), shell.javaScript
Flags().length()); | |
103 if (shell.stressOpt() || shell.stressDeopt()) { | |
104 if (shell.stressOpt()) | |
105 v8::Testing::SetStressRunType(v8::Testing::kStressTypeOpt); | |
106 else | |
107 v8::Testing::SetStressRunType(v8::Testing::kStressTypeDeopt); | |
108 for (int i = 0; i < v8::Testing::GetStressRuns(); i++) { | |
109 v8::Testing::PrepareStressRun(i); | |
110 bool isLastLoad = (i == (v8::Testing::GetStressRuns() - 1)); | |
111 shell.setDumpWhenFinished(isLastLoad); | |
112 shell.resetTestController(); | |
113 shell.runFileTest(params, command.shouldDumpPixels || forceDumpPixels)
; | |
114 } | |
115 } else { | |
116 shell.resetTestController(); | |
117 shell.runFileTest(params, command.shouldDumpPixels || forceDumpPixels); | |
118 } | |
119 shell.setLayoutTestTimeout(oldTimeoutMsec); | |
120 } | |
121 | |
122 int main(int argc, char* argv[]) | |
123 { | |
124 WebKitSupportTestEnvironment testEnvironment; | |
125 platformInit(&argc, &argv); | |
126 | |
127 TestParams params; | |
128 Vector<string> tests; | |
129 bool serverMode = false; | |
130 bool dumpAllPixels = false; | |
131 bool allowExternalPages = false; | |
132 bool startupDialog = false; | |
133 bool acceleratedCompositingForVideoEnabled = false; | |
134 bool acceleratedCompositingForFixedPositionEnabled = false; | |
135 bool acceleratedCompositingForOverflowScrollEnabled = false; | |
136 bool acceleratedCompositingForTransitionEnabled = false; | |
137 bool softwareCompositingEnabled = false; | |
138 bool threadedCompositingEnabled = false; | |
139 bool forceCompositingMode = false; | |
140 bool threadedHTMLParser = true; | |
141 bool accelerated2DCanvasEnabled = false; | |
142 bool perTilePaintingEnabled = false; | |
143 bool deferredImageDecodingEnabled = false; | |
144 bool stressOpt = false; | |
145 bool stressDeopt = false; | |
146 bool hardwareAcceleratedGL = false; | |
147 string javaScriptFlags; | |
148 bool encodeBinary = false; | |
149 bool noTimeout = false; | |
150 for (int i = 1; i < argc; ++i) { | |
151 string argument(argv[i]); | |
152 if (argument == "-") | |
153 serverMode = true; | |
154 else if (argument == optionDumpPixels || argument == optionDumpPixelsSho
rtForm) | |
155 dumpAllPixels = true; | |
156 else if (argument == optionNotree) | |
157 params.dumpTree = false; | |
158 else if (argument == optionDebugRenderTree) | |
159 params.debugRenderTree = true; | |
160 else if (argument == optionDebugLayerTree) | |
161 params.debugLayerTree = true; | |
162 else if (argument == optionAllowExternalPages) | |
163 allowExternalPages = true; | |
164 else if (argument == optionStartupDialog) | |
165 startupDialog = true; | |
166 else if (argument == optionCheckLayoutTestSystemDeps) | |
167 return checkLayoutTestSystemDependencies() ? EXIT_SUCCESS : EXIT_FAI
LURE; | |
168 else if (argument == optionHardwareAcceleratedGL) | |
169 hardwareAcceleratedGL = true; | |
170 else if (argument == optionEnableAcceleratedCompositingForVideo) | |
171 acceleratedCompositingForVideoEnabled = true; | |
172 else if (argument == optionEnableAcceleratedFixedPosition) | |
173 acceleratedCompositingForFixedPositionEnabled = true; | |
174 else if (argument == optionEnableAcceleratedOverflowScroll) | |
175 acceleratedCompositingForOverflowScrollEnabled = true; | |
176 else if (argument == optionEnableAcceleratedTransition) | |
177 acceleratedCompositingForTransitionEnabled = true; | |
178 else if (argument == optionEnableSoftwareCompositing) | |
179 softwareCompositingEnabled = true; | |
180 else if (argument == optionEnableThreadedCompositing) | |
181 threadedCompositingEnabled = true; | |
182 else if (argument == optionForceCompositingMode) | |
183 forceCompositingMode = true; | |
184 else if (argument == optionDisableThreadedHTMLParser) | |
185 threadedHTMLParser = false; | |
186 else if (argument == optionEnableAccelerated2DCanvas) | |
187 accelerated2DCanvasEnabled = true; | |
188 else if (argument == optionEnablePerTilePainting) | |
189 perTilePaintingEnabled = true; | |
190 else if (argument == optionEnableDeferredImageDecoding) | |
191 deferredImageDecodingEnabled = true; | |
192 else if (argument == optionStressOpt) | |
193 stressOpt = true; | |
194 else if (argument == optionStressDeopt) | |
195 stressDeopt = true; | |
196 else if (!argument.find(optionJavaScriptFlags)) | |
197 javaScriptFlags = argument.substr(strlen(optionJavaScriptFlags)); | |
198 else if (argument == optionEncodeBinary) | |
199 encodeBinary = true; | |
200 else if (argument == optionNoTimeout) | |
201 noTimeout = true; | |
202 else if (!argument.find(optionWebCoreLogChannels)) { | |
203 string channels = argument.substr(strlen(optionWebCoreLogChannels)); | |
204 webkit_support::EnableWebCoreLogChannels(channels); | |
205 } else if (argument.size() && argument[0] == '-') | |
206 fprintf(stderr, "Unknown option: %s\n", argv[i]); | |
207 else | |
208 tests.append(argument); | |
209 } | |
210 if (stressOpt && stressDeopt) { | |
211 fprintf(stderr, "--stress-opt and --stress-deopt are mutually exclusive.
\n"); | |
212 return EXIT_FAILURE; | |
213 } | |
214 | |
215 webkit_support::SetUpGLBindings(hardwareAcceleratedGL ? webkit_support::GL_B
INDING_DEFAULT : webkit_support::GL_BINDING_SOFTWARE_RENDERER); | |
216 | |
217 if (startupDialog) | |
218 openStartupDialog(); | |
219 | |
220 { // Explicit scope for the TestShell instance. | |
221 TestShell shell; | |
222 shell.setAllowExternalPages(allowExternalPages); | |
223 shell.setAcceleratedCompositingForVideoEnabled(acceleratedCompositingFor
VideoEnabled); | |
224 shell.setAcceleratedCompositingForFixedPositionEnabled(acceleratedCompos
itingForFixedPositionEnabled); | |
225 shell.setAcceleratedCompositingForOverflowScrollEnabled(acceleratedCompo
sitingForOverflowScrollEnabled); | |
226 shell.setAcceleratedCompositingForTransitionEnabled(acceleratedCompositi
ngForTransitionEnabled); | |
227 shell.setSoftwareCompositingEnabled(softwareCompositingEnabled); | |
228 shell.setThreadedCompositingEnabled(threadedCompositingEnabled); | |
229 shell.setForceCompositingMode(forceCompositingMode); | |
230 shell.setThreadedHTMLParser(threadedHTMLParser); | |
231 shell.setAccelerated2dCanvasEnabled(accelerated2DCanvasEnabled); | |
232 shell.setPerTilePaintingEnabled(perTilePaintingEnabled); | |
233 shell.setDeferredImageDecodingEnabled(deferredImageDecodingEnabled); | |
234 shell.setJavaScriptFlags(javaScriptFlags); | |
235 shell.setStressOpt(stressOpt); | |
236 shell.setStressDeopt(stressDeopt); | |
237 shell.setEncodeBinary(encodeBinary); | |
238 if (noTimeout) { | |
239 // 0x20000000ms is big enough for the purpose to avoid timeout in de
bugging. | |
240 shell.setLayoutTestTimeout(0x20000000); | |
241 } | |
242 shell.initialize(testEnvironment.mockPlatform()); | |
243 if (serverMode && !tests.size()) { | |
244 #if OS(ANDROID) | |
245 // Send a signal to host to indicate DRT is ready to process command
s. | |
246 puts("#READY"); | |
247 fflush(stdout); | |
248 #endif | |
249 params.printSeparators = true; | |
250 char testString[2048]; // 2048 is the same as the sizes of other pla
tforms. | |
251 while (fgets(testString, sizeof(testString), stdin)) { | |
252 char* newLinePosition = strchr(testString, '\n'); | |
253 if (newLinePosition) | |
254 *newLinePosition = '\0'; | |
255 if (testString[0] == '\0') | |
256 continue; | |
257 // Explicitly quit on platforms where EOF is not reliable. | |
258 if (!strcmp(testString, "QUIT")) | |
259 break; | |
260 runTest(shell, params, testString, dumpAllPixels); | |
261 } | |
262 } else if (!tests.size()) | |
263 puts("#EOF"); | |
264 else { | |
265 params.printSeparators = tests.size() > 1; | |
266 for (unsigned i = 0; i < tests.size(); i++) | |
267 runTest(shell, params, tests[i], dumpAllPixels); | |
268 } | |
269 | |
270 shell.callJSGC(); | |
271 shell.callJSGC(); | |
272 | |
273 // When we finish the last test, cleanup the DRTTestRunner. | |
274 // It may have references to not-yet-cleaned up windows. By cleaning up | |
275 // here we help purify reports. | |
276 shell.resetTestController(); | |
277 } | |
278 | |
279 return EXIT_SUCCESS; | |
280 } | |
OLD | NEW |