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

Commit ddf87aad authored by Elliott Hughes's avatar Elliott Hughes Committed by android-build-merger
Browse files

Merge "Switch adb over to <chrono>." am: 59826dde am: 2278b50f

am: bd51a0d3

Change-Id: I5371f94c6b5adc626bdd5bc322b183dcb6ab40f3
parents 2b739800 bd51a0d3
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -30,7 +30,9 @@
#include <sys/time.h>
#include <time.h>

#include <chrono>
#include <string>
#include <thread>
#include <vector>

#include <android-base/errors.h>
@@ -51,6 +53,7 @@
#include <sys/capability.h>
#include <sys/mount.h>
#include <android-base/properties.h>
using namespace std::chrono_literals;
#endif

std::string adb_version() {
@@ -375,7 +378,7 @@ void handle_packet(apacket *p, atransport *t)
                    adbd_auth_verified(t);
                    t->failed_auth_attempts = 0;
                } else {
                    if (t->failed_auth_attempts++ > 256) adb_sleep_ms(1000);
                    if (t->failed_auth_attempts++ > 256) std::this_thread::sleep_for(1s);
                    send_auth_request(t);
                }
                break;
+5 −3
Original line number Diff line number Diff line
@@ -28,7 +28,9 @@
#include <sys/stat.h>
#include <sys/types.h>

#include <chrono>
#include <string>
#include <thread>
#include <vector>

#include <android-base/stringprintf.h>
@@ -188,8 +190,8 @@ int adb_connect(const std::string& service, std::string* error) {
        } else {
            fprintf(stdout,"* daemon started successfully *\n");
        }
        /* give the server some time to start properly and detect devices */
        adb_sleep_ms(3000);
        // Give the server some time to start properly and detect devices.
        std::this_thread::sleep_for(std::chrono::seconds(3));
        // fall through to _adb_connect
    } else {
        // If a server is already running, check its version matches.
@@ -234,7 +236,7 @@ int adb_connect(const std::string& service, std::string* error) {
            }

            /* XXX can we better detect its death? */
            adb_sleep_ms(2000);
            std::this_thread::sleep_for(std::chrono::seconds(2));
            goto start_server;
        }
    }
+4 −1
Original line number Diff line number Diff line
@@ -20,6 +20,9 @@

#include <unistd.h>

#include <chrono>
#include <thread>

#include <android-base/stringprintf.h>

#include "adb.h"
@@ -104,7 +107,7 @@ bool WriteFdExactly(int fd, const void* buf, size_t len) {
        if (r == -1) {
            D("writex: fd=%d error %d: %s", fd, errno, strerror(errno));
            if (errno == EAGAIN) {
                adb_sleep_ms(1); // just yield some cpu time
                std::this_thread::yield();
                continue;
            } else if (errno == EPIPE) {
                D("writex: fd=%d disconnected", fd);
+3 −1
Original line number Diff line number Diff line
@@ -31,8 +31,10 @@
#include <sys/stat.h>
#include <sys/types.h>

#include <chrono>
#include <memory>
#include <string>
#include <thread>
#include <vector>

#include <android-base/file.h>
@@ -1080,7 +1082,7 @@ static bool adb_root(const char* command) {

    // Give adbd some time to kill itself and come back up.
    // We can't use wait-for-device because devices (e.g. adb over network) might not come back.
    adb_sleep_ms(3000);
    std::this_thread::sleep_for(std::chrono::seconds(3));
    return true;
}

+15 −13
Original line number Diff line number Diff line
@@ -19,9 +19,11 @@
#include <gtest/gtest.h>

#include <array>
#include <chrono>
#include <limits>
#include <queue>
#include <string>
#include <thread>
#include <vector>

#include <unistd.h>
@@ -44,7 +46,7 @@ static void FdEventThreadFunc(void*) {
    fdevent_loop();
}

const size_t SLEEP_FOR_FDEVENT_IN_MS = 100;
constexpr auto SLEEP_FOR_FDEVENT = std::chrono::milliseconds(100);

TEST_F(LocalSocketTest, smoke) {
    // Join two socketpairs with a chain of intermediate socketpairs.
@@ -101,7 +103,7 @@ TEST_F(LocalSocketTest, smoke) {
    ASSERT_EQ(0, adb_close(last[1]));

    // Wait until the local sockets are closed.
    adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS);
    std::this_thread::sleep_for(SLEEP_FOR_FDEVENT);
    ASSERT_EQ(GetAdditionalLocalSocketCount(), fdevent_installed_count());
    TerminateThread(thread);
}
@@ -154,12 +156,12 @@ TEST_F(LocalSocketTest, close_socket_with_packet) {
    ASSERT_TRUE(adb_thread_create(reinterpret_cast<void (*)(void*)>(CloseWithPacketThreadFunc),
                                  &arg, &thread));
    // Wait until the fdevent_loop() starts.
    adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS);
    std::this_thread::sleep_for(SLEEP_FOR_FDEVENT);
    ASSERT_EQ(0, adb_close(cause_close_fd[0]));
    adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS);
    std::this_thread::sleep_for(SLEEP_FOR_FDEVENT);
    EXPECT_EQ(1u + GetAdditionalLocalSocketCount(), fdevent_installed_count());
    ASSERT_EQ(0, adb_close(socket_fd[0]));
    adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS);
    std::this_thread::sleep_for(SLEEP_FOR_FDEVENT);
    ASSERT_EQ(GetAdditionalLocalSocketCount(), fdevent_installed_count());
    TerminateThread(thread);
}
@@ -179,9 +181,9 @@ TEST_F(LocalSocketTest, read_from_closing_socket) {
    ASSERT_TRUE(adb_thread_create(reinterpret_cast<void (*)(void*)>(CloseWithPacketThreadFunc),
                                  &arg, &thread));
    // Wait until the fdevent_loop() starts.
    adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS);
    std::this_thread::sleep_for(SLEEP_FOR_FDEVENT);
    ASSERT_EQ(0, adb_close(cause_close_fd[0]));
    adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS);
    std::this_thread::sleep_for(SLEEP_FOR_FDEVENT);
    EXPECT_EQ(1u + GetAdditionalLocalSocketCount(), fdevent_installed_count());

    // Verify if we can read successfully.
