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

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

Issue 862133002: Update from https://crrev.com/312398 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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
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_UNIT_TEST_LAUNCHER_H_ 5 #ifndef BASE_TEST_LAUNCHER_UNIT_TEST_LAUNCHER_H_
6 #define BASE_TEST_LAUNCHER_UNIT_TEST_LAUNCHER_H_ 6 #define BASE_TEST_LAUNCHER_UNIT_TEST_LAUNCHER_H_
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/files/file_path.h"
10 #include "base/test/launcher/test_launcher.h"
9 11
10 namespace base { 12 namespace base {
11 13
12 // Callback that runs a test suite and returns exit code. 14 // Callback that runs a test suite and returns exit code.
13 typedef base::Callback<int(void)> RunTestSuiteCallback; 15 typedef base::Callback<int(void)> RunTestSuiteCallback;
14 16
15 // Launches unit tests in given test suite. Returns exit code. 17 // Launches unit tests in given test suite. Returns exit code.
16 int LaunchUnitTests(int argc, 18 int LaunchUnitTests(int argc,
17 char** argv, 19 char** argv,
18 const RunTestSuiteCallback& run_test_suite); 20 const RunTestSuiteCallback& run_test_suite);
19 21
20 // Same as above, but always runs tests serially. 22 // Same as above, but always runs tests serially.
21 int LaunchUnitTestsSerially(int argc, 23 int LaunchUnitTestsSerially(int argc,
22 char** argv, 24 char** argv,
23 const RunTestSuiteCallback& run_test_suite); 25 const RunTestSuiteCallback& run_test_suite);
24 26
25 #if defined(OS_WIN) 27 #if defined(OS_WIN)
26 // Launches unit tests in given test suite. Returns exit code. 28 // Launches unit tests in given test suite. Returns exit code.
27 // |use_job_objects| determines whether to use job objects. 29 // |use_job_objects| determines whether to use job objects.
28 int LaunchUnitTests(int argc, 30 int LaunchUnitTests(int argc,
29 wchar_t** argv, 31 wchar_t** argv,
30 bool use_job_objects, 32 bool use_job_objects,
31 const RunTestSuiteCallback& run_test_suite); 33 const RunTestSuiteCallback& run_test_suite);
32 #endif // defined(OS_WIN) 34 #endif // defined(OS_WIN)
33 35
36 // Test launcher delegate for unit tests (mostly to support batching).
37 class UnitTestLauncherDelegate : public TestLauncherDelegate {
38 public:
39 explicit UnitTestLauncherDelegate(size_t batch_limit, bool use_job_objects);
40 ~UnitTestLauncherDelegate() override;
41
42 private:
43 struct GTestCallbackState {
44 GTestCallbackState();
45 ~GTestCallbackState();
46
47 TestLauncher* test_launcher;
48 std::vector<std::string> test_names;
49 FilePath output_file;
50 };
51
52 // TestLauncherDelegate:
53 bool GetTests(std::vector<SplitTestName>* output) override;
54 bool ShouldRunTest(const std::string& test_case_name,
55 const std::string& test_name) override;
56 size_t RunTests(TestLauncher* test_launcher,
57 const std::vector<std::string>& test_names) override;
58 size_t RetryTests(TestLauncher* test_launcher,
59 const std::vector<std::string>& test_names) override;
60
61 // Runs tests serially, each in its own process.
62 void RunSerially(TestLauncher* test_launcher,
63 const std::vector<std::string>& test_names);
64
65 // Runs tests in batches (each batch in its own process).
66 void RunBatch(TestLauncher* test_launcher,
67 const std::vector<std::string>& test_names);
68
69 // Callback for batched tests.
70 void GTestCallback(const GTestCallbackState& callback_state,
71 int exit_code,
72 const TimeDelta& elapsed_time,
73 bool was_timeout,
74 const std::string& output);
75
76 // Callback for serialized tests.
77 void SerialGTestCallback(const GTestCallbackState& callback_state,
78 const std::vector<std::string>& test_names,
79 int exit_code,
80 const TimeDelta& elapsed_time,
81 bool was_timeout,
82 const std::string& output);
83
84 // Interprets test results and reports to the test launcher. Returns true
85 // on success.
86 static bool ProcessTestResults(TestLauncher* test_launcher,
87 const std::vector<std::string>& test_names,
88 const base::FilePath& output_file,
89 const std::string& output,
90 int exit_code,
91 bool was_timeout,
92 std::vector<std::string>* tests_to_relaunch);
93
94 ThreadChecker thread_checker_;
95
96 // Maximum number of tests to run in a single batch.
97 size_t batch_limit_;
98
99 // Determines whether we use job objects on Windows.
100 bool use_job_objects_;
101
102 DISALLOW_COPY_AND_ASSIGN(UnitTestLauncherDelegate);
103 };
104
34 } // namespace base 105 } // namespace base
35 106
36 #endif // BASE_TEST_LAUNCHER_UNIT_TEST_LAUNCHER_H_ 107 #endif // BASE_TEST_LAUNCHER_UNIT_TEST_LAUNCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698