Wait longer for expected input events
Sometimes, a device can be slow. That means, some events take a long
time to process, especially if they involve kernel processing these from
userspace and sending them back to userspace.
When the input device is being added or removed, we are currently not
waiting long enough to be notified. The test currently fails because the
input device added notification never arrived.
It turns out there are 2 cases where we are currently waiting for an
input event from eventhub:
1) When we know how many events we expect, and we don't care how long
they will take. We are willing to wait for a long time, because we know
they will come eventually. When we got the expected number of events, we
can stop waiting for more
2) When we have no idea how many events to expect, and we don't want to
wait - we just need to take all immediately available.
To account for the 2 (and only the 2 cases above), refactor
EventHub_test to wait for a specific number of events instead of a
timeout. If no expected number of events is provided, read all
immediately available ones without a limit.
This change also makes the test ~ 50% faster, because we are now
stopping the wait after we have received the expected number of events.
Bug: 149155998
Test: /data/nativetest64/inputflinger_tests/inputflinger_tests --gtest_filter=*EventHubTest* --gtest_repeat=1000
Change-Id: I732c14c09567e9231bcc83141368b1614805f9ac
diff --git a/services/inputflinger/tests/UinputDevice.cpp b/services/inputflinger/tests/UinputDevice.cpp
index 99480b7..10e7293 100644
--- a/services/inputflinger/tests/UinputDevice.cpp
+++ b/services/inputflinger/tests/UinputDevice.cpp
@@ -44,9 +44,7 @@
device.id.product = 0x01;
device.id.version = 1;
- // Using EXPECT instead of ASSERT to allow the device creation to continue even when
- // some failures are reported when configuring the device.
- EXPECT_NO_FATAL_FAILURE(configureDevice(mDeviceFd, &device));
+ ASSERT_NO_FATAL_FAILURE(configureDevice(mDeviceFd, &device));
if (write(mDeviceFd, &device, sizeof(device)) < 0) {
FAIL() << "Could not write uinput_user_dev struct into uinput file descriptor: "
@@ -70,7 +68,7 @@
" with value %" PRId32 " : %s",
type, code, value, strerror(errno));
ALOGE("%s", msg.c_str());
- ADD_FAILURE() << msg.c_str();
+ FAIL() << msg.c_str();
}
}
@@ -82,41 +80,41 @@
void UinputKeyboard::configureDevice(int fd, uinput_user_dev* device) {
// enable key press/release event
if (ioctl(fd, UI_SET_EVBIT, EV_KEY)) {
- ADD_FAILURE() << "Error in ioctl : UI_SET_EVBIT : EV_KEY: " << strerror(errno);
+ FAIL() << "Error in ioctl : UI_SET_EVBIT : EV_KEY: " << strerror(errno);
}
// enable set of KEY events
std::for_each(mKeys.begin(), mKeys.end(), [fd](int key) {
if (ioctl(fd, UI_SET_KEYBIT, key)) {
- ADD_FAILURE() << "Error in ioctl : UI_SET_KEYBIT : " << key << " : " << strerror(errno);
+ FAIL() << "Error in ioctl : UI_SET_KEYBIT : " << key << " : " << strerror(errno);
}
});
// enable synchronization event
if (ioctl(fd, UI_SET_EVBIT, EV_SYN)) {
- ADD_FAILURE() << "Error in ioctl : UI_SET_EVBIT : EV_SYN: " << strerror(errno);
+ FAIL() << "Error in ioctl : UI_SET_EVBIT : EV_SYN: " << strerror(errno);
}
}
void UinputKeyboard::pressKey(int key) {
if (mKeys.find(key) == mKeys.end()) {
- ADD_FAILURE() << mName << ": Cannot inject key press: Key not found: " << key;
+ FAIL() << mName << ": Cannot inject key press: Key not found: " << key;
}
- EXPECT_NO_FATAL_FAILURE(injectEvent(EV_KEY, key, 1));
- EXPECT_NO_FATAL_FAILURE(injectEvent(EV_SYN, SYN_REPORT, 0));
+ injectEvent(EV_KEY, key, 1);
+ injectEvent(EV_SYN, SYN_REPORT, 0);
}
void UinputKeyboard::releaseKey(int key) {
if (mKeys.find(key) == mKeys.end()) {
- ADD_FAILURE() << mName << ": Cannot inject key release: Key not found: " << key;
+ FAIL() << mName << ": Cannot inject key release: Key not found: " << key;
}
- EXPECT_NO_FATAL_FAILURE(injectEvent(EV_KEY, key, 0));
- EXPECT_NO_FATAL_FAILURE(injectEvent(EV_SYN, SYN_REPORT, 0));
+ injectEvent(EV_KEY, key, 0);
+ injectEvent(EV_SYN, SYN_REPORT, 0);
}
void UinputKeyboard::pressAndReleaseKey(int key) {
- EXPECT_NO_FATAL_FAILURE(pressKey(key));
- EXPECT_NO_FATAL_FAILURE(releaseKey(key));
+ pressKey(key);
+ releaseKey(key);
}
// --- UinputHomeKey ---
@@ -124,7 +122,7 @@
UinputHomeKey::UinputHomeKey() : UinputKeyboard({KEY_HOME}) {}
void UinputHomeKey::pressAndReleaseHomeKey() {
- EXPECT_NO_FATAL_FAILURE(pressAndReleaseKey(KEY_HOME));
+ pressAndReleaseKey(KEY_HOME);
}
// --- UinputTouchScreen ---
@@ -158,35 +156,35 @@
}
void UinputTouchScreen::sendSlot(int32_t slot) {
- EXPECT_NO_FATAL_FAILURE(injectEvent(EV_ABS, ABS_MT_SLOT, slot));
+ injectEvent(EV_ABS, ABS_MT_SLOT, slot);
}
void UinputTouchScreen::sendTrackingId(int32_t trackingId) {
- EXPECT_NO_FATAL_FAILURE(injectEvent(EV_ABS, ABS_MT_TRACKING_ID, trackingId));
+ injectEvent(EV_ABS, ABS_MT_TRACKING_ID, trackingId);
}
void UinputTouchScreen::sendDown(const Point& point) {
- EXPECT_NO_FATAL_FAILURE(injectEvent(EV_KEY, BTN_TOUCH, 1));
- EXPECT_NO_FATAL_FAILURE(injectEvent(EV_ABS, ABS_MT_POSITION_X, point.x));
- EXPECT_NO_FATAL_FAILURE(injectEvent(EV_ABS, ABS_MT_POSITION_Y, point.y));
- EXPECT_NO_FATAL_FAILURE(injectEvent(EV_SYN, SYN_REPORT, 0));
+ injectEvent(EV_KEY, BTN_TOUCH, 1);
+ injectEvent(EV_ABS, ABS_MT_POSITION_X, point.x);
+ injectEvent(EV_ABS, ABS_MT_POSITION_Y, point.y);
+ injectEvent(EV_SYN, SYN_REPORT, 0);
}
void UinputTouchScreen::sendMove(const Point& point) {
- EXPECT_NO_FATAL_FAILURE(injectEvent(EV_ABS, ABS_MT_POSITION_X, point.x));
- EXPECT_NO_FATAL_FAILURE(injectEvent(EV_ABS, ABS_MT_POSITION_Y, point.y));
- EXPECT_NO_FATAL_FAILURE(injectEvent(EV_SYN, SYN_REPORT, 0));
+ injectEvent(EV_ABS, ABS_MT_POSITION_X, point.x);
+ injectEvent(EV_ABS, ABS_MT_POSITION_Y, point.y);
+ injectEvent(EV_SYN, SYN_REPORT, 0);
}
void UinputTouchScreen::sendUp() {
sendTrackingId(0xffffffff);
- EXPECT_NO_FATAL_FAILURE(injectEvent(EV_KEY, BTN_TOUCH, 0));
- EXPECT_NO_FATAL_FAILURE(injectEvent(EV_SYN, SYN_REPORT, 0));
+ injectEvent(EV_KEY, BTN_TOUCH, 0);
+ injectEvent(EV_SYN, SYN_REPORT, 0);
}
void UinputTouchScreen::sendToolType(int32_t toolType) {
- EXPECT_NO_FATAL_FAILURE(injectEvent(EV_ABS, ABS_MT_TOOL_TYPE, toolType));
- EXPECT_NO_FATAL_FAILURE(injectEvent(EV_SYN, SYN_REPORT, 0));
+ injectEvent(EV_ABS, ABS_MT_TOOL_TYPE, toolType);
+ injectEvent(EV_SYN, SYN_REPORT, 0);
}
// Get the center x, y base on the range definition.