Skip to content

Commit c8d5f1a

Browse files
author
Steven Moreland
committed
binderLibTest: epoch->uptime
NTP time reset during test causes flakes. Fixes: 368314472 Test: TH Change-Id: I759113d19721936336b355e0c363c18e7c3adfa1
1 parent 1e1a07f commit c8d5f1a

1 file changed

Lines changed: 4 additions & 11 deletions

File tree

libs/binder/tests/binderLibTest.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <input/BlockingQueue.h>
4444
#include <processgroup/processgroup.h>
4545
#include <utils/Flattenable.h>
46+
#include <utils/SystemClock.h>
4647

4748
#include <linux/sched.h>
4849
#include <sys/epoll.h>
@@ -1710,14 +1711,6 @@ TEST_F(BinderLibTest, ThreadPoolStarted) {
17101711
EXPECT_TRUE(reply.readBool());
17111712
}
17121713

1713-
size_t epochMillis() {
1714-
using std::chrono::duration_cast;
1715-
using std::chrono::milliseconds;
1716-
using std::chrono::seconds;
1717-
using std::chrono::system_clock;
1718-
return duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
1719-
}
1720-
17211714
TEST_F(BinderLibTest, HangingServices) {
17221715
Parcel data, reply;
17231716
sp<IBinder> server = addServer();
@@ -1726,7 +1719,7 @@ TEST_F(BinderLibTest, HangingServices) {
17261719
data.writeInt32(delay);
17271720
// b/266537959 - must take before taking lock, since countdown is started in the remote
17281721
// process there.
1729-
size_t epochMsBefore = epochMillis();
1722+
int64_t timeBefore = uptimeMillis();
17301723
EXPECT_THAT(server->transact(BINDER_LIB_TEST_PROCESS_TEMPORARY_LOCK, data, &reply), NO_ERROR);
17311724
std::vector<std::thread> ts;
17321725
for (size_t i = 0; i < kKernelThreads + 1; i++) {
@@ -1740,10 +1733,10 @@ TEST_F(BinderLibTest, HangingServices) {
17401733
for (auto &t : ts) {
17411734
t.join();
17421735
}
1743-
size_t epochMsAfter = epochMillis();
1736+
int64_t timeAfter = uptimeMillis();
17441737

17451738
// deadlock occurred and threads only finished after 1s passed.
1746-
EXPECT_GE(epochMsAfter, epochMsBefore + delay);
1739+
EXPECT_GE(timeAfter, timeBefore + delay);
17471740
}
17481741

17491742
TEST_F(BinderLibTest, BinderProxyCount) {

0 commit comments

Comments
 (0)