Use UintToString() for unsigned values.
[chromium-blink-merge.git] / base / test / launcher / unit_test_launcher.h
blobd5ba153e805c7a66699d290ed51984e04b168658
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
3 // found in the LICENSE file.
5 #ifndef BASE_TEST_LAUNCHER_UNIT_TEST_LAUNCHER_H_
6 #define BASE_TEST_LAUNCHER_UNIT_TEST_LAUNCHER_H_
8 #include "base/callback.h"
9 #include "base/files/file_path.h"
10 #include "base/test/launcher/test_launcher.h"
12 namespace base {
14 // Callback that runs a test suite and returns exit code.
15 typedef base::Callback<int(void)> RunTestSuiteCallback;
17 // Launches unit tests in given test suite. Returns exit code.
18 int LaunchUnitTests(int argc,
19 char** argv,
20 const RunTestSuiteCallback& run_test_suite);
22 // Same as above, but always runs tests serially.
23 int LaunchUnitTestsSerially(int argc,
24 char** argv,
25 const RunTestSuiteCallback& run_test_suite);
27 #if defined(OS_WIN)
28 // Launches unit tests in given test suite. Returns exit code.
29 // |use_job_objects| determines whether to use job objects.
30 int LaunchUnitTests(int argc,
31 wchar_t** argv,
32 bool use_job_objects,
33 const RunTestSuiteCallback& run_test_suite);
34 #endif // defined(OS_WIN)
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<TestIdentifier>* output) = 0;
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;
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;
54 // Returns wrapper to use for child GTest process. Empty string means
55 // no wrapper.
56 virtual std::string GetWrapperForChildGTestProcess() = 0;
58 // Relaunch tests, e.g. after a crash.
59 virtual void RelaunchTests(TestLauncher* test_launcher,
60 const std::vector<std::string>& test_names,
61 int launch_flags) = 0;
63 protected:
64 ~UnitTestPlatformDelegate() {}
67 // Runs tests serially, each in its own process.
68 void RunUnitTestsSerially(TestLauncher* test_launcher,
69 UnitTestPlatformDelegate* platform_delegate,
70 const std::vector<std::string>& test_names,
71 int launch_flags);
73 // Runs tests in batches (each batch in its own process).
74 void RunUnitTestsBatch(TestLauncher* test_launcher,
75 UnitTestPlatformDelegate* platform_delegate,
76 const std::vector<std::string>& test_names,
77 int launch_flags);
79 // Test launcher delegate for unit tests (mostly to support batching).
80 class UnitTestLauncherDelegate : public TestLauncherDelegate {
81 public:
82 UnitTestLauncherDelegate(UnitTestPlatformDelegate* delegate,
83 size_t batch_limit,
84 bool use_job_objects);
85 ~UnitTestLauncherDelegate() override;
87 private:
88 // TestLauncherDelegate:
89 bool GetTests(std::vector<TestIdentifier>* output) override;
90 bool ShouldRunTest(const std::string& test_case_name,
91 const std::string& test_name) override;
92 size_t RunTests(TestLauncher* test_launcher,
93 const std::vector<std::string>& test_names) override;
94 size_t RetryTests(TestLauncher* test_launcher,
95 const std::vector<std::string>& test_names) override;
97 ThreadChecker thread_checker_;
99 UnitTestPlatformDelegate* platform_delegate_;
101 // Maximum number of tests to run in a single batch.
102 size_t batch_limit_;
104 // Determines whether we use job objects on Windows.
105 bool use_job_objects_;
107 DISALLOW_COPY_AND_ASSIGN(UnitTestLauncherDelegate);
110 } // namespace base
112 #endif // BASE_TEST_LAUNCHER_UNIT_TEST_LAUNCHER_H_