Run some inputflinger_tests on host
Sometimes, it's convenient to execute the input tests without having a
connected device. This is especially useful when doing cherry-picks of
patch on a cloud device.
Allow input code to build for host, and enable the tests for running on
host.
Bug: 249591924
Test: atest --host --no-bazel-mode -c -m inputflinger_tests
Change-Id: Ib9be6a5fb6c35ffc450e41cb2a5688bfb2c8d01a
diff --git a/services/inputflinger/tests/Android.bp b/services/inputflinger/tests/Android.bp
index fcbb98f..b6d0709 100644
--- a/services/inputflinger/tests/Android.bp
+++ b/services/inputflinger/tests/Android.bp
@@ -23,6 +23,7 @@
cc_test {
name: "inputflinger_tests",
+ host_supported: true,
defaults: [
"inputflinger_defaults",
// For all targets inside inputflinger, these tests build all of their sources using their
@@ -56,10 +57,36 @@
"frameworks/native/libs/input",
],
},
+ target: {
+ android: {
+ shared_libs: [
+ "libinput",
+ "libvintf",
+ ],
+ },
+ host: {
+ include_dirs: [
+ "bionic/libc/kernel/android/uapi/",
+ "bionic/libc/kernel/uapi",
+ ],
+ cflags: [
+ "-D__ANDROID_HOST__",
+ ],
+ static_libs: [
+ "libinput",
+ ],
+ },
+ },
static_libs: [
"libc++fs",
"libgmock",
],
+ shared_libs: [
+ "libinputreader",
+ ],
require_root: true,
+ test_options: {
+ unit_test: true,
+ },
test_suites: ["device-tests"],
}
diff --git a/services/inputflinger/tests/EventHub_test.cpp b/services/inputflinger/tests/EventHub_test.cpp
index 9380c71..2e296da 100644
--- a/services/inputflinger/tests/EventHub_test.cpp
+++ b/services/inputflinger/tests/EventHub_test.cpp
@@ -68,12 +68,18 @@
int32_t mDeviceId;
virtual void SetUp() override {
+#if !defined(__ANDROID__)
+ GTEST_SKIP() << "It's only possible to interact with uinput on device";
+#endif
mEventHub = std::make_unique<EventHub>();
consumeInitialDeviceAddedEvents();
mKeyboard = createUinputDevice<UinputHomeKey>();
ASSERT_NO_FATAL_FAILURE(mDeviceId = waitForDeviceCreation());
}
virtual void TearDown() override {
+#if !defined(__ANDROID__)
+ return;
+#endif
mKeyboard.reset();
waitForDeviceClose(mDeviceId);
assertNoMoreEvents();
diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp
index 985c9c5..a1ccfc7 100644
--- a/services/inputflinger/tests/InputDispatcher_test.cpp
+++ b/services/inputflinger/tests/InputDispatcher_test.cpp
@@ -7028,7 +7028,7 @@
}
for (int i = 0; i < nFds; i++) {
ASSERT_EQ(EPOLLIN, events[i].events);
- eventOrder.push_back(events[i].data.u64);
+ eventOrder.push_back(static_cast<size_t>(events[i].data.u64));
channels[i]->consumeMotionDown();
}
}
diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp
index 8ac8dfc..3cc8e94 100644
--- a/services/inputflinger/tests/InputReader_test.cpp
+++ b/services/inputflinger/tests/InputReader_test.cpp
@@ -2300,6 +2300,9 @@
std::shared_ptr<FakePointerController> mFakePointerController;
void SetUp() override {
+#if !defined(__ANDROID__)
+ GTEST_SKIP();
+#endif
mFakePolicy = sp<FakeInputReaderPolicy>::make();
mFakePointerController = std::make_shared<FakePointerController>();
mFakePolicy->setPointerController(mFakePointerController);
@@ -2318,6 +2321,9 @@
}
void TearDown() override {
+#if !defined(__ANDROID__)
+ return;
+#endif
ASSERT_EQ(mReader->stop(), OK);
mReader.reset();
mTestListener.reset();
@@ -2432,6 +2438,9 @@
const std::string UNIQUE_ID = "local:0";
void SetUp() override {
+#if !defined(__ANDROID__)
+ GTEST_SKIP();
+#endif
InputReaderIntegrationTest::SetUp();
// At least add an internal display.
setDisplayInfoAndReconfigure(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT,
diff --git a/services/inputflinger/tests/UinputDevice.cpp b/services/inputflinger/tests/UinputDevice.cpp
index 9c93919..7862b58 100644
--- a/services/inputflinger/tests/UinputDevice.cpp
+++ b/services/inputflinger/tests/UinputDevice.cpp
@@ -17,6 +17,7 @@
#include "UinputDevice.h"
#include <android-base/stringprintf.h>
+#include <cutils/memory.h>
#include <fcntl.h>
namespace android {