Skip to content

Commit

Permalink
Add "run_testserver --sync-test" for easy chromiumsync_test.py launch…
Browse files Browse the repository at this point in the history
…ing.

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
  • Loading branch information
tim@chromium.org committed Mar 15, 2012
1 parent 4a63af5 commit 6e289c7
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 12 deletions.
29 changes: 21 additions & 8 deletions net/test/local_test_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down
11 changes: 7 additions & 4 deletions net/test/local_test_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -84,4 +88,3 @@ class LocalTestServer : public BaseTestServer {
} // namespace net

#endif // NET_TEST_LOCAL_TEST_SERVER_H_

6 changes: 6 additions & 0 deletions net/test/local_test_server_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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;
Expand Down
34 changes: 34 additions & 0 deletions net/tools/testserver/run_testserver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6e289c7

Please sign in to comment.