diff options
author | 2022-09-30 08:51:23 -0700 | |
---|---|---|
committer | 2022-10-14 16:47:36 -0700 | |
commit | 31977184520e99110e1deadceb6197636f76450a (patch) | |
tree | 647bdda2d1f182ae7ee7e7fb8390e168d77a8ece | |
parent | c08105877d67f18d6592ffacaf2402f0d07953b4 (diff) |
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
-rw-r--r-- | libs/attestation/Android.bp | 1 | ||||
-rw-r--r-- | libs/input/Input.cpp | 36 | ||||
-rw-r--r-- | services/batteryservice/Android.bp | 1 | ||||
-rw-r--r-- | services/inputflinger/Android.bp | 46 | ||||
-rw-r--r-- | services/inputflinger/InputThread.cpp | 6 | ||||
-rw-r--r-- | services/inputflinger/benchmarks/Android.bp | 1 | ||||
-rw-r--r-- | services/inputflinger/dispatcher/Android.bp | 27 | ||||
-rw-r--r-- | services/inputflinger/dispatcher/InputDispatcher.cpp | 5 | ||||
-rw-r--r-- | services/inputflinger/reader/Android.bp | 37 | ||||
-rw-r--r-- | services/inputflinger/reader/EventHub.cpp | 1 | ||||
-rw-r--r-- | services/inputflinger/reader/mapper/MultiTouchInputMapper.cpp | 8 | ||||
-rw-r--r-- | services/inputflinger/reporter/Android.bp | 3 | ||||
-rw-r--r-- | services/inputflinger/tests/Android.bp | 27 | ||||
-rw-r--r-- | services/inputflinger/tests/EventHub_test.cpp | 6 | ||||
-rw-r--r-- | services/inputflinger/tests/InputDispatcher_test.cpp | 2 | ||||
-rw-r--r-- | services/inputflinger/tests/InputReader_test.cpp | 9 | ||||
-rw-r--r-- | services/inputflinger/tests/UinputDevice.cpp | 1 |
17 files changed, 172 insertions, 45 deletions
diff --git a/libs/attestation/Android.bp b/libs/attestation/Android.bp index 2bf15d45eb..fddecc0ceb 100644 --- a/libs/attestation/Android.bp +++ b/libs/attestation/Android.bp @@ -22,6 +22,7 @@ package { cc_library_static { name: "libattestation", + host_supported: true, cflags: [ "-Wall", "-Wextra", diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index 579b28e588..a6f6b14bae 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -22,6 +22,7 @@ #include <inttypes.h> #include <string.h> +#include <android-base/file.h> #include <android-base/logging.h> #include <android-base/stringprintf.h> #include <cutils/compiler.h> @@ -34,9 +35,6 @@ #ifdef __linux__ #include <binder/Parcel.h> #endif -#ifdef __ANDROID__ -#include <sys/random.h> -#endif using android::base::StringPrintf; @@ -112,28 +110,34 @@ const char* motionToolTypeToString(int32_t toolType) { } // --- IdGenerator --- + +static status_t getRandomBytes(uint8_t* data, size_t size) { + int ret = TEMP_FAILURE_RETRY(open("/dev/urandom", O_RDONLY | O_CLOEXEC | O_NOFOLLOW)); + if (ret == -1) { + return -errno; + } + + base::unique_fd fd(ret); + if (!base::ReadFully(fd, data, size)) { + return -errno; + } + return OK; +} + IdGenerator::IdGenerator(Source source) : mSource(source) {} int32_t IdGenerator::nextId() const { constexpr uint32_t SEQUENCE_NUMBER_MASK = ~SOURCE_MASK; int32_t id = 0; -// Avoid building against syscall getrandom(2) on host, which will fail build on Mac. Host doesn't -// use sequence number so just always return mSource. -#ifdef __ANDROID__ - constexpr size_t BUF_LEN = sizeof(id); - size_t totalBytes = 0; - while (totalBytes < BUF_LEN) { - ssize_t bytes = TEMP_FAILURE_RETRY(getrandom(&id, BUF_LEN, GRND_NONBLOCK)); - if (CC_UNLIKELY(bytes < 0)) { - ALOGW("Failed to fill in random number for sequence number: %s.", strerror(errno)); - id = 0; +#if defined(__linux__) + while (true) { + status_t result = getRandomBytes(reinterpret_cast<uint8_t*>(&id), sizeof(id)); + if (result == OK) { break; } - totalBytes += bytes; } -#endif // __ANDROID__ - +#endif // __linux__ return (id & SEQUENCE_NUMBER_MASK) | static_cast<int32_t>(mSource); } diff --git a/services/batteryservice/Android.bp b/services/batteryservice/Android.bp index 1e3799185e..9b783916d3 100644 --- a/services/batteryservice/Android.bp +++ b/services/batteryservice/Android.bp @@ -9,6 +9,7 @@ package { cc_library_headers { name: "libbatteryservice_headers", + host_supported: true, vendor_available: true, recovery_available: true, export_include_dirs: ["include"], diff --git a/services/inputflinger/Android.bp b/services/inputflinger/Android.bp index ddcd51f357..4dcbba2c43 100644 --- a/services/inputflinger/Android.bp +++ b/services/inputflinger/Android.bp @@ -41,7 +41,9 @@ cc_defaults { "-DANDROID_UTILS_REF_BASE_DISABLE_IMPLICIT_CONSTRUCTION", ], sanitize: { - misc_undefined: ["bounds"], + misc_undefined: [ + "bounds", + ], }, tidy: true, tidy_checks: [ @@ -57,11 +59,11 @@ cc_defaults { filegroup { name: "libinputflinger_sources", srcs: [ - "InputProcessor.cpp", "InputCommonConverter.cpp", + "InputManager.cpp", + "InputProcessor.cpp", "PreferStylusOverTouchBlocker.cpp", "UnwantedInteractionBlocker.cpp", - "InputManager.cpp", ], } @@ -77,13 +79,10 @@ cc_defaults { "libcrypto", "libcutils", "libhidlbase", - "libinput", "libkll", "liblog", "libprotobuf-cpp-lite", "libstatslog", - "libstatspull", - "libstatssocket", "libutils", "server_configurable_flags", ], @@ -92,6 +91,23 @@ cc_defaults { "libpalmrejection", "libui-types", ], + target: { + android: { + shared_libs: [ + "libgui", + "libinput", + "libstatspull", + "libstatssocket", + ], + }, + host: { + static_libs: [ + "libinput", + "libstatspull", + "libstatssocket", + ], + }, + }, } cc_library_shared { @@ -108,9 +124,8 @@ cc_library_shared { // This should consist only of dependencies from inputflinger. Other dependencies should be // in cc_defaults so that they are included in the tests. "libinputflinger_base", - "libinputreporter", "libinputreader", - "libgui", + "libinputreporter", ], static_libs: [ "libinputdispatcher", @@ -130,6 +145,7 @@ cc_library_shared { cc_library_headers { name: "libinputflinger_headers", + host_supported: true, export_include_dirs: ["include"], } @@ -151,17 +167,29 @@ cc_defaults { "libbase", "libbinder", "libcutils", - "libinput", "liblog", "libutils", ], header_libs: [ "libinputflinger_headers", ], + target: { + android: { + shared_libs: [ + "libinput", + ], + }, + host: { + static_libs: [ + "libinput", + ], + }, + }, } cc_library_shared { name: "libinputflinger_base", + host_supported: true, defaults: [ "inputflinger_defaults", "libinputflinger_base_defaults", diff --git a/services/inputflinger/InputThread.cpp b/services/inputflinger/InputThread.cpp index e2e64f992f..e74f258168 100644 --- a/services/inputflinger/InputThread.cpp +++ b/services/inputflinger/InputThread.cpp @@ -54,7 +54,13 @@ InputThread::~InputThread() { } bool InputThread::isCallingThread() { +#if defined(__ANDROID__) return gettid() == mThread->getTid(); +#else + // Assume that the caller is doing everything correctly, + // since thread information is not available on host + return false; +#endif } } // namespace android
\ No newline at end of file diff --git a/services/inputflinger/benchmarks/Android.bp b/services/inputflinger/benchmarks/Android.bp index e5c19afead..4e2a6fbf87 100644 --- a/services/inputflinger/benchmarks/Android.bp +++ b/services/inputflinger/benchmarks/Android.bp @@ -21,7 +21,6 @@ cc_benchmark { "libbinder", "libcrypto", "libcutils", - "libinput", "libinputflinger_base", "libinputreporter", "liblog", diff --git a/services/inputflinger/dispatcher/Android.bp b/services/inputflinger/dispatcher/Android.bp index eb79b76b28..99c4936f32 100644 --- a/services/inputflinger/dispatcher/Android.bp +++ b/services/inputflinger/dispatcher/Android.bp @@ -23,6 +23,7 @@ package { cc_library_headers { name: "libinputdispatcher_headers", + host_supported: true, export_include_dirs: [ "include", ], @@ -33,6 +34,7 @@ filegroup { srcs: [ "AnrTracker.cpp", "Connection.cpp", + "DragState.cpp", "Entry.cpp", "FocusResolver.cpp", "InjectionState.cpp", @@ -45,7 +47,6 @@ filegroup { "LatencyTracker.cpp", "Monitor.cpp", "TouchState.cpp", - "DragState.cpp", ], } @@ -56,20 +57,34 @@ cc_defaults { "libbase", "libcrypto", "libcutils", - "libinput", "libkll", "liblog", "libprotobuf-cpp-lite", "libstatslog", - "libstatspull", - "libstatssocket", - "libgui", "libutils", "server_configurable_flags", ], static_libs: [ "libattestation", + "libgui_window_info_static", ], + target: { + android: { + shared_libs: [ + "libgui", + "libinput", + "libstatspull", + "libstatssocket", + ], + }, + host: { + static_libs: [ + "libinput", + "libstatspull", + "libstatssocket", + ], + }, + }, header_libs: [ "libinputdispatcher_headers", ], @@ -84,8 +99,8 @@ cc_library_static { shared_libs: [ // This should consist only of dependencies from inputflinger. Other dependencies should be // in cc_defaults so that they are included in the tests. - "libinputreporter", "libinputflinger_base", + "libinputreporter", ], export_header_lib_headers: [ "libinputdispatcher_headers", diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp index a793f57ade..5587a8f5d0 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.cpp +++ b/services/inputflinger/dispatcher/InputDispatcher.cpp @@ -25,7 +25,9 @@ #include <android/os/IInputConstants.h> #include <binder/Binder.h> #include <ftl/enum.h> +#if defined(__ANDROID__) #include <gui/SurfaceComposerClient.h> +#endif #include <input/InputDevice.h> #include <powermanager/PowerManager.h> #include <unistd.h> @@ -569,8 +571,9 @@ InputDispatcher::InputDispatcher(const sp<InputDispatcherPolicyInterface>& polic mReporter = createInputReporter(); mWindowInfoListener = sp<DispatcherWindowListener>::make(*this); +#if defined(__ANDROID__) SurfaceComposerClient::getDefault()->addWindowInfosListener(mWindowInfoListener); - +#endif mKeyRepeatState.lastKeyEntry = nullptr; policy->getDispatcherConfiguration(&mConfig); } diff --git a/services/inputflinger/reader/Android.bp b/services/inputflinger/reader/Android.bp index 0f87201caf..43259c0c5f 100644 --- a/services/inputflinger/reader/Android.bp +++ b/services/inputflinger/reader/Android.bp @@ -23,6 +23,7 @@ package { cc_library_headers { name: "libinputreader_headers", + host_supported: true, export_include_dirs: [ "controller", "include", @@ -36,11 +37,9 @@ filegroup { srcs: [ "EventHub.cpp", "InputDevice.cpp", + "InputReader.cpp", + "TouchVideoDevice.cpp", "controller/PeripheralController.cpp", - "mapper/accumulator/CursorButtonAccumulator.cpp", - "mapper/accumulator/CursorScrollAccumulator.cpp", - "mapper/accumulator/SingleTouchMotionAccumulator.cpp", - "mapper/accumulator/TouchButtonAccumulator.cpp", "mapper/CursorInputMapper.cpp", "mapper/ExternalStylusInputMapper.cpp", "mapper/InputMapper.cpp", @@ -53,8 +52,10 @@ filegroup { "mapper/SwitchInputMapper.cpp", "mapper/TouchInputMapper.cpp", "mapper/VibratorInputMapper.cpp", - "InputReader.cpp", - "TouchVideoDevice.cpp", + "mapper/accumulator/CursorButtonAccumulator.cpp", + "mapper/accumulator/CursorScrollAccumulator.cpp", + "mapper/accumulator/SingleTouchMotionAccumulator.cpp", + "mapper/accumulator/TouchButtonAccumulator.cpp", ], } @@ -66,11 +67,9 @@ cc_defaults { "libcap", "libcrypto", "libcutils", - "libinput", "liblog", "libstatslog", "libutils", - "libPlatformProperties", ], static_libs: [ "libc++fs", @@ -80,10 +79,24 @@ cc_defaults { "libbatteryservice_headers", "libinputreader_headers", ], + target: { + android: { + shared_libs: [ + "libPlatformProperties", + "libinput", + ], + }, + host: { + static_libs: [ + "libinput", + ], + }, + }, } cc_library_shared { name: "libinputreader", + host_supported: true, defaults: [ "inputflinger_defaults", "libinputreader_defaults", @@ -99,6 +112,14 @@ cc_library_shared { export_header_lib_headers: [ "libinputreader_headers", ], + target: { + host: { + include_dirs: [ + "bionic/libc/kernel/android/uapi/", + "bionic/libc/kernel/uapi", + ], + }, + }, static_libs: [ "libc++fs", ], diff --git a/services/inputflinger/reader/EventHub.cpp b/services/inputflinger/reader/EventHub.cpp index ca7e426fdf..956746d7d2 100644 --- a/services/inputflinger/reader/EventHub.cpp +++ b/services/inputflinger/reader/EventHub.cpp @@ -28,7 +28,6 @@ #include <sys/epoll.h> #include <sys/inotify.h> #include <sys/ioctl.h> -#include <sys/limits.h> #include <sys/stat.h> #include <sys/sysmacros.h> #include <unistd.h> diff --git a/services/inputflinger/reader/mapper/MultiTouchInputMapper.cpp b/services/inputflinger/reader/mapper/MultiTouchInputMapper.cpp index 1d53eaba6e..acba4f6513 100644 --- a/services/inputflinger/reader/mapper/MultiTouchInputMapper.cpp +++ b/services/inputflinger/reader/mapper/MultiTouchInputMapper.cpp @@ -17,8 +17,9 @@ #include "../Macros.h" #include "MultiTouchInputMapper.h" - +#if defined(__ANDROID__) #include <android/sysprop/InputProperties.sysprop.h> +#endif namespace android { @@ -362,7 +363,12 @@ bool MultiTouchInputMapper::hasStylus() const { bool MultiTouchInputMapper::shouldSimulateStylusWithTouch() const { static const bool SIMULATE_STYLUS_WITH_TOUCH = +#if defined(__ANDROID__) sysprop::InputProperties::simulate_stylus_with_touch().value_or(false); +#else + // Disable this developer feature where sysproperties are not available + false; +#endif return SIMULATE_STYLUS_WITH_TOUCH && mParameters.deviceType == Parameters::DeviceType::TOUCH_SCREEN; } diff --git a/services/inputflinger/reporter/Android.bp b/services/inputflinger/reporter/Android.bp index 74307310c5..693ff063b1 100644 --- a/services/inputflinger/reporter/Android.bp +++ b/services/inputflinger/reporter/Android.bp @@ -23,13 +23,14 @@ package { cc_library_headers { name: "libinputreporter_headers", + host_supported: true, export_include_dirs: ["."], } filegroup { name: "libinputreporter_sources", srcs: [ - "InputReporter.cpp", + "InputReporter.cpp", ], } diff --git a/services/inputflinger/tests/Android.bp b/services/inputflinger/tests/Android.bp index fcbb98fce8..b6d0709af0 100644 --- a/services/inputflinger/tests/Android.bp +++ b/services/inputflinger/tests/Android.bp @@ -23,6 +23,7 @@ package { 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 @@ cc_test { "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 9380c7142f..2e296daa22 100644 --- a/services/inputflinger/tests/EventHub_test.cpp +++ b/services/inputflinger/tests/EventHub_test.cpp @@ -68,12 +68,18 @@ protected: 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 985c9c570c..a1ccfc7d16 100644 --- a/services/inputflinger/tests/InputDispatcher_test.cpp +++ b/services/inputflinger/tests/InputDispatcher_test.cpp @@ -7028,7 +7028,7 @@ TEST_F(InputDispatcherSpyWindowTest, ReceivesInputInOrder) { } 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 8ac8dfc3ac..3cc8e94030 100644 --- a/services/inputflinger/tests/InputReader_test.cpp +++ b/services/inputflinger/tests/InputReader_test.cpp @@ -2300,6 +2300,9 @@ protected: 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 @@ protected: } void TearDown() override { +#if !defined(__ANDROID__) + return; +#endif ASSERT_EQ(mReader->stop(), OK); mReader.reset(); mTestListener.reset(); @@ -2432,6 +2438,9 @@ protected: 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 9c939198f3..7862b5839c 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 { |