OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef BASE_TEST_TEST_LAUNCHER_H_ | 5 #ifndef BASE_TEST_TEST_LAUNCHER_H_ |
6 #define BASE_TEST_TEST_LAUNCHER_H_ | 6 #define BASE_TEST_TEST_LAUNCHER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 Status status; | 61 Status status; |
62 | 62 |
63 // Time it took to run the test. | 63 // Time it took to run the test. |
64 base::TimeDelta elapsed_time; | 64 base::TimeDelta elapsed_time; |
65 }; | 65 }; |
66 | 66 |
67 // Interface for use with LaunchTests that abstracts away exact details | 67 // Interface for use with LaunchTests that abstracts away exact details |
68 // which tests and how are run. | 68 // which tests and how are run. |
69 class TestLauncherDelegate { | 69 class TestLauncherDelegate { |
70 public: | 70 public: |
| 71 // Called to get a test name for filtering purposes. Usually it's |
| 72 // test case's name and test's name joined by a dot (e.g. |
| 73 // "TestCaseName.TestName"). |
| 74 // TODO(phajdan.jr): Remove after transitioning away from run_test_cases.py, |
| 75 // http://crbug.com/236893 . |
| 76 virtual std::string GetTestNameForFiltering( |
| 77 const testing::TestCase* test_case, |
| 78 const testing::TestInfo* test_info) = 0; |
| 79 |
71 // Called before a test is considered for running. If it returns false, | 80 // Called before a test is considered for running. If it returns false, |
72 // the test is not run. If it returns true, the test will be run provided | 81 // the test is not run. If it returns true, the test will be run provided |
73 // it is part of the current shard. | 82 // it is part of the current shard. |
74 virtual bool ShouldRunTest(const testing::TestCase* test_case, | 83 virtual bool ShouldRunTest(const testing::TestCase* test_case, |
75 const testing::TestInfo* test_info) = 0; | 84 const testing::TestInfo* test_info) = 0; |
76 | 85 |
77 // Called to make the delegate run specified test. After the delegate | 86 // Called to make the delegate run specified test. After the delegate |
78 // finishes running the test (can do so asynchronously and out-of-order) | 87 // finishes running the test (can do so asynchronously and out-of-order) |
79 // it must call |callback| regardless of test success. | 88 // it must call |callback| regardless of test success. |
80 typedef base::Callback<void(const TestResult& result)> TestResultCallback; | 89 typedef base::Callback<void(const TestResult& result)> TestResultCallback; |
81 virtual void RunTest(const testing::TestCase* test_case, | 90 virtual void RunTest(const testing::TestCase* test_case, |
82 const testing::TestInfo* test_info, | 91 const testing::TestInfo* test_info, |
83 const TestResultCallback& callback) = 0; | 92 const TestResultCallback& callback) = 0; |
84 | 93 |
85 // If the delegate is running tests asynchronously, it must finish | 94 // If the delegate is running tests asynchronously, it must finish |
86 // running all pending tests and call their callbacks before returning | 95 // running all pending tests and call their callbacks before returning |
87 // from this method. | 96 // from this method. |
88 virtual void RunRemainingTests() = 0; | 97 virtual void RunRemainingTests() = 0; |
89 | 98 |
90 protected: | 99 protected: |
91 virtual ~TestLauncherDelegate(); | 100 virtual ~TestLauncherDelegate(); |
92 }; | 101 }; |
93 | 102 |
| 103 // If |result| is not successful, prints that test's failure message |
| 104 // (extracted from |full_output|) to stdout. |
| 105 void PrintTestOutputSnippetOnFailure(const TestResult& result, |
| 106 const std::string& full_output); |
| 107 |
94 // Launches a child process (assumed to be gtest-based binary) | 108 // Launches a child process (assumed to be gtest-based binary) |
95 // using |command_line|. If |wrapper| is not empty, it is prepended | 109 // using |command_line|. If |wrapper| is not empty, it is prepended |
96 // to the final command line. If the child process is still running | 110 // to the final command line. If the child process is still running |
97 // after |timeout|, it is terminated and |*was_timeout| is set to true. | 111 // after |timeout|, it is terminated and |*was_timeout| is set to true. |
98 int LaunchChildGTestProcess(const CommandLine& command_line, | 112 int LaunchChildGTestProcess(const CommandLine& command_line, |
99 const std::string& wrapper, | 113 const std::string& wrapper, |
100 base::TimeDelta timeout, | 114 base::TimeDelta timeout, |
101 bool* was_timeout); | 115 bool* was_timeout); |
102 | 116 |
103 // Returns command line command line after gtest-specific processing | 117 // Returns command line command line after gtest-specific processing |
(...skipping 11 matching lines...) Expand all Loading... |
115 | 129 |
116 // Launches GTest-based tests from the current executable | 130 // Launches GTest-based tests from the current executable |
117 // using |launcher_delegate|. | 131 // using |launcher_delegate|. |
118 int LaunchTests(TestLauncherDelegate* launcher_delegate, | 132 int LaunchTests(TestLauncherDelegate* launcher_delegate, |
119 int argc, | 133 int argc, |
120 char** argv) WARN_UNUSED_RESULT; | 134 char** argv) WARN_UNUSED_RESULT; |
121 | 135 |
122 } // namespace base | 136 } // namespace base |
123 | 137 |
124 #endif // BASE_TEST_TEST_LAUNCHER_H_ | 138 #endif // BASE_TEST_TEST_LAUNCHER_H_ |
OLD | NEW |