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

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

Issue 12193015: PPAPI/NaCl: Make related tests run in 1 fixture (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge 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
« no previous file with comments | « ppapi/tests/test_case.h ('k') | ppapi/tests/test_image_data.cc » ('j') | 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/test_case.h" 5 #include "ppapi/tests/test_case.h"
6 6
7 #include <string.h>
8
7 #include <sstream> 9 #include <sstream>
8 10
11 #include "ppapi/cpp/core.h"
12 #include "ppapi/cpp/module.h"
9 #include "ppapi/tests/pp_thread.h" 13 #include "ppapi/tests/pp_thread.h"
10 #include "ppapi/tests/test_utils.h" 14 #include "ppapi/tests/test_utils.h"
11 #include "ppapi/tests/testing_instance.h" 15 #include "ppapi/tests/testing_instance.h"
12 16
17 namespace {
18
19 std::string StripPrefix(const std::string& test_name) {
20 const char* const prefixes[] = {
21 "FAILS_", "FLAKY_", "DISABLED_" };
22 for (size_t i = 0; i < sizeof(prefixes)/sizeof(prefixes[0]); ++i)
23 if (test_name.find(prefixes[i]) == 0)
24 return test_name.substr(strlen(prefixes[i]));
25 return test_name;
26 }
27
28 // Strip the TestCase name off and return the remainder (i.e., everything after
29 // '_'). If there is no '_', assume only the TestCase was provided, and return
30 // an empty string.
31 // For example:
32 // StripTestCase("TestCase_TestName");
33 // returns
34 // "TestName"
35 // while
36 // StripTestCase("TestCase);
37 // returns
38 // ""
39 std::string StripTestCase(const std::string& full_test_name) {
40 size_t delim = full_test_name.find_first_of('_');
41 if (delim != std::string::npos)
42 return full_test_name.substr(delim+1);
43 // In this case, our "filter" is the empty string; the full test name is the
44 // same as the TestCase name with which we were constructed.
45 // TODO(dmichael): It might be nice to be able to PP_DCHECK against the
46 // TestCase class name, but we'd have to plumb that name to TestCase somehow.
47 return std::string();
48 }
49
50 // Parse |test_filter|, which is a comma-delimited list of (possibly prefixed)
51 // test names and insert the un-prefixed names into |remaining_tests|, with
52 // the bool indicating whether the test should be run.
53 void ParseTestFilter(const std::string& test_filter,
54 std::map<std::string, bool>* remaining_tests) {
55 // We can't use base/string_util.h::Tokenize in ppapi, so we have to do it
56 // ourselves.
57 std::istringstream filter_stream(test_filter);
58 std::string current_test;
59 while (std::getline(filter_stream, current_test, ',')) {
60 // |current_test| might include a prefix, like DISABLED_Foo_TestBar, so we
61 // we strip it off if there is one.
62 std::string stripped_test_name(StripPrefix(current_test));
63 // Strip off the test case and use the test name as a key, because the test
64 // name ShouldRunTest wants to use to look up the test doesn't have the
65 // TestCase name.
66 std::string test_name_without_case(StripTestCase(stripped_test_name));
67
68 // If the test wasn't prefixed, it should be run.
69 bool should_run_test = (current_test == stripped_test_name);
70 PP_DCHECK(remaining_tests->count(test_name_without_case) == 0);
71 remaining_tests->insert(
72 std::make_pair(test_name_without_case, should_run_test));
73 }
74 // There may be a trailing comma; ignore empty strings.
75 remaining_tests->erase(std::string());
76 }
77
78 } // namespace
79
13 TestCase::TestCase(TestingInstance* instance) 80 TestCase::TestCase(TestingInstance* instance)
14 : instance_(instance), 81 : instance_(instance),
15 testing_interface_(NULL), 82 testing_interface_(NULL),
16 callback_type_(PP_REQUIRED) { 83 callback_type_(PP_REQUIRED),
84 have_populated_remaining_tests_(false) {
17 // Get the testing_interface_ if it is available, so that we can do Resource 85 // Get the testing_interface_ if it is available, so that we can do Resource
18 // and Var checks on shutdown (see CheckResourcesAndVars). If it is not 86 // and Var checks on shutdown (see CheckResourcesAndVars). If it is not
19 // available, testing_interface_ will be NULL. Some tests do not require it. 87 // available, testing_interface_ will be NULL. Some tests do not require it.
20 testing_interface_ = GetTestingInterface(); 88 testing_interface_ = GetTestingInterface();
21 } 89 }
22 90
23 TestCase::~TestCase() { 91 TestCase::~TestCase() {
24 } 92 }
25 93
26 bool TestCase::Init() { 94 bool TestCase::Init() {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 164
97 bool TestCase::EnsureRunningOverHTTP() { 165 bool TestCase::EnsureRunningOverHTTP() {
98 if (instance_->protocol() != "http:") { 166 if (instance_->protocol() != "http:") {
99 instance_->AppendError("This test needs to be run over HTTP."); 167 instance_->AppendError("This test needs to be run over HTTP.");
100 return false; 168 return false;
101 } 169 }
102 170
103 return true; 171 return true;
104 } 172 }
105 173
106 bool TestCase::MatchesFilter(const std::string& test_name, 174 bool TestCase::ShouldRunAllTests(const std::string& filter) {
175 // If only the TestCase is listed, we're running all the tests in RunTests.
176 return (StripTestCase(filter) == std::string());
177 }
178
179 bool TestCase::ShouldRunTest(const std::string& test_name,
107 const std::string& filter) { 180 const std::string& filter) {
108 return filter.empty() || (test_name == filter); 181 if (ShouldRunAllTests(filter))
182 return true;
183
184 // Lazily initialize our "remaining_tests_" map.
185 if (!have_populated_remaining_tests_) {
186 ParseTestFilter(filter, &remaining_tests_);
187 have_populated_remaining_tests_ = true;
188 }
189 std::map<std::string, bool>::iterator iter = remaining_tests_.find(test_name);
190 if (iter == remaining_tests_.end()) {
191 // The test name wasn't listed in the filter. Don't run it, but store it
192 // so TestingInstance::ExecuteTests can report an error later.
193 skipped_tests_.insert(test_name);
194 return false;
195 }
196 bool should_run_test = iter->second;
197 remaining_tests_.erase(iter);
198 return should_run_test;
199 }
200
201 PP_TimeTicks TestCase::NowInTimeTicks() {
202 return pp::Module::Get()->core()->GetTimeTicks();
109 } 203 }
110 204
111 std::string TestCase::CheckResourcesAndVars(std::string errors) { 205 std::string TestCase::CheckResourcesAndVars(std::string errors) {
112 if (!errors.empty()) 206 if (!errors.empty())
113 return errors; 207 return errors;
114 208
115 if (testing_interface_) { 209 if (testing_interface_) {
116 // TODO(dmichael): Fix tests that leak resources and enable the following: 210 // TODO(dmichael): Fix tests that leak resources and enable the following:
117 /* 211 /*
118 uint32_t leaked_resources = 212 uint32_t leaked_resources =
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 void TestCase::RunOnThreadInternal(void (*thread_func)(void*), 257 void TestCase::RunOnThreadInternal(void (*thread_func)(void*),
164 void* thread_param, 258 void* thread_param,
165 const PPB_Testing_Dev* testing_interface) { 259 const PPB_Testing_Dev* testing_interface) {
166 PP_ThreadType thread; 260 PP_ThreadType thread;
167 PP_CreateThread(&thread, thread_func, thread_param); 261 PP_CreateThread(&thread, thread_func, thread_param);
168 // Run a message loop so pepper calls can be dispatched. The background 262 // Run a message loop so pepper calls can be dispatched. The background
169 // thread will set result_ and make us Quit when it's done. 263 // thread will set result_ and make us Quit when it's done.
170 testing_interface->RunMessageLoop(instance_->pp_instance()); 264 testing_interface->RunMessageLoop(instance_->pp_instance());
171 PP_JoinThread(thread); 265 PP_JoinThread(thread);
172 } 266 }
OLDNEW
« no previous file with comments | « ppapi/tests/test_case.h ('k') | ppapi/tests/test_image_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698