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

Side by Side Diff: base/test/launcher/test_launcher_ios.cc

Issue 885443002: Roll Chrome into Mojo. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Rebase to ToT mojo Created 5 years, 10 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
« no previous file with comments | « base/test/launcher/test_launcher.cc ('k') | base/test/launcher/unit_test_launcher.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "base/test/launcher/test_launcher.h" 5 #include "base/test/launcher/test_launcher.h"
6 6
7 #include "base/at_exit.h" 7 #include "base/at_exit.h"
8 #include "base/base_paths.h" 8 #include "base/base_paths.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
14 #include "base/format_macros.h" 14 #include "base/format_macros.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/process/launch.h" 17 #include "base/process/launch.h"
18 #include "base/strings/string_util.h"
18 #include "base/test/launcher/unit_test_launcher.h" 19 #include "base/test/launcher/unit_test_launcher.h"
19 #include "base/test/test_switches.h" 20 #include "base/test/test_switches.h"
20 #include "base/test/test_timeouts.h" 21 #include "base/test/test_timeouts.h"
21 22
22 namespace { 23 namespace {
23 24
24 const char kHelpFlag[] = "help"; 25 const char kHelpFlag[] = "help";
25 26
26 void PrintUsage() { 27 void PrintUsage() {
27 fprintf(stdout, 28 fprintf(stdout,
(...skipping 19 matching lines...) Expand all
47 " auto means to print it when the test failed.\n" 48 " auto means to print it when the test failed.\n"
48 "\n" 49 "\n"
49 " --test-launcher-total-shards=N\n" 50 " --test-launcher-total-shards=N\n"
50 " Sets the total number of shards to N.\n" 51 " Sets the total number of shards to N.\n"
51 "\n" 52 "\n"
52 " --test-launcher-shard-index=N\n" 53 " --test-launcher-shard-index=N\n"
53 " Sets the shard index to run to N (from 0 to TOTAL - 1).\n"); 54 " Sets the shard index to run to N (from 0 to TOTAL - 1).\n");
54 fflush(stdout); 55 fflush(stdout);
55 } 56 }
56 57
57 class IOSUnitTestLauncherDelegate : public base::UnitTestLauncherDelegate { 58 class IOSUnitTestPlatformDelegate : public base::UnitTestPlatformDelegate {
58 public: 59 public:
59 IOSUnitTestLauncherDelegate() : base::UnitTestLauncherDelegate(0, false) { 60 IOSUnitTestPlatformDelegate() {
60 } 61 }
61 62
62 bool Init() WARN_UNUSED_RESULT { 63 bool Init() WARN_UNUSED_RESULT {
63 if (!PathService::Get(base::DIR_EXE, &dir_exe_)) { 64 if (!PathService::Get(base::DIR_EXE, &dir_exe_)) {
64 LOG(ERROR) << "Failed to get directory of current executable."; 65 LOG(ERROR) << "Failed to get directory of current executable.";
65 return false; 66 return false;
66 } 67 }
67 68
68 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 69 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
69 std::vector<std::string> args(command_line->GetArgs()); 70 std::vector<std::string> args(command_line->GetArgs());
(...skipping 30 matching lines...) Expand all
100 101
101 base::LaunchOptions launch_options; 102 base::LaunchOptions launch_options;
102 launch_options.wait = true; 103 launch_options.wait = true;
103 104
104 if (!base::LaunchProcess(cmd_line, launch_options).IsValid()) 105 if (!base::LaunchProcess(cmd_line, launch_options).IsValid())
105 return false; 106 return false;
106 107
107 return base::ReadTestNamesFromFile(test_list_path, output); 108 return base::ReadTestNamesFromFile(test_list_path, output);
108 } 109 }
109 110
111 bool CreateTemporaryFile(base::FilePath* path) override {
112 if (!CreateTemporaryDirInDir(writable_path_, std::string(), path))
113 return false;
114 *path = path->AppendASCII("test_results.xml");
115 return true;
116 }
117
118 base::CommandLine GetCommandLineForChildGTestProcess(
119 const std::vector<std::string>& test_names,
120 const base::FilePath& output_file) override {
121 base::CommandLine cmd_line(dir_exe_.AppendASCII(test_name_ + ".app"));
122 cmd_line.AppendSwitchPath(switches::kTestLauncherOutput, output_file);
123 cmd_line.AppendSwitchASCII(base::kGTestFilterFlag,
124 JoinString(test_names, ":"));
125 return cmd_line;
126 }
127
128 std::string GetWrapperForChildGTestProcess() override {
129 return dir_exe_.AppendASCII("iossim").value();
130 }
131
110 private: 132 private:
111 // Directory containing test launcher's executable. 133 // Directory containing test launcher's executable.
112 base::FilePath dir_exe_; 134 base::FilePath dir_exe_;
113 135
114 // Name of the test executable to run. 136 // Name of the test executable to run.
115 std::string test_name_; 137 std::string test_name_;
116 138
117 // Path that launched test binary can write to. 139 // Path that launched test binary can write to.
118 base::FilePath writable_path_; 140 base::FilePath writable_path_;
119 141
120 DISALLOW_COPY_AND_ASSIGN(IOSUnitTestLauncherDelegate); 142 DISALLOW_COPY_AND_ASSIGN(IOSUnitTestPlatformDelegate);
121 }; 143 };
122 144
123 } // namespace 145 } // namespace
124 146
125 int main(int argc, char** argv) { 147 int main(int argc, char** argv) {
126 base::AtExitManager at_exit; 148 base::AtExitManager at_exit;
127 149
128 base::CommandLine::Init(argc, argv); 150 base::CommandLine::Init(argc, argv);
129 151
130 if (base::CommandLine::ForCurrentProcess()->HasSwitch(kHelpFlag)) { 152 if (base::CommandLine::ForCurrentProcess()->HasSwitch(kHelpFlag)) {
131 PrintUsage(); 153 PrintUsage();
132 return 0; 154 return 0;
133 } 155 }
134 156
135 base::TimeTicks start_time(base::TimeTicks::Now()); 157 base::TimeTicks start_time(base::TimeTicks::Now());
136 158
137 TestTimeouts::Initialize(); 159 TestTimeouts::Initialize();
138 160
139 base::MessageLoopForIO message_loop; 161 base::MessageLoopForIO message_loop;
140 162
141 IOSUnitTestLauncherDelegate delegate; 163 IOSUnitTestPlatformDelegate platform_delegate;
142 if (!delegate.Init()) { 164 if (!platform_delegate.Init()) {
143 fprintf(stderr, "Failed to intialize test launcher delegate.\n"); 165 fprintf(stderr, "Failed to intialize test launcher platform delegate.\n");
144 fflush(stderr); 166 fflush(stderr);
145 return 1; 167 return 1;
146 } 168 }
169 base::UnitTestLauncherDelegate delegate(&platform_delegate, 0, false);
147 // Force one job since we can't run multiple simulators in parallel. 170 // Force one job since we can't run multiple simulators in parallel.
148 base::TestLauncher launcher(&delegate, 1); 171 base::TestLauncher launcher(&delegate, 1);
149 bool success = launcher.Run(); 172 bool success = launcher.Run();
150 173
151 fprintf(stdout, "Tests took %" PRId64 " seconds.\n", 174 fprintf(stdout, "Tests took %" PRId64 " seconds.\n",
152 (base::TimeTicks::Now() - start_time).InSeconds()); 175 (base::TimeTicks::Now() - start_time).InSeconds());
153 fflush(stdout); 176 fflush(stdout);
154 177
155 return (success ? 0 : 1); 178 return (success ? 0 : 1);
156 } 179 }
OLDNEW
« no previous file with comments | « base/test/launcher/test_launcher.cc ('k') | base/test/launcher/unit_test_launcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698