diff options
| -rw-r--r-- | services/inputflinger/tests/InputReader_test.cpp | 3 | ||||
| -rw-r--r-- | services/inputflinger/tests/TestInputListener.cpp | 17 | ||||
| -rw-r--r-- | services/inputflinger/tests/TestInputListener.h | 6 |
3 files changed, 16 insertions, 10 deletions
diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp index 618aefc741..3d26e75933 100644 --- a/services/inputflinger/tests/InputReader_test.cpp +++ b/services/inputflinger/tests/InputReader_test.cpp @@ -1748,7 +1748,8 @@ protected: virtual void SetUp() override { mFakePolicy = new FakeInputReaderPolicy(); - mTestListener = new TestInputListener(50ms); + mTestListener = new TestInputListener(2000ms /*eventHappenedTimeout*/, + 30ms /*eventDidNotHappenTimeout*/); mReader = new InputReader(std::make_shared<EventHub>(), mFakePolicy, mTestListener); ASSERT_EQ(mReader->start(), OK); diff --git a/services/inputflinger/tests/TestInputListener.cpp b/services/inputflinger/tests/TestInputListener.cpp index 86ff3b1d4d..9bff166565 100644 --- a/services/inputflinger/tests/TestInputListener.cpp +++ b/services/inputflinger/tests/TestInputListener.cpp @@ -23,7 +23,10 @@ namespace android { // --- TestInputListener --- -TestInputListener::TestInputListener(const std::chrono::milliseconds timeout) : mTimeout(timeout) {} +TestInputListener::TestInputListener(std::chrono::milliseconds eventHappenedTimeout, + std::chrono::milliseconds eventDidNotHappenTimeout) + : mEventHappenedTimeout(eventHappenedTimeout), + mEventDidNotHappenTimeout(eventDidNotHappenTimeout) {} TestInputListener::~TestInputListener() { } @@ -86,9 +89,9 @@ void TestInputListener::assertCalled(NotifyArgsType* outEventArgs, std::string m std::vector<NotifyArgsType>& queue = std::get<std::vector<NotifyArgsType>>(mQueues); if (queue.empty()) { - const bool eventReceived = mCondition.wait_for(lock, mTimeout, [&queue]() REQUIRES(mLock) { - return !queue.empty(); - }); + const bool eventReceived = + mCondition.wait_for(lock, mEventHappenedTimeout, + [&queue]() REQUIRES(mLock) { return !queue.empty(); }); if (!eventReceived) { FAIL() << "Timed out waiting for event: " << message.c_str(); } @@ -105,9 +108,9 @@ void TestInputListener::assertNotCalled(std::string message) { base::ScopedLockAssertion assumeLocked(mLock); std::vector<NotifyArgsType>& queue = std::get<std::vector<NotifyArgsType>>(mQueues); - const bool eventReceived = mCondition.wait_for(lock, mTimeout, [&queue]() REQUIRES(mLock) { - return !queue.empty(); - }); + const bool eventReceived = + mCondition.wait_for(lock, mEventDidNotHappenTimeout, + [&queue]() REQUIRES(mLock) { return !queue.empty(); }); if (eventReceived) { FAIL() << "Unexpected event: " << message.c_str(); } diff --git a/services/inputflinger/tests/TestInputListener.h b/services/inputflinger/tests/TestInputListener.h index 4262f5adfb..d50c6bcd51 100644 --- a/services/inputflinger/tests/TestInputListener.h +++ b/services/inputflinger/tests/TestInputListener.h @@ -32,7 +32,8 @@ protected: virtual ~TestInputListener(); public: - TestInputListener(const std::chrono::milliseconds timeout = 5ms); + TestInputListener(std::chrono::milliseconds eventHappenedTimeout = 0ms, + std::chrono::milliseconds eventDidNotHappenTimeout = 0ms); void assertNotifyConfigurationChangedWasCalled( NotifyConfigurationChangedArgs* outEventArgs = nullptr); @@ -75,7 +76,8 @@ private: std::mutex mLock; std::condition_variable mCondition; - const std::chrono::milliseconds mTimeout; + const std::chrono::milliseconds mEventHappenedTimeout; + const std::chrono::milliseconds mEventDidNotHappenTimeout; std::tuple<std::vector<NotifyConfigurationChangedArgs>, // std::vector<NotifyDeviceResetArgs>, // |