summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Prabir Pradhan <prabirmsp@google.com> 2024-04-11 16:59:22 +0000
committer Prabir Pradhan <prabirmsp@google.com> 2024-04-11 16:59:22 +0000
commit6c0de2bb775bde4ba63f4190b90c4e1814040dd8 (patch)
tree0f248c85ae3ba0f7eafcf40ecf0242def19d5a5d
parent5013f984702088a0565029ed0dcb447c897be2ed (diff)
InputTracingTest: Fix test flakiness
There was a bug in the logic for tracking when the tracing thread is idle. The thread can only be idle when the queue is empty, so prevent it from being marked as idle when there are still events left to be processed. Also, a waitForTracerIdle() was missing in the TraceWindowDispatch test. Bug: 333544493 Test: InputTracingTest passes 10000 times Change-Id: I90feaeefc80d1a0e43732ee7e75d4074a9634bd7
-rw-r--r--services/inputflinger/dispatcher/trace/ThreadedBackend.cpp9
-rw-r--r--services/inputflinger/tests/InputTracingTest.cpp2
2 files changed, 8 insertions, 3 deletions
diff --git a/services/inputflinger/dispatcher/trace/ThreadedBackend.cpp b/services/inputflinger/dispatcher/trace/ThreadedBackend.cpp
index c0a98f5e5d..3c3c15a64c 100644
--- a/services/inputflinger/dispatcher/trace/ThreadedBackend.cpp
+++ b/services/inputflinger/dispatcher/trace/ThreadedBackend.cpp
@@ -57,6 +57,7 @@ void ThreadedBackend<Backend>::traceMotionEvent(const TracedMotionEvent& event,
const TracedEventMetadata& metadata) {
std::scoped_lock lock(mLock);
mQueue.emplace_back(event, metadata);
+ setIdleStatus(false);
mThreadWakeCondition.notify_all();
}
@@ -65,6 +66,7 @@ void ThreadedBackend<Backend>::traceKeyEvent(const TracedKeyEvent& event,
const TracedEventMetadata& metadata) {
std::scoped_lock lock(mLock);
mQueue.emplace_back(event, metadata);
+ setIdleStatus(false);
mThreadWakeCondition.notify_all();
}
@@ -73,6 +75,7 @@ void ThreadedBackend<Backend>::traceWindowDispatch(const WindowDispatchArgs& dis
const TracedEventMetadata& metadata) {
std::scoped_lock lock(mLock);
mQueue.emplace_back(dispatchArgs, metadata);
+ setIdleStatus(false);
mThreadWakeCondition.notify_all();
}
@@ -84,7 +87,9 @@ void ThreadedBackend<Backend>::threadLoop() {
std::unique_lock lock(mLock);
base::ScopedLockAssertion assumeLocked(mLock);
- setIdleStatus(true);
+ if (mQueue.empty()) {
+ setIdleStatus(true);
+ }
// Wait until we need to process more events or exit.
mThreadWakeCondition.wait(lock,
@@ -94,8 +99,6 @@ void ThreadedBackend<Backend>::threadLoop() {
return;
}
- setIdleStatus(false);
-
mQueue.swap(entries);
} // release lock
diff --git a/services/inputflinger/tests/InputTracingTest.cpp b/services/inputflinger/tests/InputTracingTest.cpp
index fe4d6d9a8f..23fa045f86 100644
--- a/services/inputflinger/tests/InputTracingTest.cpp
+++ b/services/inputflinger/tests/InputTracingTest.cpp
@@ -626,6 +626,8 @@ TEST_F(InputTracingTest, TraceWindowDispatch) {
consumed = window->consumeMotionEvent(WithMotionAction(ACTION_CANCEL));
s.expectMotionTraced(Level::NONE, *consumed);
s.expectDispatchTraced(Level::REDACTED, {*consumed, window});
+
+ waitForTracerIdle();
}
TEST_F(InputTracingTest, SimultaneousTracingSessions) {