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

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

Powered by Google App Engine
This is Rietveld 408576698