Commit 6e289c72 authored by tim@chromium.org's avatar tim@chromium.org

Add "run_testserver --sync-test" for easy chromiumsync_test.py launching.

BUG=none
TEST=type that command. see tests run.

Review URL: https://chromiumcodereview.appspot.com/9545019

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126847 0039d316-1c4b-4281-b951-d872f2087c98
parent 4a63af5b
......@@ -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";
......
......@@ -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_
......@@ -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;
......
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment