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_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" | 9 #include "base/files/file_path.h" |
10 #include "base/test/launcher/test_launcher.h" | 10 #include "base/test/launcher/test_launcher.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 #if defined(OS_WIN) | 27 #if defined(OS_WIN) |
28 // Launches unit tests in given test suite. Returns exit code. | 28 // Launches unit tests in given test suite. Returns exit code. |
29 // |use_job_objects| determines whether to use job objects. | 29 // |use_job_objects| determines whether to use job objects. |
30 int LaunchUnitTests(int argc, | 30 int LaunchUnitTests(int argc, |
31 wchar_t** argv, | 31 wchar_t** argv, |
32 bool use_job_objects, | 32 bool use_job_objects, |
33 const RunTestSuiteCallback& run_test_suite); | 33 const RunTestSuiteCallback& run_test_suite); |
34 #endif // defined(OS_WIN) | 34 #endif // defined(OS_WIN) |
35 | 35 |
| 36 // Delegate to abstract away platform differences for unit tests. |
| 37 class UnitTestPlatformDelegate { |
| 38 public: |
| 39 // Called to get names of tests available for running. The delegate |
| 40 // must put the result in |output| and return true on success. |
| 41 virtual bool GetTests(std::vector<SplitTestName>* output) = 0; |
| 42 |
| 43 // Called to create a temporary file. The delegate must put the resulting |
| 44 // path in |path| and return true on success. |
| 45 virtual bool CreateTemporaryFile(base::FilePath* path) = 0; |
| 46 |
| 47 // Returns command line for child GTest process based on the command line |
| 48 // of current process. |test_names| is a vector of test full names |
| 49 // (e.g. "A.B"), |output_file| is path to the GTest XML output file. |
| 50 virtual CommandLine GetCommandLineForChildGTestProcess( |
| 51 const std::vector<std::string>& test_names, |
| 52 const base::FilePath& output_file) = 0; |
| 53 |
| 54 // Returns wrapper to use for child GTest process. Empty string means |
| 55 // no wrapper. |
| 56 virtual std::string GetWrapperForChildGTestProcess() = 0; |
| 57 |
| 58 protected: |
| 59 ~UnitTestPlatformDelegate() {} |
| 60 }; |
| 61 |
36 // Test launcher delegate for unit tests (mostly to support batching). | 62 // Test launcher delegate for unit tests (mostly to support batching). |
37 class UnitTestLauncherDelegate : public TestLauncherDelegate { | 63 class UnitTestLauncherDelegate : public TestLauncherDelegate { |
38 public: | 64 public: |
39 explicit UnitTestLauncherDelegate(size_t batch_limit, bool use_job_objects); | 65 UnitTestLauncherDelegate(UnitTestPlatformDelegate* delegate, |
| 66 size_t batch_limit, |
| 67 bool use_job_objects); |
40 ~UnitTestLauncherDelegate() override; | 68 ~UnitTestLauncherDelegate() override; |
41 | 69 |
42 private: | 70 private: |
43 struct GTestCallbackState { | 71 struct GTestCallbackState { |
44 GTestCallbackState(); | 72 GTestCallbackState(); |
45 ~GTestCallbackState(); | 73 ~GTestCallbackState(); |
46 | 74 |
47 TestLauncher* test_launcher; | 75 TestLauncher* test_launcher; |
48 std::vector<std::string> test_names; | 76 std::vector<std::string> test_names; |
49 FilePath output_file; | 77 FilePath output_file; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 static bool ProcessTestResults(TestLauncher* test_launcher, | 114 static bool ProcessTestResults(TestLauncher* test_launcher, |
87 const std::vector<std::string>& test_names, | 115 const std::vector<std::string>& test_names, |
88 const base::FilePath& output_file, | 116 const base::FilePath& output_file, |
89 const std::string& output, | 117 const std::string& output, |
90 int exit_code, | 118 int exit_code, |
91 bool was_timeout, | 119 bool was_timeout, |
92 std::vector<std::string>* tests_to_relaunch); | 120 std::vector<std::string>* tests_to_relaunch); |
93 | 121 |
94 ThreadChecker thread_checker_; | 122 ThreadChecker thread_checker_; |
95 | 123 |
| 124 UnitTestPlatformDelegate* platform_delegate_; |
| 125 |
96 // Maximum number of tests to run in a single batch. | 126 // Maximum number of tests to run in a single batch. |
97 size_t batch_limit_; | 127 size_t batch_limit_; |
98 | 128 |
99 // Determines whether we use job objects on Windows. | 129 // Determines whether we use job objects on Windows. |
100 bool use_job_objects_; | 130 bool use_job_objects_; |
101 | 131 |
102 DISALLOW_COPY_AND_ASSIGN(UnitTestLauncherDelegate); | 132 DISALLOW_COPY_AND_ASSIGN(UnitTestLauncherDelegate); |
103 }; | 133 }; |
104 | 134 |
105 } // namespace base | 135 } // namespace base |
106 | 136 |
107 #endif // BASE_TEST_LAUNCHER_UNIT_TEST_LAUNCHER_H_ | 137 #endif // BASE_TEST_LAUNCHER_UNIT_TEST_LAUNCHER_H_ |
OLD | NEW |