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

Side by Side Diff: base/test/launcher/test_launcher.h

Issue 55473002: GTTF: Unify parallel test launching. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: reupload Created 7 years, 1 month 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 | « base/test/launcher/parallel_test_launcher.cc ('k') | base/test/launcher/test_launcher.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 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_LAUNCHER_TEST_LAUNCHER_H_ 5 #ifndef BASE_TEST_LAUNCHER_TEST_LAUNCHER_H_
6 #define BASE_TEST_LAUNCHER_TEST_LAUNCHER_H_ 6 #define BASE_TEST_LAUNCHER_TEST_LAUNCHER_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/callback_forward.h" 12 #include "base/callback_forward.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/test/launcher/test_result.h" 14 #include "base/test/launcher/test_result.h"
15 #include "base/test/launcher/test_results_tracker.h" 15 #include "base/test/launcher/test_results_tracker.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "base/timer/timer.h"
17 18
18 class CommandLine; 19 class CommandLine;
19 20
20 namespace testing { 21 namespace testing {
21 class TestCase; 22 class TestCase;
22 class TestInfo; 23 class TestInfo;
23 } 24 }
24 25
25 namespace base { 26 namespace base {
26 27
27 struct LaunchOptions; 28 struct LaunchOptions;
29 class SequencedWorkerPoolOwner;
28 class TestLauncher; 30 class TestLauncher;
29 31
30 // Constants for GTest command-line flags. 32 // Constants for GTest command-line flags.
31 extern const char kGTestFilterFlag[]; 33 extern const char kGTestFilterFlag[];
32 extern const char kGTestHelpFlag[]; 34 extern const char kGTestHelpFlag[];
33 extern const char kGTestListTestsFlag[]; 35 extern const char kGTestListTestsFlag[];
34 extern const char kGTestRepeatFlag[]; 36 extern const char kGTestRepeatFlag[];
35 extern const char kGTestRunDisabledTestsFlag[]; 37 extern const char kGTestRunDisabledTestsFlag[];
36 extern const char kGTestOutputFlag[]; 38 extern const char kGTestOutputFlag[];
37 39
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 virtual size_t RetryTests(TestLauncher* test_launcher, 75 virtual size_t RetryTests(TestLauncher* test_launcher,
74 const std::vector<std::string>& test_names) = 0; 76 const std::vector<std::string>& test_names) = 0;
75 77
76 protected: 78 protected:
77 virtual ~TestLauncherDelegate(); 79 virtual ~TestLauncherDelegate();
78 }; 80 };
79 81
80 // Launches tests using a TestLauncherDelegate. 82 // Launches tests using a TestLauncherDelegate.
81 class TestLauncher { 83 class TestLauncher {
82 public: 84 public:
83 explicit TestLauncher(TestLauncherDelegate* launcher_delegate); 85 // Constructor. |parallel_jobs| is the limit of simultaneous parallel test
86 // jobs.
87 TestLauncher(TestLauncherDelegate* launcher_delegate, size_t parallel_jobs);
84 ~TestLauncher(); 88 ~TestLauncher();
85 89
86 // Runs the launcher. Must be called at most once. 90 // Runs the launcher. Must be called at most once.
87 bool Run(int argc, char** argv) WARN_UNUSED_RESULT; 91 bool Run(int argc, char** argv) WARN_UNUSED_RESULT;
88 92
93 // Callback called after a child process finishes. First argument is the exit
94 // code, second one is child process elapsed time, third one is true if
95 // the child process was terminated because of a timeout, and fourth one
96 // contains output of the child (stdout and stderr together).
97 typedef Callback<void(int, const TimeDelta&, bool, const std::string&)>
98 LaunchChildGTestProcessCallback;
99
100 // Launches a child process (assumed to be gtest-based binary) using
101 // |command_line|. If |wrapper| is not empty, it is prepended to the final
102 // command line. If the child process is still running after |timeout|, it
103 // is terminated. After the child process finishes |callback| is called
104 // on the same thread this method was called.
105 void LaunchChildGTestProcess(const CommandLine& command_line,
106 const std::string& wrapper,
107 base::TimeDelta timeout,
108 const LaunchChildGTestProcessCallback& callback);
109
89 // Called when a test has finished running. 110 // Called when a test has finished running.
90 void OnTestFinished(const TestResult& result); 111 void OnTestFinished(const TestResult& result);
91 112
92 private: 113 private:
93 bool Init() WARN_UNUSED_RESULT; 114 bool Init() WARN_UNUSED_RESULT;
94 115
95 // Runs all tests in current iteration. Uses callbacks to communicate success. 116 // Runs all tests in current iteration. Uses callbacks to communicate success.
96 void RunTests(); 117 void RunTests();
97 118
98 void RunTestIteration(); 119 void RunTestIteration();
99 120
100 void OnAllTestsStarted();
101
102 // Saves test results summary as JSON if requested from command line. 121 // Saves test results summary as JSON if requested from command line.
103 void MaybeSaveSummaryAsJSON(); 122 void MaybeSaveSummaryAsJSON();
104 123
124 // Called on a worker thread after a child process finishes.
125 void OnLaunchTestProcessFinished(
126 const LaunchChildGTestProcessCallback& callback,
127 int exit_code,
128 const TimeDelta& elapsed_time,
129 bool was_timeout,
130 const std::string& output);
131
132 // Called by the delay timer when no output was made for a while.
133 void OnOutputTimeout();
134
135 // Make sure we don't accidentally call the wrong methods e.g. on the worker
136 // pool thread. With lots of callbacks used this is non-trivial.
137 // Should be the first member so that it's destroyed last: when destroying
138 // other members, especially the worker pool, we may check the code is running
139 // on the correct thread.
140 ThreadChecker thread_checker_;
141
105 TestLauncherDelegate* launcher_delegate_; 142 TestLauncherDelegate* launcher_delegate_;
106 143
107 // Support for outer sharding, just like gtest does. 144 // Support for outer sharding, just like gtest does.
108 int32 total_shards_; // Total number of outer shards, at least one. 145 int32 total_shards_; // Total number of outer shards, at least one.
109 int32 shard_index_; // Index of shard the launcher is to run. 146 int32 shard_index_; // Index of shard the launcher is to run.
110 147
111 int cycles_; // Number of remaining test itreations, or -1 for infinite. 148 int cycles_; // Number of remaining test itreations, or -1 for infinite.
112 149
113 // Test filters (empty means no filter). Entries are separated by colons. 150 // Test filters (empty means no filter). Entries are separated by colons.
114 std::string positive_test_filter_; 151 std::string positive_test_filter_;
(...skipping 19 matching lines...) Expand all
134 size_t retry_limit_; 171 size_t retry_limit_;
135 172
136 // Tests to retry in this iteration. 173 // Tests to retry in this iteration.
137 std::set<std::string> tests_to_retry_; 174 std::set<std::string> tests_to_retry_;
138 175
139 // Result to be returned from Run. 176 // Result to be returned from Run.
140 bool run_result_; 177 bool run_result_;
141 178
142 TestResultsTracker results_tracker_; 179 TestResultsTracker results_tracker_;
143 180
181 // Watchdog timer to make sure we do not go without output for too long.
182 DelayTimer<TestLauncher> watchdog_timer_;
183
184 // Worker pool used to launch processes in parallel.
185 scoped_ptr<SequencedWorkerPoolOwner> worker_pool_owner_;
186
144 DISALLOW_COPY_AND_ASSIGN(TestLauncher); 187 DISALLOW_COPY_AND_ASSIGN(TestLauncher);
145 }; 188 };
146 189
147 // Extract part from |full_output| that applies to |result|. 190 // Extract part from |full_output| that applies to |result|.
148 std::string GetTestOutputSnippet(const TestResult& result, 191 std::string GetTestOutputSnippet(const TestResult& result,
149 const std::string& full_output); 192 const std::string& full_output);
150 193
151 // Launches a child process (assumed to be gtest-based binary) 194 // Launches a child process (assumed to be gtest-based binary)
152 // using |command_line|. If |wrapper| is not empty, it is prepended 195 // using |command_line|. If |wrapper| is not empty, it is prepended
153 // to the final command line. If the child process is still running 196 // to the final command line. If the child process is still running
(...skipping 12 matching lines...) Expand all
166 // running after |timeout|, it is terminated and |*was_timeout| is set to true. 209 // running after |timeout|, it is terminated and |*was_timeout| is set to true.
167 // Returns exit code of the process. 210 // Returns exit code of the process.
168 int LaunchChildTestProcessWithOptions(const CommandLine& command_line, 211 int LaunchChildTestProcessWithOptions(const CommandLine& command_line,
169 const LaunchOptions& options, 212 const LaunchOptions& options,
170 base::TimeDelta timeout, 213 base::TimeDelta timeout,
171 bool* was_timeout); 214 bool* was_timeout);
172 215
173 } // namespace base 216 } // namespace base
174 217
175 #endif // BASE_TEST_LAUNCHER_TEST_LAUNCHER_H_ 218 #endif // BASE_TEST_LAUNCHER_TEST_LAUNCHER_H_
OLDNEW
« no previous file with comments | « base/test/launcher/parallel_test_launcher.cc ('k') | base/test/launcher/test_launcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698