Rewrite input transport using sockets.
Since we will not longer be modifying events in place, we don't need
to use an ashmem region for input. Simplified the code to instead
use a socket of type SOCK_SEQPACKET.
This is part of a series of changes to improve input system pipelining.
Bug: 5963420
Change-Id: I05909075ed8b61b93900913e44c6db84857340d8
diff --git a/libs/ui/tests/InputChannel_test.cpp b/libs/ui/tests/InputChannel_test.cpp
index eff22ee..c73dc2f 100644
--- a/libs/ui/tests/InputChannel_test.cpp
+++ b/libs/ui/tests/InputChannel_test.cpp
@@ -20,8 +20,7 @@
#include <gtest/gtest.h>
#include <unistd.h>
#include <time.h>
-#include <sys/mman.h>
-#include <cutils/ashmem.h>
+#include <errno.h>
#include "../../utils/tests/TestHelpers.h"
@@ -36,35 +35,24 @@
TEST_F(InputChannelTest, ConstructorAndDestructor_TakesOwnershipOfFileDescriptors) {
// Our purpose here is to verify that the input channel destructor closes the
- // file descriptors provided to it. One easy way is to provide it with one end
+ // file descriptor provided to it. One easy way is to provide it with one end
// of a pipe and to check for EPIPE on the other end after the channel is destroyed.
- Pipe fakeAshmem, sendPipe, receivePipe;
+ Pipe pipe;
- sp<InputChannel> inputChannel = new InputChannel(String8("channel name"),
- fakeAshmem.sendFd, receivePipe.receiveFd, sendPipe.sendFd);
+ sp<InputChannel> inputChannel = new InputChannel(String8("channel name"), pipe.sendFd);
EXPECT_STREQ("channel name", inputChannel->getName().string())
<< "channel should have provided name";
- EXPECT_EQ(fakeAshmem.sendFd, inputChannel->getAshmemFd())
- << "channel should have provided ashmem fd";
- EXPECT_EQ(receivePipe.receiveFd, inputChannel->getReceivePipeFd())
- << "channel should have provided receive pipe fd";
- EXPECT_EQ(sendPipe.sendFd, inputChannel->getSendPipeFd())
- << "channel should have provided send pipe fd";
+ EXPECT_EQ(pipe.sendFd, inputChannel->getFd())
+ << "channel should have provided fd";
inputChannel.clear(); // destroys input channel
- EXPECT_EQ(-EPIPE, fakeAshmem.readSignal())
- << "channel should have closed ashmem fd when destroyed";
- EXPECT_EQ(-EPIPE, receivePipe.writeSignal())
- << "channel should have closed receive pipe fd when destroyed";
- EXPECT_EQ(-EPIPE, sendPipe.readSignal())
- << "channel should have closed send pipe fd when destroyed";
+ EXPECT_EQ(-EPIPE, pipe.readSignal())
+ << "channel should have closed fd when destroyed";
// clean up fds of Pipe endpoints that were closed so we don't try to close them again
- fakeAshmem.sendFd = -1;
- receivePipe.receiveFd = -1;
- sendPipe.sendFd = -1;
+ pipe.sendFd = -1;
}
TEST_F(InputChannelTest, OpenInputChannelPair_ReturnsAPairOfConnectedChannels) {
@@ -82,43 +70,37 @@
EXPECT_STREQ("channel name (client)", clientChannel->getName().string())
<< "client channel should have suffixed name";
- // Ashmem uniqueness
- EXPECT_NE(serverChannel->getAshmemFd(), clientChannel->getAshmemFd())
- << "server and client channel should have different ashmem fds because it was dup'd";
-
- // Ashmem usability
- ssize_t serverAshmemSize = ashmem_get_size_region(serverChannel->getAshmemFd());
- ssize_t clientAshmemSize = ashmem_get_size_region(clientChannel->getAshmemFd());
- uint32_t* serverAshmem = static_cast<uint32_t*>(mmap(NULL, serverAshmemSize,
- PROT_READ | PROT_WRITE, MAP_SHARED, serverChannel->getAshmemFd(), 0));
- uint32_t* clientAshmem = static_cast<uint32_t*>(mmap(NULL, clientAshmemSize,
- PROT_READ | PROT_WRITE, MAP_SHARED, clientChannel->getAshmemFd(), 0));
- ASSERT_TRUE(serverAshmem != NULL)
- << "server channel ashmem should be mappable";
- ASSERT_TRUE(clientAshmem != NULL)
- << "client channel ashmem should be mappable";
- *serverAshmem = 0xf00dd00d;
- EXPECT_EQ(0xf00dd00d, *clientAshmem)
- << "ashmem buffer should be shared by client and server";
- munmap(serverAshmem, serverAshmemSize);
- munmap(clientAshmem, clientAshmemSize);
-
// Server->Client communication
- EXPECT_EQ(OK, serverChannel->sendSignal('S'))
- << "server channel should be able to send signal to client channel";
- char signal;
- EXPECT_EQ(OK, clientChannel->receiveSignal(& signal))
- << "client channel should be able to receive signal from server channel";
- EXPECT_EQ('S', signal)
- << "client channel should receive the correct signal from server channel";
+ InputMessage serverMsg;
+ memset(&serverMsg, 0, sizeof(InputMessage));
+ serverMsg.header.type = InputMessage::TYPE_KEY;
+ serverMsg.body.key.action = AKEY_EVENT_ACTION_DOWN;
+ EXPECT_EQ(OK, serverChannel->sendMessage(&serverMsg))
+ << "server channel should be able to send message to client channel";
+
+ InputMessage clientMsg;
+ EXPECT_EQ(OK, clientChannel->receiveMessage(&clientMsg))
+ << "client channel should be able to receive message from server channel";
+ EXPECT_EQ(serverMsg.header.type, clientMsg.header.type)
+ << "client channel should receive the correct message from server channel";
+ EXPECT_EQ(serverMsg.body.key.action, clientMsg.body.key.action)
+ << "client channel should receive the correct message from server channel";
// Client->Server communication
- EXPECT_EQ(OK, clientChannel->sendSignal('c'))
- << "client channel should be able to send signal to server channel";
- EXPECT_EQ(OK, serverChannel->receiveSignal(& signal))
- << "server channel should be able to receive signal from client channel";
- EXPECT_EQ('c', signal)
- << "server channel should receive the correct signal from client channel";
+ InputMessage clientReply;
+ memset(&clientReply, 0, sizeof(InputMessage));
+ clientReply.header.type = InputMessage::TYPE_FINISHED;
+ clientReply.body.finished.handled = true;
+ EXPECT_EQ(OK, clientChannel->sendMessage(&clientReply))
+ << "client channel should be able to send message to server channel";
+
+ InputMessage serverReply;
+ EXPECT_EQ(OK, serverChannel->receiveMessage(&serverReply))
+ << "server channel should be able to receive message from client channel";
+ EXPECT_EQ(clientReply.header.type, serverReply.header.type)
+ << "server channel should receive the correct message from client channel";
+ EXPECT_EQ(clientReply.body.finished.handled, serverReply.body.finished.handled)
+ << "server channel should receive the correct message from client channel";
}
TEST_F(InputChannelTest, ReceiveSignal_WhenNoSignalPresent_ReturnsAnError) {
@@ -130,9 +112,9 @@
ASSERT_EQ(OK, result)
<< "should have successfully opened a channel pair";
- char signal;
- EXPECT_EQ(WOULD_BLOCK, clientChannel->receiveSignal(& signal))
- << "receiveSignal should have returned WOULD_BLOCK";
+ InputMessage msg;
+ EXPECT_EQ(WOULD_BLOCK, clientChannel->receiveMessage(&msg))
+ << "receiveMessage should have returned WOULD_BLOCK";
}
TEST_F(InputChannelTest, ReceiveSignal_WhenPeerClosed_ReturnsAnError) {
@@ -146,9 +128,9 @@
serverChannel.clear(); // close server channel
- char signal;
- EXPECT_EQ(DEAD_OBJECT, clientChannel->receiveSignal(& signal))
- << "receiveSignal should have returned DEAD_OBJECT";
+ InputMessage msg;
+ EXPECT_EQ(DEAD_OBJECT, clientChannel->receiveMessage(&msg))
+ << "receiveMessage should have returned DEAD_OBJECT";
}
TEST_F(InputChannelTest, SendSignal_WhenPeerClosed_ReturnsAnError) {
@@ -162,8 +144,10 @@
serverChannel.clear(); // close server channel
- EXPECT_EQ(DEAD_OBJECT, clientChannel->sendSignal('S'))
- << "sendSignal should have returned DEAD_OBJECT";
+ InputMessage msg;
+ msg.header.type = InputMessage::TYPE_KEY;
+ EXPECT_EQ(DEAD_OBJECT, clientChannel->sendMessage(&msg))
+ << "sendMessage should have returned DEAD_OBJECT";
}
diff --git a/libs/ui/tests/InputPublisherAndConsumer_test.cpp b/libs/ui/tests/InputPublisherAndConsumer_test.cpp
index fcc4cad..a0ee94b 100644
--- a/libs/ui/tests/InputPublisherAndConsumer_test.cpp
+++ b/libs/ui/tests/InputPublisherAndConsumer_test.cpp
@@ -57,11 +57,8 @@
clientChannel.clear();
}
- void Initialize();
void PublishAndConsumeKeyEvent();
- void PublishAndConsumeMotionEvent(
- size_t samplesToAppendBeforeDispatch = 0,
- size_t samplesToAppendAfterDispatch = 0);
+ void PublishAndConsumeMotionEvent();
};
TEST_F(InputPublisherAndConsumerTest, GetChannel_ReturnsTheChannel) {
@@ -69,18 +66,6 @@
EXPECT_EQ(clientChannel.get(), mConsumer->getChannel().get());
}
-void InputPublisherAndConsumerTest::Initialize() {
- status_t status;
-
- status = mPublisher->initialize();
- ASSERT_EQ(OK, status)
- << "publisher initialize should return OK";
-
- status = mConsumer->initialize();
- ASSERT_EQ(OK, status)
- << "consumer initialize should return OK";
-}
-
void InputPublisherAndConsumerTest::PublishAndConsumeKeyEvent() {
status_t status;
@@ -100,14 +85,6 @@
ASSERT_EQ(OK, status)
<< "publisher publishKeyEvent should return OK";
- status = mPublisher->sendDispatchSignal();
- ASSERT_EQ(OK, status)
- << "publisher sendDispatchSignal should return OK";
-
- status = mConsumer->receiveDispatchSignal();
- ASSERT_EQ(OK, status)
- << "consumer receiveDispatchSignal should return OK";
-
InputEvent* event;
status = mConsumer->consume(& mEventFactory, & event);
ASSERT_EQ(OK, status)
@@ -140,14 +117,9 @@
<< "publisher receiveFinishedSignal should return OK";
ASSERT_TRUE(handled)
<< "publisher receiveFinishedSignal should have set handled to consumer's reply";
-
- status = mPublisher->reset();
- ASSERT_EQ(OK, status)
- << "publisher reset should return OK";
}
-void InputPublisherAndConsumerTest::PublishAndConsumeMotionEvent(
- size_t samplesToAppendBeforeDispatch, size_t samplesToAppendAfterDispatch) {
+void InputPublisherAndConsumerTest::PublishAndConsumeMotionEvent() {
status_t status;
const int32_t deviceId = 1;
@@ -163,65 +135,33 @@
const float yPrecision = 0.5;
const nsecs_t downTime = 3;
const size_t pointerCount = 3;
+ const nsecs_t eventTime = 4;
PointerProperties pointerProperties[pointerCount];
+ PointerCoords pointerCoords[pointerCount];
for (size_t i = 0; i < pointerCount; i++) {
pointerProperties[i].clear();
pointerProperties[i].id = (i + 2) % pointerCount;
pointerProperties[i].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER;
- }
- Vector<nsecs_t> sampleEventTimes;
- Vector<PointerCoords> samplePointerCoords;
-
- for (size_t i = 0; i <= samplesToAppendAfterDispatch + samplesToAppendBeforeDispatch; i++) {
- sampleEventTimes.push(i + 10);
- for (size_t j = 0; j < pointerCount; j++) {
- samplePointerCoords.push();
- PointerCoords& pc = samplePointerCoords.editTop();
- pc.clear();
- pc.setAxisValue(AMOTION_EVENT_AXIS_X, 100 * i + j);
- pc.setAxisValue(AMOTION_EVENT_AXIS_Y, 200 * i + j);
- pc.setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 0.5 * i + j);
- pc.setAxisValue(AMOTION_EVENT_AXIS_SIZE, 0.7 * i + j);
- pc.setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, 1.5 * i + j);
- pc.setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, 1.7 * i + j);
- pc.setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 2.5 * i + j);
- pc.setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 2.7 * i + j);
- pc.setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, 3.5 * i + j);
- }
+ pointerCoords[i].clear();
+ pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_X, 100 * i);
+ pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_Y, 200 * i);
+ pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 0.5 * i);
+ pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_SIZE, 0.7 * i);
+ pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, 1.5 * i);
+ pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, 1.7 * i);
+ pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 2.5 * i);
+ pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 2.7 * i);
+ pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, 3.5 * i);
}
status = mPublisher->publishMotionEvent(deviceId, source, action, flags, edgeFlags,
metaState, buttonState, xOffset, yOffset, xPrecision, yPrecision,
- downTime, sampleEventTimes[0], pointerCount,
- pointerProperties, samplePointerCoords.array());
+ downTime, eventTime, pointerCount,
+ pointerProperties, pointerCoords);
ASSERT_EQ(OK, status)
<< "publisher publishMotionEvent should return OK";
- for (size_t i = 0; i < samplesToAppendBeforeDispatch; i++) {
- size_t sampleIndex = i + 1;
- status = mPublisher->appendMotionSample(sampleEventTimes[sampleIndex],
- samplePointerCoords.array() + sampleIndex * pointerCount);
- ASSERT_EQ(OK, status)
- << "publisher appendMotionEvent should return OK";
- }
-
- status = mPublisher->sendDispatchSignal();
- ASSERT_EQ(OK, status)
- << "publisher sendDispatchSignal should return OK";
-
- for (size_t i = 0; i < samplesToAppendAfterDispatch; i++) {
- size_t sampleIndex = i + 1 + samplesToAppendBeforeDispatch;
- status = mPublisher->appendMotionSample(sampleEventTimes[sampleIndex],
- samplePointerCoords.array() + sampleIndex * pointerCount);
- ASSERT_EQ(OK, status)
- << "publisher appendMotionEvent should return OK";
- }
-
- status = mConsumer->receiveDispatchSignal();
- ASSERT_EQ(OK, status)
- << "consumer receiveDispatchSignal should return OK";
-
InputEvent* event;
status = mConsumer->consume(& mEventFactory, & event);
ASSERT_EQ(OK, status)
@@ -232,8 +172,6 @@
ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, event->getType())
<< "consumer should have returned a motion event";
- size_t lastSampleIndex = samplesToAppendBeforeDispatch + samplesToAppendAfterDispatch;
-
MotionEvent* motionEvent = static_cast<MotionEvent*>(event);
EXPECT_EQ(deviceId, motionEvent->getDeviceId());
EXPECT_EQ(source, motionEvent->getSource());
@@ -245,74 +183,36 @@
EXPECT_EQ(xPrecision, motionEvent->getXPrecision());
EXPECT_EQ(yPrecision, motionEvent->getYPrecision());
EXPECT_EQ(downTime, motionEvent->getDownTime());
- EXPECT_EQ(sampleEventTimes[lastSampleIndex], motionEvent->getEventTime());
+ EXPECT_EQ(eventTime, motionEvent->getEventTime());
EXPECT_EQ(pointerCount, motionEvent->getPointerCount());
- EXPECT_EQ(lastSampleIndex, motionEvent->getHistorySize());
+ EXPECT_EQ(0U, motionEvent->getHistorySize());
for (size_t i = 0; i < pointerCount; i++) {
SCOPED_TRACE(i);
EXPECT_EQ(pointerProperties[i].id, motionEvent->getPointerId(i));
EXPECT_EQ(pointerProperties[i].toolType, motionEvent->getToolType(i));
- }
- for (size_t sampleIndex = 0; sampleIndex < lastSampleIndex; sampleIndex++) {
- SCOPED_TRACE(sampleIndex);
- EXPECT_EQ(sampleEventTimes[sampleIndex],
- motionEvent->getHistoricalEventTime(sampleIndex));
- for (size_t i = 0; i < pointerCount; i++) {
- SCOPED_TRACE(i);
- size_t offset = sampleIndex * pointerCount + i;
- EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AMOTION_EVENT_AXIS_X),
- motionEvent->getHistoricalRawX(i, sampleIndex));
- EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AMOTION_EVENT_AXIS_Y),
- motionEvent->getHistoricalRawY(i, sampleIndex));
- EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AMOTION_EVENT_AXIS_X) + xOffset,
- motionEvent->getHistoricalX(i, sampleIndex));
- EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AMOTION_EVENT_AXIS_Y) + yOffset,
- motionEvent->getHistoricalY(i, sampleIndex));
- EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE),
- motionEvent->getHistoricalPressure(i, sampleIndex));
- EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AMOTION_EVENT_AXIS_SIZE),
- motionEvent->getHistoricalSize(i, sampleIndex));
- EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR),
- motionEvent->getHistoricalTouchMajor(i, sampleIndex));
- EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR),
- motionEvent->getHistoricalTouchMinor(i, sampleIndex));
- EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR),
- motionEvent->getHistoricalToolMajor(i, sampleIndex));
- EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR),
- motionEvent->getHistoricalToolMinor(i, sampleIndex));
- EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION),
- motionEvent->getHistoricalOrientation(i, sampleIndex));
- }
- }
-
- SCOPED_TRACE(lastSampleIndex);
- EXPECT_EQ(sampleEventTimes[lastSampleIndex], motionEvent->getEventTime());
- for (size_t i = 0; i < pointerCount; i++) {
- SCOPED_TRACE(i);
- size_t offset = lastSampleIndex * pointerCount + i;
- EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AMOTION_EVENT_AXIS_X),
+ EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_X),
motionEvent->getRawX(i));
- EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AMOTION_EVENT_AXIS_Y),
+ EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_Y),
motionEvent->getRawY(i));
- EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AMOTION_EVENT_AXIS_X) + xOffset,
+ EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_X) + xOffset,
motionEvent->getX(i));
- EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AMOTION_EVENT_AXIS_Y) + yOffset,
+ EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_Y) + yOffset,
motionEvent->getY(i));
- EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE),
+ EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE),
motionEvent->getPressure(i));
- EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AMOTION_EVENT_AXIS_SIZE),
+ EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_SIZE),
motionEvent->getSize(i));
- EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR),
+ EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR),
motionEvent->getTouchMajor(i));
- EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR),
+ EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR),
motionEvent->getTouchMinor(i));
- EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR),
+ EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR),
motionEvent->getToolMajor(i));
- EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR),
+ EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR),
motionEvent->getToolMinor(i));
- EXPECT_EQ(samplePointerCoords[offset].getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION),
+ EXPECT_EQ(pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION),
motionEvent->getOrientation(i));
}
@@ -326,64 +226,18 @@
<< "publisher receiveFinishedSignal should return OK";
ASSERT_FALSE(handled)
<< "publisher receiveFinishedSignal should have set handled to consumer's reply";
-
- status = mPublisher->reset();
- ASSERT_EQ(OK, status)
- << "publisher reset should return OK";
}
TEST_F(InputPublisherAndConsumerTest, PublishKeyEvent_EndToEnd) {
- ASSERT_NO_FATAL_FAILURE(Initialize());
ASSERT_NO_FATAL_FAILURE(PublishAndConsumeKeyEvent());
}
-TEST_F(InputPublisherAndConsumerTest, PublishKeyEvent_WhenNotReset_ReturnsError) {
- status_t status;
- ASSERT_NO_FATAL_FAILURE(Initialize());
-
- status = mPublisher->publishKeyEvent(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
- ASSERT_EQ(OK, status)
- << "publisher publishKeyEvent should return OK first time";
-
- status = mPublisher->publishKeyEvent(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
- ASSERT_EQ(INVALID_OPERATION, status)
- << "publisher publishKeyEvent should return INVALID_OPERATION because "
- "the publisher was not reset";
-}
-
TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_EndToEnd) {
- ASSERT_NO_FATAL_FAILURE(Initialize());
ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent());
}
-TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenNotReset_ReturnsError) {
- status_t status;
- ASSERT_NO_FATAL_FAILURE(Initialize());
-
- const size_t pointerCount = 1;
- PointerProperties pointerProperties[pointerCount];
- PointerCoords pointerCoords[pointerCount];
- for (size_t i = 0; i < pointerCount; i++) {
- pointerProperties[i].clear();
- pointerCoords[i].clear();
- }
-
- status = mPublisher->publishMotionEvent(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- pointerCount, pointerProperties, pointerCoords);
- ASSERT_EQ(OK, status)
- << "publisher publishMotionEvent should return OK";
-
- status = mPublisher->publishMotionEvent(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- pointerCount, pointerProperties, pointerCoords);
- ASSERT_EQ(INVALID_OPERATION, status)
- << "publisher publishMotionEvent should return INVALID_OPERATION because ";
- "the publisher was not reset";
-}
-
TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenPointerCountLessThan1_ReturnsError) {
status_t status;
- ASSERT_NO_FATAL_FAILURE(Initialize());
-
const size_t pointerCount = 0;
PointerProperties pointerProperties[pointerCount];
PointerCoords pointerCoords[pointerCount];
@@ -396,8 +250,6 @@
TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenPointerCountGreaterThanMax_ReturnsError) {
status_t status;
- ASSERT_NO_FATAL_FAILURE(Initialize());
-
const size_t pointerCount = MAX_POINTERS + 1;
PointerProperties pointerProperties[pointerCount];
PointerCoords pointerCoords[pointerCount];
@@ -413,7 +265,6 @@
}
TEST_F(InputPublisherAndConsumerTest, PublishMultipleEvents_EndToEnd) {
- ASSERT_NO_FATAL_FAILURE(Initialize());
ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent());
ASSERT_NO_FATAL_FAILURE(PublishAndConsumeKeyEvent());
ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent());
@@ -421,111 +272,4 @@
ASSERT_NO_FATAL_FAILURE(PublishAndConsumeKeyEvent());
}
-TEST_F(InputPublisherAndConsumerTest, AppendMotionSample_WhenCalledBeforeDispatchSignal_AppendsSamples) {
- status_t status;
- ASSERT_NO_FATAL_FAILURE(Initialize());
- ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent(3, 0));
-}
-
-TEST_F(InputPublisherAndConsumerTest, AppendMotionSample_WhenCalledAfterDispatchSignalAndNotConsumed_AppendsSamples) {
- status_t status;
- ASSERT_NO_FATAL_FAILURE(Initialize());
- ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent(0, 4));
-}
-
-TEST_F(InputPublisherAndConsumerTest, AppendMotionSample_WhenNoMotionEventPublished_ReturnsError) {
- status_t status;
- ASSERT_NO_FATAL_FAILURE(Initialize());
-
- PointerCoords pointerCoords[1];
- status = mPublisher->appendMotionSample(0, pointerCoords);
- ASSERT_EQ(INVALID_OPERATION, status)
- << "publisher appendMotionSample should return INVALID_OPERATION";
-}
-
-TEST_F(InputPublisherAndConsumerTest, AppendMotionSample_WhenPublishedMotionEventIsNotAMove_ReturnsError) {
- status_t status;
- ASSERT_NO_FATAL_FAILURE(Initialize());
-
- const size_t pointerCount = MAX_POINTERS;
- PointerProperties pointerProperties[pointerCount];
- PointerCoords pointerCoords[pointerCount];
- for (size_t i = 0; i < pointerCount; i++) {
- pointerProperties[i].clear();
- pointerCoords[i].clear();
- }
-
- status = mPublisher->publishMotionEvent(0, 0, AMOTION_EVENT_ACTION_DOWN,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, pointerCount, pointerProperties, pointerCoords);
- ASSERT_EQ(OK, status);
-
- status = mPublisher->appendMotionSample(0, pointerCoords);
- ASSERT_EQ(INVALID_OPERATION, status)
- << "publisher appendMotionSample should return INVALID_OPERATION";
-}
-
-TEST_F(InputPublisherAndConsumerTest, AppendMotionSample_WhenAlreadyConsumed_ReturnsError) {
- status_t status;
- ASSERT_NO_FATAL_FAILURE(Initialize());
-
- const size_t pointerCount = MAX_POINTERS;
- PointerProperties pointerProperties[pointerCount];
- PointerCoords pointerCoords[pointerCount];
- for (size_t i = 0; i < pointerCount; i++) {
- pointerProperties[i].clear();
- pointerCoords[i].clear();
- }
-
- status = mPublisher->publishMotionEvent(0, 0, AMOTION_EVENT_ACTION_MOVE,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, pointerCount, pointerProperties, pointerCoords);
- ASSERT_EQ(OK, status);
-
- status = mPublisher->sendDispatchSignal();
- ASSERT_EQ(OK, status);
-
- status = mConsumer->receiveDispatchSignal();
- ASSERT_EQ(OK, status);
-
- InputEvent* event;
- status = mConsumer->consume(& mEventFactory, & event);
- ASSERT_EQ(OK, status);
-
- status = mPublisher->appendMotionSample(0, pointerCoords);
- ASSERT_EQ(status_t(FAILED_TRANSACTION), status)
- << "publisher appendMotionSample should return FAILED_TRANSACTION";
-}
-
-TEST_F(InputPublisherAndConsumerTest, AppendMotionSample_WhenBufferFull_ReturnsError) {
- status_t status;
- ASSERT_NO_FATAL_FAILURE(Initialize());
-
- const size_t pointerCount = MAX_POINTERS;
- PointerProperties pointerProperties[pointerCount];
- PointerCoords pointerCoords[pointerCount];
- for (size_t i = 0; i < pointerCount; i++) {
- pointerProperties[i].clear();
- pointerCoords[i].clear();
- }
-
- status = mPublisher->publishMotionEvent(0, 0, AMOTION_EVENT_ACTION_MOVE,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, pointerCount, pointerProperties, pointerCoords);
- ASSERT_EQ(OK, status);
-
- for (int count = 1;; count++) {
- ASSERT_LT(count, 100000) << "should eventually reach OOM";
-
- status = mPublisher->appendMotionSample(0, pointerCoords);
- if (status != OK) {
- ASSERT_GT(count, 12) << "should be able to add at least a dozen samples";
- ASSERT_EQ(NO_MEMORY, status)
- << "publisher appendMotionSample should return NO_MEMORY when buffer is full";
- break;
- }
- }
-
- status = mPublisher->appendMotionSample(0, pointerCoords);
- ASSERT_EQ(NO_MEMORY, status)
- << "publisher appendMotionSample should return NO_MEMORY persistently until reset";
-}
-
} // namespace android