Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 1 | /* |
| 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" |
Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 28 | #include "IncrementalServiceValidation.h" |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 29 | #include "Metadata.pb.h" |
| 30 | #include "ServiceWrappers.h" |
| 31 | |
| 32 | using namespace testing; |
| 33 | using namespace android::incremental; |
| 34 | using namespace std::literals; |
| 35 | using testing::_; |
| 36 | using testing::Invoke; |
| 37 | using testing::NiceMock; |
| 38 | |
| 39 | #undef LOG_TAG |
| 40 | #define LOG_TAG "IncrementalServiceTest" |
| 41 | |
| 42 | using namespace android::incfs; |
| 43 | using namespace android::content::pm; |
| 44 | |
| 45 | namespace android::os::incremental { |
| 46 | |
| 47 | class MockVoldService : public VoldServiceWrapper { |
| 48 | public: |
| 49 | MOCK_CONST_METHOD4(mountIncFs, |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 50 | binder::Status(const std::string& backingPath, const std::string& targetDir, |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 51 | int32_t flags, |
| 52 | IncrementalFileSystemControlParcel* _aidl_return)); |
| 53 | MOCK_CONST_METHOD1(unmountIncFs, binder::Status(const std::string& dir)); |
| 54 | MOCK_CONST_METHOD2(bindMount, |
| 55 | binder::Status(const std::string& sourceDir, const std::string& argetDir)); |
Alex Buynytskyy | 5e860ba | 2020-03-31 15:30:21 -0700 | [diff] [blame] | 56 | MOCK_CONST_METHOD2(setIncFsMountOptions, |
| 57 | binder::Status(const ::android::os::incremental::IncrementalFileSystemControlParcel&, bool)); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 58 | |
| 59 | void mountIncFsFails() { |
| 60 | ON_CALL(*this, mountIncFs(_, _, _, _)) |
| 61 | .WillByDefault( |
| 62 | Return(binder::Status::fromExceptionCode(1, String8("failed to mount")))); |
| 63 | } |
| 64 | void mountIncFsInvalidControlParcel() { |
| 65 | ON_CALL(*this, mountIncFs(_, _, _, _)) |
| 66 | .WillByDefault(Invoke(this, &MockVoldService::getInvalidControlParcel)); |
| 67 | } |
| 68 | void mountIncFsSuccess() { |
| 69 | ON_CALL(*this, mountIncFs(_, _, _, _)) |
| 70 | .WillByDefault(Invoke(this, &MockVoldService::incFsSuccess)); |
| 71 | } |
| 72 | void bindMountFails() { |
| 73 | ON_CALL(*this, bindMount(_, _)) |
| 74 | .WillByDefault(Return( |
| 75 | binder::Status::fromExceptionCode(1, String8("failed to bind-mount")))); |
| 76 | } |
| 77 | void bindMountSuccess() { |
| 78 | ON_CALL(*this, bindMount(_, _)).WillByDefault(Return(binder::Status::ok())); |
| 79 | } |
Alex Buynytskyy | 5e860ba | 2020-03-31 15:30:21 -0700 | [diff] [blame] | 80 | void setIncFsMountOptionsFails() const { |
| 81 | ON_CALL(*this, setIncFsMountOptions(_, _)) |
| 82 | .WillByDefault( |
| 83 | Return(binder::Status::fromExceptionCode(1, String8("failed to set options")))); |
| 84 | } |
| 85 | void setIncFsMountOptionsSuccess() { |
| 86 | ON_CALL(*this, setIncFsMountOptions(_, _)).WillByDefault(Return(binder::Status::ok())); |
| 87 | } |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 88 | binder::Status getInvalidControlParcel(const std::string& imagePath, |
| 89 | const std::string& targetDir, int32_t flags, |
| 90 | IncrementalFileSystemControlParcel* _aidl_return) { |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 91 | _aidl_return = {}; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 92 | return binder::Status::ok(); |
| 93 | } |
| 94 | binder::Status incFsSuccess(const std::string& imagePath, const std::string& targetDir, |
| 95 | int32_t flags, IncrementalFileSystemControlParcel* _aidl_return) { |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 96 | _aidl_return->pendingReads.reset(base::unique_fd(dup(STDIN_FILENO))); |
| 97 | _aidl_return->cmd.reset(base::unique_fd(dup(STDIN_FILENO))); |
| 98 | _aidl_return->log.reset(base::unique_fd(dup(STDIN_FILENO))); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 99 | return binder::Status::ok(); |
| 100 | } |
| 101 | |
| 102 | private: |
| 103 | TemporaryFile cmdFile; |
| 104 | TemporaryFile logFile; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 105 | }; |
| 106 | |
Alex Buynytskyy | 0b20266 | 2020-04-13 09:53:04 -0700 | [diff] [blame] | 107 | class MockDataLoader : public IDataLoader { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 108 | public: |
Alex Buynytskyy | 0b20266 | 2020-04-13 09:53:04 -0700 | [diff] [blame] | 109 | MockDataLoader() { |
Alex Buynytskyy | ab65cb1 | 2020-04-17 10:01:47 -0700 | [diff] [blame] | 110 | ON_CALL(*this, create(_, _, _, _)).WillByDefault(Invoke(this, &MockDataLoader::createOk)); |
| 111 | ON_CALL(*this, start(_)).WillByDefault(Invoke(this, &MockDataLoader::startOk)); |
| 112 | ON_CALL(*this, stop(_)).WillByDefault(Invoke(this, &MockDataLoader::stopOk)); |
| 113 | ON_CALL(*this, destroy(_)).WillByDefault(Invoke(this, &MockDataLoader::destroyOk)); |
| 114 | ON_CALL(*this, prepareImage(_, _, _)) |
| 115 | .WillByDefault(Invoke(this, &MockDataLoader::prepareImageOk)); |
Alex Buynytskyy | 0b20266 | 2020-04-13 09:53:04 -0700 | [diff] [blame] | 116 | } |
Songchun Fan | 68645c4 | 2020-02-27 15:57:35 -0800 | [diff] [blame] | 117 | IBinder* onAsBinder() override { return nullptr; } |
Alex Buynytskyy | 0b20266 | 2020-04-13 09:53:04 -0700 | [diff] [blame] | 118 | MOCK_METHOD4(create, |
| 119 | binder::Status(int32_t id, const DataLoaderParamsParcel& params, |
| 120 | const FileSystemControlParcel& control, |
| 121 | const sp<IDataLoaderStatusListener>& listener)); |
| 122 | MOCK_METHOD1(start, binder::Status(int32_t id)); |
| 123 | MOCK_METHOD1(stop, binder::Status(int32_t id)); |
| 124 | MOCK_METHOD1(destroy, binder::Status(int32_t id)); |
| 125 | MOCK_METHOD3(prepareImage, |
| 126 | binder::Status(int32_t id, const std::vector<InstallationFileParcel>& addedFiles, |
| 127 | const std::vector<std::string>& removedFiles)); |
Alex Buynytskyy | ab65cb1 | 2020-04-17 10:01:47 -0700 | [diff] [blame] | 128 | |
| 129 | void initializeCreateOkNoStatus() { |
| 130 | ON_CALL(*this, create(_, _, _, _)) |
| 131 | .WillByDefault(Invoke(this, &MockDataLoader::createOkNoStatus)); |
| 132 | } |
| 133 | |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 134 | binder::Status createOk(int32_t id, const content::pm::DataLoaderParamsParcel& params, |
| 135 | const content::pm::FileSystemControlParcel& control, |
Alex Buynytskyy | ab65cb1 | 2020-04-17 10:01:47 -0700 | [diff] [blame] | 136 | const sp<content::pm::IDataLoaderStatusListener>& listener) { |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 137 | createOkNoStatus(id, params, control, listener); |
Alex Buynytskyy | ab65cb1 | 2020-04-17 10:01:47 -0700 | [diff] [blame] | 138 | if (mListener) { |
| 139 | mListener->onStatusChanged(id, IDataLoaderStatusListener::DATA_LOADER_CREATED); |
| 140 | } |
| 141 | return binder::Status::ok(); |
| 142 | } |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 143 | binder::Status createOkNoStatus(int32_t id, const content::pm::DataLoaderParamsParcel& params, |
| 144 | const content::pm::FileSystemControlParcel& control, |
Alex Buynytskyy | ab65cb1 | 2020-04-17 10:01:47 -0700 | [diff] [blame] | 145 | const sp<content::pm::IDataLoaderStatusListener>& listener) { |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 146 | mServiceConnector = control.service; |
Alex Buynytskyy | ab65cb1 | 2020-04-17 10:01:47 -0700 | [diff] [blame] | 147 | mListener = listener; |
| 148 | return binder::Status::ok(); |
| 149 | } |
| 150 | binder::Status startOk(int32_t id) { |
| 151 | if (mListener) { |
| 152 | mListener->onStatusChanged(id, IDataLoaderStatusListener::DATA_LOADER_STARTED); |
| 153 | } |
| 154 | return binder::Status::ok(); |
| 155 | } |
| 156 | binder::Status stopOk(int32_t id) { |
| 157 | if (mListener) { |
| 158 | mListener->onStatusChanged(id, IDataLoaderStatusListener::DATA_LOADER_STOPPED); |
| 159 | } |
| 160 | return binder::Status::ok(); |
| 161 | } |
| 162 | binder::Status destroyOk(int32_t id) { |
| 163 | if (mListener) { |
| 164 | mListener->onStatusChanged(id, IDataLoaderStatusListener::DATA_LOADER_DESTROYED); |
| 165 | } |
| 166 | mListener = nullptr; |
| 167 | return binder::Status::ok(); |
| 168 | } |
| 169 | binder::Status prepareImageOk(int32_t id, |
| 170 | const ::std::vector<content::pm::InstallationFileParcel>&, |
| 171 | const ::std::vector<::std::string>&) { |
| 172 | if (mListener) { |
| 173 | mListener->onStatusChanged(id, IDataLoaderStatusListener::DATA_LOADER_IMAGE_READY); |
| 174 | } |
| 175 | return binder::Status::ok(); |
| 176 | } |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 177 | int32_t setStorageParams(bool enableReadLogs) { |
| 178 | int32_t result = -1; |
| 179 | EXPECT_NE(mServiceConnector.get(), nullptr); |
| 180 | EXPECT_TRUE(mServiceConnector->setStorageParams(enableReadLogs, &result).isOk()); |
| 181 | return result; |
| 182 | } |
Alex Buynytskyy | ab65cb1 | 2020-04-17 10:01:47 -0700 | [diff] [blame] | 183 | |
| 184 | private: |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 185 | sp<IIncrementalServiceConnector> mServiceConnector; |
Alex Buynytskyy | ab65cb1 | 2020-04-17 10:01:47 -0700 | [diff] [blame] | 186 | sp<IDataLoaderStatusListener> mListener; |
Songchun Fan | 68645c4 | 2020-02-27 15:57:35 -0800 | [diff] [blame] | 187 | }; |
| 188 | |
| 189 | class MockDataLoaderManager : public DataLoaderManagerWrapper { |
| 190 | public: |
Alex Buynytskyy | 0b20266 | 2020-04-13 09:53:04 -0700 | [diff] [blame] | 191 | MockDataLoaderManager(sp<IDataLoader> dataLoader) : mDataLoaderHolder(std::move(dataLoader)) { |
| 192 | EXPECT_TRUE(mDataLoaderHolder != nullptr); |
| 193 | } |
| 194 | |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 195 | MOCK_CONST_METHOD4(bindToDataLoader, |
Songchun Fan | 68645c4 | 2020-02-27 15:57:35 -0800 | [diff] [blame] | 196 | binder::Status(int32_t mountId, const DataLoaderParamsParcel& params, |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 197 | const sp<IDataLoaderStatusListener>& listener, |
| 198 | bool* _aidl_return)); |
Songchun Fan | 68645c4 | 2020-02-27 15:57:35 -0800 | [diff] [blame] | 199 | MOCK_CONST_METHOD2(getDataLoader, |
| 200 | binder::Status(int32_t mountId, sp<IDataLoader>* _aidl_return)); |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 201 | MOCK_CONST_METHOD1(unbindFromDataLoader, binder::Status(int32_t mountId)); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 202 | |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 203 | void bindToDataLoaderSuccess() { |
| 204 | ON_CALL(*this, bindToDataLoader(_, _, _, _)) |
| 205 | .WillByDefault(Invoke(this, &MockDataLoaderManager::bindToDataLoaderOk)); |
Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 206 | } |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 207 | void bindToDataLoaderFails() { |
| 208 | ON_CALL(*this, bindToDataLoader(_, _, _, _)) |
Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 209 | .WillByDefault(Return( |
| 210 | (binder::Status::fromExceptionCode(1, String8("failed to prepare"))))); |
| 211 | } |
| 212 | void getDataLoaderSuccess() { |
| 213 | ON_CALL(*this, getDataLoader(_, _)) |
| 214 | .WillByDefault(Invoke(this, &MockDataLoaderManager::getDataLoaderOk)); |
| 215 | } |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 216 | void unbindFromDataLoaderSuccess() { |
| 217 | ON_CALL(*this, unbindFromDataLoader(_)) |
| 218 | .WillByDefault(Invoke(this, &MockDataLoaderManager::unbindFromDataLoaderOk)); |
Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 219 | } |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 220 | binder::Status bindToDataLoaderOk(int32_t mountId, const DataLoaderParamsParcel& params, |
| 221 | const sp<IDataLoaderStatusListener>& listener, |
| 222 | bool* _aidl_return) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 223 | mId = mountId; |
| 224 | mListener = listener; |
Alex Buynytskyy | 0b20266 | 2020-04-13 09:53:04 -0700 | [diff] [blame] | 225 | mDataLoader = mDataLoaderHolder; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 226 | *_aidl_return = true; |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 227 | if (mListener) { |
| 228 | mListener->onStatusChanged(mId, IDataLoaderStatusListener::DATA_LOADER_BOUND); |
| 229 | } |
| 230 | return binder::Status::ok(); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 231 | } |
Songchun Fan | 68645c4 | 2020-02-27 15:57:35 -0800 | [diff] [blame] | 232 | binder::Status getDataLoaderOk(int32_t mountId, sp<IDataLoader>* _aidl_return) { |
| 233 | *_aidl_return = mDataLoader; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 234 | return binder::Status::ok(); |
| 235 | } |
Alex Buynytskyy | 0b20266 | 2020-04-13 09:53:04 -0700 | [diff] [blame] | 236 | void setDataLoaderStatusCreated() { |
Alex Buynytskyy | 1ecfcec | 2019-12-17 12:10:41 -0800 | [diff] [blame] | 237 | mListener->onStatusChanged(mId, IDataLoaderStatusListener::DATA_LOADER_CREATED); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 238 | } |
Alex Buynytskyy | 0b20266 | 2020-04-13 09:53:04 -0700 | [diff] [blame] | 239 | void setDataLoaderStatusStarted() { |
| 240 | mListener->onStatusChanged(mId, IDataLoaderStatusListener::DATA_LOADER_STARTED); |
| 241 | } |
| 242 | void setDataLoaderStatusDestroyed() { |
| 243 | mListener->onStatusChanged(mId, IDataLoaderStatusListener::DATA_LOADER_DESTROYED); |
| 244 | } |
Alex Buynytskyy | cca2c11 | 2020-05-05 12:48:41 -0700 | [diff] [blame] | 245 | void setDataLoaderStatusUnavailable() { |
| 246 | mListener->onStatusChanged(mId, IDataLoaderStatusListener::DATA_LOADER_UNAVAILABLE); |
| 247 | } |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 248 | binder::Status unbindFromDataLoaderOk(int32_t id) { |
Alex Buynytskyy | 0b20266 | 2020-04-13 09:53:04 -0700 | [diff] [blame] | 249 | if (mDataLoader) { |
| 250 | if (auto status = mDataLoader->destroy(id); !status.isOk()) { |
| 251 | return status; |
| 252 | } |
| 253 | mDataLoader = nullptr; |
| 254 | } |
Alex Buynytskyy | 0ea4ff4 | 2020-04-09 17:25:42 -0700 | [diff] [blame] | 255 | if (mListener) { |
| 256 | mListener->onStatusChanged(id, IDataLoaderStatusListener::DATA_LOADER_DESTROYED); |
| 257 | } |
| 258 | return binder::Status::ok(); |
| 259 | } |
Alex Buynytskyy | 0a646ca | 2020-04-08 12:18:01 -0700 | [diff] [blame] | 260 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 261 | private: |
| 262 | int mId; |
| 263 | sp<IDataLoaderStatusListener> mListener; |
Alex Buynytskyy | 0b20266 | 2020-04-13 09:53:04 -0700 | [diff] [blame] | 264 | sp<IDataLoader> mDataLoader; |
| 265 | sp<IDataLoader> mDataLoaderHolder; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 266 | }; |
| 267 | |
| 268 | class MockIncFs : public IncFsWrapper { |
| 269 | public: |
Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 270 | MOCK_CONST_METHOD1(listExistingMounts, void(const ExistingMountCallback& cb)); |
| 271 | MOCK_CONST_METHOD1(openMount, Control(std::string_view path)); |
Songchun Fan | 20d6ef2 | 2020-03-03 09:47:15 -0800 | [diff] [blame] | 272 | MOCK_CONST_METHOD3(createControl, Control(IncFsFd cmd, IncFsFd pendingReads, IncFsFd logs)); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 273 | MOCK_CONST_METHOD5(makeFile, |
Songchun Fan | 20d6ef2 | 2020-03-03 09:47:15 -0800 | [diff] [blame] | 274 | ErrorCode(const Control& control, std::string_view path, int mode, FileId id, |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 275 | NewFileParams params)); |
Songchun Fan | 20d6ef2 | 2020-03-03 09:47:15 -0800 | [diff] [blame] | 276 | MOCK_CONST_METHOD3(makeDir, ErrorCode(const Control& control, std::string_view path, int mode)); |
Yurii Zubrytskyi | efebb45 | 2020-04-22 13:59:06 -0700 | [diff] [blame] | 277 | MOCK_CONST_METHOD3(makeDirs, |
| 278 | ErrorCode(const Control& control, std::string_view path, int mode)); |
Songchun Fan | 20d6ef2 | 2020-03-03 09:47:15 -0800 | [diff] [blame] | 279 | MOCK_CONST_METHOD2(getMetadata, RawMetadata(const Control& control, FileId fileid)); |
| 280 | MOCK_CONST_METHOD2(getMetadata, RawMetadata(const Control& control, std::string_view path)); |
| 281 | MOCK_CONST_METHOD2(getFileId, FileId(const Control& control, std::string_view path)); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 282 | MOCK_CONST_METHOD3(link, |
Songchun Fan | 20d6ef2 | 2020-03-03 09:47:15 -0800 | [diff] [blame] | 283 | ErrorCode(const Control& control, std::string_view from, std::string_view to)); |
| 284 | MOCK_CONST_METHOD2(unlink, ErrorCode(const Control& control, std::string_view path)); |
Yurii Zubrytskyi | e82cdd7 | 2020-04-01 12:19:26 -0700 | [diff] [blame] | 285 | MOCK_CONST_METHOD2(openForSpecialOps, base::unique_fd(const Control& control, FileId id)); |
Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 286 | MOCK_CONST_METHOD1(writeBlocks, ErrorCode(std::span<const DataBlock> blocks)); |
| 287 | |
| 288 | MockIncFs() { ON_CALL(*this, listExistingMounts(_)).WillByDefault(Return()); } |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 289 | |
| 290 | void makeFileFails() { ON_CALL(*this, makeFile(_, _, _, _, _)).WillByDefault(Return(-1)); } |
| 291 | void makeFileSuccess() { ON_CALL(*this, makeFile(_, _, _, _, _)).WillByDefault(Return(0)); } |
Alex Buynytskyy | cca2c11 | 2020-05-05 12:48:41 -0700 | [diff] [blame] | 292 | void openMountSuccess() { |
| 293 | ON_CALL(*this, openMount(_)).WillByDefault(Invoke(this, &MockIncFs::openMountForHealth)); |
| 294 | } |
| 295 | |
| 296 | static constexpr auto kPendingReadsFd = 42; |
| 297 | Control openMountForHealth(std::string_view) { |
| 298 | return UniqueControl(IncFs_CreateControl(-1, kPendingReadsFd, -1)); |
| 299 | } |
Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 300 | |
Songchun Fan | 20d6ef2 | 2020-03-03 09:47:15 -0800 | [diff] [blame] | 301 | RawMetadata getMountInfoMetadata(const Control& control, std::string_view path) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 302 | metadata::Mount m; |
| 303 | m.mutable_storage()->set_id(100); |
| 304 | m.mutable_loader()->set_package_name("com.test"); |
| 305 | m.mutable_loader()->set_arguments("com.uri"); |
| 306 | const auto metadata = m.SerializeAsString(); |
| 307 | m.mutable_loader()->release_arguments(); |
| 308 | m.mutable_loader()->release_package_name(); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 309 | return {metadata.begin(), metadata.end()}; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 310 | } |
Songchun Fan | 20d6ef2 | 2020-03-03 09:47:15 -0800 | [diff] [blame] | 311 | RawMetadata getStorageMetadata(const Control& control, std::string_view path) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 312 | metadata::Storage st; |
| 313 | st.set_id(100); |
| 314 | auto metadata = st.SerializeAsString(); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 315 | return {metadata.begin(), metadata.end()}; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 316 | } |
Songchun Fan | 20d6ef2 | 2020-03-03 09:47:15 -0800 | [diff] [blame] | 317 | RawMetadata getBindPointMetadata(const Control& control, std::string_view path) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 318 | metadata::BindPoint bp; |
| 319 | std::string destPath = "dest"; |
| 320 | std::string srcPath = "src"; |
| 321 | bp.set_storage_id(100); |
| 322 | bp.set_allocated_dest_path(&destPath); |
| 323 | bp.set_allocated_source_subdir(&srcPath); |
| 324 | const auto metadata = bp.SerializeAsString(); |
| 325 | bp.release_source_subdir(); |
| 326 | bp.release_dest_path(); |
| 327 | return std::vector<char>(metadata.begin(), metadata.end()); |
| 328 | } |
| 329 | }; |
| 330 | |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 331 | class MockAppOpsManager : public AppOpsManagerWrapper { |
Alex Buynytskyy | 1d89216 | 2020-04-03 23:00:19 -0700 | [diff] [blame] | 332 | public: |
| 333 | MOCK_CONST_METHOD3(checkPermission, binder::Status(const char*, const char*, const char*)); |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 334 | MOCK_METHOD3(startWatchingMode, void(int32_t, const String16&, const sp<IAppOpsCallback>&)); |
Alex Buynytskyy | 1d89216 | 2020-04-03 23:00:19 -0700 | [diff] [blame] | 335 | MOCK_METHOD1(stopWatchingMode, void(const sp<IAppOpsCallback>&)); |
| 336 | |
| 337 | void checkPermissionSuccess() { |
| 338 | ON_CALL(*this, checkPermission(_, _, _)).WillByDefault(Return(android::incremental::Ok())); |
| 339 | } |
| 340 | void checkPermissionFails() { |
| 341 | ON_CALL(*this, checkPermission(_, _, _)) |
| 342 | .WillByDefault( |
| 343 | Return(android::incremental::Exception(binder::Status::EX_SECURITY, {}))); |
| 344 | } |
| 345 | void initializeStartWatchingMode() { |
| 346 | ON_CALL(*this, startWatchingMode(_, _, _)) |
| 347 | .WillByDefault(Invoke(this, &MockAppOpsManager::storeCallback)); |
| 348 | } |
| 349 | void storeCallback(int32_t, const String16&, const sp<IAppOpsCallback>& cb) { |
| 350 | mStoredCallback = cb; |
| 351 | } |
| 352 | |
| 353 | sp<IAppOpsCallback> mStoredCallback; |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 354 | }; |
| 355 | |
Yurii Zubrytskyi | 8632140 | 2020-04-09 19:22:30 -0700 | [diff] [blame] | 356 | class MockJniWrapper : public JniWrapper { |
| 357 | public: |
| 358 | MOCK_CONST_METHOD0(initializeForCurrentThread, void()); |
| 359 | |
Alex Buynytskyy | cca2c11 | 2020-05-05 12:48:41 -0700 | [diff] [blame] | 360 | MockJniWrapper() { EXPECT_CALL(*this, initializeForCurrentThread()).Times(2); } |
| 361 | }; |
| 362 | |
| 363 | class MockLooperWrapper : public LooperWrapper { |
| 364 | public: |
| 365 | MOCK_METHOD5(addFd, int(int, int, int, android::Looper_callbackFunc, void*)); |
| 366 | MOCK_METHOD1(removeFd, int(int)); |
| 367 | MOCK_METHOD0(wake, void()); |
| 368 | MOCK_METHOD1(pollAll, int(int)); |
| 369 | |
| 370 | MockLooperWrapper() { |
| 371 | ON_CALL(*this, addFd(_, _, _, _, _)) |
| 372 | .WillByDefault(Invoke(this, &MockLooperWrapper::storeCallback)); |
| 373 | ON_CALL(*this, removeFd(_)).WillByDefault(Invoke(this, &MockLooperWrapper::clearCallback)); |
| 374 | ON_CALL(*this, pollAll(_)).WillByDefault(Invoke(this, &MockLooperWrapper::sleepFor)); |
| 375 | } |
| 376 | |
| 377 | int storeCallback(int, int, int, android::Looper_callbackFunc callback, void* data) { |
| 378 | mCallback = callback; |
| 379 | mCallbackData = data; |
| 380 | return 0; |
| 381 | } |
| 382 | |
| 383 | int clearCallback(int) { |
| 384 | mCallback = nullptr; |
| 385 | mCallbackData = nullptr; |
| 386 | return 0; |
| 387 | } |
| 388 | |
| 389 | int sleepFor(int timeoutMillis) { |
| 390 | std::this_thread::sleep_for(std::chrono::milliseconds(timeoutMillis)); |
| 391 | return 0; |
| 392 | } |
| 393 | |
| 394 | android::Looper_callbackFunc mCallback = nullptr; |
| 395 | void* mCallbackData = nullptr; |
Yurii Zubrytskyi | 8632140 | 2020-04-09 19:22:30 -0700 | [diff] [blame] | 396 | }; |
| 397 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 398 | class MockServiceManager : public ServiceManagerWrapper { |
| 399 | public: |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 400 | MockServiceManager(std::unique_ptr<MockVoldService> vold, |
Yurii Zubrytskyi | 8632140 | 2020-04-09 19:22:30 -0700 | [diff] [blame] | 401 | std::unique_ptr<MockDataLoaderManager> dataLoaderManager, |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 402 | std::unique_ptr<MockIncFs> incfs, |
Yurii Zubrytskyi | 8632140 | 2020-04-09 19:22:30 -0700 | [diff] [blame] | 403 | std::unique_ptr<MockAppOpsManager> appOpsManager, |
Alex Buynytskyy | cca2c11 | 2020-05-05 12:48:41 -0700 | [diff] [blame] | 404 | std::unique_ptr<MockJniWrapper> jni, |
| 405 | std::unique_ptr<MockLooperWrapper> looper) |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 406 | : mVold(std::move(vold)), |
Yurii Zubrytskyi | 8632140 | 2020-04-09 19:22:30 -0700 | [diff] [blame] | 407 | mDataLoaderManager(std::move(dataLoaderManager)), |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 408 | mIncFs(std::move(incfs)), |
Yurii Zubrytskyi | 8632140 | 2020-04-09 19:22:30 -0700 | [diff] [blame] | 409 | mAppOpsManager(std::move(appOpsManager)), |
Alex Buynytskyy | cca2c11 | 2020-05-05 12:48:41 -0700 | [diff] [blame] | 410 | mJni(std::move(jni)), |
| 411 | mLooper(std::move(looper)) {} |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 412 | std::unique_ptr<VoldServiceWrapper> getVoldService() final { return std::move(mVold); } |
Songchun Fan | 68645c4 | 2020-02-27 15:57:35 -0800 | [diff] [blame] | 413 | std::unique_ptr<DataLoaderManagerWrapper> getDataLoaderManager() final { |
| 414 | return std::move(mDataLoaderManager); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 415 | } |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 416 | std::unique_ptr<IncFsWrapper> getIncFs() final { return std::move(mIncFs); } |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 417 | std::unique_ptr<AppOpsManagerWrapper> getAppOpsManager() final { return std::move(mAppOpsManager); } |
Yurii Zubrytskyi | 8632140 | 2020-04-09 19:22:30 -0700 | [diff] [blame] | 418 | std::unique_ptr<JniWrapper> getJni() final { return std::move(mJni); } |
Alex Buynytskyy | cca2c11 | 2020-05-05 12:48:41 -0700 | [diff] [blame] | 419 | std::unique_ptr<LooperWrapper> getLooper() final { return std::move(mLooper); } |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 420 | |
| 421 | private: |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 422 | std::unique_ptr<MockVoldService> mVold; |
Songchun Fan | 68645c4 | 2020-02-27 15:57:35 -0800 | [diff] [blame] | 423 | std::unique_ptr<MockDataLoaderManager> mDataLoaderManager; |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 424 | std::unique_ptr<MockIncFs> mIncFs; |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 425 | std::unique_ptr<MockAppOpsManager> mAppOpsManager; |
Yurii Zubrytskyi | 8632140 | 2020-04-09 19:22:30 -0700 | [diff] [blame] | 426 | std::unique_ptr<MockJniWrapper> mJni; |
Alex Buynytskyy | cca2c11 | 2020-05-05 12:48:41 -0700 | [diff] [blame] | 427 | std::unique_ptr<MockLooperWrapper> mLooper; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 428 | }; |
| 429 | |
| 430 | // --- IncrementalServiceTest --- |
| 431 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 432 | class IncrementalServiceTest : public testing::Test { |
| 433 | public: |
| 434 | void SetUp() override { |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 435 | auto vold = std::make_unique<NiceMock<MockVoldService>>(); |
| 436 | mVold = vold.get(); |
Alex Buynytskyy | 0b20266 | 2020-04-13 09:53:04 -0700 | [diff] [blame] | 437 | sp<NiceMock<MockDataLoader>> dataLoader{new NiceMock<MockDataLoader>}; |
| 438 | mDataLoader = dataLoader.get(); |
| 439 | auto dataloaderManager = std::make_unique<NiceMock<MockDataLoaderManager>>(dataLoader); |
Songchun Fan | 68645c4 | 2020-02-27 15:57:35 -0800 | [diff] [blame] | 440 | mDataLoaderManager = dataloaderManager.get(); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 441 | auto incFs = std::make_unique<NiceMock<MockIncFs>>(); |
| 442 | mIncFs = incFs.get(); |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 443 | auto appOps = std::make_unique<NiceMock<MockAppOpsManager>>(); |
| 444 | mAppOpsManager = appOps.get(); |
Yurii Zubrytskyi | 8632140 | 2020-04-09 19:22:30 -0700 | [diff] [blame] | 445 | auto jni = std::make_unique<NiceMock<MockJniWrapper>>(); |
| 446 | mJni = jni.get(); |
Alex Buynytskyy | cca2c11 | 2020-05-05 12:48:41 -0700 | [diff] [blame] | 447 | auto looper = std::make_unique<NiceMock<MockLooperWrapper>>(); |
| 448 | mLooper = looper.get(); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 449 | mIncrementalService = |
| 450 | std::make_unique<IncrementalService>(MockServiceManager(std::move(vold), |
Yurii Zubrytskyi | 8632140 | 2020-04-09 19:22:30 -0700 | [diff] [blame] | 451 | std::move( |
| 452 | dataloaderManager), |
Alex Buynytskyy | 96e350b | 2020-04-02 20:03:47 -0700 | [diff] [blame] | 453 | std::move(incFs), |
Yurii Zubrytskyi | 8632140 | 2020-04-09 19:22:30 -0700 | [diff] [blame] | 454 | std::move(appOps), |
Alex Buynytskyy | cca2c11 | 2020-05-05 12:48:41 -0700 | [diff] [blame] | 455 | std::move(jni), |
| 456 | std::move(looper)), |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 457 | mRootDir.path); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 458 | mDataLoaderParcel.packageName = "com.test"; |
Alex Buynytskyy | 1ecfcec | 2019-12-17 12:10:41 -0800 | [diff] [blame] | 459 | mDataLoaderParcel.arguments = "uri"; |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 460 | mDataLoaderManager->unbindFromDataLoaderSuccess(); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 461 | mIncrementalService->onSystemReady(); |
| 462 | } |
| 463 | |
| 464 | void setUpExistingMountDir(const std::string& rootDir) { |
| 465 | const auto dir = rootDir + "/dir1"; |
| 466 | const auto mountDir = dir + "/mount"; |
| 467 | const auto backingDir = dir + "/backing_store"; |
| 468 | const auto storageDir = mountDir + "/st0"; |
| 469 | ASSERT_EQ(0, mkdir(dir.c_str(), 0755)); |
| 470 | ASSERT_EQ(0, mkdir(mountDir.c_str(), 0755)); |
| 471 | ASSERT_EQ(0, mkdir(backingDir.c_str(), 0755)); |
| 472 | ASSERT_EQ(0, mkdir(storageDir.c_str(), 0755)); |
| 473 | const auto mountInfoFile = rootDir + "/dir1/mount/.info"; |
| 474 | const auto mountPointsFile = rootDir + "/dir1/mount/.mountpoint.abcd"; |
| 475 | ASSERT_TRUE(base::WriteStringToFile("info", mountInfoFile)); |
| 476 | ASSERT_TRUE(base::WriteStringToFile("mounts", mountPointsFile)); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 477 | ON_CALL(*mIncFs, getMetadata(_, std::string_view(mountInfoFile))) |
| 478 | .WillByDefault(Invoke(mIncFs, &MockIncFs::getMountInfoMetadata)); |
| 479 | ON_CALL(*mIncFs, getMetadata(_, std::string_view(mountPointsFile))) |
| 480 | .WillByDefault(Invoke(mIncFs, &MockIncFs::getBindPointMetadata)); |
| 481 | ON_CALL(*mIncFs, getMetadata(_, std::string_view(rootDir + "/dir1/mount/st0"))) |
| 482 | .WillByDefault(Invoke(mIncFs, &MockIncFs::getStorageMetadata)); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | protected: |
Alex Buynytskyy | cca2c11 | 2020-05-05 12:48:41 -0700 | [diff] [blame] | 486 | NiceMock<MockVoldService>* mVold = nullptr; |
| 487 | NiceMock<MockIncFs>* mIncFs = nullptr; |
| 488 | NiceMock<MockDataLoaderManager>* mDataLoaderManager = nullptr; |
| 489 | NiceMock<MockAppOpsManager>* mAppOpsManager = nullptr; |
| 490 | NiceMock<MockJniWrapper>* mJni = nullptr; |
| 491 | NiceMock<MockLooperWrapper>* mLooper = nullptr; |
| 492 | NiceMock<MockDataLoader>* mDataLoader = nullptr; |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 493 | std::unique_ptr<IncrementalService> mIncrementalService; |
| 494 | TemporaryDir mRootDir; |
| 495 | DataLoaderParamsParcel mDataLoaderParcel; |
| 496 | }; |
| 497 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 498 | TEST_F(IncrementalServiceTest, testCreateStorageMountIncFsFails) { |
| 499 | mVold->mountIncFsFails(); |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 500 | EXPECT_CALL(*mDataLoaderManager, bindToDataLoader(_, _, _, _)).Times(0); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 501 | TemporaryDir tempDir; |
| 502 | int storageId = |
Alex Buynytskyy | 04f7391 | 2020-02-10 08:34:18 -0800 | [diff] [blame] | 503 | mIncrementalService->createStorage(tempDir.path, std::move(mDataLoaderParcel), {}, |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 504 | IncrementalService::CreateOptions::CreateNew); |
| 505 | ASSERT_LT(storageId, 0); |
| 506 | } |
| 507 | |
| 508 | TEST_F(IncrementalServiceTest, testCreateStorageMountIncFsInvalidControlParcel) { |
| 509 | mVold->mountIncFsInvalidControlParcel(); |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 510 | EXPECT_CALL(*mDataLoaderManager, bindToDataLoader(_, _, _, _)).Times(0); |
| 511 | EXPECT_CALL(*mDataLoaderManager, unbindFromDataLoader(_)).Times(0); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 512 | TemporaryDir tempDir; |
| 513 | int storageId = |
Alex Buynytskyy | 04f7391 | 2020-02-10 08:34:18 -0800 | [diff] [blame] | 514 | mIncrementalService->createStorage(tempDir.path, std::move(mDataLoaderParcel), {}, |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 515 | IncrementalService::CreateOptions::CreateNew); |
| 516 | ASSERT_LT(storageId, 0); |
| 517 | } |
| 518 | |
| 519 | TEST_F(IncrementalServiceTest, testCreateStorageMakeFileFails) { |
| 520 | mVold->mountIncFsSuccess(); |
| 521 | mIncFs->makeFileFails(); |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 522 | EXPECT_CALL(*mDataLoaderManager, bindToDataLoader(_, _, _, _)).Times(0); |
| 523 | EXPECT_CALL(*mDataLoaderManager, unbindFromDataLoader(_)).Times(0); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 524 | EXPECT_CALL(*mVold, unmountIncFs(_)); |
| 525 | TemporaryDir tempDir; |
| 526 | int storageId = |
Alex Buynytskyy | 04f7391 | 2020-02-10 08:34:18 -0800 | [diff] [blame] | 527 | mIncrementalService->createStorage(tempDir.path, std::move(mDataLoaderParcel), {}, |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 528 | IncrementalService::CreateOptions::CreateNew); |
| 529 | ASSERT_LT(storageId, 0); |
| 530 | } |
| 531 | |
| 532 | TEST_F(IncrementalServiceTest, testCreateStorageBindMountFails) { |
| 533 | mVold->mountIncFsSuccess(); |
| 534 | mIncFs->makeFileSuccess(); |
| 535 | mVold->bindMountFails(); |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 536 | EXPECT_CALL(*mDataLoaderManager, bindToDataLoader(_, _, _, _)).Times(0); |
| 537 | EXPECT_CALL(*mDataLoaderManager, unbindFromDataLoader(_)).Times(0); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 538 | EXPECT_CALL(*mVold, unmountIncFs(_)); |
| 539 | TemporaryDir tempDir; |
| 540 | int storageId = |
Alex Buynytskyy | 04f7391 | 2020-02-10 08:34:18 -0800 | [diff] [blame] | 541 | mIncrementalService->createStorage(tempDir.path, std::move(mDataLoaderParcel), {}, |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 542 | IncrementalService::CreateOptions::CreateNew); |
| 543 | ASSERT_LT(storageId, 0); |
| 544 | } |
| 545 | |
| 546 | TEST_F(IncrementalServiceTest, testCreateStoragePrepareDataLoaderFails) { |
| 547 | mVold->mountIncFsSuccess(); |
| 548 | mIncFs->makeFileSuccess(); |
| 549 | mVold->bindMountSuccess(); |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 550 | mDataLoaderManager->bindToDataLoaderFails(); |
| 551 | EXPECT_CALL(*mDataLoaderManager, bindToDataLoader(_, _, _, _)).Times(1); |
| 552 | EXPECT_CALL(*mDataLoaderManager, unbindFromDataLoader(_)).Times(0); |
Alex Buynytskyy | 0b20266 | 2020-04-13 09:53:04 -0700 | [diff] [blame] | 553 | EXPECT_CALL(*mDataLoader, create(_, _, _, _)).Times(0); |
| 554 | EXPECT_CALL(*mDataLoader, start(_)).Times(0); |
| 555 | EXPECT_CALL(*mDataLoader, destroy(_)).Times(0); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 556 | EXPECT_CALL(*mVold, unmountIncFs(_)).Times(2); |
| 557 | TemporaryDir tempDir; |
| 558 | int storageId = |
Alex Buynytskyy | 04f7391 | 2020-02-10 08:34:18 -0800 | [diff] [blame] | 559 | mIncrementalService->createStorage(tempDir.path, std::move(mDataLoaderParcel), {}, |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 560 | IncrementalService::CreateOptions::CreateNew); |
| 561 | ASSERT_LT(storageId, 0); |
| 562 | } |
| 563 | |
| 564 | TEST_F(IncrementalServiceTest, testDeleteStorageSuccess) { |
| 565 | mVold->mountIncFsSuccess(); |
| 566 | mIncFs->makeFileSuccess(); |
| 567 | mVold->bindMountSuccess(); |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 568 | mDataLoaderManager->bindToDataLoaderSuccess(); |
| 569 | mDataLoaderManager->getDataLoaderSuccess(); |
| 570 | EXPECT_CALL(*mDataLoaderManager, bindToDataLoader(_, _, _, _)).Times(1); |
| 571 | EXPECT_CALL(*mDataLoaderManager, unbindFromDataLoader(_)).Times(1); |
Alex Buynytskyy | 0b20266 | 2020-04-13 09:53:04 -0700 | [diff] [blame] | 572 | EXPECT_CALL(*mDataLoader, create(_, _, _, _)).Times(1); |
| 573 | EXPECT_CALL(*mDataLoader, start(_)).Times(0); |
| 574 | EXPECT_CALL(*mDataLoader, destroy(_)).Times(1); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 575 | EXPECT_CALL(*mVold, unmountIncFs(_)).Times(2); |
| 576 | TemporaryDir tempDir; |
| 577 | int storageId = |
Alex Buynytskyy | 04f7391 | 2020-02-10 08:34:18 -0800 | [diff] [blame] | 578 | mIncrementalService->createStorage(tempDir.path, std::move(mDataLoaderParcel), {}, |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 579 | IncrementalService::CreateOptions::CreateNew); |
| 580 | ASSERT_GE(storageId, 0); |
| 581 | mIncrementalService->deleteStorage(storageId); |
| 582 | } |
| 583 | |
Alex Buynytskyy | 0b20266 | 2020-04-13 09:53:04 -0700 | [diff] [blame] | 584 | TEST_F(IncrementalServiceTest, testDataLoaderDestroyed) { |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 585 | mVold->mountIncFsSuccess(); |
| 586 | mIncFs->makeFileSuccess(); |
| 587 | mVold->bindMountSuccess(); |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 588 | mDataLoaderManager->bindToDataLoaderSuccess(); |
Songchun Fan | 68645c4 | 2020-02-27 15:57:35 -0800 | [diff] [blame] | 589 | mDataLoaderManager->getDataLoaderSuccess(); |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 590 | EXPECT_CALL(*mDataLoaderManager, bindToDataLoader(_, _, _, _)).Times(2); |
| 591 | EXPECT_CALL(*mDataLoaderManager, unbindFromDataLoader(_)).Times(1); |
Alex Buynytskyy | 0b20266 | 2020-04-13 09:53:04 -0700 | [diff] [blame] | 592 | EXPECT_CALL(*mDataLoader, create(_, _, _, _)).Times(2); |
| 593 | EXPECT_CALL(*mDataLoader, start(_)).Times(0); |
| 594 | EXPECT_CALL(*mDataLoader, destroy(_)).Times(1); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 595 | EXPECT_CALL(*mVold, unmountIncFs(_)).Times(2); |
| 596 | TemporaryDir tempDir; |
| 597 | int storageId = |
Alex Buynytskyy | 04f7391 | 2020-02-10 08:34:18 -0800 | [diff] [blame] | 598 | mIncrementalService->createStorage(tempDir.path, std::move(mDataLoaderParcel), {}, |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 599 | IncrementalService::CreateOptions::CreateNew); |
| 600 | ASSERT_GE(storageId, 0); |
Alex Buynytskyy | 0b20266 | 2020-04-13 09:53:04 -0700 | [diff] [blame] | 601 | // Simulated crash/other connection breakage. |
| 602 | mDataLoaderManager->setDataLoaderStatusDestroyed(); |
| 603 | } |
| 604 | |
| 605 | TEST_F(IncrementalServiceTest, testStartDataLoaderCreate) { |
| 606 | mVold->mountIncFsSuccess(); |
| 607 | mIncFs->makeFileSuccess(); |
| 608 | mVold->bindMountSuccess(); |
Alex Buynytskyy | ab65cb1 | 2020-04-17 10:01:47 -0700 | [diff] [blame] | 609 | mDataLoader->initializeCreateOkNoStatus(); |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 610 | mDataLoaderManager->bindToDataLoaderSuccess(); |
Alex Buynytskyy | 0b20266 | 2020-04-13 09:53:04 -0700 | [diff] [blame] | 611 | mDataLoaderManager->getDataLoaderSuccess(); |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 612 | EXPECT_CALL(*mDataLoaderManager, bindToDataLoader(_, _, _, _)).Times(1); |
| 613 | EXPECT_CALL(*mDataLoaderManager, unbindFromDataLoader(_)).Times(1); |
Alex Buynytskyy | 0b20266 | 2020-04-13 09:53:04 -0700 | [diff] [blame] | 614 | EXPECT_CALL(*mDataLoader, create(_, _, _, _)).Times(1); |
| 615 | EXPECT_CALL(*mDataLoader, start(_)).Times(1); |
| 616 | EXPECT_CALL(*mDataLoader, destroy(_)).Times(1); |
| 617 | EXPECT_CALL(*mVold, unmountIncFs(_)).Times(2); |
| 618 | TemporaryDir tempDir; |
| 619 | int storageId = |
| 620 | mIncrementalService->createStorage(tempDir.path, std::move(mDataLoaderParcel), {}, |
| 621 | IncrementalService::CreateOptions::CreateNew); |
| 622 | ASSERT_GE(storageId, 0); |
| 623 | mDataLoaderManager->setDataLoaderStatusCreated(); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 624 | ASSERT_TRUE(mIncrementalService->startLoading(storageId)); |
Alex Buynytskyy | 0b20266 | 2020-04-13 09:53:04 -0700 | [diff] [blame] | 625 | mDataLoaderManager->setDataLoaderStatusStarted(); |
| 626 | } |
| 627 | |
| 628 | TEST_F(IncrementalServiceTest, testStartDataLoaderPendingStart) { |
| 629 | mVold->mountIncFsSuccess(); |
| 630 | mIncFs->makeFileSuccess(); |
| 631 | mVold->bindMountSuccess(); |
Alex Buynytskyy | ab65cb1 | 2020-04-17 10:01:47 -0700 | [diff] [blame] | 632 | mDataLoader->initializeCreateOkNoStatus(); |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 633 | mDataLoaderManager->bindToDataLoaderSuccess(); |
Alex Buynytskyy | 0b20266 | 2020-04-13 09:53:04 -0700 | [diff] [blame] | 634 | mDataLoaderManager->getDataLoaderSuccess(); |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 635 | EXPECT_CALL(*mDataLoaderManager, bindToDataLoader(_, _, _, _)).Times(1); |
| 636 | EXPECT_CALL(*mDataLoaderManager, unbindFromDataLoader(_)).Times(1); |
Alex Buynytskyy | ab65cb1 | 2020-04-17 10:01:47 -0700 | [diff] [blame] | 637 | EXPECT_CALL(*mDataLoader, create(_, _, _, _)).Times(2); |
Alex Buynytskyy | 0b20266 | 2020-04-13 09:53:04 -0700 | [diff] [blame] | 638 | EXPECT_CALL(*mDataLoader, start(_)).Times(1); |
| 639 | EXPECT_CALL(*mDataLoader, destroy(_)).Times(1); |
| 640 | EXPECT_CALL(*mVold, unmountIncFs(_)).Times(2); |
| 641 | TemporaryDir tempDir; |
| 642 | int storageId = |
| 643 | mIncrementalService->createStorage(tempDir.path, std::move(mDataLoaderParcel), {}, |
| 644 | IncrementalService::CreateOptions::CreateNew); |
| 645 | ASSERT_GE(storageId, 0); |
| 646 | ASSERT_TRUE(mIncrementalService->startLoading(storageId)); |
| 647 | mDataLoaderManager->setDataLoaderStatusCreated(); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 648 | } |
| 649 | |
Alex Buynytskyy | cca2c11 | 2020-05-05 12:48:41 -0700 | [diff] [blame] | 650 | TEST_F(IncrementalServiceTest, testStartDataLoaderCreateUnavailable) { |
| 651 | mVold->mountIncFsSuccess(); |
| 652 | mIncFs->makeFileSuccess(); |
| 653 | mVold->bindMountSuccess(); |
| 654 | mDataLoader->initializeCreateOkNoStatus(); |
| 655 | mDataLoaderManager->bindToDataLoaderSuccess(); |
| 656 | mDataLoaderManager->getDataLoaderSuccess(); |
| 657 | EXPECT_CALL(*mDataLoaderManager, bindToDataLoader(_, _, _, _)).Times(1); |
| 658 | EXPECT_CALL(*mDataLoaderManager, unbindFromDataLoader(_)).Times(1); |
| 659 | EXPECT_CALL(*mDataLoader, create(_, _, _, _)).Times(1); |
| 660 | EXPECT_CALL(*mDataLoader, start(_)).Times(0); |
| 661 | EXPECT_CALL(*mDataLoader, destroy(_)).Times(1); |
| 662 | EXPECT_CALL(*mVold, unmountIncFs(_)).Times(2); |
| 663 | TemporaryDir tempDir; |
| 664 | int storageId = |
| 665 | mIncrementalService->createStorage(tempDir.path, std::move(mDataLoaderParcel), {}, |
| 666 | IncrementalService::CreateOptions::CreateNew); |
| 667 | ASSERT_GE(storageId, 0); |
| 668 | mDataLoaderManager->setDataLoaderStatusUnavailable(); |
| 669 | } |
| 670 | |
| 671 | TEST_F(IncrementalServiceTest, testStartDataLoaderRecreateOnPendingReads) { |
| 672 | mVold->mountIncFsSuccess(); |
| 673 | mIncFs->makeFileSuccess(); |
| 674 | mIncFs->openMountSuccess(); |
| 675 | mVold->bindMountSuccess(); |
| 676 | mDataLoader->initializeCreateOkNoStatus(); |
| 677 | mDataLoaderManager->bindToDataLoaderSuccess(); |
| 678 | mDataLoaderManager->getDataLoaderSuccess(); |
| 679 | EXPECT_CALL(*mDataLoaderManager, bindToDataLoader(_, _, _, _)).Times(2); |
| 680 | EXPECT_CALL(*mDataLoaderManager, unbindFromDataLoader(_)).Times(1); |
| 681 | EXPECT_CALL(*mDataLoader, create(_, _, _, _)).Times(2); |
| 682 | EXPECT_CALL(*mDataLoader, start(_)).Times(0); |
| 683 | EXPECT_CALL(*mDataLoader, destroy(_)).Times(1); |
| 684 | EXPECT_CALL(*mVold, unmountIncFs(_)).Times(2); |
| 685 | EXPECT_CALL(*mLooper, addFd(MockIncFs::kPendingReadsFd, _, _, _, _)).Times(1); |
| 686 | EXPECT_CALL(*mLooper, removeFd(MockIncFs::kPendingReadsFd)).Times(1); |
| 687 | TemporaryDir tempDir; |
| 688 | int storageId = |
| 689 | mIncrementalService->createStorage(tempDir.path, std::move(mDataLoaderParcel), {}, |
| 690 | IncrementalService::CreateOptions::CreateNew); |
| 691 | ASSERT_GE(storageId, 0); |
| 692 | mDataLoaderManager->setDataLoaderStatusUnavailable(); |
| 693 | ASSERT_NE(nullptr, mLooper->mCallback); |
| 694 | ASSERT_NE(nullptr, mLooper->mCallbackData); |
| 695 | mLooper->mCallback(-1, -1, mLooper->mCallbackData); |
| 696 | } |
| 697 | |
Alex Buynytskyy | 5e860ba | 2020-03-31 15:30:21 -0700 | [diff] [blame] | 698 | TEST_F(IncrementalServiceTest, testSetIncFsMountOptionsSuccess) { |
| 699 | mVold->mountIncFsSuccess(); |
| 700 | mIncFs->makeFileSuccess(); |
| 701 | mVold->bindMountSuccess(); |
| 702 | mVold->setIncFsMountOptionsSuccess(); |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 703 | mDataLoaderManager->bindToDataLoaderSuccess(); |
Alex Buynytskyy | 5e860ba | 2020-03-31 15:30:21 -0700 | [diff] [blame] | 704 | mDataLoaderManager->getDataLoaderSuccess(); |
Alex Buynytskyy | 1d89216 | 2020-04-03 23:00:19 -0700 | [diff] [blame] | 705 | mAppOpsManager->checkPermissionSuccess(); |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 706 | EXPECT_CALL(*mDataLoaderManager, unbindFromDataLoader(_)); |
Alex Buynytskyy | 5e860ba | 2020-03-31 15:30:21 -0700 | [diff] [blame] | 707 | EXPECT_CALL(*mVold, unmountIncFs(_)).Times(2); |
Alex Buynytskyy | 1d89216 | 2020-04-03 23:00:19 -0700 | [diff] [blame] | 708 | // We are calling setIncFsMountOptions(true). |
| 709 | EXPECT_CALL(*mVold, setIncFsMountOptions(_, true)).Times(1); |
| 710 | // After setIncFsMountOptions succeeded expecting to start watching. |
| 711 | EXPECT_CALL(*mAppOpsManager, startWatchingMode(_, _, _)).Times(1); |
| 712 | // Not expecting callback removal. |
| 713 | EXPECT_CALL(*mAppOpsManager, stopWatchingMode(_)).Times(0); |
Alex Buynytskyy | 5e860ba | 2020-03-31 15:30:21 -0700 | [diff] [blame] | 714 | TemporaryDir tempDir; |
| 715 | int storageId = |
| 716 | mIncrementalService->createStorage(tempDir.path, std::move(mDataLoaderParcel), {}, |
| 717 | IncrementalService::CreateOptions::CreateNew); |
| 718 | ASSERT_GE(storageId, 0); |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 719 | ASSERT_GE(mDataLoader->setStorageParams(true), 0); |
Alex Buynytskyy | 5e860ba | 2020-03-31 15:30:21 -0700 | [diff] [blame] | 720 | } |
| 721 | |
Alex Buynytskyy | 1d89216 | 2020-04-03 23:00:19 -0700 | [diff] [blame] | 722 | TEST_F(IncrementalServiceTest, testSetIncFsMountOptionsSuccessAndPermissionChanged) { |
| 723 | mVold->mountIncFsSuccess(); |
| 724 | mIncFs->makeFileSuccess(); |
| 725 | mVold->bindMountSuccess(); |
| 726 | mVold->setIncFsMountOptionsSuccess(); |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 727 | mDataLoaderManager->bindToDataLoaderSuccess(); |
Alex Buynytskyy | 1d89216 | 2020-04-03 23:00:19 -0700 | [diff] [blame] | 728 | mDataLoaderManager->getDataLoaderSuccess(); |
| 729 | mAppOpsManager->checkPermissionSuccess(); |
| 730 | mAppOpsManager->initializeStartWatchingMode(); |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 731 | EXPECT_CALL(*mDataLoaderManager, unbindFromDataLoader(_)); |
Alex Buynytskyy | 1d89216 | 2020-04-03 23:00:19 -0700 | [diff] [blame] | 732 | EXPECT_CALL(*mVold, unmountIncFs(_)).Times(2); |
| 733 | // We are calling setIncFsMountOptions(true). |
| 734 | EXPECT_CALL(*mVold, setIncFsMountOptions(_, true)).Times(1); |
| 735 | // setIncFsMountOptions(false) is called on the callback. |
| 736 | EXPECT_CALL(*mVold, setIncFsMountOptions(_, false)).Times(1); |
| 737 | // After setIncFsMountOptions succeeded expecting to start watching. |
| 738 | EXPECT_CALL(*mAppOpsManager, startWatchingMode(_, _, _)).Times(1); |
| 739 | // After callback is called, disable read logs and remove callback. |
| 740 | EXPECT_CALL(*mAppOpsManager, stopWatchingMode(_)).Times(1); |
| 741 | TemporaryDir tempDir; |
| 742 | int storageId = |
| 743 | mIncrementalService->createStorage(tempDir.path, std::move(mDataLoaderParcel), {}, |
| 744 | IncrementalService::CreateOptions::CreateNew); |
| 745 | ASSERT_GE(storageId, 0); |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 746 | ASSERT_GE(mDataLoader->setStorageParams(true), 0); |
Alex Buynytskyy | 1d89216 | 2020-04-03 23:00:19 -0700 | [diff] [blame] | 747 | ASSERT_NE(nullptr, mAppOpsManager->mStoredCallback.get()); |
| 748 | mAppOpsManager->mStoredCallback->opChanged(0, {}); |
| 749 | } |
| 750 | |
| 751 | TEST_F(IncrementalServiceTest, testSetIncFsMountOptionsCheckPermissionFails) { |
| 752 | mVold->mountIncFsSuccess(); |
| 753 | mIncFs->makeFileSuccess(); |
| 754 | mVold->bindMountSuccess(); |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 755 | mDataLoaderManager->bindToDataLoaderSuccess(); |
Alex Buynytskyy | 1d89216 | 2020-04-03 23:00:19 -0700 | [diff] [blame] | 756 | mDataLoaderManager->getDataLoaderSuccess(); |
| 757 | mAppOpsManager->checkPermissionFails(); |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 758 | EXPECT_CALL(*mDataLoaderManager, unbindFromDataLoader(_)); |
Alex Buynytskyy | 1d89216 | 2020-04-03 23:00:19 -0700 | [diff] [blame] | 759 | EXPECT_CALL(*mVold, unmountIncFs(_)).Times(2); |
| 760 | // checkPermission fails, no calls to set opitions, start or stop WatchingMode. |
| 761 | EXPECT_CALL(*mVold, setIncFsMountOptions(_, true)).Times(0); |
| 762 | EXPECT_CALL(*mAppOpsManager, startWatchingMode(_, _, _)).Times(0); |
| 763 | EXPECT_CALL(*mAppOpsManager, stopWatchingMode(_)).Times(0); |
| 764 | TemporaryDir tempDir; |
| 765 | int storageId = |
| 766 | mIncrementalService->createStorage(tempDir.path, std::move(mDataLoaderParcel), {}, |
| 767 | IncrementalService::CreateOptions::CreateNew); |
| 768 | ASSERT_GE(storageId, 0); |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 769 | ASSERT_LT(mDataLoader->setStorageParams(true), 0); |
Alex Buynytskyy | 1d89216 | 2020-04-03 23:00:19 -0700 | [diff] [blame] | 770 | } |
| 771 | |
Alex Buynytskyy | 5e860ba | 2020-03-31 15:30:21 -0700 | [diff] [blame] | 772 | TEST_F(IncrementalServiceTest, testSetIncFsMountOptionsFails) { |
| 773 | mVold->mountIncFsSuccess(); |
| 774 | mIncFs->makeFileSuccess(); |
| 775 | mVold->bindMountSuccess(); |
| 776 | mVold->setIncFsMountOptionsFails(); |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 777 | mDataLoaderManager->bindToDataLoaderSuccess(); |
Alex Buynytskyy | 5e860ba | 2020-03-31 15:30:21 -0700 | [diff] [blame] | 778 | mDataLoaderManager->getDataLoaderSuccess(); |
Alex Buynytskyy | 1d89216 | 2020-04-03 23:00:19 -0700 | [diff] [blame] | 779 | mAppOpsManager->checkPermissionSuccess(); |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 780 | EXPECT_CALL(*mDataLoaderManager, unbindFromDataLoader(_)); |
Alex Buynytskyy | 5e860ba | 2020-03-31 15:30:21 -0700 | [diff] [blame] | 781 | EXPECT_CALL(*mVold, unmountIncFs(_)).Times(2); |
Alex Buynytskyy | 1d89216 | 2020-04-03 23:00:19 -0700 | [diff] [blame] | 782 | // We are calling setIncFsMountOptions. |
| 783 | EXPECT_CALL(*mVold, setIncFsMountOptions(_, true)).Times(1); |
| 784 | // setIncFsMountOptions fails, no calls to start or stop WatchingMode. |
| 785 | EXPECT_CALL(*mAppOpsManager, startWatchingMode(_, _, _)).Times(0); |
| 786 | EXPECT_CALL(*mAppOpsManager, stopWatchingMode(_)).Times(0); |
Alex Buynytskyy | 5e860ba | 2020-03-31 15:30:21 -0700 | [diff] [blame] | 787 | TemporaryDir tempDir; |
| 788 | int storageId = |
| 789 | mIncrementalService->createStorage(tempDir.path, std::move(mDataLoaderParcel), {}, |
| 790 | IncrementalService::CreateOptions::CreateNew); |
| 791 | ASSERT_GE(storageId, 0); |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 792 | ASSERT_LT(mDataLoader->setStorageParams(true), 0); |
Alex Buynytskyy | 5e860ba | 2020-03-31 15:30:21 -0700 | [diff] [blame] | 793 | } |
| 794 | |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 795 | TEST_F(IncrementalServiceTest, testMakeDirectory) { |
| 796 | mVold->mountIncFsSuccess(); |
| 797 | mIncFs->makeFileSuccess(); |
| 798 | mVold->bindMountSuccess(); |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 799 | mDataLoaderManager->bindToDataLoaderSuccess(); |
Songchun Fan | 68645c4 | 2020-02-27 15:57:35 -0800 | [diff] [blame] | 800 | mDataLoaderManager->getDataLoaderSuccess(); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 801 | TemporaryDir tempDir; |
| 802 | int storageId = |
Alex Buynytskyy | 04f7391 | 2020-02-10 08:34:18 -0800 | [diff] [blame] | 803 | mIncrementalService->createStorage(tempDir.path, std::move(mDataLoaderParcel), {}, |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 804 | IncrementalService::CreateOptions::CreateNew); |
Songchun Fan | 103ba1d | 2020-02-03 17:32:32 -0800 | [diff] [blame] | 805 | std::string dir_path("test"); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 806 | |
Songchun Fan | 103ba1d | 2020-02-03 17:32:32 -0800 | [diff] [blame] | 807 | // Expecting incfs to call makeDir on a path like: |
Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 808 | // <root>/*/mount/<storage>/test |
| 809 | EXPECT_CALL(*mIncFs, |
| 810 | makeDir(_, Truly([&](std::string_view arg) { |
| 811 | return arg.starts_with(mRootDir.path) && |
| 812 | arg.ends_with("/mount/st_1_0/" + dir_path); |
| 813 | }), |
| 814 | _)); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 815 | auto res = mIncrementalService->makeDir(storageId, dir_path, 0555); |
| 816 | ASSERT_EQ(res, 0); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | TEST_F(IncrementalServiceTest, testMakeDirectories) { |
| 820 | mVold->mountIncFsSuccess(); |
| 821 | mIncFs->makeFileSuccess(); |
| 822 | mVold->bindMountSuccess(); |
Alex Buynytskyy | ea1390f | 2020-04-22 16:08:50 -0700 | [diff] [blame] | 823 | mDataLoaderManager->bindToDataLoaderSuccess(); |
Songchun Fan | 68645c4 | 2020-02-27 15:57:35 -0800 | [diff] [blame] | 824 | mDataLoaderManager->getDataLoaderSuccess(); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 825 | TemporaryDir tempDir; |
| 826 | int storageId = |
Alex Buynytskyy | 04f7391 | 2020-02-10 08:34:18 -0800 | [diff] [blame] | 827 | mIncrementalService->createStorage(tempDir.path, std::move(mDataLoaderParcel), {}, |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 828 | IncrementalService::CreateOptions::CreateNew); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 829 | auto first = "first"sv; |
| 830 | auto second = "second"sv; |
| 831 | auto third = "third"sv; |
Yurii Zubrytskyi | efebb45 | 2020-04-22 13:59:06 -0700 | [diff] [blame] | 832 | auto dir_path = std::string(first) + "/" + std::string(second) + "/" + std::string(third); |
Songchun Fan | 103ba1d | 2020-02-03 17:32:32 -0800 | [diff] [blame] | 833 | |
Yurii Zubrytskyi | efebb45 | 2020-04-22 13:59:06 -0700 | [diff] [blame] | 834 | EXPECT_CALL(*mIncFs, |
| 835 | makeDirs(_, Truly([&](std::string_view arg) { |
| 836 | return arg.starts_with(mRootDir.path) && |
| 837 | arg.ends_with("/mount/st_1_0/" + dir_path); |
| 838 | }), |
| 839 | _)); |
Yurii Zubrytskyi | 629051fd | 2020-04-17 23:13:47 -0700 | [diff] [blame] | 840 | auto res = mIncrementalService->makeDirs(storageId, dir_path, 0555); |
Yurii Zubrytskyi | 4a25dfb | 2020-01-10 11:53:24 -0800 | [diff] [blame] | 841 | ASSERT_EQ(res, 0); |
Songchun Fan | 3c82a30 | 2019-11-29 14:23:45 -0800 | [diff] [blame] | 842 | } |
| 843 | } // namespace android::os::incremental |