Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: ppapi/tests/testing_instance.cc

Issue 12193015: PPAPI/NaCl: Make related tests run in 1 fixture (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: pre-review cleanup Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« ppapi/tests/test_case.cc ('K') | « ppapi/tests/testing_instance.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/tests/testing_instance.h" 5 #include "ppapi/tests/testing_instance.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cstring> 8 #include <cstring>
9 #include <iomanip>
9 #include <sstream> 10 #include <sstream>
10 #include <vector> 11 #include <vector>
11 12
13 #include "ppapi/cpp/core.h"
12 #include "ppapi/cpp/module.h" 14 #include "ppapi/cpp/module.h"
13 #include "ppapi/cpp/var.h" 15 #include "ppapi/cpp/var.h"
14 #include "ppapi/cpp/view.h" 16 #include "ppapi/cpp/view.h"
15 #include "ppapi/tests/test_case.h" 17 #include "ppapi/tests/test_case.h"
16 18
17 TestCaseFactory* TestCaseFactory::head_ = NULL; 19 TestCaseFactory* TestCaseFactory::head_ = NULL;
18 20
19 // Cookie value we use to signal "we're still working." See the comment above 21 // Cookie value we use to signal "we're still working." See the comment above
20 // the class declaration for how this works. 22 // the class declaration for how this works.
21 static const char kProgressSignal[] = "..."; 23 static const char kProgressSignal[] = "...";
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 } else if (std::strcmp(argn[i], "ssl_server_port") == 0) { 59 } else if (std::strcmp(argn[i], "ssl_server_port") == 0) {
58 ssl_server_port_ = atoi(argv[i]); 60 ssl_server_port_ = atoi(argv[i]);
59 } 61 }
60 } 62 }
61 // Create the proper test case from the argument. 63 // Create the proper test case from the argument.
62 for (uint32_t i = 0; i < argc; i++) { 64 for (uint32_t i = 0; i < argc; i++) {
63 if (std::strcmp(argn[i], "testcase") == 0) { 65 if (std::strcmp(argn[i], "testcase") == 0) {
64 if (argv[i][0] == '\0') 66 if (argv[i][0] == '\0')
65 break; 67 break;
66 current_case_ = CaseForTestName(argv[i]); 68 current_case_ = CaseForTestName(argv[i]);
67 test_filter_ = FilterForTestName(argv[i]); 69 test_filter_ = argv[i];
68 if (!current_case_) 70 if (!current_case_)
69 errors_.append(std::string("Unknown test case ") + argv[i]); 71 errors_.append(std::string("Unknown test case ") + argv[i]);
70 else if (!current_case_->Init()) 72 else if (!current_case_->Init())
71 errors_.append(" Test case could not initialize."); 73 errors_.append(" Test case could not initialize.");
72 return true; 74 return true;
73 } 75 }
74 } 76 }
75 77
76 // In DidChangeView, we'll dump out a list of all available tests. 78 // In DidChangeView, we'll dump out a list of all available tests.
77 return true; 79 return true;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 void TestingInstance::EvalScript(const std::string& script) { 113 void TestingInstance::EvalScript(const std::string& script) {
112 SendTestCommand("EvalScript", script); 114 SendTestCommand("EvalScript", script);
113 } 115 }
114 116
115 void TestingInstance::SetCookie(const std::string& name, 117 void TestingInstance::SetCookie(const std::string& name,
116 const std::string& value) { 118 const std::string& value) {
117 SendTestCommand("SetCookie", name + "=" + value); 119 SendTestCommand("SetCookie", name + "=" + value);
118 } 120 }
119 121
120 void TestingInstance::LogTest(const std::string& test_name, 122 void TestingInstance::LogTest(const std::string& test_name,
121 const std::string& error_message) { 123 const std::string& error_message,
124 PP_TimeTicks start_time) {
125 // Compute the time to run the test and save it in a string for logging:
126 PP_TimeTicks end_time(pp::Module::Get()->core()->GetTimeTicks());
127 std::ostringstream number_stream;
128 PP_TimeTicks elapsed_time(end_time - start_time);
129 number_stream << std::fixed << std::setprecision(3) << elapsed_time;
130 std::string time_string(number_stream.str());
131
122 // Tell the browser we're still working. 132 // Tell the browser we're still working.
123 ReportProgress(kProgressSignal); 133 ReportProgress(kProgressSignal);
124 134
125 number_tests_executed_++; 135 number_tests_executed_++;
126 136
127 std::string html; 137 std::string html;
128 html.append("<div class=\"test_line\"><span class=\"test_name\">"); 138 html.append("<div class=\"test_line\"><span class=\"test_name\">");
129 html.append(test_name); 139 html.append(test_name);
130 html.append("</span> "); 140 html.append("</span> ");
131 if (error_message.empty()) { 141 if (error_message.empty()) {
132 html.append("<span class=\"pass\">PASS</span>"); 142 html.append("<span class=\"pass\">PASS</span>");
133 } else { 143 } else {
134 html.append("<span class=\"fail\">FAIL</span>: <span class=\"err_msg\">"); 144 html.append("<span class=\"fail\">FAIL</span>: <span class=\"err_msg\">");
135 html.append(error_message); 145 html.append(error_message);
136 html.append("</span>"); 146 html.append("</span>");
137 147
138 if (!errors_.empty()) 148 if (!errors_.empty())
139 errors_.append(", "); // Separator for different error messages. 149 errors_.append(", "); // Separator for different error messages.
140 errors_.append(test_name + " FAIL: " + error_message); 150 errors_.append(test_name + " FAIL: " + error_message);
141 } 151 }
152 html.append(" <span class=\"time\">(");
153 html.append(time_string);
154 html.append("s)</span>");
155
142 html.append("</div>"); 156 html.append("</div>");
143 LogHTML(html); 157 LogHTML(html);
144 } 158 }
145 159
146 void TestingInstance::AppendError(const std::string& message) { 160 void TestingInstance::AppendError(const std::string& message) {
147 if (!errors_.empty()) 161 if (!errors_.empty())
148 errors_.append(", "); 162 errors_.append(", ");
149 errors_.append(message); 163 errors_.append(message);
150 } 164 }
151 165
(...skipping 11 matching lines...) Expand all
163 LogAvailableTests(); 177 LogAvailableTests();
164 errors_.append("FAIL: Only listed tests"); 178 errors_.append("FAIL: Only listed tests");
165 } else { 179 } else {
166 current_case_->RunTests(test_filter_); 180 current_case_->RunTests(test_filter_);
167 181
168 if (number_tests_executed_ == 0) { 182 if (number_tests_executed_ == 0) {
169 errors_.append("No tests executed. The test filter might be too " 183 errors_.append("No tests executed. The test filter might be too "
170 "restrictive: '" + test_filter_ + "'."); 184 "restrictive: '" + test_filter_ + "'.");
171 LogError(errors_); 185 LogError(errors_);
172 } 186 }
173 else { 187 if (current_case_->skipped_tests().size()) {
174 // Automated PyAuto tests rely on finding the exact strings below. 188 // TODO(dmichael): Convert all TestCases to run all tests in one fixture,
175 LogHTML(errors_.empty() ? 189 // and enable this check. Currently, a lot of our tests
176 "<span class=\"pass\">[SHUTDOWN]</span> All tests passed." : 190 // run 1 test per fixture, which is slow.
177 "<span class=\"fail\">[SHUTDOWN]</span> Some tests failed."); 191 /*
192 errors_.append("Some tests were not listed and thus were not run. Make "
193 "sure all tests are passed in the test_case URL (even if "
194 "they are marked DISABLED_). Forgotten tests: ");
195 std::set<std::string>::const_iterator iter =
196 current_case_->skipped_tests().begin();
197 for (; iter != current_case_->skipped_tests().end(); ++iter) {
198 errors_.append(*iter);
199 errors_.append(" ");
200 }
201 LogError(errors_);
202 */
203 }
204 if (current_case_->remaining_tests().size()) {
205 errors_.append("Some listed tests were not found in the TestCase. Check "
206 "the test names that were passed to make sure they match "
207 "tests in the TestCase. Forgotten tests: ");
bbudge 2013/02/06 14:51:26 s/Forgotten/Unknown
208 std::map<std::string, bool>::const_iterator iter =
209 current_case_->remaining_tests().begin();
210 for (; iter != current_case_->remaining_tests().end(); ++iter) {
211 errors_.append(iter->first);
212 errors_.append(" ");
213 }
214 LogError(errors_);
178 } 215 }
179 } 216 }
180 217
181 // Declare we're done by setting a cookie to either "PASS" or the errors. 218 // Declare we're done by setting a cookie to either "PASS" or the errors.
182 ReportProgress(errors_.empty() ? "PASS" : errors_); 219 ReportProgress(errors_.empty() ? "PASS" : errors_);
183 if (remove_plugin_) 220 if (remove_plugin_)
184 SendTestCommand("DidExecuteTests"); 221 SendTestCommand("DidExecuteTests");
185 // Note, DidExecuteTests unloads the plugin. We can't really do anthing after 222 // Note, DidExecuteTests unloads the plugin. We can't really do anthing after
186 // this point. 223 // this point.
187 } 224 }
188 225
189 TestCase* TestingInstance::CaseForTestName(const std::string& name) { 226 TestCase* TestingInstance::CaseForTestName(const std::string& name) {
190 std::string case_name = name.substr(0, name.find_first_of('_')); 227 std::string case_name = name.substr(0, name.find_first_of('_'));
191 TestCaseFactory* iter = TestCaseFactory::head_; 228 TestCaseFactory* iter = TestCaseFactory::head_;
192 while (iter != NULL) { 229 while (iter != NULL) {
193 if (case_name == iter->name_) 230 if (case_name == iter->name_)
194 return iter->method_(this); 231 return iter->method_(this);
195 iter = iter->next_; 232 iter = iter->next_;
196 } 233 }
197 return NULL; 234 return NULL;
198 } 235 }
199 236
200 std::string TestingInstance::FilterForTestName(const std::string& name) {
201 size_t delim = name.find_first_of('_');
202 if (delim != std::string::npos)
203 return name.substr(delim+1);
204 return "";
205 }
206
207 void TestingInstance::SendTestCommand(const std::string& command) { 237 void TestingInstance::SendTestCommand(const std::string& command) {
208 std::string msg("TESTING_MESSAGE:"); 238 std::string msg("TESTING_MESSAGE:");
209 msg += command; 239 msg += command;
210 PostMessage(pp::Var(msg)); 240 PostMessage(pp::Var(msg));
211 } 241 }
212 242
213 void TestingInstance::SendTestCommand(const std::string& command, 243 void TestingInstance::SendTestCommand(const std::string& command,
214 const std::string& params) { 244 const std::string& params) {
215 SendTestCommand(command + ":" + params); 245 SendTestCommand(command + ":" + params);
216 } 246 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 } 307 }
278 }; 308 };
279 309
280 namespace pp { 310 namespace pp {
281 311
282 Module* CreateModule() { 312 Module* CreateModule() {
283 return new ::Module(); 313 return new ::Module();
284 } 314 }
285 315
286 } // namespace pp 316 } // namespace pp
OLDNEW
« ppapi/tests/test_case.cc ('K') | « ppapi/tests/testing_instance.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698