summaryrefslogtreecommitdiffstats
path: root/net/tools
diff options
context:
space:
mode:
authorrsimha@chromium.org <rsimha@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-24 20:40:21 +0000
committerrsimha@chromium.org <rsimha@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-24 20:40:21 +0000
commite0c9e24599c1bffa614af97b60ba77a8e9826d99 (patch)
tree374a0061c7fbaf6238c18ace46783e07009a3933 /net/tools
parentb5db5eefdea45fb50601433e13fc6e2c7ac6f4a0 (diff)
downloadchromium_src-e0c9e24599c1bffa614af97b60ba77a8e9826d99.zip
chromium_src-e0c9e24599c1bffa614af97b60ba77a8e9826d99.tar.gz
chromium_src-e0c9e24599c1bffa614af97b60ba77a8e9826d99.tar.bz2
[sync] Add --port and --xmpp-port parameters to run_testserver.cc
run_testserver is a useful test utility that launches a python testserver after setting the required python path. When it is used to start a sync testserver, the only parameter it supports is --sync, indicating that we want a sync server. It doesn't support the --port and --xmpp-port flags, that are used to specify the ports on which we want the sync server and sync xmpp server to run. This patch adds the parameters to run_testserver.cc and plumbs them down to the TestServer objects created by run_testserver.cc. It also separates out sync specific testserver code into a new class called LocalSyncTestServer. Separating the sync server in python code is out of the scope of this CL because it requires significant refactoring, since it is in use on multiple platforms, and will be dealt with separately. BUG= 117559 TEST=Build and run run_testserver with the paramters --sync, --port and --xmpp-port Review URL: https://chromiumcodereview.appspot.com/10388206 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138878 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/tools')
-rw-r--r--net/tools/testserver/run_testserver.cc60
-rwxr-xr-xnet/tools/testserver/testserver.py10
2 files changed, 58 insertions, 12 deletions
diff --git a/net/tools/testserver/run_testserver.cc b/net/tools/testserver/run_testserver.cc
index f00f9f2..f1e4362 100644
--- a/net/tools/testserver/run_testserver.cc
+++ b/net/tools/testserver/run_testserver.cc
@@ -10,15 +10,19 @@
#include "base/logging.h"
#include "base/message_loop.h"
#include "base/process_util.h"
+#include "base/string_number_conversions.h"
#include "base/test/test_timeouts.h"
#include "base/utf_string_conversions.h"
+#include "net/test/local_sync_test_server.h"
#include "net/test/python_utils.h"
#include "net/test/test_server.h"
static void PrintUsage() {
printf("run_testserver --doc-root=relpath [--http|--https|--ftp|--sync]\n"
- " [--https-cert=ok|mismatched-name|expired]\n");
- printf("(NOTE: relpath should be relative to the 'src' directory)\n");
+ " [--https-cert=ok|mismatched-name|expired]\n"
+ " [--port=<port>] [--xmpp-port=<xmpp_port>]\n");
+ printf("(NOTE: relpath should be relative to the 'src' directory.\n");
+ printf(" --port and --xmpp-port only work with the --sync flag.)\n");
}
// Launches the chromiumsync_test script, testing the --sync functionality.
@@ -51,6 +55,23 @@ static bool RunSyncTest() {
return true;
}
+// Gets a port value from the switch with name |switch_name| and writes it to
+// |port|. Returns true if successful and false otherwise.
+static bool GetPortFromSwitch(const std::string& switch_name, uint16* port) {
+ DCHECK(port != NULL) << "|port| is NULL";
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+ int port_int = 0;
+ if (command_line->HasSwitch(switch_name)) {
+ std::string port_str = command_line->GetSwitchValueASCII(switch_name);
+ if (!base::StringToInt(port_str, &port_int)) {
+ LOG(WARNING) << "Could not extract port from switch " << switch_name;
+ return false;
+ }
+ }
+ *port = static_cast<uint16>(port_int);
+ return true;
+}
+
int main(int argc, const char* argv[]) {
base::AtExitManager at_exit_manager;
MessageLoopForIO message_loop;
@@ -71,7 +92,11 @@ int main(int argc, const char* argv[]) {
TestTimeouts::Initialize();
- if (command_line->GetSwitches().empty() || command_line->HasSwitch("help")) {
+ if (command_line->GetSwitches().empty() ||
+ command_line->HasSwitch("help") ||
+ ((command_line->HasSwitch("port") ||
+ command_line->HasSwitch("xmpp-port")) &&
+ !command_line->HasSwitch("sync"))) {
PrintUsage();
return -1;
}
@@ -114,12 +139,29 @@ int main(int argc, const char* argv[]) {
}
scoped_ptr<net::TestServer> test_server;
- if (server_type == net::TestServer::TYPE_HTTPS)
- test_server.reset(new net::TestServer(https_options, doc_root));
- else
- test_server.reset(new net::TestServer(server_type,
- net::TestServer::kLocalhost,
- doc_root));
+ switch (server_type) {
+ case net::TestServer::TYPE_HTTPS: {
+ test_server.reset(new net::TestServer(https_options, doc_root));
+ break;
+ }
+ case net::TestServer::TYPE_SYNC: {
+ uint16 port = 0;
+ uint16 xmpp_port = 0;
+ if (!GetPortFromSwitch("port", &port) ||
+ !GetPortFromSwitch("xmpp-port", &xmpp_port)) {
+ printf("Error: Could not extract --port and/or --xmpp-port.\n");
+ return -1;
+ }
+ test_server.reset(new net::LocalSyncTestServer(port, xmpp_port));
+ break;
+ }
+ default: {
+ test_server.reset(new net::TestServer(server_type,
+ net::TestServer::kLocalhost,
+ doc_root));
+ break;
+ }
+ }
if (!test_server->Start()) {
printf("Error: failed to start test server. Exiting.\n");
diff --git a/net/tools/testserver/testserver.py b/net/tools/testserver/testserver.py
index 82e9b61..2a0284a 100755
--- a/net/tools/testserver/testserver.py
+++ b/net/tools/testserver/testserver.py
@@ -180,7 +180,7 @@ class HTTPSServer(tlslite.api.TLSSocketServerMixIn,
class SyncHTTPServer(ClientRestrictingServerMixIn, StoppableHTTPServer):
"""An HTTP server that handles sync commands."""
- def __init__(self, server_address, request_handler_class):
+ def __init__(self, server_address, xmpp_port, request_handler_class):
# We import here to avoid pulling in chromiumsync's dependencies
# unless strictly necessary.
import chromiumsync
@@ -189,7 +189,7 @@ class SyncHTTPServer(ClientRestrictingServerMixIn, StoppableHTTPServer):
self._sync_handler = chromiumsync.TestServer()
self._xmpp_socket_map = {}
self._xmpp_server = xmppserver.XmppServer(
- self._xmpp_socket_map, ('localhost', 0))
+ self._xmpp_socket_map, ('localhost', xmpp_port))
self.xmpp_port = self._xmpp_server.getsockname()[1]
self.authenticated = True
@@ -2063,7 +2063,8 @@ def main(options, args):
server.policy_user = options.policy_user
server.gdata_auth_token = options.auth_token
elif options.server_type == SERVER_SYNC:
- server = SyncHTTPServer((host, port), SyncPageHandler)
+ xmpp_port = options.xmpp_port
+ server = SyncHTTPServer((host, port), xmpp_port, SyncPageHandler)
print 'Sync HTTP server started on port %d...' % server.server_port
print 'Sync XMPP server started on port %d...' % server.xmpp_port
server_data['port'] = server.server_port
@@ -2164,6 +2165,9 @@ if __name__ == '__main__':
option_parser.add_option('', '--port', default='0', type='int',
help='Port used by the server. If unspecified, the '
'server will listen on an ephemeral port.')
+ option_parser.add_option('', '--xmpp-port', default='0', type='int',
+ help='Port used by the XMPP server. If unspecified, '
+ 'the XMPP server will listen on an ephemeral port.')
option_parser.add_option('', '--data-dir', dest='data_dir',
help='Directory from which to read the files.')
option_parser.add_option('', '--https', action='store_true', dest='https',