| 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 #include <stdio.h> | 5 #include <stdio.h> |
| 6 | 6 |
| 7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 } | 31 } |
| 32 | 32 |
| 33 base::FilePath sync_test_script_path; | 33 base::FilePath sync_test_script_path; |
| 34 if (!test_server->GetTestScriptPath(sync_test_script_name, | 34 if (!test_server->GetTestScriptPath(sync_test_script_name, |
| 35 &sync_test_script_path)) { | 35 &sync_test_script_path)) { |
| 36 LOG(ERROR) << "Error trying to get path for test script " | 36 LOG(ERROR) << "Error trying to get path for test script " |
| 37 << sync_test_script_name; | 37 << sync_test_script_name; |
| 38 return false; | 38 return false; |
| 39 } | 39 } |
| 40 | 40 |
| 41 CommandLine python_command(CommandLine::NO_PROGRAM); | 41 base::CommandLine python_command(base::CommandLine::NO_PROGRAM); |
| 42 if (!GetPythonCommand(&python_command)) { | 42 if (!GetPythonCommand(&python_command)) { |
| 43 LOG(ERROR) << "Could not get python runtime command."; | 43 LOG(ERROR) << "Could not get python runtime command."; |
| 44 return false; | 44 return false; |
| 45 } | 45 } |
| 46 | 46 |
| 47 python_command.AppendArgPath(sync_test_script_path); | 47 python_command.AppendArgPath(sync_test_script_path); |
| 48 if (!base::LaunchProcess(python_command, base::LaunchOptions()).IsValid()) { | 48 if (!base::LaunchProcess(python_command, base::LaunchOptions()).IsValid()) { |
| 49 LOG(ERROR) << "Failed to launch test script " << sync_test_script_name; | 49 LOG(ERROR) << "Failed to launch test script " << sync_test_script_name; |
| 50 return false; | 50 return false; |
| 51 } | 51 } |
| 52 return true; | 52 return true; |
| 53 } | 53 } |
| 54 | 54 |
| 55 // Gets a port value from the switch with name |switch_name| and writes it to | 55 // Gets a port value from the switch with name |switch_name| and writes it to |
| 56 // |port|. Returns true if a port was provided and false otherwise. | 56 // |port|. Returns true if a port was provided and false otherwise. |
| 57 static bool GetPortFromSwitch(const std::string& switch_name, uint16* port) { | 57 static bool GetPortFromSwitch(const std::string& switch_name, uint16* port) { |
| 58 DCHECK(port != NULL) << "|port| is NULL"; | 58 DCHECK(port != NULL) << "|port| is NULL"; |
| 59 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 59 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 60 int port_int = 0; | 60 int port_int = 0; |
| 61 if (command_line->HasSwitch(switch_name)) { | 61 if (command_line->HasSwitch(switch_name)) { |
| 62 std::string port_str = command_line->GetSwitchValueASCII(switch_name); | 62 std::string port_str = command_line->GetSwitchValueASCII(switch_name); |
| 63 if (!base::StringToInt(port_str, &port_int)) { | 63 if (!base::StringToInt(port_str, &port_int)) { |
| 64 return false; | 64 return false; |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 *port = static_cast<uint16>(port_int); | 67 *port = static_cast<uint16>(port_int); |
| 68 return true; | 68 return true; |
| 69 } | 69 } |
| 70 | 70 |
| 71 int main(int argc, const char* argv[]) { | 71 int main(int argc, const char* argv[]) { |
| 72 base::AtExitManager at_exit_manager; | 72 base::AtExitManager at_exit_manager; |
| 73 base::MessageLoopForIO message_loop; | 73 base::MessageLoopForIO message_loop; |
| 74 | 74 |
| 75 // Process command line | 75 // Process command line |
| 76 CommandLine::Init(argc, argv); | 76 base::CommandLine::Init(argc, argv); |
| 77 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 77 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 78 | 78 |
| 79 logging::LoggingSettings settings; | 79 logging::LoggingSettings settings; |
| 80 settings.logging_dest = logging::LOG_TO_ALL; | 80 settings.logging_dest = logging::LOG_TO_ALL; |
| 81 settings.log_file = FILE_PATH_LITERAL("sync_testserver.log"); | 81 settings.log_file = FILE_PATH_LITERAL("sync_testserver.log"); |
| 82 if (!logging::InitLogging(settings)) { | 82 if (!logging::InitLogging(settings)) { |
| 83 printf("Error: could not initialize logging. Exiting.\n"); | 83 printf("Error: could not initialize logging. Exiting.\n"); |
| 84 return -1; | 84 return -1; |
| 85 } | 85 } |
| 86 | 86 |
| 87 TestTimeouts::Initialize(); | 87 TestTimeouts::Initialize(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 111 printf("Error: failed to start python sync test server. Exiting.\n"); | 111 printf("Error: failed to start python sync test server. Exiting.\n"); |
| 112 return -1; | 112 return -1; |
| 113 } | 113 } |
| 114 | 114 |
| 115 printf("Python sync test server running at %s (type ctrl+c to exit)\n", | 115 printf("Python sync test server running at %s (type ctrl+c to exit)\n", |
| 116 test_server->host_port_pair().ToString().c_str()); | 116 test_server->host_port_pair().ToString().c_str()); |
| 117 | 117 |
| 118 message_loop.Run(); | 118 message_loop.Run(); |
| 119 return 0; | 119 return 0; |
| 120 } | 120 } |
| OLD | NEW |