summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortbarzic@chromium.org <tbarzic@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-11 02:46:43 +0000
committertbarzic@chromium.org <tbarzic@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-11 02:46:43 +0000
commit250f7f898298cdc34763fbf4a22e2ea69c9ffdd9 (patch)
tree7398fc64b753f8e0fa6583aa11338469f690621d
parentaacd4a4d02fc6be17d040b419031d1348ca5e82b (diff)
downloadchromium_src-250f7f898298cdc34763fbf4a22e2ea69c9ffdd9.zip
chromium_src-250f7f898298cdc34763fbf4a22e2ea69c9ffdd9.tar.gz
chromium_src-250f7f898298cdc34763fbf4a22e2ea69c9ffdd9.tar.bz2
Fix ProcessOutputWatcherTest.OutputWatcher under ASAN
String length was being set using arraysize of string that had an extra character. BUG=122700 TEST=ProcessOutputWatcher.OutputWatcher under ASAN Review URL: https://chromiumcodereview.appspot.com/10033015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@131703 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/process_proxy/process_output_watcher_unittest.cc120
1 files changed, 66 insertions, 54 deletions
diff --git a/chrome/browser/chromeos/process_proxy/process_output_watcher_unittest.cc b/chrome/browser/chromeos/process_proxy/process_output_watcher_unittest.cc
index 778e905..91112c2 100644
--- a/chrome/browser/chromeos/process_proxy/process_output_watcher_unittest.cc
+++ b/chrome/browser/chromeos/process_proxy/process_output_watcher_unittest.cc
@@ -19,17 +19,12 @@
struct TestCase {
std::string str;
- ProcessOutputType type;
+ bool should_send_terminating_null;
- TestCase(const char* expected_string,
- size_t expected_string_length,
- ProcessOutputType expected_type)
- : str(expected_string, expected_string_length),
- type(expected_type) {
- }
- TestCase(const std::string& expected_string, ProcessOutputType expected_type)
+ TestCase(const std::string& expected_string,
+ bool send_terminating_null)
: str(expected_string),
- type(expected_type) {
+ should_send_terminating_null(send_terminating_null) {
}
};
@@ -41,8 +36,9 @@ class ProcessWatcherExpectations {
received_from_out_ = 0;
for (size_t i = 0; i < expectations.size(); i++) {
- out_expectations_.append(expectations[i].str.c_str(),
- expectations[i].str.length());
+ out_expectations_.append(expectations[i].str);
+ if (expectations[i].should_send_terminating_null)
+ out_expectations_.append(std::string("", 1));
}
}
@@ -97,6 +93,44 @@ public:
return result;
}
+ void RunTest(const std::vector<TestCase>& test_cases) {
+ all_data_received_.reset(new base::WaitableEvent(true, false));
+
+ base::Thread output_watch_thread("ProcessOutpuWatchThread");
+ ASSERT_TRUE(output_watch_thread.Start());
+
+ int pt_pipe[2], stop_pipe[2];
+ ASSERT_FALSE(HANDLE_EINTR(pipe(pt_pipe)));
+ ASSERT_FALSE(HANDLE_EINTR(pipe(stop_pipe)));
+
+ output_watch_thread.message_loop()->PostTask(FROM_HERE,
+ base::Bind(&ProcessOutputWatcherTest::StartWatch,
+ base::Unretained(this),
+ pt_pipe[0], stop_pipe[0], test_cases));
+
+ for (size_t i = 0; i < test_cases.size(); i++) {
+ const std::string& test_str = test_cases[i].str;
+ // Let's make inputs not NULL terminated, unless other is specified in
+ // the test case.
+ ssize_t test_size = test_str.length() * sizeof(*test_str.c_str());
+ if (test_cases[i].should_send_terminating_null)
+ test_size += sizeof(*test_str.c_str());
+ EXPECT_EQ(test_size,
+ file_util::WriteFileDescriptor(pt_pipe[1], test_str.c_str(),
+ test_size));
+ }
+
+ all_data_received_->Wait();
+
+ // Send stop signal. It is not important which string we send.
+ EXPECT_EQ(1, file_util::WriteFileDescriptor(stop_pipe[1], "q", 1));
+
+ EXPECT_NE(-1, HANDLE_EINTR(close(stop_pipe[1])));
+ EXPECT_NE(-1, HANDLE_EINTR(close(pt_pipe[1])));
+
+ output_watch_thread.Stop();
+ }
+
scoped_ptr<base::WaitableEvent> all_data_received_;
private:
@@ -106,50 +140,28 @@ public:
TEST_F(ProcessOutputWatcherTest, OutputWatcher) {
- all_data_received_.reset(new base::WaitableEvent(true, false));
-
- base::Thread output_watch_thread("ProcessOutpuWatchThread");
- ASSERT_TRUE(output_watch_thread.Start());
-
- int pt_pipe[2], stop_pipe[2];
- ASSERT_FALSE(HANDLE_EINTR(pipe(pt_pipe)));
- ASSERT_FALSE(HANDLE_EINTR(pipe(stop_pipe)));
-
- // TODO(tbarzic): We don't support stderr anymore, so this can be simplified.
std::vector<TestCase> test_cases;
- test_cases.push_back(TestCase("testing output\n", PROCESS_OUTPUT_TYPE_OUT));
- test_cases.push_back(TestCase("testing error\n", PROCESS_OUTPUT_TYPE_OUT));
- test_cases.push_back(TestCase("testing error1\n", PROCESS_OUTPUT_TYPE_OUT));
- test_cases.push_back(TestCase("testing output1\n", PROCESS_OUTPUT_TYPE_OUT));
- test_cases.push_back(TestCase("testing output2\n", PROCESS_OUTPUT_TYPE_OUT));
- test_cases.push_back(TestCase("testing output3\n", PROCESS_OUTPUT_TYPE_OUT));
- test_cases.push_back(TestCase(VeryLongString(), PROCESS_OUTPUT_TYPE_OUT));
- test_cases.push_back(TestCase("testing error2\n", PROCESS_OUTPUT_TYPE_OUT));
- test_cases.push_back(TestCase("line with \0 in it\n",
- arraysize("line with \0 in it \n"),
- PROCESS_OUTPUT_TYPE_OUT));
-
- output_watch_thread.message_loop()->PostTask(FROM_HERE,
- base::Bind(&ProcessOutputWatcherTest::StartWatch, base::Unretained(this),
- pt_pipe[0], stop_pipe[0], test_cases));
-
- for (size_t i = 0; i < test_cases.size(); i++) {
- // Let's make inputs not NULL terminated.
- const std::string& test_str = test_cases[i].str;
- ssize_t test_size = test_str.length() * sizeof(*test_str.c_str());
- EXPECT_EQ(test_size,
- file_util::WriteFileDescriptor(pt_pipe[1], test_str.c_str(),
- test_size));
- }
-
- all_data_received_->Wait();
-
- // Send stop signal. It is not important which string we send.
- EXPECT_EQ(1, file_util::WriteFileDescriptor(stop_pipe[1], "q", 1));
+ test_cases.push_back(TestCase("testing output\n", false));
+ test_cases.push_back(TestCase("testing error\n", false));
+ test_cases.push_back(TestCase("testing error1\n", false));
+ test_cases.push_back(TestCase("testing output1\n", false));
+ test_cases.push_back(TestCase("testing output2\n", false));
+ test_cases.push_back(TestCase("testing output3\n", false));
+ test_cases.push_back(TestCase(VeryLongString(), false));
+ test_cases.push_back(TestCase("testing error2\n", false));
+
+ RunTest(test_cases);
+};
- EXPECT_NE(-1, HANDLE_EINTR(close(stop_pipe[1])));
- EXPECT_NE(-1, HANDLE_EINTR(close(pt_pipe[1])));
+// Verifies that sending '\0' generates PROCESS_OUTPUT_TYPE_OUT event and does
+// not terminate output watcher.
+TEST_F(ProcessOutputWatcherTest, SendNull) {
+ std::vector<TestCase> test_cases;
+ // This will send '\0' to output wathcer.
+ test_cases.push_back(TestCase("", true));
+ // Let's verify that next input also gets detected (i.e. output watcher does
+ // not exit after seeing '\0' from previous test case).
+ test_cases.push_back(TestCase("a", true));
- output_watch_thread.Stop();
+ RunTest(test_cases);
};
-