summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaichi Hirono2017-03-06 00:23:16 -0600
committerDaichi Hirono2017-03-27 00:46:58 -0500
commitf5d15f9fc4b8bd7a866660fe208bf857dea839ba (patch)
tree5b4dd335b79a511817db15409c72aeb21e000a77 /libappfuse/tests
parent0bc3add41b366819149405e571c3a718a340f1cb (diff)
downloadplatform-system-core-f5d15f9fc4b8bd7a866660fe208bf857dea839ba.tar.gz
platform-system-core-f5d15f9fc4b8bd7a866660fe208bf857dea839ba.tar.xz
platform-system-core-f5d15f9fc4b8bd7a866660fe208bf857dea839ba.zip
Change FuseAppLoop so that it can process messages asynchronously.
Previously FuseAppLoopCallback needs to return values in a synchrnous manner. The CL changes it to asynchronous mannger so that apps can process FUSE message asynchrnously. Bug: 35229514 Test: FuseAppLoopTest Change-Id: I8edcfdb003a25cfd5e9c490ec871140220b21e35
Diffstat (limited to 'libappfuse/tests')
-rw-r--r--libappfuse/tests/FuseAppLoopTest.cc111
1 files changed, 53 insertions, 58 deletions
diff --git a/libappfuse/tests/FuseAppLoopTest.cc b/libappfuse/tests/FuseAppLoopTest.cc
index 64dd81330..98e36652a 100644
--- a/libappfuse/tests/FuseAppLoopTest.cc
+++ b/libappfuse/tests/FuseAppLoopTest.cc
@@ -23,6 +23,9 @@
23#include <gtest/gtest.h> 23#include <gtest/gtest.h>
24#include <thread> 24#include <thread>
25 25
26#include "libappfuse/EpollController.h"
27#include "libappfuse/FuseBridgeLoop.h"
28
26namespace android { 29namespace android {
27namespace fuse { 30namespace fuse {
28namespace { 31namespace {
@@ -37,82 +40,61 @@ struct CallbackRequest {
37class Callback : public FuseAppLoopCallback { 40class Callback : public FuseAppLoopCallback {
38 public: 41 public:
39 std::vector<CallbackRequest> requests; 42 std::vector<CallbackRequest> requests;
43 FuseAppLoop* loop;
40 44
41 bool IsActive() override { 45 void OnGetAttr(uint64_t seq, uint64_t inode) override {
42 return true; 46 EXPECT_NE(FUSE_ROOT_ID, static_cast<int>(inode));
47 EXPECT_TRUE(loop->ReplyGetAttr(seq, inode, kTestFileSize, S_IFREG | 0777));
43 } 48 }
44 49
45 int64_t OnGetSize(uint64_t inode) override { 50 void OnLookup(uint64_t unique, uint64_t inode) override {
46 if (inode == FUSE_ROOT_ID) { 51 EXPECT_NE(FUSE_ROOT_ID, static_cast<int>(inode));
47 return 0; 52 EXPECT_TRUE(loop->ReplyLookup(unique, inode, kTestFileSize));
48 } else {
49 return kTestFileSize;
50 }
51 } 53 }
52 54
53 int32_t OnFsync(uint64_t inode) override { 55 void OnFsync(uint64_t seq, uint64_t inode) override {
54 requests.push_back({ 56 requests.push_back({.code = FUSE_FSYNC, .inode = inode});
55 .code = FUSE_FSYNC, 57 loop->ReplySimple(seq, 0);
56 .inode = inode
57 });
58 return 0;
59 } 58 }
60 59
61 int32_t OnWrite(uint64_t inode, 60 void OnWrite(uint64_t seq, uint64_t inode, uint64_t offset ATTRIBUTE_UNUSED,
62 uint64_t offset ATTRIBUTE_UNUSED, 61 uint32_t size ATTRIBUTE_UNUSED, const void* data ATTRIBUTE_UNUSED) override {
63 uint32_t size ATTRIBUTE_UNUSED, 62 requests.push_back({.code = FUSE_WRITE, .inode = inode});
64 const void* data ATTRIBUTE_UNUSED) override { 63 loop->ReplyWrite(seq, 0);
65 requests.push_back({
66 .code = FUSE_WRITE,
67 .inode = inode
68 });
69 return 0;
70 } 64 }
71 65
72 int32_t OnRead(uint64_t inode, 66 void OnRead(uint64_t seq, uint64_t inode, uint64_t offset ATTRIBUTE_UNUSED,
73 uint64_t offset ATTRIBUTE_UNUSED, 67 uint32_t size ATTRIBUTE_UNUSED) override {
74 uint32_t size ATTRIBUTE_UNUSED, 68 requests.push_back({.code = FUSE_READ, .inode = inode});
75 void* data ATTRIBUTE_UNUSED) override { 69 loop->ReplySimple(seq, 0);
76 requests.push_back({
77 .code = FUSE_READ,
78 .inode = inode
79 });
80 return 0;
81 } 70 }
82 71
83 int32_t OnOpen(uint64_t inode) override { 72 void OnOpen(uint64_t seq, uint64_t inode) override {
84 requests.push_back({ 73 requests.push_back({.code = FUSE_OPEN, .inode = inode});
85 .code = FUSE_OPEN, 74 loop->ReplyOpen(seq, inode);
86 .inode = inode
87 });
88 return 0;
89 } 75 }
90 76
91 int32_t OnRelease(uint64_t inode) override { 77 void OnRelease(uint64_t seq, uint64_t inode) override {
92 requests.push_back({ 78 requests.push_back({.code = FUSE_RELEASE, .inode = inode});
93 .code = FUSE_RELEASE, 79 loop->ReplySimple(seq, 0);
94 .inode = inode
95 });
96 return 0;
97 } 80 }
98}; 81};
99 82
100class FuseAppLoopTest : public ::testing::Test { 83class FuseAppLoopTest : public ::testing::Test {
101 private:
102 std::thread thread_;
103
104 protected: 84 protected:
105 base::unique_fd sockets_[2]; 85 std::thread thread_;
106 Callback callback_; 86 base::unique_fd sockets_[2];
107 FuseRequest request_; 87 Callback callback_;
108 FuseResponse response_; 88 FuseRequest request_;
109 89 FuseResponse response_;
110 void SetUp() override { 90 std::unique_ptr<FuseAppLoop> loop_;
111 base::SetMinimumLogSeverity(base::VERBOSE); 91
112 ASSERT_TRUE(SetupMessageSockets(&sockets_)); 92 void SetUp() override {
113 thread_ = std::thread([this] { 93 base::SetMinimumLogSeverity(base::VERBOSE);
114 StartFuseAppLoop(sockets_[1].release(), &callback_); 94 ASSERT_TRUE(SetupMessageSockets(&sockets_));
115 }); 95 loop_.reset(new FuseAppLoop(std::move(sockets_[1])));
96 callback_.loop = loop_.get();
97 thread_ = std::thread([this] { loop_->Start(&callback_); });
116 } 98 }
117 99
118 void CheckCallback( 100 void CheckCallback(
@@ -300,5 +282,18 @@ TEST_F(FuseAppLoopTest, Write) {
300 CheckCallback(sizeof(fuse_write_in), FUSE_WRITE, sizeof(fuse_write_out)); 282 CheckCallback(sizeof(fuse_write_in), FUSE_WRITE, sizeof(fuse_write_out));
301} 283}
302 284
285TEST_F(FuseAppLoopTest, Break) {
286 // Ensure that the loop started.
287 request_.Reset(sizeof(fuse_open_in), FUSE_OPEN, 1);
288 request_.header.nodeid = 10;
289 ASSERT_TRUE(request_.Write(sockets_[0]));
290 ASSERT_TRUE(response_.Read(sockets_[0]));
291
292 loop_->Break();
293 if (thread_.joinable()) {
294 thread_.join();
295 }
296}
297
303} // namespace fuse 298} // namespace fuse
304} // namespace android 299} // namespace android