summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaichi Hirono2016-12-07 23:22:13 -0600
committerDaichi Hirono2016-12-11 23:53:03 -0600
commitcb9153bf4324d72c6f1b34a8a1c2f8b9954697d2 (patch)
treeac21b82aed499cc9accb363a8767495bb3962e85 /libappfuse/tests
parenta6373ec1d47c0b370c87b3915feeba8f2b4523f7 (diff)
downloadplatform-system-core-cb9153bf4324d72c6f1b34a8a1c2f8b9954697d2.tar.gz
platform-system-core-cb9153bf4324d72c6f1b34a8a1c2f8b9954697d2.tar.xz
platform-system-core-cb9153bf4324d72c6f1b34a8a1c2f8b9954697d2.zip
Support SOCK_STREAM for bridge between system and app
Previously AppFuse use SOCK_SEQPACKET for sockets communicating system and app. However SOCK_SEQPACKET requires the buffer of message size in the kernel and sometimes failed to write with ENOBUF. The CL updates libappfuse so that it can use SOCK_STREAM instead of SOCK_SEQPACKET. Bug: 33279206 Test: libappfuse_test Change-Id: I622ada9ac1d71d0c57b6cfff0904c7829cea7995
Diffstat (limited to 'libappfuse/tests')
-rw-r--r--libappfuse/tests/FuseBufferTest.cc26
1 files changed, 26 insertions, 0 deletions
diff --git a/libappfuse/tests/FuseBufferTest.cc b/libappfuse/tests/FuseBufferTest.cc
index c82213513..db35d330d 100644
--- a/libappfuse/tests/FuseBufferTest.cc
+++ b/libappfuse/tests/FuseBufferTest.cc
@@ -20,6 +20,8 @@
20#include <string.h> 20#include <string.h>
21#include <sys/socket.h> 21#include <sys/socket.h>
22 22
23#include <thread>
24
23#include <android-base/unique_fd.h> 25#include <android-base/unique_fd.h>
24#include <gtest/gtest.h> 26#include <gtest/gtest.h>
25 27
@@ -110,6 +112,30 @@ TEST(FuseMessageTest, Write_TooShort) {
110 TestWriteInvalidLength(sizeof(fuse_in_header) - 1); 112 TestWriteInvalidLength(sizeof(fuse_in_header) - 1);
111} 113}
112 114
115TEST(FuseMessageTest, ShortWriteAndRead) {
116 int raw_fds[2];
117 ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, raw_fds));
118
119 android::base::unique_fd fds[2];
120 fds[0].reset(raw_fds[0]);
121 fds[1].reset(raw_fds[1]);
122
123 const int send_buffer_size = 1024;
124 ASSERT_EQ(0, setsockopt(fds[0], SOL_SOCKET, SO_SNDBUF, &send_buffer_size,
125 sizeof(int)));
126
127 bool succeed = false;
128 const int sender_fd = fds[0].get();
129 std::thread thread([sender_fd, &succeed] {
130 FuseRequest request;
131 request.header.len = 1024 * 4;
132 succeed = request.Write(sender_fd);
133 });
134 thread.detach();
135 FuseRequest request;
136 ASSERT_TRUE(request.Read(fds[1]));
137}
138
113TEST(FuseResponseTest, Reset) { 139TEST(FuseResponseTest, Reset) {
114 FuseResponse response; 140 FuseResponse response;
115 // Write 1 to the first ten bytes. 141 // Write 1 to the first ten bytes.