OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #define _CRT_SECURE_NO_WARNINGS | 5 #define _CRT_SECURE_NO_WARNINGS |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/eintr_wrapper.h" | 10 #include "base/eintr_wrapper.h" |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 | 287 |
288 int ret; | 288 int ret; |
289 ret = HANDLE_EINTR(close(sockets[0])); | 289 ret = HANDLE_EINTR(close(sockets[0])); |
290 DPCHECK(ret == 0); | 290 DPCHECK(ret == 0); |
291 ret = HANDLE_EINTR(close(sockets[1])); | 291 ret = HANDLE_EINTR(close(sockets[1])); |
292 DPCHECK(ret == 0); | 292 DPCHECK(ret == 0); |
293 ret = HANDLE_EINTR(close(dev_null)); | 293 ret = HANDLE_EINTR(close(dev_null)); |
294 DPCHECK(ret == 0); | 294 DPCHECK(ret == 0); |
295 } | 295 } |
296 | 296 |
| 297 static std::string TestLaunchApp(const base::environment_vector& env_changes) { |
| 298 std::vector<std::string> args; |
| 299 base::file_handle_mapping_vector fds_to_remap; |
| 300 ProcessHandle handle; |
| 301 |
| 302 args.push_back("bash"); |
| 303 args.push_back("-c"); |
| 304 args.push_back("echo $BASE_TEST"); |
| 305 |
| 306 int fds[2]; |
| 307 PCHECK(pipe(fds) == 0); |
| 308 |
| 309 fds_to_remap.push_back(std::make_pair(fds[1], 1)); |
| 310 EXPECT_TRUE(LaunchApp(args, env_changes, fds_to_remap, |
| 311 true /* wait for exit */, &handle)); |
| 312 PCHECK(close(fds[1]) == 0); |
| 313 |
| 314 char buf[32]; |
| 315 const ssize_t n = HANDLE_EINTR(read(fds[0], buf, sizeof(buf))); |
| 316 PCHECK(n > 0); |
| 317 return std::string(buf, n); |
| 318 } |
| 319 |
| 320 TEST_F(ProcessUtilTest, LaunchApp) { |
| 321 base::environment_vector env_changes; |
| 322 |
| 323 setenv("BASE_TEST", "testing", 1 /* override */); |
| 324 EXPECT_EQ("testing\n", TestLaunchApp(env_changes)); |
| 325 |
| 326 env_changes.push_back(std::make_pair(std::string("BASE_TEST"), |
| 327 std::string(""))); |
| 328 EXPECT_EQ("\n", TestLaunchApp(env_changes)); |
| 329 |
| 330 env_changes[0].second = "foo"; |
| 331 EXPECT_EQ("foo\n", TestLaunchApp(env_changes)); |
| 332 } |
| 333 |
297 TEST_F(ProcessUtilTest, GetAppOutput) { | 334 TEST_F(ProcessUtilTest, GetAppOutput) { |
298 std::string output; | 335 std::string output; |
299 EXPECT_TRUE(GetAppOutput(CommandLine(FilePath("true")), &output)); | 336 EXPECT_TRUE(GetAppOutput(CommandLine(FilePath("true")), &output)); |
300 EXPECT_STREQ("", output.c_str()); | 337 EXPECT_STREQ("", output.c_str()); |
301 | 338 |
302 EXPECT_FALSE(GetAppOutput(CommandLine(FilePath("false")), &output)); | 339 EXPECT_FALSE(GetAppOutput(CommandLine(FilePath("false")), &output)); |
303 | 340 |
304 std::vector<std::string> argv; | 341 std::vector<std::string> argv; |
305 argv.push_back("/bin/echo"); | 342 argv.push_back("/bin/echo"); |
306 argv.push_back("-n"); | 343 argv.push_back("-n"); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 TEST_F(OutOfMemoryTest, Posix_memalign) { | 518 TEST_F(OutOfMemoryTest, Posix_memalign) { |
482 // Grab the return value of posix_memalign to silence a compiler warning | 519 // Grab the return value of posix_memalign to silence a compiler warning |
483 // about unused return values. We don't actually care about the return | 520 // about unused return values. We don't actually care about the return |
484 // value, since we're asserting death. | 521 // value, since we're asserting death. |
485 ASSERT_DEATH(EXPECT_EQ(ENOMEM, posix_memalign(&value_, 8, test_size_)), ""); | 522 ASSERT_DEATH(EXPECT_EQ(ENOMEM, posix_memalign(&value_, 8, test_size_)), ""); |
486 } | 523 } |
487 | 524 |
488 #endif // defined(OS_LINUX) | 525 #endif // defined(OS_LINUX) |
489 | 526 |
490 } // namespace base | 527 } // namespace base |
OLD | NEW |