diff options
| author | 2022-10-05 22:46:36 +0000 | |
|---|---|---|
| committer | 2022-10-05 22:46:36 +0000 | |
| commit | 19a25ec03e4764f263af1f4bff3dbb63e17d1fc8 (patch) | |
| tree | 56015478f9992969a4fef1b85b5dd441f4c92b85 | |
| parent | a824ab6122e9936e39f86f4e7e67351692c92fa4 (diff) | |
| parent | 37b8481c1cab4fccc89e4b73455eacb421427372 (diff) | |
Merge "Add binder test for transfer of non-blocking fd" am: 6c27114c21 am: 7c1e973f23 am: ed8592aaf3 am: b5176adb3f am: 37b8481c1c
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/2239719
Change-Id: I393a0c6bb44814b4cba93abcdfd16135a0f625b2
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
| -rw-r--r-- | libs/binder/tests/binderLibTest.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/libs/binder/tests/binderLibTest.cpp b/libs/binder/tests/binderLibTest.cpp index 6e1c8ac16a..25b524fcf2 100644 --- a/libs/binder/tests/binderLibTest.cpp +++ b/libs/binder/tests/binderLibTest.cpp @@ -115,6 +115,7 @@ enum BinderLibTestTranscationCode { BINDER_LIB_TEST_NOP_TRANSACTION_WAIT, BINDER_LIB_TEST_GETPID, BINDER_LIB_TEST_ECHO_VECTOR, + BINDER_LIB_TEST_GET_NON_BLOCKING_FD, BINDER_LIB_TEST_REJECT_OBJECTS, BINDER_LIB_TEST_CAN_GET_SID, BINDER_LIB_TEST_GET_MAX_THREAD_COUNT, @@ -1158,6 +1159,21 @@ TEST_F(BinderLibTest, VectorSent) { EXPECT_EQ(readValue, testValue); } +TEST_F(BinderLibTest, FileDescriptorRemainsNonBlocking) { + sp<IBinder> server = addServer(); + ASSERT_TRUE(server != nullptr); + + Parcel reply; + EXPECT_THAT(server->transact(BINDER_LIB_TEST_GET_NON_BLOCKING_FD, {} /*data*/, &reply), + StatusEq(NO_ERROR)); + base::unique_fd fd; + EXPECT_THAT(reply.readUniqueFileDescriptor(&fd), StatusEq(OK)); + + const int result = fcntl(fd.get(), F_GETFL); + ASSERT_NE(result, -1); + EXPECT_EQ(result & O_NONBLOCK, O_NONBLOCK); +} + // see ProcessState.cpp BINDER_VM_SIZE = 1MB. // This value is not exposed, but some code in the framework relies on being able to use // buffers near the cap size. @@ -1801,6 +1817,28 @@ public: reply->writeUint64Vector(vector); return NO_ERROR; } + case BINDER_LIB_TEST_GET_NON_BLOCKING_FD: { + std::array<int, 2> sockets; + const bool created = socketpair(AF_UNIX, SOCK_SEQPACKET, 0, sockets.data()) == 0; + if (!created) { + ALOGE("Could not create socket pair"); + return UNKNOWN_ERROR; + } + + const int result = fcntl(sockets[0], F_SETFL, O_NONBLOCK); + if (result != 0) { + ALOGE("Could not make socket non-blocking: %s", strerror(errno)); + return UNKNOWN_ERROR; + } + base::unique_fd out(sockets[0]); + status_t writeResult = reply->writeUniqueFileDescriptor(out); + if (writeResult != NO_ERROR) { + ALOGE("Could not write unique_fd"); + return writeResult; + } + close(sockets[1]); // we don't need the other side of the fd + return NO_ERROR; + } case BINDER_LIB_TEST_REJECT_OBJECTS: { return data.objectsCount() == 0 ? BAD_VALUE : NO_ERROR; } |