Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2018 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 <stdint.h> |
| 18 | |
| 19 | #include <memory> |
Yifan Hong | 6eec995 | 2019-12-04 13:12:01 -0800 | [diff] [blame] | 20 | #include <set> |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 21 | #include <string> |
| 22 | |
| 23 | #include <gmock/gmock.h> |
| 24 | |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 25 | #include "update_engine/common/boot_control_interface.h" |
Yifan Hong | 15726b9 | 2019-11-05 19:06:48 -0800 | [diff] [blame] | 26 | #include "update_engine/common/dynamic_partition_control_interface.h" |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 27 | #include "update_engine/dynamic_partition_control_android.h" |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 28 | |
| 29 | namespace chromeos_update_engine { |
| 30 | |
Yifan Hong | 012508e | 2019-07-22 18:30:40 -0700 | [diff] [blame] | 31 | class MockDynamicPartitionControlAndroid |
| 32 | : public DynamicPartitionControlAndroid { |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 33 | public: |
Yifan Hong | af65ef1 | 2018-10-29 11:09:06 -0700 | [diff] [blame] | 34 | MOCK_METHOD5(MapPartitionOnDeviceMapper, |
| 35 | bool(const std::string&, |
| 36 | const std::string&, |
| 37 | uint32_t, |
| 38 | bool, |
| 39 | std::string*)); |
David Anderson | 4c891c9 | 2019-06-21 17:45:23 -0700 | [diff] [blame] | 40 | MOCK_METHOD1(UnmapPartitionOnDeviceMapper, bool(const std::string&)); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 41 | MOCK_METHOD0(Cleanup, void()); |
| 42 | MOCK_METHOD1(DeviceExists, bool(const std::string&)); |
| 43 | MOCK_METHOD1(GetState, ::android::dm::DmDeviceState(const std::string&)); |
| 44 | MOCK_METHOD2(GetDmDevicePathByName, bool(const std::string&, std::string*)); |
Yifan Hong | 6e706b1 | 2018-11-09 16:50:51 -0800 | [diff] [blame] | 45 | MOCK_METHOD3(LoadMetadataBuilder, |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 46 | std::unique_ptr<::android::fs_mgr::MetadataBuilder>( |
Yifan Hong | 6e706b1 | 2018-11-09 16:50:51 -0800 | [diff] [blame] | 47 | const std::string&, uint32_t, uint32_t)); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 48 | MOCK_METHOD3(StoreMetadata, |
| 49 | bool(const std::string&, |
| 50 | android::fs_mgr::MetadataBuilder*, |
| 51 | uint32_t)); |
| 52 | MOCK_METHOD1(GetDeviceDir, bool(std::string*)); |
Yifan Hong | 186bb68 | 2019-07-23 14:04:39 -0700 | [diff] [blame] | 53 | MOCK_METHOD0(GetDynamicPartitionsFeatureFlag, FeatureFlag()); |
Yifan Hong | 700d7c1 | 2019-07-23 20:49:16 -0700 | [diff] [blame] | 54 | MOCK_METHOD1(GetSuperPartitionName, std::string(uint32_t)); |
Yifan Hong | 413d572 | 2019-07-23 14:21:09 -0700 | [diff] [blame] | 55 | MOCK_METHOD0(GetVirtualAbFeatureFlag, FeatureFlag()); |
Yifan Hong | 7b3910a | 2020-03-24 17:47:32 -0700 | [diff] [blame] | 56 | MOCK_METHOD1(FinishUpdate, bool(bool)); |
Yifan Hong | 2969290 | 2020-03-26 12:47:05 -0700 | [diff] [blame] | 57 | MOCK_METHOD5( |
| 58 | GetSystemOtherPath, |
| 59 | bool(uint32_t, uint32_t, const std::string&, std::string*, bool*)); |
| 60 | MOCK_METHOD2(EraseSystemOtherAvbFooter, bool(uint32_t, uint32_t)); |
| 61 | MOCK_METHOD0(IsAvbEnabledOnSystemOther, std::optional<bool>()); |
Yifan Hong | 6eec995 | 2019-12-04 13:12:01 -0800 | [diff] [blame] | 62 | |
| 63 | void set_fake_mapped_devices(const std::set<std::string>& fake) override { |
| 64 | DynamicPartitionControlAndroid::set_fake_mapped_devices(fake); |
| 65 | } |
Yifan Hong | 2969290 | 2020-03-26 12:47:05 -0700 | [diff] [blame] | 66 | |
| 67 | bool RealGetSystemOtherPath(uint32_t source_slot, |
| 68 | uint32_t target_slot, |
| 69 | const std::string& partition_name_suffix, |
| 70 | std::string* path, |
| 71 | bool* should_unmap) { |
| 72 | return DynamicPartitionControlAndroid::GetSystemOtherPath( |
| 73 | source_slot, target_slot, partition_name_suffix, path, should_unmap); |
| 74 | } |
| 75 | |
| 76 | bool RealEraseSystemOtherAvbFooter(uint32_t source_slot, |
| 77 | uint32_t target_slot) { |
| 78 | return DynamicPartitionControlAndroid::EraseSystemOtherAvbFooter( |
| 79 | source_slot, target_slot); |
| 80 | } |
| 81 | |
| 82 | std::optional<bool> RealIsAvbEnabledInFstab(const std::string& path) { |
| 83 | return DynamicPartitionControlAndroid::IsAvbEnabledInFstab(path); |
| 84 | } |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | } // namespace chromeos_update_engine |