summaryrefslogtreecommitdiffstats
path: root/net/test
diff options
context:
space:
mode:
authorrsimha@google.com <rsimha@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-12 20:12:46 +0000
committerrsimha@google.com <rsimha@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-12 20:12:46 +0000
commitf352e796c7634f9ac6482150845896ddb6ffb262 (patch)
treee673f29f36fbdad2b54920546e2de211f79105ee /net/test
parentd148b610cbeac4acc3c0e6c7e513ea443293781b (diff)
downloadchromium_src-f352e796c7634f9ac6482150845896ddb6ffb262.zip
chromium_src-f352e796c7634f9ac6482150845896ddb6ffb262.tar.gz
chromium_src-f352e796c7634f9ac6482150845896ddb6ffb262.tar.bz2
Take 2: Force python test server output to be unbuffered, so it doesn't mix with gtest output
In browser tests that use a local python server, the python output in the test logs sometimes overlaps with gtest output, resulting in gtest falsely detecting passing tests as incomplete. This is a result of python's default use of buffered output, which gets written to the log file out of order. This patch forces the python process for local test servers to use unbuffered mode via the -u switch. This way, by the time gtest is ready to log a passing test, all testserver output is already written to the log file. BUG=147368 TEST= See sync integration test output when it is redirected to a log file, and make sure there are no false negatives. Review URL: https://chromiumcodereview.appspot.com/10907162 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@156361 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/test')
-rw-r--r--net/test/local_test_server_posix.cc8
-rw-r--r--net/test/local_test_server_win.cc10
-rw-r--r--net/test/python_utils.cc21
-rw-r--r--net/test/python_utils.h5
-rw-r--r--net/test/python_utils_unittest.cc5
5 files changed, 28 insertions, 21 deletions
diff --git a/net/test/local_test_server_posix.cc b/net/test/local_test_server_posix.cc
index 7afd422..eda65fd 100644
--- a/net/test/local_test_server_posix.cc
+++ b/net/test/local_test_server_posix.cc
@@ -97,9 +97,11 @@ 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")));
+ VLOG(1) << "LaunchPython called with PYTHONPATH = " << getenv(kPythonPathEnv);
+
+ CommandLine python_command(CommandLine::NO_PROGRAM);
+ if (!GetPythonCommand(&python_command))
+ return false;
python_command.AppendArgPath(testserver_path);
if (!AddCommandLineArguments(&python_command))
diff --git a/net/test/local_test_server_win.cc b/net/test/local_test_server_win.cc
index 0b30312..ba2a8cd 100644
--- a/net/test/local_test_server_win.cc
+++ b/net/test/local_test_server_win.cc
@@ -20,6 +20,7 @@
#include "base/threading/thread.h"
#include "base/utf_string_conversions.h"
#include "base/win/scoped_handle.h"
+#include "net/test/python_utils.h"
#pragma comment(lib, "crypt32.lib")
@@ -85,15 +86,10 @@ bool ReadData(HANDLE read_fd, HANDLE write_fd,
namespace net {
bool LocalTestServer::LaunchPython(const FilePath& testserver_path) {
- FilePath python_exe;
- if (!PathService::Get(base::DIR_SOURCE_ROOT, &python_exe))
+ CommandLine python_command(CommandLine::NO_PROGRAM);
+ if (!GetPythonCommand(&python_command))
return false;
- python_exe = python_exe
- .Append(FILE_PATH_LITERAL("third_party"))
- .Append(FILE_PATH_LITERAL("python_26"))
- .Append(FILE_PATH_LITERAL("python.exe"));
- CommandLine python_command(python_exe);
python_command.AppendArgPath(testserver_path);
if (!AddCommandLineArguments(&python_command))
return false;
diff --git a/net/test/python_utils.cc b/net/test/python_utils.cc
index 0eec816..82d0c5c 100644
--- a/net/test/python_utils.cc
+++ b/net/test/python_utils.cc
@@ -5,6 +5,7 @@
#include "net/test/python_utils.h"
#include "base/base_paths.h"
+#include "base/command_line.h"
#include "base/environment.h"
#include "base/file_path.h"
#include "base/file_util.h"
@@ -103,15 +104,23 @@ bool GetPyProtoPath(FilePath* dir) {
return true;
}
-bool GetPythonRunTime(FilePath* dir) {
+bool GetPythonCommand(CommandLine* python_cmd) {
+ DCHECK(python_cmd);
+ FilePath dir;
#if defined(OS_WIN)
- if (!PathService::Get(base::DIR_SOURCE_ROOT, dir))
+ if (!PathService::Get(base::DIR_SOURCE_ROOT, &dir))
return false;
- *dir = dir->Append(FILE_PATH_LITERAL("third_party"))
- .Append(FILE_PATH_LITERAL("python_26"))
- .Append(FILE_PATH_LITERAL("python.exe"));
+ dir = dir.Append(FILE_PATH_LITERAL("third_party"))
+ .Append(FILE_PATH_LITERAL("python_26"))
+ .Append(FILE_PATH_LITERAL("python.exe"));
#elif defined(OS_POSIX)
- *dir = FilePath("python");
+ dir = FilePath("python");
#endif
+ python_cmd->SetProgram(dir);
+
+ // Launch python in unbuffered mode, so that python output doesn't mix with
+ // gtest output in buildbot log files. See http://crbug.com/147368.
+ python_cmd->AppendArg("-u");
+
return true;
}
diff --git a/net/test/python_utils.h b/net/test/python_utils.h
index 583fb27..c7cf289 100644
--- a/net/test/python_utils.h
+++ b/net/test/python_utils.h
@@ -7,6 +7,7 @@
#include "base/compiler_specific.h"
+class CommandLine;
class FilePath;
// This is the python path variable name.
@@ -18,7 +19,7 @@ void AppendToPythonPath(const FilePath& dir);
// Return the location of the compiler-generated python protobuf.
bool GetPyProtoPath(FilePath* dir);
-// Returns the path that should be used to launch Python.
-bool GetPythonRunTime(FilePath* path) WARN_UNUSED_RESULT;
+// Returns the command that should be used to launch Python.
+bool GetPythonCommand(CommandLine* python_cmd) WARN_UNUSED_RESULT;
#endif // NET_TEST_PYTHON_UTILS_H_
diff --git a/net/test/python_utils_unittest.cc b/net/test/python_utils_unittest.cc
index 0114774..f81a440 100644
--- a/net/test/python_utils_unittest.cc
+++ b/net/test/python_utils_unittest.cc
@@ -45,12 +45,11 @@ TEST(PythonUtils, Append) {
}
TEST(PythonUtils, PythonRunTime) {
- FilePath dir;
- EXPECT_TRUE(GetPythonRunTime(&dir));
+ CommandLine cmd_line(CommandLine::NO_PROGRAM);
+ EXPECT_TRUE(GetPythonCommand(&cmd_line));
// Run a python command to print a string and make sure the output is what
// we want.
- CommandLine cmd_line(dir);
cmd_line.AppendArg("-c");
std::string input("PythonUtilsTest");
std::string python_cmd = StringPrintf("print '%s';", input.c_str());