diff options
| author | Ben Murdoch <benm@google.com> | 2010-11-18 18:32:45 +0000 |
|---|---|---|
| committer | Ben Murdoch <benm@google.com> | 2010-11-18 18:38:07 +0000 |
| commit | 513209b27ff55e2841eac0e4120199c23acce758 (patch) | |
| tree | aeba30bb08c5f47c57003544e378a377c297eee6 /net/test/test_server_posix.cc | |
| parent | 164f7496de0fbee436b385a79ead9e3cb81a50c1 (diff) | |
| download | external_chromium-513209b27ff55e2841eac0e4120199c23acce758.zip external_chromium-513209b27ff55e2841eac0e4120199c23acce758.tar.gz external_chromium-513209b27ff55e2841eac0e4120199c23acce758.tar.bz2 | |
Merge Chromium at r65505: Initial merge by git.
Change-Id: I31d8f1d8cd33caaf7f47ffa7350aef42d5fbdb45
Diffstat (limited to 'net/test/test_server_posix.cc')
| -rw-r--r-- | net/test/test_server_posix.cc | 52 |
1 files changed, 28 insertions, 24 deletions
diff --git a/net/test/test_server_posix.cc b/net/test/test_server_posix.cc index 6e65bcf..707eb93 100644 --- a/net/test/test_server_posix.cc +++ b/net/test/test_server_posix.cc @@ -4,13 +4,17 @@ #include "net/test/test_server.h" +#include <poll.h> + #include <vector> +#include "base/command_line.h" #include "base/file_util.h" #include "base/logging.h" #include "base/process_util.h" #include "base/string_number_conversions.h" #include "base/string_util.h" +#include "base/test/test_timeouts.h" namespace { @@ -52,28 +56,12 @@ class OrphanedTestServerFilter : public base::ProcessFilter { } // namespace namespace net { -bool TestServer::LaunchPython(const FilePath& testserver_path) { - std::vector<std::string> command_line; - command_line.push_back("python"); - command_line.push_back(testserver_path.value()); - command_line.push_back("--port=" + base::IntToString(host_port_pair_.port())); - command_line.push_back("--data-dir=" + document_root_.value()); - - if (type_ == TYPE_FTP) - command_line.push_back("-f"); - - FilePath certificate_path(GetCertificatePath()); - if (!certificate_path.value().empty()) { - if (!file_util::PathExists(certificate_path)) { - LOG(ERROR) << "Certificate path " << certificate_path.value() - << " doesn't exist. Can't launch https server."; - return false; - } - command_line.push_back("--https=" + certificate_path.value()); - } - if (type_ == TYPE_HTTPS_CLIENT_AUTH) - command_line.push_back("--ssl-client-auth"); +bool TestServer::LaunchPython(const FilePath& testserver_path) { + CommandLine python_command(FilePath(FILE_PATH_LITERAL("python"))); + python_command.AppendArgPath(testserver_path); + if (!AddCommandLineArguments(&python_command)) + return false; int pipefd[2]; if (pipe(pipefd) != 0) { @@ -88,7 +76,8 @@ bool TestServer::LaunchPython(const FilePath& testserver_path) { base::file_handle_mapping_vector map_write_fd; map_write_fd.push_back(std::make_pair(pipefd[1], pipefd[1])); - command_line.push_back("--startup-pipe=" + base::IntToString(pipefd[1])); + python_command.AppendSwitchASCII("startup-pipe", + base::IntToString(pipefd[1])); // Try to kill any orphaned testserver processes that may be running. OrphanedTestServerFilter filter(testserver_path.value(), @@ -98,8 +87,10 @@ bool TestServer::LaunchPython(const FilePath& testserver_path) { } // Launch a new testserver process. - if (!base::LaunchApp(command_line, map_write_fd, false, &process_handle_)) { - LOG(ERROR) << "Failed to launch " << command_line[0] << " ..."; + if (!base::LaunchApp(python_command.argv(), map_write_fd, false, + &process_handle_)) { + LOG(ERROR) << "Failed to launch " << python_command.command_line_string() + << " ..."; return false; } @@ -107,6 +98,19 @@ bool TestServer::LaunchPython(const FilePath& testserver_path) { } bool TestServer::WaitToStart() { + struct pollfd poll_fds[1]; + + poll_fds[0].fd = child_fd_; + poll_fds[0].events = POLLIN | POLLPRI; + poll_fds[0].revents = 0; + + int rv = HANDLE_EINTR(poll(poll_fds, 1, + TestTimeouts::action_max_timeout_ms())); + if (rv != 1) { + LOG(ERROR) << "Failed to poll for the child file descriptor."; + return false; + } + char buf[8]; ssize_t n = HANDLE_EINTR(read(child_fd_, buf, sizeof(buf))); // We don't need the FD anymore. |
