blob: f9737fee450dc2c7d04158078e7218198652a0f1 [file] [log] [blame]
Songchun Fan3c82a302019-11-29 14:23:45 -08001/*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <android-base/file.h>
18#include <android-base/logging.h>
19#include <android-base/unique_fd.h>
20#include <binder/ParcelFileDescriptor.h>
21#include <gmock/gmock.h>
22#include <gtest/gtest.h>
23#include <utils/Log.h>
24
25#include <future>
26
27#include "IncrementalService.h"
28#include "Metadata.pb.h"
29#include "ServiceWrappers.h"
30
31using namespace testing;
32using namespace android::incremental;
33using namespace std::literals;
34using testing::_;
35using testing::Invoke;
36using testing::NiceMock;
37
38#undef LOG_TAG
39#define LOG_TAG "IncrementalServiceTest"
40
41using namespace android::incfs;
42using namespace android::content::pm;
43
44namespace android::os::incremental {
45
46class MockVoldService : public VoldServiceWrapper {
47public:
48 MOCK_CONST_METHOD4(mountIncFs,
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -080049 binder::Status(const std::string& backingPath, const std::string& targetDir,
Songchun Fan3c82a302019-11-29 14:23:45 -080050 int32_t flags,
51 IncrementalFileSystemControlParcel* _aidl_return));
52 MOCK_CONST_METHOD1(unmountIncFs, binder::Status(const std::string& dir));
53 MOCK_CONST_METHOD2(bindMount,
54 binder::Status(const std::string& sourceDir, const std::string& argetDir));
Alex Buynytskyy5e860ba2020-03-31 15:30:21 -070055 MOCK_CONST_METHOD2(setIncFsMountOptions,
56 binder::Status(const ::android::os::incremental::IncrementalFileSystemControlParcel&, bool));
Songchun Fan3c82a302019-11-29 14:23:45 -080057
58 void mountIncFsFails() {
59 ON_CALL(*this, mountIncFs(_, _, _, _))
60 .WillByDefault(
61 Return(binder::Status::fromExceptionCode(1, String8("failed to mount"))));
62 }
63 void mountIncFsInvalidControlParcel() {
64 ON_CALL(*this, mountIncFs(_, _, _, _))
65 .WillByDefault(Invoke(this, &MockVoldService::getInvalidControlParcel));
66 }
67 void mountIncFsSuccess() {
68 ON_CALL(*this, mountIncFs(_, _, _, _))
69 .WillByDefault(Invoke(this, &MockVoldService::incFsSuccess));
70 }
71 void bindMountFails() {
72 ON_CALL(*this, bindMount(_, _))
73 .WillByDefault(Return(
74 binder::Status::fromExceptionCode(1, String8("failed to bind-mount"))));
75 }
76 void bindMountSuccess() {
77 ON_CALL(*this, bindMount(_, _)).WillByDefault(Return(binder::Status::ok()));
78 }
Alex Buynytskyy5e860ba2020-03-31 15:30:21 -070079 void setIncFsMountOptionsFails() const {
80 ON_CALL(*this, setIncFsMountOptions(_, _))
81 .WillByDefault(
82 Return(binder::Status::fromExceptionCode(1, String8("failed to set options"))));
83 }
84 void setIncFsMountOptionsSuccess() {
85 ON_CALL(*this, setIncFsMountOptions(_, _)).WillByDefault(Return(binder::Status::ok()));
86 }
Songchun Fan3c82a302019-11-29 14:23:45 -080087 binder::Status getInvalidControlParcel(const std::string& imagePath,
88 const std::string& targetDir, int32_t flags,
89 IncrementalFileSystemControlParcel* _aidl_return) {
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -080090 _aidl_return = {};
Songchun Fan3c82a302019-11-29 14:23:45 -080091 return binder::Status::ok();
92 }
93 binder::Status incFsSuccess(const std::string& imagePath, const std::string& targetDir,
94 int32_t flags, IncrementalFileSystemControlParcel* _aidl_return) {
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -080095 _aidl_return->pendingReads.reset(base::unique_fd(dup(STDIN_FILENO)));
96 _aidl_return->cmd.reset(base::unique_fd(dup(STDIN_FILENO)));
97 _aidl_return->log.reset(base::unique_fd(dup(STDIN_FILENO)));
Songchun Fan3c82a302019-11-29 14:23:45 -080098 return binder::Status::ok();
99 }
100
101private:
102 TemporaryFile cmdFile;
103 TemporaryFile logFile;
Songchun Fan3c82a302019-11-29 14:23:45 -0800104};
105
Alex Buynytskyy0b202662020-04-13 09:53:04 -0700106class MockDataLoader : public IDataLoader {
Songchun Fan3c82a302019-11-29 14:23:45 -0800107public:
Alex Buynytskyy0b202662020-04-13 09:53:04 -0700108 MockDataLoader() {
109 ON_CALL(*this, create(_, _, _, _)).WillByDefault(Return((binder::Status::ok())));
110 ON_CALL(*this, start(_)).WillByDefault(Return((binder::Status::ok())));
111 ON_CALL(*this, stop(_)).WillByDefault(Return((binder::Status::ok())));
112 ON_CALL(*this, destroy(_)).WillByDefault(Return((binder::Status::ok())));
113 ON_CALL(*this, prepareImage(_, _, _)).WillByDefault(Return((binder::Status::ok())));
114 }
Songchun Fan68645c42020-02-27 15:57:35 -0800115 IBinder* onAsBinder() override { return nullptr; }
Alex Buynytskyy0b202662020-04-13 09:53:04 -0700116 MOCK_METHOD4(create,
117 binder::Status(int32_t id, const DataLoaderParamsParcel& params,
118 const FileSystemControlParcel& control,
119 const sp<IDataLoaderStatusListener>& listener));
120 MOCK_METHOD1(start, binder::Status(int32_t id));
121 MOCK_METHOD1(stop, binder::Status(int32_t id));
122 MOCK_METHOD1(destroy, binder::Status(int32_t id));
123 MOCK_METHOD3(prepareImage,
124 binder::Status(int32_t id, const std::vector<InstallationFileParcel>& addedFiles,
125 const std::vector<std::string>& removedFiles));
Songchun Fan68645c42020-02-27 15:57:35 -0800126};
127
128class MockDataLoaderManager : public DataLoaderManagerWrapper {
129public:
Alex Buynytskyy0b202662020-04-13 09:53:04 -0700130 MockDataLoaderManager(sp<IDataLoader> dataLoader) : mDataLoaderHolder(std::move(dataLoader)) {
131 EXPECT_TRUE(mDataLoaderHolder != nullptr);
132 }
133
Songchun Fan68645c42020-02-27 15:57:35 -0800134 MOCK_CONST_METHOD5(initializeDataLoader,
135 binder::Status(int32_t mountId, const DataLoaderParamsParcel& params,
136 const FileSystemControlParcel& control,
Songchun Fan3c82a302019-11-29 14:23:45 -0800137 const sp<IDataLoaderStatusListener>& listener,
138 bool* _aidl_return));
Songchun Fan68645c42020-02-27 15:57:35 -0800139 MOCK_CONST_METHOD2(getDataLoader,
140 binder::Status(int32_t mountId, sp<IDataLoader>* _aidl_return));
Songchun Fan3c82a302019-11-29 14:23:45 -0800141 MOCK_CONST_METHOD1(destroyDataLoader, binder::Status(int32_t mountId));
Songchun Fan3c82a302019-11-29 14:23:45 -0800142
Alex Buynytskyy0ea4ff42020-04-09 17:25:42 -0700143 void initializeDataLoaderSuccess() {
144 ON_CALL(*this, initializeDataLoader(_, _, _, _, _))
145 .WillByDefault(Invoke(this, &MockDataLoaderManager::initializeDataLoaderOk));
146 }
147 void initializeDataLoaderFails() {
148 ON_CALL(*this, initializeDataLoader(_, _, _, _, _))
149 .WillByDefault(Return(
150 (binder::Status::fromExceptionCode(1, String8("failed to prepare")))));
151 }
152 void getDataLoaderSuccess() {
153 ON_CALL(*this, getDataLoader(_, _))
154 .WillByDefault(Invoke(this, &MockDataLoaderManager::getDataLoaderOk));
155 }
Alex Buynytskyy0b202662020-04-13 09:53:04 -0700156 void destroyDataLoaderSuccess() {
Alex Buynytskyy0ea4ff42020-04-09 17:25:42 -0700157 ON_CALL(*this, destroyDataLoader(_))
Alex Buynytskyy0b202662020-04-13 09:53:04 -0700158 .WillByDefault(Invoke(this, &MockDataLoaderManager::destroyDataLoaderOk));
Alex Buynytskyy0ea4ff42020-04-09 17:25:42 -0700159 }
Songchun Fan68645c42020-02-27 15:57:35 -0800160 binder::Status initializeDataLoaderOk(int32_t mountId, const DataLoaderParamsParcel& params,
161 const FileSystemControlParcel& control,
162 const sp<IDataLoaderStatusListener>& listener,
163 bool* _aidl_return) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800164 mId = mountId;
165 mListener = listener;
Alex Buynytskyy0a646ca2020-04-08 12:18:01 -0700166 mServiceConnector = control.service;
Alex Buynytskyy0b202662020-04-13 09:53:04 -0700167 mDataLoader = mDataLoaderHolder;
Songchun Fan3c82a302019-11-29 14:23:45 -0800168 *_aidl_return = true;
Alex Buynytskyy0b202662020-04-13 09:53:04 -0700169 return mDataLoader->create(mountId, params, control, listener);
Songchun Fan3c82a302019-11-29 14:23:45 -0800170 }
Songchun Fan68645c42020-02-27 15:57:35 -0800171 binder::Status getDataLoaderOk(int32_t mountId, sp<IDataLoader>* _aidl_return) {
172 *_aidl_return = mDataLoader;
Songchun Fan3c82a302019-11-29 14:23:45 -0800173 return binder::Status::ok();
174 }
Alex Buynytskyy0b202662020-04-13 09:53:04 -0700175 void setDataLoaderStatusCreated() {
Alex Buynytskyy1ecfcec2019-12-17 12:10:41 -0800176 mListener->onStatusChanged(mId, IDataLoaderStatusListener::DATA_LOADER_CREATED);
Songchun Fan3c82a302019-11-29 14:23:45 -0800177 }
Alex Buynytskyy0b202662020-04-13 09:53:04 -0700178 void setDataLoaderStatusStarted() {
179 mListener->onStatusChanged(mId, IDataLoaderStatusListener::DATA_LOADER_STARTED);
180 }
181 void setDataLoaderStatusDestroyed() {
182 mListener->onStatusChanged(mId, IDataLoaderStatusListener::DATA_LOADER_DESTROYED);
183 }
184 binder::Status destroyDataLoaderOk(int32_t id) {
185 if (mDataLoader) {
186 if (auto status = mDataLoader->destroy(id); !status.isOk()) {
187 return status;
188 }
189 mDataLoader = nullptr;
190 }
Alex Buynytskyy0ea4ff42020-04-09 17:25:42 -0700191 if (mListener) {
192 mListener->onStatusChanged(id, IDataLoaderStatusListener::DATA_LOADER_DESTROYED);
193 }
194 return binder::Status::ok();
195 }
Alex Buynytskyy0a646ca2020-04-08 12:18:01 -0700196 int32_t setStorageParams(bool enableReadLogs) {
197 int32_t result = -1;
198 EXPECT_NE(mServiceConnector.get(), nullptr);
199 EXPECT_TRUE(mServiceConnector->setStorageParams(enableReadLogs, &result).isOk());
200 return result;
201 }
202
Songchun Fan3c82a302019-11-29 14:23:45 -0800203private:
204 int mId;
205 sp<IDataLoaderStatusListener> mListener;
Alex Buynytskyy0a646ca2020-04-08 12:18:01 -0700206 sp<IIncrementalServiceConnector> mServiceConnector;
Alex Buynytskyy0b202662020-04-13 09:53:04 -0700207 sp<IDataLoader> mDataLoader;
208 sp<IDataLoader> mDataLoaderHolder;
Songchun Fan3c82a302019-11-29 14:23:45 -0800209};
210
211class MockIncFs : public IncFsWrapper {
212public:
Songchun Fan20d6ef22020-03-03 09:47:15 -0800213 MOCK_CONST_METHOD3(createControl, Control(IncFsFd cmd, IncFsFd pendingReads, IncFsFd logs));
Songchun Fan3c82a302019-11-29 14:23:45 -0800214 MOCK_CONST_METHOD5(makeFile,
Songchun Fan20d6ef22020-03-03 09:47:15 -0800215 ErrorCode(const Control& control, std::string_view path, int mode, FileId id,
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800216 NewFileParams params));
Songchun Fan20d6ef22020-03-03 09:47:15 -0800217 MOCK_CONST_METHOD3(makeDir, ErrorCode(const Control& control, std::string_view path, int mode));
218 MOCK_CONST_METHOD2(getMetadata, RawMetadata(const Control& control, FileId fileid));
219 MOCK_CONST_METHOD2(getMetadata, RawMetadata(const Control& control, std::string_view path));
220 MOCK_CONST_METHOD2(getFileId, FileId(const Control& control, std::string_view path));
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800221 MOCK_CONST_METHOD3(link,
Songchun Fan20d6ef22020-03-03 09:47:15 -0800222 ErrorCode(const Control& control, std::string_view from, std::string_view to));
223 MOCK_CONST_METHOD2(unlink, ErrorCode(const Control& control, std::string_view path));
Yurii Zubrytskyie82cdd72020-04-01 12:19:26 -0700224 MOCK_CONST_METHOD2(openForSpecialOps, base::unique_fd(const Control& control, FileId id));
Songchun Fan9b753082020-02-26 13:08:06 -0800225 MOCK_CONST_METHOD1(writeBlocks, ErrorCode(Span<const DataBlock> blocks));
Songchun Fan3c82a302019-11-29 14:23:45 -0800226
227 void makeFileFails() { ON_CALL(*this, makeFile(_, _, _, _, _)).WillByDefault(Return(-1)); }
228 void makeFileSuccess() { ON_CALL(*this, makeFile(_, _, _, _, _)).WillByDefault(Return(0)); }
Songchun Fan20d6ef22020-03-03 09:47:15 -0800229 RawMetadata getMountInfoMetadata(const Control& control, std::string_view path) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800230 metadata::Mount m;
231 m.mutable_storage()->set_id(100);
232 m.mutable_loader()->set_package_name("com.test");
233 m.mutable_loader()->set_arguments("com.uri");
234 const auto metadata = m.SerializeAsString();
235 m.mutable_loader()->release_arguments();
236 m.mutable_loader()->release_package_name();
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800237 return {metadata.begin(), metadata.end()};
Songchun Fan3c82a302019-11-29 14:23:45 -0800238 }
Songchun Fan20d6ef22020-03-03 09:47:15 -0800239 RawMetadata getStorageMetadata(const Control& control, std::string_view path) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800240 metadata::Storage st;
241 st.set_id(100);
242 auto metadata = st.SerializeAsString();
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800243 return {metadata.begin(), metadata.end()};
Songchun Fan3c82a302019-11-29 14:23:45 -0800244 }
Songchun Fan20d6ef22020-03-03 09:47:15 -0800245 RawMetadata getBindPointMetadata(const Control& control, std::string_view path) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800246 metadata::BindPoint bp;
247 std::string destPath = "dest";
248 std::string srcPath = "src";
249 bp.set_storage_id(100);
250 bp.set_allocated_dest_path(&destPath);
251 bp.set_allocated_source_subdir(&srcPath);
252 const auto metadata = bp.SerializeAsString();
253 bp.release_source_subdir();
254 bp.release_dest_path();
255 return std::vector<char>(metadata.begin(), metadata.end());
256 }
257};
258
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700259class MockAppOpsManager : public AppOpsManagerWrapper {
Alex Buynytskyy1d892162020-04-03 23:00:19 -0700260public:
261 MOCK_CONST_METHOD3(checkPermission, binder::Status(const char*, const char*, const char*));
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700262 MOCK_METHOD3(startWatchingMode, void(int32_t, const String16&, const sp<IAppOpsCallback>&));
Alex Buynytskyy1d892162020-04-03 23:00:19 -0700263 MOCK_METHOD1(stopWatchingMode, void(const sp<IAppOpsCallback>&));
264
265 void checkPermissionSuccess() {
266 ON_CALL(*this, checkPermission(_, _, _)).WillByDefault(Return(android::incremental::Ok()));
267 }
268 void checkPermissionFails() {
269 ON_CALL(*this, checkPermission(_, _, _))
270 .WillByDefault(
271 Return(android::incremental::Exception(binder::Status::EX_SECURITY, {})));
272 }
273 void initializeStartWatchingMode() {
274 ON_CALL(*this, startWatchingMode(_, _, _))
275 .WillByDefault(Invoke(this, &MockAppOpsManager::storeCallback));
276 }
277 void storeCallback(int32_t, const String16&, const sp<IAppOpsCallback>& cb) {
278 mStoredCallback = cb;
279 }
280
281 sp<IAppOpsCallback> mStoredCallback;
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700282};
283
Yurii Zubrytskyi86321402020-04-09 19:22:30 -0700284class MockJniWrapper : public JniWrapper {
285public:
286 MOCK_CONST_METHOD0(initializeForCurrentThread, void());
287
288 MockJniWrapper() { EXPECT_CALL(*this, initializeForCurrentThread()).Times(1); }
289};
290
Songchun Fan3c82a302019-11-29 14:23:45 -0800291class MockServiceManager : public ServiceManagerWrapper {
292public:
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800293 MockServiceManager(std::unique_ptr<MockVoldService> vold,
Yurii Zubrytskyi86321402020-04-09 19:22:30 -0700294 std::unique_ptr<MockDataLoaderManager> dataLoaderManager,
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700295 std::unique_ptr<MockIncFs> incfs,
Yurii Zubrytskyi86321402020-04-09 19:22:30 -0700296 std::unique_ptr<MockAppOpsManager> appOpsManager,
297 std::unique_ptr<MockJniWrapper> jni)
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800298 : mVold(std::move(vold)),
Yurii Zubrytskyi86321402020-04-09 19:22:30 -0700299 mDataLoaderManager(std::move(dataLoaderManager)),
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700300 mIncFs(std::move(incfs)),
Yurii Zubrytskyi86321402020-04-09 19:22:30 -0700301 mAppOpsManager(std::move(appOpsManager)),
302 mJni(std::move(jni)) {}
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800303 std::unique_ptr<VoldServiceWrapper> getVoldService() final { return std::move(mVold); }
Songchun Fan68645c42020-02-27 15:57:35 -0800304 std::unique_ptr<DataLoaderManagerWrapper> getDataLoaderManager() final {
305 return std::move(mDataLoaderManager);
Songchun Fan3c82a302019-11-29 14:23:45 -0800306 }
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800307 std::unique_ptr<IncFsWrapper> getIncFs() final { return std::move(mIncFs); }
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700308 std::unique_ptr<AppOpsManagerWrapper> getAppOpsManager() final { return std::move(mAppOpsManager); }
Yurii Zubrytskyi86321402020-04-09 19:22:30 -0700309 std::unique_ptr<JniWrapper> getJni() final { return std::move(mJni); }
Songchun Fan3c82a302019-11-29 14:23:45 -0800310
311private:
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800312 std::unique_ptr<MockVoldService> mVold;
Songchun Fan68645c42020-02-27 15:57:35 -0800313 std::unique_ptr<MockDataLoaderManager> mDataLoaderManager;
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800314 std::unique_ptr<MockIncFs> mIncFs;
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700315 std::unique_ptr<MockAppOpsManager> mAppOpsManager;
Yurii Zubrytskyi86321402020-04-09 19:22:30 -0700316 std::unique_ptr<MockJniWrapper> mJni;
Songchun Fan3c82a302019-11-29 14:23:45 -0800317};
318
319// --- IncrementalServiceTest ---
320
Songchun Fan3c82a302019-11-29 14:23:45 -0800321class IncrementalServiceTest : public testing::Test {
322public:
323 void SetUp() override {
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800324 auto vold = std::make_unique<NiceMock<MockVoldService>>();
325 mVold = vold.get();
Alex Buynytskyy0b202662020-04-13 09:53:04 -0700326 sp<NiceMock<MockDataLoader>> dataLoader{new NiceMock<MockDataLoader>};
327 mDataLoader = dataLoader.get();
328 auto dataloaderManager = std::make_unique<NiceMock<MockDataLoaderManager>>(dataLoader);
Songchun Fan68645c42020-02-27 15:57:35 -0800329 mDataLoaderManager = dataloaderManager.get();
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800330 auto incFs = std::make_unique<NiceMock<MockIncFs>>();
331 mIncFs = incFs.get();
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700332 auto appOps = std::make_unique<NiceMock<MockAppOpsManager>>();
333 mAppOpsManager = appOps.get();
Yurii Zubrytskyi86321402020-04-09 19:22:30 -0700334 auto jni = std::make_unique<NiceMock<MockJniWrapper>>();
335 mJni = jni.get();
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800336 mIncrementalService =
337 std::make_unique<IncrementalService>(MockServiceManager(std::move(vold),
Yurii Zubrytskyi86321402020-04-09 19:22:30 -0700338 std::move(
339 dataloaderManager),
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700340 std::move(incFs),
Yurii Zubrytskyi86321402020-04-09 19:22:30 -0700341 std::move(appOps),
342 std::move(jni)),
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800343 mRootDir.path);
Songchun Fan3c82a302019-11-29 14:23:45 -0800344 mDataLoaderParcel.packageName = "com.test";
Alex Buynytskyy1ecfcec2019-12-17 12:10:41 -0800345 mDataLoaderParcel.arguments = "uri";
Alex Buynytskyy0b202662020-04-13 09:53:04 -0700346 mDataLoaderManager->destroyDataLoaderSuccess();
Songchun Fan3c82a302019-11-29 14:23:45 -0800347 mIncrementalService->onSystemReady();
348 }
349
350 void setUpExistingMountDir(const std::string& rootDir) {
351 const auto dir = rootDir + "/dir1";
352 const auto mountDir = dir + "/mount";
353 const auto backingDir = dir + "/backing_store";
354 const auto storageDir = mountDir + "/st0";
355 ASSERT_EQ(0, mkdir(dir.c_str(), 0755));
356 ASSERT_EQ(0, mkdir(mountDir.c_str(), 0755));
357 ASSERT_EQ(0, mkdir(backingDir.c_str(), 0755));
358 ASSERT_EQ(0, mkdir(storageDir.c_str(), 0755));
359 const auto mountInfoFile = rootDir + "/dir1/mount/.info";
360 const auto mountPointsFile = rootDir + "/dir1/mount/.mountpoint.abcd";
361 ASSERT_TRUE(base::WriteStringToFile("info", mountInfoFile));
362 ASSERT_TRUE(base::WriteStringToFile("mounts", mountPointsFile));
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800363 ON_CALL(*mIncFs, getMetadata(_, std::string_view(mountInfoFile)))
364 .WillByDefault(Invoke(mIncFs, &MockIncFs::getMountInfoMetadata));
365 ON_CALL(*mIncFs, getMetadata(_, std::string_view(mountPointsFile)))
366 .WillByDefault(Invoke(mIncFs, &MockIncFs::getBindPointMetadata));
367 ON_CALL(*mIncFs, getMetadata(_, std::string_view(rootDir + "/dir1/mount/st0")))
368 .WillByDefault(Invoke(mIncFs, &MockIncFs::getStorageMetadata));
Songchun Fan3c82a302019-11-29 14:23:45 -0800369 }
370
371protected:
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800372 NiceMock<MockVoldService>* mVold;
373 NiceMock<MockIncFs>* mIncFs;
Songchun Fan68645c42020-02-27 15:57:35 -0800374 NiceMock<MockDataLoaderManager>* mDataLoaderManager;
Alex Buynytskyy96e350b2020-04-02 20:03:47 -0700375 NiceMock<MockAppOpsManager>* mAppOpsManager;
Yurii Zubrytskyi86321402020-04-09 19:22:30 -0700376 NiceMock<MockJniWrapper>* mJni;
Alex Buynytskyy0b202662020-04-13 09:53:04 -0700377 NiceMock<MockDataLoader>* mDataLoader;
Songchun Fan3c82a302019-11-29 14:23:45 -0800378 std::unique_ptr<IncrementalService> mIncrementalService;
379 TemporaryDir mRootDir;
380 DataLoaderParamsParcel mDataLoaderParcel;
381};
382
Songchun Fan3c82a302019-11-29 14:23:45 -0800383TEST_F(IncrementalServiceTest, testCreateStorageMountIncFsFails) {
384 mVold->mountIncFsFails();
Songchun Fan68645c42020-02-27 15:57:35 -0800385 EXPECT_CALL(*mDataLoaderManager, initializeDataLoader(_, _, _, _, _)).Times(0);
Songchun Fan3c82a302019-11-29 14:23:45 -0800386 TemporaryDir tempDir;
387 int storageId =
Alex Buynytskyy04f73912020-02-10 08:34:18 -0800388 mIncrementalService->createStorage(tempDir.path, std::move(mDataLoaderParcel), {},
Songchun Fan3c82a302019-11-29 14:23:45 -0800389 IncrementalService::CreateOptions::CreateNew);
390 ASSERT_LT(storageId, 0);
391}
392
393TEST_F(IncrementalServiceTest, testCreateStorageMountIncFsInvalidControlParcel) {
394 mVold->mountIncFsInvalidControlParcel();
Songchun Fan68645c42020-02-27 15:57:35 -0800395 EXPECT_CALL(*mDataLoaderManager, initializeDataLoader(_, _, _, _, _)).Times(0);
Alex Buynytskyy0ea4ff42020-04-09 17:25:42 -0700396 EXPECT_CALL(*mDataLoaderManager, destroyDataLoader(_)).Times(0);
Songchun Fan3c82a302019-11-29 14:23:45 -0800397 TemporaryDir tempDir;
398 int storageId =
Alex Buynytskyy04f73912020-02-10 08:34:18 -0800399 mIncrementalService->createStorage(tempDir.path, std::move(mDataLoaderParcel), {},
Songchun Fan3c82a302019-11-29 14:23:45 -0800400 IncrementalService::CreateOptions::CreateNew);
401 ASSERT_LT(storageId, 0);
402}
403
404TEST_F(IncrementalServiceTest, testCreateStorageMakeFileFails) {
405 mVold->mountIncFsSuccess();
406 mIncFs->makeFileFails();
Songchun Fan68645c42020-02-27 15:57:35 -0800407 EXPECT_CALL(*mDataLoaderManager, initializeDataLoader(_, _, _, _, _)).Times(0);
Alex Buynytskyy0ea4ff42020-04-09 17:25:42 -0700408 EXPECT_CALL(*mDataLoaderManager, destroyDataLoader(_)).Times(0);
Songchun Fan3c82a302019-11-29 14:23:45 -0800409 EXPECT_CALL(*mVold, unmountIncFs(_));
410 TemporaryDir tempDir;
411 int storageId =
Alex Buynytskyy04f73912020-02-10 08:34:18 -0800412 mIncrementalService->createStorage(tempDir.path, std::move(mDataLoaderParcel), {},
Songchun Fan3c82a302019-11-29 14:23:45 -0800413 IncrementalService::CreateOptions::CreateNew);
414 ASSERT_LT(storageId, 0);
415}
416
417TEST_F(IncrementalServiceTest, testCreateStorageBindMountFails) {
418 mVold->mountIncFsSuccess();
419 mIncFs->makeFileSuccess();
420 mVold->bindMountFails();
Songchun Fan68645c42020-02-27 15:57:35 -0800421 EXPECT_CALL(*mDataLoaderManager, initializeDataLoader(_, _, _, _, _)).Times(0);
Alex Buynytskyy0ea4ff42020-04-09 17:25:42 -0700422 EXPECT_CALL(*mDataLoaderManager, destroyDataLoader(_)).Times(0);
Songchun Fan3c82a302019-11-29 14:23:45 -0800423 EXPECT_CALL(*mVold, unmountIncFs(_));
424 TemporaryDir tempDir;
425 int storageId =
Alex Buynytskyy04f73912020-02-10 08:34:18 -0800426 mIncrementalService->createStorage(tempDir.path, std::move(mDataLoaderParcel), {},
Songchun Fan3c82a302019-11-29 14:23:45 -0800427 IncrementalService::CreateOptions::CreateNew);
428 ASSERT_LT(storageId, 0);
429}
430
431TEST_F(IncrementalServiceTest, testCreateStoragePrepareDataLoaderFails) {
432 mVold->mountIncFsSuccess();
433 mIncFs->makeFileSuccess();
434 mVold->bindMountSuccess();
Songchun Fan68645c42020-02-27 15:57:35 -0800435 mDataLoaderManager->initializeDataLoaderFails();
Alex Buynytskyy0b202662020-04-13 09:53:04 -0700436 EXPECT_CALL(*mDataLoaderManager, initializeDataLoader(_, _, _, _, _)).Times(1);
Alex Buynytskyy0ea4ff42020-04-09 17:25:42 -0700437 EXPECT_CALL(*mDataLoaderManager, destroyDataLoader(_)).Times(1);
Alex Buynytskyy0b202662020-04-13 09:53:04 -0700438 EXPECT_CALL(*mDataLoader, create(_, _, _, _)).Times(0);
439 EXPECT_CALL(*mDataLoader, start(_)).Times(0);
440 EXPECT_CALL(*mDataLoader, destroy(_)).Times(0);
Songchun Fan3c82a302019-11-29 14:23:45 -0800441 EXPECT_CALL(*mVold, unmountIncFs(_)).Times(2);
442 TemporaryDir tempDir;
443 int storageId =
Alex Buynytskyy04f73912020-02-10 08:34:18 -0800444 mIncrementalService->createStorage(tempDir.path, std::move(mDataLoaderParcel), {},
Songchun Fan3c82a302019-11-29 14:23:45 -0800445 IncrementalService::CreateOptions::CreateNew);
446 ASSERT_LT(storageId, 0);
447}
448
449TEST_F(IncrementalServiceTest, testDeleteStorageSuccess) {
450 mVold->mountIncFsSuccess();
451 mIncFs->makeFileSuccess();
452 mVold->bindMountSuccess();
Songchun Fan68645c42020-02-27 15:57:35 -0800453 mDataLoaderManager->initializeDataLoaderSuccess();
Alex Buynytskyy0b202662020-04-13 09:53:04 -0700454 EXPECT_CALL(*mDataLoaderManager, initializeDataLoader(_, _, _, _, _)).Times(1);
Alex Buynytskyy0ea4ff42020-04-09 17:25:42 -0700455 EXPECT_CALL(*mDataLoaderManager, destroyDataLoader(_)).Times(1);
Alex Buynytskyy0b202662020-04-13 09:53:04 -0700456 EXPECT_CALL(*mDataLoader, create(_, _, _, _)).Times(1);
457 EXPECT_CALL(*mDataLoader, start(_)).Times(0);
458 EXPECT_CALL(*mDataLoader, destroy(_)).Times(1);
Songchun Fan3c82a302019-11-29 14:23:45 -0800459 EXPECT_CALL(*mVold, unmountIncFs(_)).Times(2);
460 TemporaryDir tempDir;
461 int storageId =
Alex Buynytskyy04f73912020-02-10 08:34:18 -0800462 mIncrementalService->createStorage(tempDir.path, std::move(mDataLoaderParcel), {},
Songchun Fan3c82a302019-11-29 14:23:45 -0800463 IncrementalService::CreateOptions::CreateNew);
464 ASSERT_GE(storageId, 0);
Alex Buynytskyy0b202662020-04-13 09:53:04 -0700465 mDataLoaderManager->setDataLoaderStatusCreated();
Songchun Fan3c82a302019-11-29 14:23:45 -0800466 mIncrementalService->deleteStorage(storageId);
467}
468
Alex Buynytskyy0b202662020-04-13 09:53:04 -0700469TEST_F(IncrementalServiceTest, testDataLoaderDestroyed) {
Songchun Fan3c82a302019-11-29 14:23:45 -0800470 mVold->mountIncFsSuccess();
471 mIncFs->makeFileSuccess();
472 mVold->bindMountSuccess();
Songchun Fan68645c42020-02-27 15:57:35 -0800473 mDataLoaderManager->initializeDataLoaderSuccess();
474 mDataLoaderManager->getDataLoaderSuccess();
Alex Buynytskyy0b202662020-04-13 09:53:04 -0700475 EXPECT_CALL(*mDataLoaderManager, initializeDataLoader(_, _, _, _, _)).Times(2);
476 EXPECT_CALL(*mDataLoaderManager, destroyDataLoader(_)).Times(1);
477 EXPECT_CALL(*mDataLoader, create(_, _, _, _)).Times(2);
478 EXPECT_CALL(*mDataLoader, start(_)).Times(0);
479 EXPECT_CALL(*mDataLoader, destroy(_)).Times(1);
Songchun Fan3c82a302019-11-29 14:23:45 -0800480 EXPECT_CALL(*mVold, unmountIncFs(_)).Times(2);
481 TemporaryDir tempDir;
482 int storageId =
Alex Buynytskyy04f73912020-02-10 08:34:18 -0800483 mIncrementalService->createStorage(tempDir.path, std::move(mDataLoaderParcel), {},
Songchun Fan3c82a302019-11-29 14:23:45 -0800484 IncrementalService::CreateOptions::CreateNew);
485 ASSERT_GE(storageId, 0);
Alex Buynytskyy0b202662020-04-13 09:53:04 -0700486 mDataLoaderManager->setDataLoaderStatusCreated();
487 // Simulated crash/other connection breakage.
488 mDataLoaderManager->setDataLoaderStatusDestroyed();
489}
490
491TEST_F(IncrementalServiceTest, testStartDataLoaderCreate) {
492 mVold->mountIncFsSuccess();
493 mIncFs->makeFileSuccess();
494 mVold->bindMountSuccess();
495 mDataLoaderManager->initializeDataLoaderSuccess();
496 mDataLoaderManager->getDataLoaderSuccess();
497 EXPECT_CALL(*mDataLoaderManager, initializeDataLoader(_, _, _, _, _)).Times(1);
498 EXPECT_CALL(*mDataLoaderManager, destroyDataLoader(_)).Times(1);
499 EXPECT_CALL(*mDataLoader, create(_, _, _, _)).Times(1);
500 EXPECT_CALL(*mDataLoader, start(_)).Times(1);
501 EXPECT_CALL(*mDataLoader, destroy(_)).Times(1);
502 EXPECT_CALL(*mVold, unmountIncFs(_)).Times(2);
503 TemporaryDir tempDir;
504 int storageId =
505 mIncrementalService->createStorage(tempDir.path, std::move(mDataLoaderParcel), {},
506 IncrementalService::CreateOptions::CreateNew);
507 ASSERT_GE(storageId, 0);
508 mDataLoaderManager->setDataLoaderStatusCreated();
Songchun Fan3c82a302019-11-29 14:23:45 -0800509 ASSERT_TRUE(mIncrementalService->startLoading(storageId));
Alex Buynytskyy0b202662020-04-13 09:53:04 -0700510 mDataLoaderManager->setDataLoaderStatusStarted();
511}
512
513TEST_F(IncrementalServiceTest, testStartDataLoaderPendingStart) {
514 mVold->mountIncFsSuccess();
515 mIncFs->makeFileSuccess();
516 mVold->bindMountSuccess();
517 mDataLoaderManager->initializeDataLoaderSuccess();
518 mDataLoaderManager->getDataLoaderSuccess();
519 EXPECT_CALL(*mDataLoaderManager, initializeDataLoader(_, _, _, _, _)).Times(1);
520 EXPECT_CALL(*mDataLoaderManager, destroyDataLoader(_)).Times(1);
521 EXPECT_CALL(*mDataLoader, create(_, _, _, _)).Times(1);
522 EXPECT_CALL(*mDataLoader, start(_)).Times(1);
523 EXPECT_CALL(*mDataLoader, destroy(_)).Times(1);
524 EXPECT_CALL(*mVold, unmountIncFs(_)).Times(2);
525 TemporaryDir tempDir;
526 int storageId =
527 mIncrementalService->createStorage(tempDir.path, std::move(mDataLoaderParcel), {},
528 IncrementalService::CreateOptions::CreateNew);
529 ASSERT_GE(storageId, 0);
530 ASSERT_TRUE(mIncrementalService->startLoading(storageId));
531 mDataLoaderManager->setDataLoaderStatusCreated();
Songchun Fan3c82a302019-11-29 14:23:45 -0800532}
533
Alex Buynytskyy5e860ba2020-03-31 15:30:21 -0700534TEST_F(IncrementalServiceTest, testSetIncFsMountOptionsSuccess) {
535 mVold->mountIncFsSuccess();
536 mIncFs->makeFileSuccess();
537 mVold->bindMountSuccess();
538 mVold->setIncFsMountOptionsSuccess();
539 mDataLoaderManager->initializeDataLoaderSuccess();
540 mDataLoaderManager->getDataLoaderSuccess();
Alex Buynytskyy1d892162020-04-03 23:00:19 -0700541 mAppOpsManager->checkPermissionSuccess();
Alex Buynytskyy5e860ba2020-03-31 15:30:21 -0700542 EXPECT_CALL(*mDataLoaderManager, destroyDataLoader(_));
543 EXPECT_CALL(*mVold, unmountIncFs(_)).Times(2);
Alex Buynytskyy1d892162020-04-03 23:00:19 -0700544 // We are calling setIncFsMountOptions(true).
545 EXPECT_CALL(*mVold, setIncFsMountOptions(_, true)).Times(1);
546 // After setIncFsMountOptions succeeded expecting to start watching.
547 EXPECT_CALL(*mAppOpsManager, startWatchingMode(_, _, _)).Times(1);
548 // Not expecting callback removal.
549 EXPECT_CALL(*mAppOpsManager, stopWatchingMode(_)).Times(0);
Alex Buynytskyy5e860ba2020-03-31 15:30:21 -0700550 TemporaryDir tempDir;
551 int storageId =
552 mIncrementalService->createStorage(tempDir.path, std::move(mDataLoaderParcel), {},
553 IncrementalService::CreateOptions::CreateNew);
554 ASSERT_GE(storageId, 0);
Alex Buynytskyy0a646ca2020-04-08 12:18:01 -0700555 ASSERT_GE(mDataLoaderManager->setStorageParams(true), 0);
Alex Buynytskyy5e860ba2020-03-31 15:30:21 -0700556}
557
Alex Buynytskyy1d892162020-04-03 23:00:19 -0700558TEST_F(IncrementalServiceTest, testSetIncFsMountOptionsSuccessAndPermissionChanged) {
559 mVold->mountIncFsSuccess();
560 mIncFs->makeFileSuccess();
561 mVold->bindMountSuccess();
562 mVold->setIncFsMountOptionsSuccess();
563 mDataLoaderManager->initializeDataLoaderSuccess();
564 mDataLoaderManager->getDataLoaderSuccess();
565 mAppOpsManager->checkPermissionSuccess();
566 mAppOpsManager->initializeStartWatchingMode();
567 EXPECT_CALL(*mDataLoaderManager, destroyDataLoader(_));
568 EXPECT_CALL(*mVold, unmountIncFs(_)).Times(2);
569 // We are calling setIncFsMountOptions(true).
570 EXPECT_CALL(*mVold, setIncFsMountOptions(_, true)).Times(1);
571 // setIncFsMountOptions(false) is called on the callback.
572 EXPECT_CALL(*mVold, setIncFsMountOptions(_, false)).Times(1);
573 // After setIncFsMountOptions succeeded expecting to start watching.
574 EXPECT_CALL(*mAppOpsManager, startWatchingMode(_, _, _)).Times(1);
575 // After callback is called, disable read logs and remove callback.
576 EXPECT_CALL(*mAppOpsManager, stopWatchingMode(_)).Times(1);
577 TemporaryDir tempDir;
578 int storageId =
579 mIncrementalService->createStorage(tempDir.path, std::move(mDataLoaderParcel), {},
580 IncrementalService::CreateOptions::CreateNew);
581 ASSERT_GE(storageId, 0);
Alex Buynytskyy0a646ca2020-04-08 12:18:01 -0700582 ASSERT_GE(mDataLoaderManager->setStorageParams(true), 0);
Alex Buynytskyy1d892162020-04-03 23:00:19 -0700583 ASSERT_NE(nullptr, mAppOpsManager->mStoredCallback.get());
584 mAppOpsManager->mStoredCallback->opChanged(0, {});
585}
586
587TEST_F(IncrementalServiceTest, testSetIncFsMountOptionsCheckPermissionFails) {
588 mVold->mountIncFsSuccess();
589 mIncFs->makeFileSuccess();
590 mVold->bindMountSuccess();
591 mDataLoaderManager->initializeDataLoaderSuccess();
592 mDataLoaderManager->getDataLoaderSuccess();
593 mAppOpsManager->checkPermissionFails();
594 EXPECT_CALL(*mDataLoaderManager, destroyDataLoader(_));
595 EXPECT_CALL(*mVold, unmountIncFs(_)).Times(2);
596 // checkPermission fails, no calls to set opitions, start or stop WatchingMode.
597 EXPECT_CALL(*mVold, setIncFsMountOptions(_, true)).Times(0);
598 EXPECT_CALL(*mAppOpsManager, startWatchingMode(_, _, _)).Times(0);
599 EXPECT_CALL(*mAppOpsManager, stopWatchingMode(_)).Times(0);
600 TemporaryDir tempDir;
601 int storageId =
602 mIncrementalService->createStorage(tempDir.path, std::move(mDataLoaderParcel), {},
603 IncrementalService::CreateOptions::CreateNew);
604 ASSERT_GE(storageId, 0);
Alex Buynytskyy0a646ca2020-04-08 12:18:01 -0700605 ASSERT_LT(mDataLoaderManager->setStorageParams(true), 0);
Alex Buynytskyy1d892162020-04-03 23:00:19 -0700606}
607
Alex Buynytskyy5e860ba2020-03-31 15:30:21 -0700608TEST_F(IncrementalServiceTest, testSetIncFsMountOptionsFails) {
609 mVold->mountIncFsSuccess();
610 mIncFs->makeFileSuccess();
611 mVold->bindMountSuccess();
612 mVold->setIncFsMountOptionsFails();
613 mDataLoaderManager->initializeDataLoaderSuccess();
614 mDataLoaderManager->getDataLoaderSuccess();
Alex Buynytskyy1d892162020-04-03 23:00:19 -0700615 mAppOpsManager->checkPermissionSuccess();
Alex Buynytskyy5e860ba2020-03-31 15:30:21 -0700616 EXPECT_CALL(*mDataLoaderManager, destroyDataLoader(_));
617 EXPECT_CALL(*mVold, unmountIncFs(_)).Times(2);
Alex Buynytskyy1d892162020-04-03 23:00:19 -0700618 // We are calling setIncFsMountOptions.
619 EXPECT_CALL(*mVold, setIncFsMountOptions(_, true)).Times(1);
620 // setIncFsMountOptions fails, no calls to start or stop WatchingMode.
621 EXPECT_CALL(*mAppOpsManager, startWatchingMode(_, _, _)).Times(0);
622 EXPECT_CALL(*mAppOpsManager, stopWatchingMode(_)).Times(0);
Alex Buynytskyy5e860ba2020-03-31 15:30:21 -0700623 TemporaryDir tempDir;
624 int storageId =
625 mIncrementalService->createStorage(tempDir.path, std::move(mDataLoaderParcel), {},
626 IncrementalService::CreateOptions::CreateNew);
627 ASSERT_GE(storageId, 0);
Alex Buynytskyy0a646ca2020-04-08 12:18:01 -0700628 ASSERT_LT(mDataLoaderManager->setStorageParams(true), 0);
Alex Buynytskyy5e860ba2020-03-31 15:30:21 -0700629}
630
Songchun Fan3c82a302019-11-29 14:23:45 -0800631TEST_F(IncrementalServiceTest, testMakeDirectory) {
632 mVold->mountIncFsSuccess();
633 mIncFs->makeFileSuccess();
634 mVold->bindMountSuccess();
Songchun Fan68645c42020-02-27 15:57:35 -0800635 mDataLoaderManager->initializeDataLoaderSuccess();
636 mDataLoaderManager->getDataLoaderSuccess();
Songchun Fan3c82a302019-11-29 14:23:45 -0800637 TemporaryDir tempDir;
638 int storageId =
Alex Buynytskyy04f73912020-02-10 08:34:18 -0800639 mIncrementalService->createStorage(tempDir.path, std::move(mDataLoaderParcel), {},
Songchun Fan3c82a302019-11-29 14:23:45 -0800640 IncrementalService::CreateOptions::CreateNew);
Songchun Fan103ba1d2020-02-03 17:32:32 -0800641 std::string dir_path("test");
Songchun Fan3c82a302019-11-29 14:23:45 -0800642
Songchun Fan103ba1d2020-02-03 17:32:32 -0800643 std::string tempPath(tempDir.path);
644 std::replace(tempPath.begin(), tempPath.end(), '/', '_');
Songchun Fan1124fd32020-02-10 12:49:41 -0800645 std::string mount_dir = std::string(mRootDir.path) + "/MT_" + tempPath.substr(1);
Songchun Fan103ba1d2020-02-03 17:32:32 -0800646 std::string normalized_dir_path = mount_dir + "/mount/st_1_0/" + dir_path;
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800647
Songchun Fan103ba1d2020-02-03 17:32:32 -0800648 // Expecting incfs to call makeDir on a path like:
649 // /data/local/tmp/TemporaryDir-06yixG/data_local_tmp_TemporaryDir-xwdFhT/mount/st_1_0/test
650 EXPECT_CALL(*mIncFs, makeDir(_, std::string_view(normalized_dir_path), _));
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800651 auto res = mIncrementalService->makeDir(storageId, dir_path, 0555);
652 ASSERT_EQ(res, 0);
Songchun Fan3c82a302019-11-29 14:23:45 -0800653}
654
655TEST_F(IncrementalServiceTest, testMakeDirectories) {
656 mVold->mountIncFsSuccess();
657 mIncFs->makeFileSuccess();
658 mVold->bindMountSuccess();
Songchun Fan68645c42020-02-27 15:57:35 -0800659 mDataLoaderManager->initializeDataLoaderSuccess();
660 mDataLoaderManager->getDataLoaderSuccess();
Songchun Fan3c82a302019-11-29 14:23:45 -0800661 TemporaryDir tempDir;
662 int storageId =
Alex Buynytskyy04f73912020-02-10 08:34:18 -0800663 mIncrementalService->createStorage(tempDir.path, std::move(mDataLoaderParcel), {},
Songchun Fan3c82a302019-11-29 14:23:45 -0800664 IncrementalService::CreateOptions::CreateNew);
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800665 auto first = "first"sv;
666 auto second = "second"sv;
667 auto third = "third"sv;
Songchun Fan103ba1d2020-02-03 17:32:32 -0800668
669 std::string tempPath(tempDir.path);
670 std::replace(tempPath.begin(), tempPath.end(), '/', '_');
Songchun Fan1124fd32020-02-10 12:49:41 -0800671 std::string mount_dir = std::string(mRootDir.path) + "/MT_" + tempPath.substr(1);
Songchun Fan103ba1d2020-02-03 17:32:32 -0800672
Songchun Fan3c82a302019-11-29 14:23:45 -0800673 InSequence seq;
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800674 auto parent_path = std::string(first) + "/" + std::string(second);
675 auto dir_path = parent_path + "/" + std::string(third);
Songchun Fan103ba1d2020-02-03 17:32:32 -0800676
677 std::string normalized_first_path = mount_dir + "/mount/st_1_0/" + std::string(first);
678 std::string normalized_parent_path = mount_dir + "/mount/st_1_0/" + parent_path;
679 std::string normalized_dir_path = mount_dir + "/mount/st_1_0/" + dir_path;
680
681 EXPECT_CALL(*mIncFs, makeDir(_, std::string_view(normalized_dir_path), _))
682 .WillOnce(Return(-ENOENT));
683 EXPECT_CALL(*mIncFs, makeDir(_, std::string_view(normalized_parent_path), _))
684 .WillOnce(Return(-ENOENT));
685 EXPECT_CALL(*mIncFs, makeDir(_, std::string_view(normalized_first_path), _))
686 .WillOnce(Return(0));
687 EXPECT_CALL(*mIncFs, makeDir(_, std::string_view(normalized_parent_path), _))
688 .WillOnce(Return(0));
689 EXPECT_CALL(*mIncFs, makeDir(_, std::string_view(normalized_dir_path), _)).WillOnce(Return(0));
690 auto res = mIncrementalService->makeDirs(storageId, normalized_dir_path, 0555);
Yurii Zubrytskyi4a25dfb2020-01-10 11:53:24 -0800691 ASSERT_EQ(res, 0);
Songchun Fan3c82a302019-11-29 14:23:45 -0800692}
693} // namespace android::os::incremental