From fd3718c0dd22c3a8a2317cb659b0eed2305e579c Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Thu, 28 Feb 2019 08:16:26 -0800 Subject: [PATCH] Initialize PointerCoords in input tests The struct PointerCoords in VelocityTracker_test is created on the stack, but never initialized. Later, the coords are used to add an x and y value to the MotionEvent. The field "bits" in the struct is therefore initialized to whatever was previously occupying that stack address. It is possible that stack contained some non-zero data. This would cause enough of the bits of the 'bits' variable to be set, but without any of them being X or Y. As a result, when a new X or Y value is assigned, it does not fit into the bits (there's a 30-axes limit), and therefore remains at zero. Later, when velocity is computed, the coordinates evaluate to zero, and therefore, zero velocity is produced. The test fails, because a non-zero velocity is expected. After an audit of the entire Android codebase for usage of PointerCoords, found another potential issue in InputClassifier_test. Likely the code was copied over from VelocityTracker_test. Add a fix for that as well. Bug: 126536349 Test: atest -it -a libinput_tests, but only executed after building and flashing asanified libinput and libinput_tests onto device. Change-Id: Id8b870b6201d7489284bf9fc646750770bb9321a --- libs/input/tests/VelocityTracker_test.cpp | 1 + services/inputflinger/tests/InputClassifier_test.cpp | 18 +++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/libs/input/tests/VelocityTracker_test.cpp b/libs/input/tests/VelocityTracker_test.cpp index 3c6754289f..515209ea5e 100644 --- a/libs/input/tests/VelocityTracker_test.cpp +++ b/libs/input/tests/VelocityTracker_test.cpp @@ -90,6 +90,7 @@ MotionEvent* createSimpleMotionEvent(const Position* positions, size_t numSample MotionEvent* event = new MotionEvent(); PointerCoords coords; + coords.clear(); constexpr size_t pointerCount = 1; PointerProperties properties[pointerCount]; diff --git a/services/inputflinger/tests/InputClassifier_test.cpp b/services/inputflinger/tests/InputClassifier_test.cpp index 20699c9288..16510577bf 100644 --- a/services/inputflinger/tests/InputClassifier_test.cpp +++ b/services/inputflinger/tests/InputClassifier_test.cpp @@ -29,20 +29,20 @@ namespace android { static NotifyMotionArgs generateBasicMotionArgs() { // Create a basic motion event for testing - constexpr size_t pointerCount = 1; - PointerProperties properties[pointerCount]; - properties[0].id = 0; - properties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; - - PointerCoords coords[pointerCount]; - coords[0].setAxisValue(AMOTION_EVENT_AXIS_X, 1); - coords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, 1); + PointerProperties properties; + properties.id = 0; + properties.toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; + + PointerCoords coords; + coords.clear(); + coords.setAxisValue(AMOTION_EVENT_AXIS_X, 1); + coords.setAxisValue(AMOTION_EVENT_AXIS_Y, 1); static constexpr nsecs_t downTime = 2; NotifyMotionArgs motionArgs(1/*sequenceNum*/, downTime/*eventTime*/, 3/*deviceId*/, AINPUT_SOURCE_ANY, ADISPLAY_ID_DEFAULT, 4/*policyFlags*/, AMOTION_EVENT_ACTION_DOWN, 0/*actionButton*/, 0/*flags*/, AMETA_NONE, 0/*buttonState*/, MotionClassification::NONE, AMOTION_EVENT_EDGE_FLAG_NONE, 5/*deviceTimestamp*/, - 0/*pointerCount*/, properties, coords, 0/*xPrecision*/, 0/*yPrecision*/, + 1/*pointerCount*/, &properties, &coords, 0/*xPrecision*/, 0/*yPrecision*/, downTime, {}/*videoFrames*/); return motionArgs; } -- 2.11.0