summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaichi Hirono2017-03-05 23:02:42 -0600
committerDaichi Hirono2017-03-13 19:09:29 -0500
commit57b780fbc3e2c2442c2f58dcb83818e786246b35 (patch)
treecf2426a800b3566d8f65b884831bf75e42cd47e1 /libappfuse/tests
parentcc9d94ce04dbb63a745001323213bb667ea2e00f (diff)
downloadplatform-system-core-57b780fbc3e2c2442c2f58dcb83818e786246b35.tar.gz
platform-system-core-57b780fbc3e2c2442c2f58dcb83818e786246b35.tar.xz
platform-system-core-57b780fbc3e2c2442c2f58dcb83818e786246b35.zip
Add ReadOrAgain and WriteOrAgain methods to FuseMessage.
These methods return kAgain if operation cannot be done without blocking the current thread. The CL also introduecs new helper function SetupMessageSockets so that FuseMessages are always transfered via sockets that save message boundaries. Bug: 34903085 Test: libappfuse_test Change-Id: I34544372cc1b0c7bc9622e581ae16c018a123fa9
Diffstat (limited to 'libappfuse/tests')
-rw-r--r--libappfuse/tests/FuseAppLoopTest.cc5
-rw-r--r--libappfuse/tests/FuseBridgeLoopTest.cc11
-rw-r--r--libappfuse/tests/FuseBufferTest.cc48
3 files changed, 27 insertions, 37 deletions
diff --git a/libappfuse/tests/FuseAppLoopTest.cc b/libappfuse/tests/FuseAppLoopTest.cc
index 25906cf1c..64dd81330 100644
--- a/libappfuse/tests/FuseAppLoopTest.cc
+++ b/libappfuse/tests/FuseAppLoopTest.cc
@@ -109,10 +109,7 @@ class FuseAppLoopTest : public ::testing::Test {
109 109
110 void SetUp() override { 110 void SetUp() override {
111 base::SetMinimumLogSeverity(base::VERBOSE); 111 base::SetMinimumLogSeverity(base::VERBOSE);
112 int sockets[2]; 112 ASSERT_TRUE(SetupMessageSockets(&sockets_));
113 ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_SEQPACKET, 0, sockets));
114 sockets_[0].reset(sockets[0]);
115 sockets_[1].reset(sockets[1]);
116 thread_ = std::thread([this] { 113 thread_ = std::thread([this] {
117 StartFuseAppLoop(sockets_[1].release(), &callback_); 114 StartFuseAppLoop(sockets_[1].release(), &callback_);
118 }); 115 });
diff --git a/libappfuse/tests/FuseBridgeLoopTest.cc b/libappfuse/tests/FuseBridgeLoopTest.cc
index e74d9e700..b4c1efb01 100644
--- a/libappfuse/tests/FuseBridgeLoopTest.cc
+++ b/libappfuse/tests/FuseBridgeLoopTest.cc
@@ -50,15 +50,8 @@ class FuseBridgeLoopTest : public ::testing::Test {
50 50
51 void SetUp() override { 51 void SetUp() override {
52 base::SetMinimumLogSeverity(base::VERBOSE); 52 base::SetMinimumLogSeverity(base::VERBOSE);
53 int dev_sockets[2]; 53 ASSERT_TRUE(SetupMessageSockets(&dev_sockets_));
54 int proxy_sockets[2]; 54 ASSERT_TRUE(SetupMessageSockets(&proxy_sockets_));
55 ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_SEQPACKET, 0, dev_sockets));
56 ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_SEQPACKET, 0, proxy_sockets));
57 dev_sockets_[0].reset(dev_sockets[0]);
58 dev_sockets_[1].reset(dev_sockets[1]);
59 proxy_sockets_[0].reset(proxy_sockets[0]);
60 proxy_sockets_[1].reset(proxy_sockets[1]);
61
62 thread_ = std::thread([this] { 55 thread_ = std::thread([this] {
63 StartFuseBridgeLoop( 56 StartFuseBridgeLoop(
64 dev_sockets_[1].release(), proxy_sockets_[0].release(), &callback_); 57 dev_sockets_[1].release(), proxy_sockets_[0].release(), &callback_);
diff --git a/libappfuse/tests/FuseBufferTest.cc b/libappfuse/tests/FuseBufferTest.cc
index 1a1abd57e..ade34acc1 100644
--- a/libappfuse/tests/FuseBufferTest.cc
+++ b/libappfuse/tests/FuseBufferTest.cc
@@ -112,30 +112,6 @@ TEST(FuseMessageTest, Write_TooShort) {
112 TestWriteInvalidLength(sizeof(fuse_in_header) - 1); 112 TestWriteInvalidLength(sizeof(fuse_in_header) - 1);
113} 113}
114 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
139TEST(FuseResponseTest, Reset) { 115TEST(FuseResponseTest, Reset) {
140 FuseResponse response; 116 FuseResponse response;
141 // Write 1 to the first ten bytes. 117 // Write 1 to the first ten bytes.
@@ -211,5 +187,29 @@ TEST(FuseBufferTest, HandleNotImpl) {
211 EXPECT_EQ(-ENOSYS, buffer.response.header.error); 187 EXPECT_EQ(-ENOSYS, buffer.response.header.error);
212} 188}
213 189
190TEST(SetupMessageSocketsTest, Stress) {
191 constexpr int kCount = 1000;
192
193 FuseRequest request;
194 request.header.len = sizeof(FuseRequest);
195
196 base::unique_fd fds[2];
197 SetupMessageSockets(&fds);
198
199 std::thread thread([&fds] {
200 FuseRequest request;
201 for (int i = 0; i < kCount; ++i) {
202 ASSERT_TRUE(request.Read(fds[1]));
203 usleep(1000);
204 }
205 });
206
207 for (int i = 0; i < kCount; ++i) {
208 ASSERT_TRUE(request.Write(fds[0]));
209 }
210
211 thread.join();
212}
213
214} // namespace fuse 214} // namespace fuse
215} // namespace android 215} // namespace android