@@ -190,7 +192,7 @@ TEST_F(LocalSocketTest, read_from_closing_socket) {
    ASSERT_EQ(true, ReadFdExactly(socket_fd[0], buf.data(), buf.size()));
    ASSERT_EQ(0, adb_close(socket_fd[0]));

    adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS);
    std::this_thread::sleep_for(SLEEP_FOR_FDEVENT);
    ASSERT_EQ(GetAdditionalLocalSocketCount(), fdevent_installed_count());
    TerminateThread(thread);
}
@@ -214,11 +216,11 @@ TEST_F(LocalSocketTest, write_error_when_having_packets) {
                                  &arg, &thread));

    // Wait until the fdevent_loop() starts.
    adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS);
    std::this_thread::sleep_for(SLEEP_FOR_FDEVENT);
    EXPECT_EQ(2u + GetAdditionalLocalSocketCount(), fdevent_installed_count());
    ASSERT_EQ(0, adb_close(socket_fd[0]));

    adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS);
    std::this_thread::sleep_for(SLEEP_FOR_FDEVENT);
    ASSERT_EQ(GetAdditionalLocalSocketCount(), fdevent_installed_count());
    TerminateThread(thread);
}
@@ -229,7 +231,7 @@ static void ClientThreadFunc() {
    std::string error;
    int fd = network_loopback_client(5038, SOCK_STREAM, &error);
    ASSERT_GE(fd, 0) << error;
    adb_sleep_ms(200);
    std::this_thread::sleep_for(std::chrono::milliseconds(200));
    ASSERT_EQ(0, adb_close(fd));
}

@@ -265,13 +267,13 @@ TEST_F(LocalSocketTest, close_socket_in_CLOSE_WAIT_state) {
                                  &arg, &thread));

    // Wait until the fdevent_loop() starts.
    adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS);
    std::this_thread::sleep_for(SLEEP_FOR_FDEVENT);
    EXPECT_EQ(1u + GetAdditionalLocalSocketCount(), fdevent_installed_count());

    // Wait until the client closes its socket.
    ASSERT_TRUE(adb_thread_join(client_thread));

    adb_sleep_ms(SLEEP_FOR_FDEVENT_IN_MS);
    std::this_thread::sleep_for(SLEEP_FOR_FDEVENT);
    ASSERT_EQ(GetAdditionalLocalSocketCount(), fdevent_installed_count());
    TerminateThread(thread);
}
Loading