OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/test/local_test_server.h" | 5 #include "net/test/local_test_server.h" |
6 | 6 |
7 #include <poll.h> | 7 #include <poll.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/process_util.h" | 14 #include "base/process_util.h" |
15 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
17 #include "base/test/test_timeouts.h" | 17 #include "base/test/test_timeouts.h" |
| 18 #include "net/test/python_utils.h" |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 // Helper class used to detect and kill orphaned python test server processes. | 22 // Helper class used to detect and kill orphaned python test server processes. |
22 // Checks if the command line of a process contains |path_string| (the path | 23 // Checks if the command line of a process contains |path_string| (the path |
23 // from which the test server was launched) and |port_string| (the port used by | 24 // from which the test server was launched) and |port_string| (the port used by |
24 // the test server), and if the parent pid of the process is 1 (indicating that | 25 // the test server), and if the parent pid of the process is 1 (indicating that |
25 // it is an orphaned process). | 26 // it is an orphaned process). |
26 class OrphanedTestServerFilter : public base::ProcessFilter { | 27 class OrphanedTestServerFilter : public base::ProcessFilter { |
27 public: | 28 public: |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 bytes_read += num_bytes; | 88 bytes_read += num_bytes; |
88 } | 89 } |
89 return true; | 90 return true; |
90 } | 91 } |
91 | 92 |
92 } // namespace | 93 } // namespace |
93 | 94 |
94 namespace net { | 95 namespace net { |
95 | 96 |
96 bool LocalTestServer::LaunchPython(const FilePath& testserver_path) { | 97 bool LocalTestServer::LaunchPython(const FilePath& testserver_path) { |
| 98 // Log is useful in the event you want to run a nearby script (e.g. a test) in |
| 99 // the same environment as the TestServer. |
| 100 VLOG(1) << "LaunchPython called with PYTHONPATH = " << |
| 101 getenv(kPythonPathEnv); |
97 CommandLine python_command(FilePath(FILE_PATH_LITERAL("python"))); | 102 CommandLine python_command(FilePath(FILE_PATH_LITERAL("python"))); |
| 103 |
98 python_command.AppendArgPath(testserver_path); | 104 python_command.AppendArgPath(testserver_path); |
99 if (!AddCommandLineArguments(&python_command)) | 105 if (!AddCommandLineArguments(&python_command)) |
100 return false; | 106 return false; |
101 | 107 |
102 int pipefd[2]; | 108 int pipefd[2]; |
103 if (pipe(pipefd) != 0) { | 109 if (pipe(pipefd) != 0) { |
104 PLOG(ERROR) << "Could not create pipe."; | 110 PLOG(ERROR) << "Could not create pipe."; |
105 return false; | 111 return false; |
106 } | 112 } |
107 | 113 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 | 162 |
157 if (!ParseServerData(server_data)) { | 163 if (!ParseServerData(server_data)) { |
158 LOG(ERROR) << "Could not parse server_data: " << server_data; | 164 LOG(ERROR) << "Could not parse server_data: " << server_data; |
159 return false; | 165 return false; |
160 } | 166 } |
161 | 167 |
162 return true; | 168 return true; |
163 } | 169 } |
164 | 170 |
165 } // namespace net | 171 } // namespace net |
OLD | NEW |