diff options
author | Josh Gao <jmgao@google.com> | 2018-03-16 22:18:43 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2018-03-16 22:18:43 +0000 |
commit | 32caa9870ff8dde8fdd4d71a75dead9ab538e627 (patch) | |
tree | 8c09cbb8623b14623b2ef70a333a26725f6da2ac /adb/socket_test.cpp | |
parent | 40858e95b6b3fdb37d846164fbbd3e098d250258 (diff) | |
parent | df3bae9f0675f6cfbe68e64600166e62a403ce7d (diff) | |
download | system_core-32caa9870ff8dde8fdd4d71a75dead9ab538e627.tar.gz system_core-32caa9870ff8dde8fdd4d71a75dead9ab538e627.tar.bz2 system_core-32caa9870ff8dde8fdd4d71a75dead9ab538e627.zip |
Merge "adb: add test for flushing socket data after a write failure."
Diffstat (limited to 'adb/socket_test.cpp')
-rw-r--r-- | adb/socket_test.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/adb/socket_test.cpp b/adb/socket_test.cpp index 04ad6f366..c818fca09 100644 --- a/adb/socket_test.cpp +++ b/adb/socket_test.cpp @@ -213,6 +213,46 @@ TEST_F(LocalSocketTest, write_error_when_having_packets) { TerminateThread(thread); } +#if 0 +// Ensure that if we fail to write output to an fd, we will still flush data coming from it. +TEST_F(LocalSocketTest, flush_after_shutdown) { + int head_fd[2]; + int tail_fd[2]; + ASSERT_EQ(0, adb_socketpair(head_fd)); + ASSERT_EQ(0, adb_socketpair(tail_fd)); + + asocket* head = create_local_socket(head_fd[1]); + asocket* tail = create_local_socket(tail_fd[1]); + + head->peer = tail; + head->ready(head); + + tail->peer = head; + tail->ready(tail); + + PrepareThread(); + std::thread thread(fdevent_loop); + + ASSERT_TRUE(WriteFdExactly(head_fd[0], "foo", 3)); + ASSERT_EQ(0, adb_shutdown(head_fd[0], SHUT_RD)); + const char* str = "write succeeds, but local_socket will fail to write"; + ASSERT_TRUE(WriteFdExactly(tail_fd[0], str, strlen(str))); + ASSERT_TRUE(WriteFdExactly(head_fd[0], "bar", 3)); + char buf[6]; + ASSERT_TRUE(ReadFdExactly(tail_fd[0], buf, 6)); + + ASSERT_EQ(0, memcmp(buf, "foobar", 6)); + + adb_close(head_fd[0]); + adb_close(tail_fd[0]); + + // Wait until the local sockets are closed. + std::this_thread::sleep_for(SLEEP_FOR_FDEVENT); + ASSERT_EQ(GetAdditionalLocalSocketCount(), fdevent_installed_count()); + TerminateThread(thread); +} +#endif + #if defined(__linux__) static void ClientThreadFunc() { |