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

Side by Side Diff: base/test/parallel_test_launcher.h

Issue 23757033: GTTF: Support running browser tests in parallel (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 3 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
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_PARALLEL_TEST_LAUNCHER_H_ 5 #ifndef BASE_TEST_PARALLEL_TEST_LAUNCHER_H_
6 #define BASE_TEST_PARALLEL_TEST_LAUNCHER_H_ 6 #define BASE_TEST_PARALLEL_TEST_LAUNCHER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/threading/sequenced_worker_pool.h"
12 #include "base/threading/thread_checker.h" 13 #include "base/threading/thread_checker.h"
13 #include "base/time/time.h" 14 #include "base/time/time.h"
14 #include "base/timer/timer.h" 15 #include "base/timer/timer.h"
15 16
16 class CommandLine; 17 class CommandLine;
17 18
18 namespace base { 19 namespace base {
19 20
20 class SequencedWorkerPoolOwner; 21 class SequencedWorkerPoolOwner;
21 class Timer; 22 class Timer;
22 23
23 // Launches child gtest process in parallel. Keeps track of running processes, 24 // Launches child gtest process in parallel. Keeps track of running processes,
24 // prints a message in case no output is produced for a while. 25 // prints a message in case no output is produced for a while.
25 class ParallelTestLauncher { 26 class ParallelTestLauncher {
26 public: 27 public:
27 // Constructor. |jobs| is the maximum number of tests launched in parallel. 28 // Constructor. |jobs| is the maximum number of tests launched in parallel.
28 explicit ParallelTestLauncher(size_t jobs); 29 explicit ParallelTestLauncher(size_t jobs);
29 ~ParallelTestLauncher(); 30 ~ParallelTestLauncher();
30 31
31 // Callback called after a child process finishes. First argument is the exit 32 // Callback called after a child process finishes. First argument is the exit
32 // code, second one is true if the child process was terminated because of 33 // code, second one is child process elapsed time, third one is true if
33 // a timeout, and third one contains output of the child (stdout and stderr 34 // the child process was terminated because of a timeout, and fourth one
34 // together). 35 // contains output of the child (stdout and stderr together).
35 typedef Callback<void(int, bool, const std::string&)> 36 typedef Callback<void(int, const TimeDelta&, bool, const std::string&)>
36 LaunchChildGTestProcessCallback; 37 LaunchChildGTestProcessCallback;
37 38
38 // Launches a child process (assumed to be gtest-based binary) using 39 // Launches a child process (assumed to be gtest-based binary) using
39 // |command_line|. If |wrapper| is not empty, it is prepended to the final 40 // |command_line|. If |wrapper| is not empty, it is prepended to the final
40 // command line. If the child process is still running after |timeout|, it 41 // command line. If the child process is still running after |timeout|, it
41 // is terminated. After the child process finishes |callback| is called 42 // is terminated. After the child process finishes |callback| is called
42 // on the same thread this method was called. 43 // on the same thread this method was called.
43 void LaunchChildGTestProcess(const CommandLine& command_line, 44 void LaunchChildGTestProcess(const CommandLine& command_line,
44 const std::string& wrapper, 45 const std::string& wrapper,
45 base::TimeDelta timeout, 46 base::TimeDelta timeout,
46 const LaunchChildGTestProcessCallback& callback); 47 const LaunchChildGTestProcessCallback& callback);
47 48
49 // Similar to above, but with processes sharing the same value of |token_name|
50 // being serialized, with order matching order of calls of this method.
51 void LaunchNamedSequencedChildGTestProcess(
52 const std::string& token_name,
53 const CommandLine& command_line,
54 const std::string& wrapper,
55 base::TimeDelta timeout,
56 const LaunchChildGTestProcessCallback& callback);
57
48 // Resets the output watchdog, indicating some test results have been printed 58 // Resets the output watchdog, indicating some test results have been printed
49 // out. If a pause between the calls exceeds an internal treshold, a message 59 // out. If a pause between the calls exceeds an internal treshold, a message
50 // will be printed listing all child processes we're still waiting for. 60 // will be printed listing all child processes we're still waiting for.
51 void ResetOutputWatchdog(); 61 void ResetOutputWatchdog();
52 62
53 private: 63 private:
64 void LaunchSequencedChildGTestProcess(
65 SequencedWorkerPool::SequenceToken sequence_token,
66 const CommandLine& command_line,
67 const std::string& wrapper,
68 base::TimeDelta timeout,
69 const LaunchChildGTestProcessCallback& callback);
70
54 // Called on a worker thread after a child process finishes. 71 // Called on a worker thread after a child process finishes.
55 void OnLaunchTestProcessFinished( 72 void OnLaunchTestProcessFinished(
56 size_t sequence_number, 73 size_t sequence_number,
57 const LaunchChildGTestProcessCallback& callback, 74 const LaunchChildGTestProcessCallback& callback,
58 int exit_code, 75 int exit_code,
76 const TimeDelta& elapsed_time,
59 bool was_timeout, 77 bool was_timeout,
60 const std::string& output); 78 const std::string& output);
61 79
62 // Called by the delay timer when no output was made for a while. 80 // Called by the delay timer when no output was made for a while.
63 void OnOutputTimeout(); 81 void OnOutputTimeout();
64 82
65 // Watchdog timer to make sure we do not go without output for too long. 83 // Watchdog timer to make sure we do not go without output for too long.
66 DelayTimer<ParallelTestLauncher> timer_; 84 DelayTimer<ParallelTestLauncher> timer_;
67 85
68 // Monotonically increasing sequence number to uniquely identify each 86 // Monotonically increasing sequence number to uniquely identify each
(...skipping 10 matching lines...) Expand all
79 // Make sure we don't accidentally call the wrong methods e.g. on the worker 97 // Make sure we don't accidentally call the wrong methods e.g. on the worker
80 // pool thread. With lots of callbacks used this is non-trivial. 98 // pool thread. With lots of callbacks used this is non-trivial.
81 ThreadChecker thread_checker_; 99 ThreadChecker thread_checker_;
82 100
83 DISALLOW_COPY_AND_ASSIGN(ParallelTestLauncher); 101 DISALLOW_COPY_AND_ASSIGN(ParallelTestLauncher);
84 }; 102 };
85 103
86 } // namespace base 104 } // namespace base
87 105
88 #endif // BASE_TEST_PARALLEL_TEST_LAUNCHER_H_ 106 #endif // BASE_TEST_PARALLEL_TEST_LAUNCHER_H_
OLDNEW
« no previous file with comments | « no previous file | base/test/parallel_test_launcher.cc » ('j') | content/public/test/test_launcher.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698