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>
20 #include <set>
21 #include <string>
22 
23 #include <gmock/gmock.h>
24 
25 #include "update_engine/common/boot_control_interface.h"
26 #include "update_engine/common/dynamic_partition_control_interface.h"
27 #include "update_engine/dynamic_partition_control_android.h"
28 
29 namespace chromeos_update_engine {
30 
31 class MockDynamicPartitionControl : public DynamicPartitionControlInterface {
32  public:
33   MOCK_METHOD5(MapPartitionOnDeviceMapper,
34                bool(const std::string&,
35                     const std::string&,
36                     uint32_t,
37                     bool,
38                     std::string*));
39   MOCK_METHOD0(Cleanup, void());
40   MOCK_METHOD0(GetDynamicPartitionsFeatureFlag, FeatureFlag());
41   MOCK_METHOD5(
42       PreparePartitionsForUpdate,
43       bool(uint32_t, uint32_t, const DeltaArchiveManifest&, bool, uint64_t*));
44   MOCK_METHOD0(GetVirtualAbFeatureFlag, FeatureFlag());
45   MOCK_METHOD1(FinishUpdate, bool(bool));
46   MOCK_METHOD0(CleanupSuccessfulUpdate, ErrorCode());
47   MOCK_METHOD3(GetCleanupPreviousUpdateAction,
48                std::unique_ptr<AbstractAction>(
49                    BootControlInterface*,
50                    PrefsInterface*,
51                    CleanupPreviousUpdateActionDelegateInterface*));
52 };
53 
54 class MockDynamicPartitionControlAndroid
55     : public DynamicPartitionControlAndroid {
56  public:
57   MOCK_METHOD5(MapPartitionOnDeviceMapper,
58                bool(const std::string&,
59                     const std::string&,
60                     uint32_t,
61                     bool,
62                     std::string*));
63   MOCK_METHOD1(UnmapPartitionOnDeviceMapper, bool(const std::string&));
64   MOCK_METHOD0(Cleanup, void());
65   MOCK_METHOD1(DeviceExists, bool(const std::string&));
66   MOCK_METHOD1(GetState, ::android::dm::DmDeviceState(const std::string&));
67   MOCK_METHOD2(GetDmDevicePathByName, bool(const std::string&, std::string*));
68   MOCK_METHOD3(LoadMetadataBuilder,
69                std::unique_ptr<::android::fs_mgr::MetadataBuilder>(
70                    const std::string&, uint32_t, uint32_t));
71   MOCK_METHOD3(StoreMetadata,
72                bool(const std::string&,
73                     android::fs_mgr::MetadataBuilder*,
74                     uint32_t));
75   MOCK_METHOD1(GetDeviceDir, bool(std::string*));
76   MOCK_METHOD0(GetDynamicPartitionsFeatureFlag, FeatureFlag());
77   MOCK_METHOD1(GetSuperPartitionName, std::string(uint32_t));
78   MOCK_METHOD0(GetVirtualAbFeatureFlag, FeatureFlag());
79   MOCK_METHOD1(FinishUpdate, bool(bool));
80   MOCK_METHOD5(
81       GetSystemOtherPath,
82       bool(uint32_t, uint32_t, const std::string&, std::string*, bool*));
83   MOCK_METHOD2(EraseSystemOtherAvbFooter, bool(uint32_t, uint32_t));
84   MOCK_METHOD0(IsAvbEnabledOnSystemOther, std::optional<bool>());
85 
86   void set_fake_mapped_devices(const std::set<std::string>& fake) override {
87     DynamicPartitionControlAndroid::set_fake_mapped_devices(fake);
88   }
89 
90   bool RealGetSystemOtherPath(uint32_t source_slot,
91                               uint32_t target_slot,
92                               const std::string& partition_name_suffix,
93                               std::string* path,
94                               bool* should_unmap) {
95     return DynamicPartitionControlAndroid::GetSystemOtherPath(
96         source_slot, target_slot, partition_name_suffix, path, should_unmap);
97   }
98 
99   bool RealEraseSystemOtherAvbFooter(uint32_t source_slot,
100                                      uint32_t target_slot) {
101     return DynamicPartitionControlAndroid::EraseSystemOtherAvbFooter(
102         source_slot, target_slot);
103   }
104 
105   std::optional<bool> RealIsAvbEnabledInFstab(const std::string& path) {
106     return DynamicPartitionControlAndroid::IsAvbEnabledInFstab(path);
107   }
108 };
109 
110 }  // namespace chromeos_update_engine
111