| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 const base::FilePath& output_file) = 0; | 52 const base::FilePath& output_file) = 0; |
| 53 | 53 |
| 54 // Returns wrapper to use for child GTest process. Empty string means | 54 // Returns wrapper to use for child GTest process. Empty string means |
| 55 // no wrapper. | 55 // no wrapper. |
| 56 virtual std::string GetWrapperForChildGTestProcess() = 0; | 56 virtual std::string GetWrapperForChildGTestProcess() = 0; |
| 57 | 57 |
| 58 protected: | 58 protected: |
| 59 ~UnitTestPlatformDelegate() {} | 59 ~UnitTestPlatformDelegate() {} |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 // Runs tests serially, each in its own process. |
| 63 void RunUnitTestsSerially(TestLauncher* test_launcher, |
| 64 UnitTestPlatformDelegate* platform_delegate, |
| 65 const std::vector<std::string>& test_names, |
| 66 int launch_flags); |
| 67 |
| 68 // Runs tests in batches (each batch in its own process). |
| 69 void RunUnitTestsBatch(TestLauncher* test_launcher, |
| 70 UnitTestPlatformDelegate* platform_delegate, |
| 71 const std::vector<std::string>& test_names, |
| 72 int launch_flags); |
| 73 |
| 62 // Test launcher delegate for unit tests (mostly to support batching). | 74 // Test launcher delegate for unit tests (mostly to support batching). |
| 63 class UnitTestLauncherDelegate : public TestLauncherDelegate { | 75 class UnitTestLauncherDelegate : public TestLauncherDelegate { |
| 64 public: | 76 public: |
| 65 UnitTestLauncherDelegate(UnitTestPlatformDelegate* delegate, | 77 UnitTestLauncherDelegate(UnitTestPlatformDelegate* delegate, |
| 66 size_t batch_limit, | 78 size_t batch_limit, |
| 67 bool use_job_objects); | 79 bool use_job_objects); |
| 68 ~UnitTestLauncherDelegate() override; | 80 ~UnitTestLauncherDelegate() override; |
| 69 | 81 |
| 70 private: | 82 private: |
| 71 struct GTestCallbackState { | |
| 72 GTestCallbackState(); | |
| 73 ~GTestCallbackState(); | |
| 74 | |
| 75 TestLauncher* test_launcher; | |
| 76 std::vector<std::string> test_names; | |
| 77 FilePath output_file; | |
| 78 }; | |
| 79 | |
| 80 // TestLauncherDelegate: | 83 // TestLauncherDelegate: |
| 81 bool GetTests(std::vector<SplitTestName>* output) override; | 84 bool GetTests(std::vector<SplitTestName>* output) override; |
| 82 bool ShouldRunTest(const std::string& test_case_name, | 85 bool ShouldRunTest(const std::string& test_case_name, |
| 83 const std::string& test_name) override; | 86 const std::string& test_name) override; |
| 84 size_t RunTests(TestLauncher* test_launcher, | 87 size_t RunTests(TestLauncher* test_launcher, |
| 85 const std::vector<std::string>& test_names) override; | 88 const std::vector<std::string>& test_names) override; |
| 86 size_t RetryTests(TestLauncher* test_launcher, | 89 size_t RetryTests(TestLauncher* test_launcher, |
| 87 const std::vector<std::string>& test_names) override; | 90 const std::vector<std::string>& test_names) override; |
| 88 | 91 |
| 89 // Runs tests serially, each in its own process. | |
| 90 void RunSerially(TestLauncher* test_launcher, | |
| 91 const std::vector<std::string>& test_names); | |
| 92 | |
| 93 // Runs tests in batches (each batch in its own process). | |
| 94 void RunBatch(TestLauncher* test_launcher, | |
| 95 const std::vector<std::string>& test_names); | |
| 96 | |
| 97 // Callback for batched tests. | |
| 98 void GTestCallback(const GTestCallbackState& callback_state, | |
| 99 int exit_code, | |
| 100 const TimeDelta& elapsed_time, | |
| 101 bool was_timeout, | |
| 102 const std::string& output); | |
| 103 | |
| 104 // Callback for serialized tests. | |
| 105 void SerialGTestCallback(const GTestCallbackState& callback_state, | |
| 106 const std::vector<std::string>& test_names, | |
| 107 int exit_code, | |
| 108 const TimeDelta& elapsed_time, | |
| 109 bool was_timeout, | |
| 110 const std::string& output); | |
| 111 | |
| 112 // Interprets test results and reports to the test launcher. Returns true | |
| 113 // on success. | |
| 114 static bool ProcessTestResults(TestLauncher* test_launcher, | |
| 115 const std::vector<std::string>& test_names, | |
| 116 const base::FilePath& output_file, | |
| 117 const std::string& output, | |
| 118 int exit_code, | |
| 119 bool was_timeout, | |
| 120 std::vector<std::string>* tests_to_relaunch); | |
| 121 | |
| 122 ThreadChecker thread_checker_; | 92 ThreadChecker thread_checker_; |
| 123 | 93 |
| 124 UnitTestPlatformDelegate* platform_delegate_; | 94 UnitTestPlatformDelegate* platform_delegate_; |
| 125 | 95 |
| 126 // Maximum number of tests to run in a single batch. | 96 // Maximum number of tests to run in a single batch. |
| 127 size_t batch_limit_; | 97 size_t batch_limit_; |
| 128 | 98 |
| 129 // Determines whether we use job objects on Windows. | 99 // Determines whether we use job objects on Windows. |
| 130 bool use_job_objects_; | 100 bool use_job_objects_; |
| 131 | 101 |
| 132 DISALLOW_COPY_AND_ASSIGN(UnitTestLauncherDelegate); | 102 DISALLOW_COPY_AND_ASSIGN(UnitTestLauncherDelegate); |
| 133 }; | 103 }; |
| 134 | 104 |
| 135 } // namespace base | 105 } // namespace base |
| 136 | 106 |
| 137 #endif // BASE_TEST_LAUNCHER_UNIT_TEST_LAUNCHER_H_ | 107 #endif // BASE_TEST_LAUNCHER_UNIT_TEST_LAUNCHER_H_ |
| OLD | NEW |