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

Side by Side Diff: sync/tools/testserver/run_sync_testserver.cc

Issue 11971025: [sync] Divorce python sync test server chromiumsync.py from testserver.py (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Philippe's comments. Created 7 years, 11 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 | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include <stdio.h>
6
7 #include "base/at_exit.h"
8 #include "base/command_line.h"
9 #include "base/file_path.h"
10 #include "base/logging.h"
11 #include "base/message_loop.h"
12 #include "base/process_util.h"
13 #include "base/string_number_conversions.h"
14 #include "base/test/test_timeouts.h"
15 #include "base/utf_string_conversions.h"
16 #include "net/test/python_utils.h"
17 #include "sync/test/local_sync_test_server.h"
18
19 static void PrintUsage() {
20 printf("run_sync_testserver [--port=<port>] [--xmpp-port=<xmpp_port>]\n");
21 }
22
23 // Launches the chromiumsync_test.py or xmppserver_test.py scripts, which test
24 // the sync HTTP and XMPP sever functionality respectively.
25 static bool RunSyncTest(const FilePath::StringType& sync_test_script_name) {
26 scoped_ptr<syncer::LocalSyncTestServer> test_server(
27 new syncer::LocalSyncTestServer());
28 if (!test_server->SetPythonPath()) {
29 LOG(ERROR) << "Error trying to set python path. Exiting.";
30 return false;
31 }
32
33 FilePath sync_test_script_path;
34 if (!test_server->GetTestScriptPath(sync_test_script_name,
35 &sync_test_script_path)) {
36 LOG(ERROR) << "Error trying to get path for test script "
37 << sync_test_script_name;
38 return false;
39 }
40
41 CommandLine python_command(CommandLine::NO_PROGRAM);
42 if (!GetPythonCommand(&python_command)) {
43 LOG(ERROR) << "Could not get python runtime command.";
44 return false;
45 }
46
47 python_command.AppendArgPath(sync_test_script_path);
48 if (!base::LaunchProcess(python_command, base::LaunchOptions(), NULL)) {
49 LOG(ERROR) << "Failed to launch test script " << sync_test_script_name;
50 return false;
51 }
52 return true;
53 }
54
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.
57 static bool GetPortFromSwitch(const std::string& switch_name, uint16* port) {
58 DCHECK(port != NULL) << "|port| is NULL";
59 CommandLine* command_line = CommandLine::ForCurrentProcess();
60 int port_int = 0;
61 if (command_line->HasSwitch(switch_name)) {
62 std::string port_str = command_line->GetSwitchValueASCII(switch_name);
63 if (!base::StringToInt(port_str, &port_int)) {
64 return false;
65 }
66 }
67 *port = static_cast<uint16>(port_int);
68 return true;
69 }
70
71 int main(int argc, const char* argv[]) {
72 base::AtExitManager at_exit_manager;
73 MessageLoopForIO message_loop;
74
75 // Process command line
76 CommandLine::Init(argc, argv);
77 CommandLine* command_line = CommandLine::ForCurrentProcess();
78
79 if (!logging::InitLogging(
80 FILE_PATH_LITERAL("sync_testserver.log"),
81 logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG,
82 logging::LOCK_LOG_FILE,
83 logging::APPEND_TO_OLD_LOG_FILE,
84 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS)) {
85 printf("Error: could not initialize logging. Exiting.\n");
86 return -1;
87 }
88
89 TestTimeouts::Initialize();
90
91 if (command_line->HasSwitch("help")) {
92 PrintUsage();
93 return 0;
94 }
95
96 if (command_line->HasSwitch("sync-test")) {
97 return RunSyncTest(FILE_PATH_LITERAL("chromiumsync_test.py")) ? 0 : -1;
98 }
99
100 if (command_line->HasSwitch("xmpp-test")) {
101 return RunSyncTest(FILE_PATH_LITERAL("xmppserver_test.py")) ? 0 : -1;
102 }
103
104 uint16 port = 0;
105 GetPortFromSwitch("port", &port);
106
107 uint16 xmpp_port = 0;
108 GetPortFromSwitch("xmpp-port", &xmpp_port);
109
110 scoped_ptr<syncer::LocalSyncTestServer> test_server(
111 new syncer::LocalSyncTestServer(port, xmpp_port));
112 if (!test_server->Start()) {
113 printf("Error: failed to start python sync test server. Exiting.\n");
114 return -1;
115 }
116
117 printf("Python sync test server running at %s (type ctrl+c to exit)\n",
118 test_server->host_port_pair().ToString().c_str());
119
120 message_loop.Run();
121 return 0;
122 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698