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

Unified Diff: ppapi/tests/test_case.h

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 side-by-side diff with in-line comments
Download patch
Index: ppapi/tests/test_case.h
diff --git a/ppapi/tests/test_case.h b/ppapi/tests/test_case.h
index c7699963b64f112e50a9e08f6e1cbb2cbdb3a051..3feb2f14032dfab5d367f1fd03467ada0a50ec4a 100644
--- a/ppapi/tests/test_case.h
+++ b/ppapi/tests/test_case.h
@@ -7,11 +7,13 @@
#include <cmath>
#include <limits>
+#include <map>
#include <set>
#include <string>
-#include "ppapi/c/pp_resource.h"
#include "ppapi/c/dev/ppb_testing_dev.h"
+#include "ppapi/c/pp_resource.h"
+#include "ppapi/c/pp_time.h"
#include "ppapi/cpp/dev/scrollbar_dev.h"
#include "ppapi/cpp/message_loop.h"
#include "ppapi/cpp/view.h"
@@ -43,10 +45,14 @@ class TestCase {
virtual bool Init();
// Override to implement the test case. It will be called after the plugin is
- // first displayed, passing a string. If the string is empty, the
- // should run all tests for this test case. Otherwise, it should run the test
- // whose name matches test_filter exactly (if there is one). This should
- // generally be implemented using the RUN_TEST* macros.
+ // first displayed, passing a string. If the string is empty, RunTests should
+ // run all tests for this test case. Otherwise, it must be a comma-delimited
+ // list of test names, possibly prefixed. E.g.:
+ // "Foo_GoodTest,DISABLED_Foo_BadTest,Foo_OtherGoodTest"
+ // All listed tests which are not prefixed will be run.
+ //
+ // This should generally be implemented in a TestCase subclass using the
+ // RUN_TEST* macros.
virtual void RunTests(const std::string& test_filter) = 0;
static std::string MakeFailureMessage(const char* file, int line,
@@ -82,6 +88,14 @@ class TestCase {
static void QuitMainMessageLoop(PP_Instance instance);
+ const std::map<std::string, bool>& remaining_tests() {
+ return remaining_tests_;
+ }
+ const std::set<std::string>& skipped_tests() {
+ return skipped_tests_;
+ }
+
+
bbudge 2013/02/06 14:51:26 extra line
protected:
#if !(defined __native_client__)
// Overridden by each test to supply a ScriptableObject corresponding to the
@@ -102,7 +116,8 @@ class TestCase {
bool EnsureRunningOverHTTP();
// Return true if the given test name matches the filter. This is true if
- // (a) filter is empty or (b) test_name and filter match exactly.
+ // (a) filter is empty or (b) test_name matches a test name listed in filter
+ // exactly.
bool MatchesFilter(const std::string& test_name, const std::string& filter);
// Check for leaked resources and vars at the end of the test. If any exist,
@@ -113,6 +128,8 @@ class TestCase {
// CheckResourcesAndVars will do nothing and return the same string.
std::string CheckResourcesAndVars(std::string errors);
+ PP_TimeTicks NowInTimeTicks();
+
// Run the given test method on a background thread and return the result.
template <class T>
std::string RunOnThread(std::string(T::*test_to_run)()) {
@@ -212,6 +229,24 @@ class TestCase {
// Var ids that should be ignored when checking for leaks on shutdown.
std::set<int64_t> ignored_leaked_vars_;
+ // The tests that were found in test_filter but have not yet been run. The
+ // bool indicates whether the test should be run (i.e., it will be false if
+ // the test name was prefixed in the test_filter string).
+ //
+ // This is initialized lazily the first time that MatchesFilter is called by
+ // RunTests. When RunTests is finished, this should be empty. Any remaining
+ // tests are tests that were listed in the test_filter but didn't match
+ // any calls to MatchesFilter, meaning it was probably a typo. TestingInstance
+ // should log this and consider it a failure.
+ std::map<std::string, bool> remaining_tests_;
+ // Flag indicating whether we have populated remaining_tests_ yet.
+ bool have_populated_remaining_tests_;
+
+ // If MatchesFilter is called but the given test name doesn't match anything
+ // in the test_filter, the test name will be added here. This allows
+ // TestingInstance to detect when not all tests were listed.
+ std::set<std::string> skipped_tests_;
+
#if !(defined __native_client__)
// Holds the test object, if any was retrieved from CreateTestObject.
pp::VarPrivate test_object_;
@@ -262,7 +297,10 @@ class TestCaseFactory {
#define RUN_TEST(name, test_filter) \
if (MatchesFilter(#name, test_filter)) { \
set_callback_type(PP_OPTIONAL); \
- instance_->LogTest(#name, CheckResourcesAndVars(Test##name())); \
+ PP_TimeTicks start_time(NowInTimeTicks()); \
+ instance_->LogTest(#name, \
+ CheckResourcesAndVars(Test##name()), \
+ start_time); \
}
// Like RUN_TEST above but forces functions taking callbacks to complete
@@ -270,21 +308,29 @@ class TestCaseFactory {
#define RUN_TEST_FORCEASYNC(name, test_filter) \
if (MatchesFilter(#name, test_filter)) { \
set_callback_type(PP_REQUIRED); \
+ PP_TimeTicks start_time(NowInTimeTicks()); \
instance_->LogTest(#name"ForceAsync", \
- CheckResourcesAndVars(Test##name())); \
+ CheckResourcesAndVars(Test##name()), \
+ start_time); \
}
#define RUN_TEST_BLOCKING(test_case, name, test_filter) \
if (MatchesFilter(#name, test_filter)) { \
set_callback_type(PP_BLOCKING); \
- instance_->LogTest(#name"Blocking", \
- CheckResourcesAndVars(RunOnThread(&test_case::Test##name))); \
+ PP_TimeTicks start_time(NowInTimeTicks()); \
+ instance_->LogTest( \
+ #name"Blocking", \
+ CheckResourcesAndVars(RunOnThread(&test_case::Test##name)), \
+ start_time); \
}
#define RUN_TEST_BACKGROUND(test_case, name, test_filter) \
if (MatchesFilter(#name, test_filter)) { \
- instance_->LogTest(#name"Background", \
- CheckResourcesAndVars(RunOnThread(&test_case::Test##name))); \
+ PP_TimeTicks start_time(NowInTimeTicks()); \
+ instance_->LogTest( \
+ #name"Background", \
+ CheckResourcesAndVars(RunOnThread(&test_case::Test##name)), \
+ start_time); \
}
#define RUN_TEST_FORCEASYNC_AND_NOT(name, test_filter) \
@@ -313,7 +359,10 @@ class TestCaseFactory {
instance_->pp_instance()) != objects) \
error_message = MakeFailureMessage(__FILE__, __LINE__, \
"reference leak check"); \
- instance_->LogTest(#name, error_message); \
+ PP_TimeTicks start_time(NowInTimeTicks()); \
+ instance_->LogTest(#name, \
+ error_message, \
+ start_time); \
}
// TODO(dmichael): Add CheckResourcesAndVars above when Windows tests pass
// cleanly. crbug.com/173503

Powered by Google App Engine
This is Rietveld 408576698