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

Side by Side Diff: net/tools/testserver/run_testserver.cc

Issue 10388206: [sync] Add --port and --xmpp-port parameters to run_testserver.cc (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase Created 8 years, 7 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 | « net/test/local_test_server.h ('k') | net/tools/testserver/testserver.py » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/file_path.h" 9 #include "base/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/process_util.h" 12 #include "base/process_util.h"
13 #include "base/string_number_conversions.h"
13 #include "base/test/test_timeouts.h" 14 #include "base/test/test_timeouts.h"
14 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "net/test/local_sync_test_server.h"
15 #include "net/test/python_utils.h" 17 #include "net/test/python_utils.h"
16 #include "net/test/test_server.h" 18 #include "net/test/test_server.h"
17 19
18 static void PrintUsage() { 20 static void PrintUsage() {
19 printf("run_testserver --doc-root=relpath [--http|--https|--ftp|--sync]\n" 21 printf("run_testserver --doc-root=relpath [--http|--https|--ftp|--sync]\n"
20 " [--https-cert=ok|mismatched-name|expired]\n"); 22 " [--https-cert=ok|mismatched-name|expired]\n"
21 printf("(NOTE: relpath should be relative to the 'src' directory)\n"); 23 " [--port=<port>] [--xmpp-port=<xmpp_port>]\n");
24 printf("(NOTE: relpath should be relative to the 'src' directory.\n");
25 printf(" --port and --xmpp-port only work with the --sync flag.)\n");
22 } 26 }
23 27
24 // Launches the chromiumsync_test script, testing the --sync functionality. 28 // Launches the chromiumsync_test script, testing the --sync functionality.
25 static bool RunSyncTest() { 29 static bool RunSyncTest() {
26 if (!net::TestServer::SetPythonPath()) { 30 if (!net::TestServer::SetPythonPath()) {
27 LOG(ERROR) << "Error trying to set python path. Exiting."; 31 LOG(ERROR) << "Error trying to set python path. Exiting.";
28 return false; 32 return false;
29 } 33 }
30 34
31 FilePath sync_test_path; 35 FilePath sync_test_path;
(...skipping 12 matching lines...) Expand all
44 48
45 CommandLine python_command(python_runtime); 49 CommandLine python_command(python_runtime);
46 python_command.AppendArgPath(sync_test_path); 50 python_command.AppendArgPath(sync_test_path);
47 if (!base::LaunchProcess(python_command, base::LaunchOptions(), NULL)) { 51 if (!base::LaunchProcess(python_command, base::LaunchOptions(), NULL)) {
48 LOG(ERROR) << "Failed to launch test script."; 52 LOG(ERROR) << "Failed to launch test script.";
49 return false; 53 return false;
50 } 54 }
51 return true; 55 return true;
52 } 56 }
53 57
58 // Gets a port value from the switch with name |switch_name| and writes it to
59 // |port|. Returns true if successful and false otherwise.
60 static bool GetPortFromSwitch(const std::string& switch_name, uint16* port) {
61 DCHECK(port != NULL) << "|port| is NULL";
62 CommandLine* command_line = CommandLine::ForCurrentProcess();
63 int port_int = 0;
64 if (command_line->HasSwitch(switch_name)) {
65 std::string port_str = command_line->GetSwitchValueASCII(switch_name);
66 if (!base::StringToInt(port_str, &port_int)) {
67 LOG(WARNING) << "Could not extract port from switch " << switch_name;
68 return false;
69 }
70 }
71 *port = static_cast<uint16>(port_int);
72 return true;
73 }
74
54 int main(int argc, const char* argv[]) { 75 int main(int argc, const char* argv[]) {
55 base::AtExitManager at_exit_manager; 76 base::AtExitManager at_exit_manager;
56 MessageLoopForIO message_loop; 77 MessageLoopForIO message_loop;
57 78
58 // Process command line 79 // Process command line
59 CommandLine::Init(argc, argv); 80 CommandLine::Init(argc, argv);
60 CommandLine* command_line = CommandLine::ForCurrentProcess(); 81 CommandLine* command_line = CommandLine::ForCurrentProcess();
61 82
62 if (!logging::InitLogging( 83 if (!logging::InitLogging(
63 FILE_PATH_LITERAL("testserver.log"), 84 FILE_PATH_LITERAL("testserver.log"),
64 logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG, 85 logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG,
65 logging::LOCK_LOG_FILE, 86 logging::LOCK_LOG_FILE,
66 logging::APPEND_TO_OLD_LOG_FILE, 87 logging::APPEND_TO_OLD_LOG_FILE,
67 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS)) { 88 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS)) {
68 printf("Error: could not initialize logging. Exiting.\n"); 89 printf("Error: could not initialize logging. Exiting.\n");
69 return -1; 90 return -1;
70 } 91 }
71 92
72 TestTimeouts::Initialize(); 93 TestTimeouts::Initialize();
73 94
74 if (command_line->GetSwitches().empty() || command_line->HasSwitch("help")) { 95 if (command_line->GetSwitches().empty() ||
96 command_line->HasSwitch("help") ||
97 ((command_line->HasSwitch("port") ||
98 command_line->HasSwitch("xmpp-port")) &&
99 !command_line->HasSwitch("sync"))) {
75 PrintUsage(); 100 PrintUsage();
76 return -1; 101 return -1;
77 } 102 }
78 103
79 net::TestServer::Type server_type(net::TestServer::TYPE_HTTP); 104 net::TestServer::Type server_type(net::TestServer::TYPE_HTTP);
80 if (command_line->HasSwitch("https")) { 105 if (command_line->HasSwitch("https")) {
81 server_type = net::TestServer::TYPE_HTTPS; 106 server_type = net::TestServer::TYPE_HTTPS;
82 } else if (command_line->HasSwitch("ftp")) { 107 } else if (command_line->HasSwitch("ftp")) {
83 server_type = net::TestServer::TYPE_FTP; 108 server_type = net::TestServer::TYPE_FTP;
84 } else if (command_line->HasSwitch("sync")) { 109 } else if (command_line->HasSwitch("sync")) {
(...skipping 22 matching lines...) Expand all
107 } 132 }
108 133
109 FilePath doc_root = command_line->GetSwitchValuePath("doc-root"); 134 FilePath doc_root = command_line->GetSwitchValuePath("doc-root");
110 if ((server_type != net::TestServer::TYPE_SYNC) && doc_root.empty()) { 135 if ((server_type != net::TestServer::TYPE_SYNC) && doc_root.empty()) {
111 printf("Error: --doc-root must be specified\n"); 136 printf("Error: --doc-root must be specified\n");
112 PrintUsage(); 137 PrintUsage();
113 return -1; 138 return -1;
114 } 139 }
115 140
116 scoped_ptr<net::TestServer> test_server; 141 scoped_ptr<net::TestServer> test_server;
117 if (server_type == net::TestServer::TYPE_HTTPS) 142 switch (server_type) {
118 test_server.reset(new net::TestServer(https_options, doc_root)); 143 case net::TestServer::TYPE_HTTPS: {
119 else 144 test_server.reset(new net::TestServer(https_options, doc_root));
120 test_server.reset(new net::TestServer(server_type, 145 break;
121 net::TestServer::kLocalhost, 146 }
122 doc_root)); 147 case net::TestServer::TYPE_SYNC: {
148 uint16 port = 0;
149 uint16 xmpp_port = 0;
150 if (!GetPortFromSwitch("port", &port) ||
151 !GetPortFromSwitch("xmpp-port", &xmpp_port)) {
152 printf("Error: Could not extract --port and/or --xmpp-port.\n");
153 return -1;
154 }
155 test_server.reset(new net::LocalSyncTestServer(port, xmpp_port));
156 break;
157 }
158 default: {
159 test_server.reset(new net::TestServer(server_type,
160 net::TestServer::kLocalhost,
161 doc_root));
162 break;
163 }
164 }
123 165
124 if (!test_server->Start()) { 166 if (!test_server->Start()) {
125 printf("Error: failed to start test server. Exiting.\n"); 167 printf("Error: failed to start test server. Exiting.\n");
126 return -1; 168 return -1;
127 } 169 }
128 170
129 if (!file_util::DirectoryExists(test_server->document_root())) { 171 if (!file_util::DirectoryExists(test_server->document_root())) {
130 printf("Error: invalid doc root: \"%s\" does not exist!\n", 172 printf("Error: invalid doc root: \"%s\" does not exist!\n",
131 UTF16ToUTF8(test_server->document_root().LossyDisplayName()).c_str()); 173 UTF16ToUTF8(test_server->document_root().LossyDisplayName()).c_str());
132 return -1; 174 return -1;
133 } 175 }
134 176
135 printf("testserver running at %s (type ctrl+c to exit)\n", 177 printf("testserver running at %s (type ctrl+c to exit)\n",
136 test_server->host_port_pair().ToString().c_str()); 178 test_server->host_port_pair().ToString().c_str());
137 179
138 message_loop.Run(); 180 message_loop.Run();
139 return 0; 181 return 0;
140 } 182 }
OLDNEW
« no previous file with comments | « net/test/local_test_server.h ('k') | net/tools/testserver/testserver.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698