Switch adb over to <chrono>.
Clearer code, and lets us lose some more portability cruft.
Bug: http://b/32878766
Test: manual
Change-Id: Ie44928bbf8d68a74127aaf76e7e0060e25fa2cc8
diff --git a/socket_test.cpp b/socket_test.cpp
index 5e79b5e..b6aff54 100644
--- a/socket_test.cpp
+++ b/socket_test.cpp
@@ -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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
&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 @@
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 @@
&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);
}