summaryrefslogtreecommitdiffstats
path: root/base/process_util_unittest.cc
diff options
context:
space:
mode:
authoragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-10 19:00:58 +0000
committeragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-10 19:00:58 +0000
commitcd3cf12588560bf1c1ffc780ce7fdeae044b100e (patch)
tree8ab79805aa9e50db3a2eae36e324af2f92bc13d4 /base/process_util_unittest.cc
parent2fc4c21d0b6cebaf8ebc101cc3fe20ef38407373 (diff)
downloadchromium_src-cd3cf12588560bf1c1ffc780ce7fdeae044b100e.zip
chromium_src-cd3cf12588560bf1c1ffc780ce7fdeae044b100e.tar.gz
chromium_src-cd3cf12588560bf1c1ffc780ce7fdeae044b100e.tar.bz2
POSIX: don't allocate memory after forking.
Previously we would allocate memory in the child process. However, the allocation might have happened while the malloc lock was held, resulting in a deadlock. This patch removes allocation from the child but probably makes Mac's startup time slower until a Mac person can implement dir_reader_posix.h. TEST=Unittest for new code BUG=36678 http://codereview.chromium.org/672003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41181 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/process_util_unittest.cc')
-rw-r--r--base/process_util_unittest.cc42
1 files changed, 42 insertions, 0 deletions
diff --git a/base/process_util_unittest.cc b/base/process_util_unittest.cc
index 3170b6a..d22a60a 100644
--- a/base/process_util_unittest.cc
+++ b/base/process_util_unittest.cc
@@ -294,6 +294,48 @@ TEST_F(ProcessUtilTest, FDRemapping) {
DPCHECK(ret == 0);
}
+static std::string TestLaunchApp(const base::environment_vector& env_changes) {
+ std::vector<std::string> args;
+ base::file_handle_mapping_vector fds_to_remap;
+ ProcessHandle handle;
+
+ args.push_back("bash");
+ args.push_back("-c");
+ args.push_back("echo $BASE_TEST");
+
+ int fds[2];
+ PCHECK(pipe(fds) == 0);
+
+ fds_to_remap.push_back(std::make_pair(fds[1], 1));
+ EXPECT_TRUE(LaunchApp(args, env_changes, fds_to_remap,
+ true /* wait for exit */, &handle));
+ PCHECK(close(fds[1]) == 0);
+
+ char buf[32];
+ const ssize_t n = HANDLE_EINTR(read(fds[0], buf, sizeof(buf)));
+ PCHECK(n > 0);
+ return std::string(buf, n);
+}
+
+TEST_F(ProcessUtilTest, LaunchApp) {
+ base::environment_vector env_changes;
+
+ env_changes.push_back(std::make_pair(std::string("BASE_TEST"),
+ std::string("bar")));
+ EXPECT_EQ("bar\n", TestLaunchApp(env_changes));
+ env_changes.clear();
+
+ setenv("BASE_TEST", "testing", 1 /* override */);
+ EXPECT_EQ("testing\n", TestLaunchApp(env_changes));
+
+ env_changes.push_back(std::make_pair(std::string("BASE_TEST"),
+ std::string("")));
+ EXPECT_EQ("\n", TestLaunchApp(env_changes));
+
+ env_changes[0].second = "foo";
+ EXPECT_EQ("foo\n", TestLaunchApp(env_changes));
+}
+
TEST_F(ProcessUtilTest, GetAppOutput) {
std::string output;
EXPECT_TRUE(GetAppOutput(CommandLine(FilePath("true")), &output));