diff options
-rw-r--r-- | net/test/local_test_server.cc | 29 | ||||
-rw-r--r-- | net/test/local_test_server.h | 11 | ||||
-rw-r--r-- | net/test/local_test_server_posix.cc | 6 | ||||
-rw-r--r-- | net/tools/testserver/run_testserver.cc | 34 |
4 files changed, 68 insertions, 12 deletions
diff --git a/net/test/local_test_server.cc b/net/test/local_test_server.cc index 463cd80..7fe3e58 100644 --- a/net/test/local_test_server.cc +++ b/net/test/local_test_server.cc @@ -76,18 +76,30 @@ LocalTestServer::~LocalTestServer() { Stop(); } -bool LocalTestServer::Start() { - // Get path to Python server script. - FilePath testserver_path; - if (!PathService::Get(base::DIR_SOURCE_ROOT, &testserver_path)) { +// static +bool LocalTestServer::GetTestServerDirectory(FilePath* directory) { + // Get path to python server script. + FilePath testserver_dir; + if (!PathService::Get(base::DIR_SOURCE_ROOT, &testserver_dir)) { LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT"; return false; } - testserver_path = testserver_path + + testserver_dir = testserver_dir .Append(FILE_PATH_LITERAL("net")) .Append(FILE_PATH_LITERAL("tools")) - .Append(FILE_PATH_LITERAL("testserver")) - .Append(FILE_PATH_LITERAL("testserver.py")); + .Append(FILE_PATH_LITERAL("testserver")); + *directory = testserver_dir; + return true; +} + +bool LocalTestServer::Start() { + // Get path to Python server script. + FilePath testserver_path; + if (!GetTestServerDirectory(&testserver_path)) + return false; + testserver_path = + testserver_path.Append(FILE_PATH_LITERAL("testserver.py")); if (!SetPythonPath()) return false; @@ -146,7 +158,8 @@ bool LocalTestServer::Init(const FilePath& document_root) { return true; } -bool LocalTestServer::SetPythonPath() const { +// static +bool LocalTestServer::SetPythonPath() { FilePath third_party_dir; if (!PathService::Get(base::DIR_SOURCE_ROOT, &third_party_dir)) { LOG(ERROR) << "Failed to get DIR_SOURCE_ROOT"; diff --git a/net/test/local_test_server.h b/net/test/local_test_server.h index 48c2186..90ba160 100644 --- a/net/test/local_test_server.h +++ b/net/test/local_test_server.h @@ -42,12 +42,16 @@ class LocalTestServer : public BaseTestServer { // Stop the server started by Start(). bool Stop(); + // Modify PYTHONPATH to contain libraries we need. + static bool SetPythonPath() WARN_UNUSED_RESULT; + + // Returns true if successfully stored the FilePath for the directory of the + // testserver python script in |*directory|. + static bool GetTestServerDirectory(FilePath* directory) WARN_UNUSED_RESULT; + private: bool Init(const FilePath& document_root); - // Modify PYTHONPATH to contain libraries we need. - bool SetPythonPath() const WARN_UNUSED_RESULT; - // Launches the Python test server. Returns true on success. bool LaunchPython(const FilePath& testserver_path) WARN_UNUSED_RESULT; @@ -84,4 +88,3 @@ class LocalTestServer : public BaseTestServer { } // namespace net #endif // NET_TEST_LOCAL_TEST_SERVER_H_ - diff --git a/net/test/local_test_server_posix.cc b/net/test/local_test_server_posix.cc index 0cb4857..3756b69 100644 --- a/net/test/local_test_server_posix.cc +++ b/net/test/local_test_server_posix.cc @@ -15,6 +15,7 @@ #include "base/string_number_conversions.h" #include "base/string_util.h" #include "base/test/test_timeouts.h" +#include "net/test/python_utils.h" namespace { @@ -94,7 +95,12 @@ bool ReadData(int fd, ssize_t bytes_max, uint8* buffer, namespace net { bool LocalTestServer::LaunchPython(const FilePath& testserver_path) { + // Log is useful in the event you want to run a nearby script (e.g. a test) in + // the same environment as the TestServer. + VLOG(1) << "LaunchPython called with PYTHONPATH = " << + getenv(kPythonPathEnv); CommandLine python_command(FilePath(FILE_PATH_LITERAL("python"))); + python_command.AppendArgPath(testserver_path); if (!AddCommandLineArguments(&python_command)) return false; diff --git a/net/tools/testserver/run_testserver.cc b/net/tools/testserver/run_testserver.cc index 51b9aac..f00f9f2 100644 --- a/net/tools/testserver/run_testserver.cc +++ b/net/tools/testserver/run_testserver.cc @@ -9,8 +9,10 @@ #include "base/file_path.h" #include "base/logging.h" #include "base/message_loop.h" +#include "base/process_util.h" #include "base/test/test_timeouts.h" #include "base/utf_string_conversions.h" +#include "net/test/python_utils.h" #include "net/test/test_server.h" static void PrintUsage() { @@ -19,6 +21,36 @@ static void PrintUsage() { printf("(NOTE: relpath should be relative to the 'src' directory)\n"); } +// Launches the chromiumsync_test script, testing the --sync functionality. +static bool RunSyncTest() { + if (!net::TestServer::SetPythonPath()) { + LOG(ERROR) << "Error trying to set python path. Exiting."; + return false; + } + + FilePath sync_test_path; + if (!net::TestServer::GetTestServerDirectory(&sync_test_path)) { + LOG(ERROR) << "Error trying to get python test server path."; + return false; + } + + sync_test_path = + sync_test_path.Append(FILE_PATH_LITERAL("chromiumsync_test.py")); + FilePath python_runtime; + if (!GetPythonRunTime(&python_runtime)) { + LOG(ERROR) << "Could not get python runtime command."; + return false; + } + + CommandLine python_command(python_runtime); + python_command.AppendArgPath(sync_test_path); + if (!base::LaunchProcess(python_command, base::LaunchOptions(), NULL)) { + LOG(ERROR) << "Failed to launch test script."; + return false; + } + return true; +} + int main(int argc, const char* argv[]) { base::AtExitManager at_exit_manager; MessageLoopForIO message_loop; @@ -51,6 +83,8 @@ int main(int argc, const char* argv[]) { server_type = net::TestServer::TYPE_FTP; } else if (command_line->HasSwitch("sync")) { server_type = net::TestServer::TYPE_SYNC; + } else if (command_line->HasSwitch("sync-test")) { + return RunSyncTest() ? 0 : -1; } net::TestServer::HTTPSOptions https_options; |