Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: net/test/test_server_win.cc

Issue 3368012: Wait on a pipe for the test server to start up (Closed)
Patch Set: Sigh. Rebase onto trunk. Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/test/test_server_posix.cc ('k') | net/tools/testserver/testserver.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/test_server.h" 5 #include "net/test/test_server.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <wincrypt.h> 8 #include <wincrypt.h>
9 9
10 #include "base/base_paths.h" 10 #include "base/base_paths.h"
(...skipping 16 matching lines...) Expand all
27 startup_info.cb = sizeof(startup_info); 27 startup_info.cb = sizeof(startup_info);
28 startup_info.dwFlags = STARTF_USESHOWWINDOW; 28 startup_info.dwFlags = STARTF_USESHOWWINDOW;
29 startup_info.wShowWindow = start_hidden ? SW_HIDE : SW_SHOW; 29 startup_info.wShowWindow = start_hidden ? SW_HIDE : SW_SHOW;
30 PROCESS_INFORMATION process_info; 30 PROCESS_INFORMATION process_info;
31 31
32 // If this code is run under a debugger, the test server process is 32 // If this code is run under a debugger, the test server process is
33 // automatically associated with a job object created by the debugger. 33 // automatically associated with a job object created by the debugger.
34 // The CREATE_BREAKAWAY_FROM_JOB flag is used to prevent this. 34 // The CREATE_BREAKAWAY_FROM_JOB flag is used to prevent this.
35 if (!CreateProcess(NULL, 35 if (!CreateProcess(NULL,
36 const_cast<wchar_t*>(cmdline.c_str()), NULL, NULL, 36 const_cast<wchar_t*>(cmdline.c_str()), NULL, NULL,
37 FALSE, CREATE_BREAKAWAY_FROM_JOB, NULL, NULL, 37 TRUE, CREATE_BREAKAWAY_FROM_JOB, NULL, NULL,
38 &startup_info, &process_info)) { 38 &startup_info, &process_info)) {
39 LOG(ERROR) << "Could not create process."; 39 LOG(ERROR) << "Could not create process.";
40 return false; 40 return false;
41 } 41 }
42 CloseHandle(process_info.hThread); 42 CloseHandle(process_info.hThread);
43 43
44 // If the caller wants the process handle, we won't close it. 44 // If the caller wants the process handle, we won't close it.
45 if (process_handle) { 45 if (process_handle) {
46 *process_handle = process_info.hProcess; 46 *process_handle = process_info.hProcess;
47 } else { 47 } else {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 return false; 100 return false;
101 } 101 }
102 command_line.append(L" --https=\""); 102 command_line.append(L" --https=\"");
103 command_line.append(certificate_path.value()); 103 command_line.append(certificate_path.value());
104 command_line.append(L"\""); 104 command_line.append(L"\"");
105 } 105 }
106 106
107 if (type_ == TYPE_HTTPS_CLIENT_AUTH) 107 if (type_ == TYPE_HTTPS_CLIENT_AUTH)
108 command_line.append(L" --ssl-client-auth"); 108 command_line.append(L" --ssl-client-auth");
109 109
110 HANDLE child_read = NULL;
111 HANDLE child_write = NULL;
112 if (!CreatePipe(&child_read, &child_write, NULL, 0)) {
113 PLOG(ERROR) << "Failed to create pipe";
114 return false;
115 }
116 child_fd_.Set(child_read);
117 ScopedHandle scoped_child_write(child_write);
118
119 // Have the child inherit the write half.
120 if (!SetHandleInformation(child_write, HANDLE_FLAG_INHERIT,
121 HANDLE_FLAG_INHERIT)) {
122 PLOG(ERROR) << "Failed to enable pipe inheritance";
123 return false;
124 }
125
126 // Pass the handle on the command-line. Although HANDLE is a
127 // pointer, truncating it on 64-bit machines is okay. See
128 // http://msdn.microsoft.com/en-us/library/aa384203.aspx
129 //
130 // "64-bit versions of Windows use 32-bit handles for
131 // interoperability. When sharing a handle between 32-bit and 64-bit
132 // applications, only the lower 32 bits are significant, so it is
133 // safe to truncate the handle (when passing it from 64-bit to
134 // 32-bit) or sign-extend the handle (when passing it from 32-bit to
135 // 64-bit)."
136 command_line.append(
137 L" --startup-pipe=" +
138 ASCIIToWide(base::IntToString(reinterpret_cast<uintptr_t>(child_write))));
139
110 if (!LaunchTestServerAsJob(command_line, 140 if (!LaunchTestServerAsJob(command_line,
111 true, 141 true,
112 &process_handle_, 142 &process_handle_,
113 &job_handle_)) { 143 &job_handle_)) {
114 LOG(ERROR) << "Failed to launch " << command_line; 144 LOG(ERROR) << "Failed to launch " << command_line;
115 return false; 145 return false;
116 } 146 }
117 147
118 return true; 148 return true;
119 } 149 }
120 150
151 bool TestServer::WaitToStart() {
152 char buf[8];
153 DWORD bytes_read;
154 BOOL result = ReadFile(child_fd_, buf, sizeof(buf), &bytes_read, NULL);
155 child_fd_.Close();
156 return result && bytes_read > 0;
157 }
158
121 bool TestServer::CheckCATrusted() { 159 bool TestServer::CheckCATrusted() {
122 HCERTSTORE cert_store = CertOpenSystemStore(NULL, L"ROOT"); 160 HCERTSTORE cert_store = CertOpenSystemStore(NULL, L"ROOT");
123 if (!cert_store) { 161 if (!cert_store) {
124 LOG(ERROR) << " could not open trusted root CA store"; 162 LOG(ERROR) << " could not open trusted root CA store";
125 return false; 163 return false;
126 } 164 }
127 PCCERT_CONTEXT cert = 165 PCCERT_CONTEXT cert =
128 CertFindCertificateInStore(cert_store, 166 CertFindCertificateInStore(cert_store,
129 X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, 167 X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
130 0, 168 0,
131 CERT_FIND_ISSUER_STR, 169 CERT_FIND_ISSUER_STR,
132 L"Test CA", 170 L"Test CA",
133 NULL); 171 NULL);
134 if (cert) 172 if (cert)
135 CertFreeCertificateContext(cert); 173 CertFreeCertificateContext(cert);
136 CertCloseStore(cert_store, 0); 174 CertCloseStore(cert_store, 0);
137 175
138 if (!cert) { 176 if (!cert) {
139 LOG(ERROR) << " TEST CONFIGURATION ERROR: you need to import the test ca " 177 LOG(ERROR) << " TEST CONFIGURATION ERROR: you need to import the test ca "
140 "certificate to your trusted roots for this test to work. " 178 "certificate to your trusted roots for this test to work. "
141 "For more info visit:\n" 179 "For more info visit:\n"
142 "http://dev.chromium.org/developers/testing\n"; 180 "http://dev.chromium.org/developers/testing\n";
143 return false; 181 return false;
144 } 182 }
145 183
146 return true; 184 return true;
147 } 185 }
148 186
149 } // namespace net 187 } // namespace net
OLDNEW
« no previous file with comments | « net/test/test_server_posix.cc ('k') | net/tools/testserver/testserver.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698