libhidl_test: remove flake
We have many other performance tests for passthrough
mode. I've changed the TaskRunner test here to only
test that the task is run.
Bug: 64020862
Test: libhidl_test (100 times)
Change-Id: I045718a4f8cfbd08b3d88a4f7c4232e2b54ea869
diff --git a/test_main.cpp b/test_main.cpp
index 1f2f845..b265607 100644
--- a/test_main.cpp
+++ b/test_main.cpp
@@ -17,6 +17,7 @@
#define LOG_TAG "LibHidlTest"
#include <android-base/logging.h>
+#include <condition_variable>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <hidl/HidlSupport.h>
@@ -296,16 +297,23 @@
TEST_F(LibHidlTest, TaskRunnerTest) {
using android::hardware::details::TaskRunner;
+ using namespace std::chrono_literals;
+
+ std::condition_variable cv;
+ std::mutex m;
+
TaskRunner tr;
tr.start(1 /* limit */);
bool flag = false;
tr.push([&] {
- usleep(1000);
flag = true;
+ cv.notify_all();
});
- usleep(500);
- EXPECT_FALSE(flag);
- usleep(1000);
+
+ std::unique_lock<std::mutex> lock(m);
+
+ // 1s so this doesn't deadlock. This isn't a performance test.
+ EXPECT_TRUE(cv.wait_for(lock, 1s, [&]{return flag;}));
EXPECT_TRUE(flag);
}