Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ecb96ac0 authored by Josh Gao's avatar Josh Gao
Browse files

adb: improve socket tests.

Make it so that the socket tests don't leak until your machine blows up
by switching an infinite loop into an assertion failure.

Bug: http://b/74616284
Test: adb_test
Change-Id: If618c26b224b660548454f542cab79bebe46f80e
parent 6156420f
Loading
Loading
Loading
Loading
+14 −17
Original line number Diff line number Diff line
@@ -113,16 +113,12 @@ static void CloseWithPacketThreadFunc(CloseWithPacketArg* arg) {
    asocket* s = create_local_socket(arg->socket_fd);
    ASSERT_TRUE(s != nullptr);
    arg->bytes_written = 0;
    while (true) {

    std::string data;
    data.resize(MAX_PAYLOAD);
    arg->bytes_written += data.size();
    int ret = s->enqueue(s, std::move(data));
        if (ret == 1) {
            // The writer has one packet waiting to send.
            break;
        }
    }
    ASSERT_EQ(1, ret);

    asocket* cause_close_s = create_local_socket(arg->cause_close_fd);
    ASSERT_TRUE(cause_close_s != nullptr);
@@ -233,15 +229,16 @@ TEST_F(LocalSocketTest, flush_after_shutdown) {
    PrepareThread();
    std::thread thread(fdevent_loop);

    ASSERT_TRUE(WriteFdExactly(head_fd[0], "foo", 3));
    ASSERT_EQ(0, adb_shutdown(head_fd[0], SHUT_RD));
    EXPECT_TRUE(WriteFdExactly(head_fd[0], "foo", 3));

    EXPECT_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));
    EXPECT_TRUE(WriteFdExactly(tail_fd[0], str, strlen(str)));
    EXPECT_TRUE(WriteFdExactly(head_fd[0], "bar", 3));

    ASSERT_EQ(0, memcmp(buf, "foobar", 6));
    char buf[6];
    EXPECT_TRUE(ReadFdExactly(tail_fd[0], buf, 6));
    EXPECT_EQ(0, memcmp(buf, "foobar", 6));

    adb_close(head_fd[0]);
    adb_close(tail_fd[0]);