blob: d281803bcc9f23558695eca186654edd3f3b7bc9 [file] [log] [blame]
Yifan Hong537802d2018-08-15 13:15:42 -07001//
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 Hong6eec9952019-12-04 13:12:01 -080020#include <set>
Yifan Hong537802d2018-08-15 13:15:42 -070021#include <string>
22
23#include <gmock/gmock.h>
24
Kelvin Zhang34618522020-09-28 09:21:02 -040025#include <libsnapshot/cow_writer.h>
Tianjie5b589872020-11-03 11:16:33 -080026#include <libsnapshot/snapshot_writer.h>
Kelvin Zhang34618522020-09-28 09:21:02 -040027
Kelvin Zhangc82511c2020-11-06 16:01:24 -050028#include "payload_consumer/file_descriptor.h"
Amin Hassaniec7bc112020-10-29 16:47:58 -070029#include "update_engine/aosp/dynamic_partition_control_android.h"
Yifan Hong012508e2019-07-22 18:30:40 -070030#include "update_engine/common/boot_control_interface.h"
Yifan Hong15726b92019-11-05 19:06:48 -080031#include "update_engine/common/dynamic_partition_control_interface.h"
Yifan Hong537802d2018-08-15 13:15:42 -070032
33namespace chromeos_update_engine {
34
Yifan Hong012508e2019-07-22 18:30:40 -070035class MockDynamicPartitionControlAndroid
36 : public DynamicPartitionControlAndroid {
Yifan Hong537802d2018-08-15 13:15:42 -070037 public:
Yifan Hong5f32ee22020-04-15 18:22:39 -070038 MOCK_METHOD(
39 bool,
40 MapPartitionOnDeviceMapper,
41 (const std::string&, const std::string&, uint32_t, bool, std::string*),
42 (override));
43 MOCK_METHOD(bool,
44 UnmapPartitionOnDeviceMapper,
45 (const std::string&),
46 (override));
47 MOCK_METHOD(void, Cleanup, (), (override));
48 MOCK_METHOD(bool, DeviceExists, (const std::string&), (override));
49 MOCK_METHOD(::android::dm::DmDeviceState,
50 GetState,
51 (const std::string&),
52 (override));
53 MOCK_METHOD(bool,
54 GetDmDevicePathByName,
55 (const std::string&, std::string*),
56 (override));
57 MOCK_METHOD(std::unique_ptr<::android::fs_mgr::MetadataBuilder>,
58 LoadMetadataBuilder,
Tianjie24f96092020-06-30 12:26:25 -070059 (const std::string&, uint32_t),
60 (override));
61 MOCK_METHOD(std::unique_ptr<::android::fs_mgr::MetadataBuilder>,
62 LoadMetadataBuilder,
Yifan Hong5f32ee22020-04-15 18:22:39 -070063 (const std::string&, uint32_t, uint32_t),
64 (override));
65 MOCK_METHOD(bool,
66 StoreMetadata,
67 (const std::string&, android::fs_mgr::MetadataBuilder*, uint32_t),
68 (override));
69 MOCK_METHOD(bool, GetDeviceDir, (std::string*), (override));
70 MOCK_METHOD(FeatureFlag, GetDynamicPartitionsFeatureFlag, (), (override));
71 MOCK_METHOD(std::string, GetSuperPartitionName, (uint32_t), (override));
72 MOCK_METHOD(FeatureFlag, GetVirtualAbFeatureFlag, (), (override));
73 MOCK_METHOD(bool, FinishUpdate, (bool), (override));
74 MOCK_METHOD(bool,
75 GetSystemOtherPath,
76 (uint32_t, uint32_t, const std::string&, std::string*, bool*),
77 (override));
78 MOCK_METHOD(bool,
79 EraseSystemOtherAvbFooter,
80 (uint32_t, uint32_t),
81 (override));
82 MOCK_METHOD(std::optional<bool>, IsAvbEnabledOnSystemOther, (), (override));
Yifan Hong302fa702020-04-16 09:48:29 -070083 MOCK_METHOD(bool, IsRecovery, (), (override));
84 MOCK_METHOD(bool,
85 PrepareDynamicPartitionsForUpdate,
86 (uint32_t, uint32_t, const DeltaArchiveManifest&, bool),
87 (override));
Kelvin Zhang34618522020-09-28 09:21:02 -040088 MOCK_METHOD(std::unique_ptr<android::snapshot::ISnapshotWriter>,
89 OpenCowWriter,
90 (const std::string& unsuffixed_partition_name,
91 const std::optional<std::string>& source_path,
92 bool is_append),
93 (override));
Kelvin Zhangc82511c2020-11-06 16:01:24 -050094 MOCK_METHOD(FileDescriptorPtr,
95 OpenCowReader,
96 (const std::string& unsuffixed_partition_name,
97 const std::optional<std::string>& source_path,
98 bool is_append),
99 (override));
Kelvin Zhang9d87d6d2020-10-23 17:03:59 -0400100 MOCK_METHOD(bool, MapAllPartitions, (), (override));
101 MOCK_METHOD(bool, UnmapAllPartitions, (), (override));
Yifan Hong6eec9952019-12-04 13:12:01 -0800102
103 void set_fake_mapped_devices(const std::set<std::string>& fake) override {
104 DynamicPartitionControlAndroid::set_fake_mapped_devices(fake);
105 }
Yifan Hong29692902020-03-26 12:47:05 -0700106
107 bool RealGetSystemOtherPath(uint32_t source_slot,
108 uint32_t target_slot,
109 const std::string& partition_name_suffix,
110 std::string* path,
111 bool* should_unmap) {
112 return DynamicPartitionControlAndroid::GetSystemOtherPath(
113 source_slot, target_slot, partition_name_suffix, path, should_unmap);
114 }
115
116 bool RealEraseSystemOtherAvbFooter(uint32_t source_slot,
117 uint32_t target_slot) {
118 return DynamicPartitionControlAndroid::EraseSystemOtherAvbFooter(
119 source_slot, target_slot);
120 }
121
122 std::optional<bool> RealIsAvbEnabledInFstab(const std::string& path) {
123 return DynamicPartitionControlAndroid::IsAvbEnabledInFstab(path);
124 }
Yifan Hong302fa702020-04-16 09:48:29 -0700125
126 bool RealPrepareDynamicPartitionsForUpdate(
127 uint32_t source_slot,
128 uint32_t target_slot,
129 const DeltaArchiveManifest& manifest,
130 bool delete_source) {
131 return DynamicPartitionControlAndroid::PrepareDynamicPartitionsForUpdate(
132 source_slot, target_slot, manifest, delete_source);
133 }
Yifan Hong537802d2018-08-15 13:15:42 -0700134};
135
136} // namespace chromeos_update_engine