blob: df7208edfb9bc44939f9183e4d8d11193864883a [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
Amin Hassaniec7bc112020-10-29 16:47:58 -070028#include "update_engine/aosp/dynamic_partition_control_android.h"
Yifan Hong012508e2019-07-22 18:30:40 -070029#include "update_engine/common/boot_control_interface.h"
Yifan Hong15726b92019-11-05 19:06:48 -080030#include "update_engine/common/dynamic_partition_control_interface.h"
Yifan Hong537802d2018-08-15 13:15:42 -070031
32namespace chromeos_update_engine {
33
Yifan Hong012508e2019-07-22 18:30:40 -070034class MockDynamicPartitionControlAndroid
35 : public DynamicPartitionControlAndroid {
Yifan Hong537802d2018-08-15 13:15:42 -070036 public:
Yifan Hong5f32ee22020-04-15 18:22:39 -070037 MOCK_METHOD(
38 bool,
39 MapPartitionOnDeviceMapper,
40 (const std::string&, const std::string&, uint32_t, bool, std::string*),
41 (override));
42 MOCK_METHOD(bool,
43 UnmapPartitionOnDeviceMapper,
44 (const std::string&),
45 (override));
46 MOCK_METHOD(void, Cleanup, (), (override));
47 MOCK_METHOD(bool, DeviceExists, (const std::string&), (override));
48 MOCK_METHOD(::android::dm::DmDeviceState,
49 GetState,
50 (const std::string&),
51 (override));
52 MOCK_METHOD(bool,
53 GetDmDevicePathByName,
54 (const std::string&, std::string*),
55 (override));
56 MOCK_METHOD(std::unique_ptr<::android::fs_mgr::MetadataBuilder>,
57 LoadMetadataBuilder,
Tianjie24f96092020-06-30 12:26:25 -070058 (const std::string&, uint32_t),
59 (override));
60 MOCK_METHOD(std::unique_ptr<::android::fs_mgr::MetadataBuilder>,
61 LoadMetadataBuilder,
Yifan Hong5f32ee22020-04-15 18:22:39 -070062 (const std::string&, uint32_t, uint32_t),
63 (override));
64 MOCK_METHOD(bool,
65 StoreMetadata,
66 (const std::string&, android::fs_mgr::MetadataBuilder*, uint32_t),
67 (override));
68 MOCK_METHOD(bool, GetDeviceDir, (std::string*), (override));
69 MOCK_METHOD(FeatureFlag, GetDynamicPartitionsFeatureFlag, (), (override));
70 MOCK_METHOD(std::string, GetSuperPartitionName, (uint32_t), (override));
71 MOCK_METHOD(FeatureFlag, GetVirtualAbFeatureFlag, (), (override));
72 MOCK_METHOD(bool, FinishUpdate, (bool), (override));
73 MOCK_METHOD(bool,
74 GetSystemOtherPath,
75 (uint32_t, uint32_t, const std::string&, std::string*, bool*),
76 (override));
77 MOCK_METHOD(bool,
78 EraseSystemOtherAvbFooter,
79 (uint32_t, uint32_t),
80 (override));
81 MOCK_METHOD(std::optional<bool>, IsAvbEnabledOnSystemOther, (), (override));
Yifan Hong302fa702020-04-16 09:48:29 -070082 MOCK_METHOD(bool, IsRecovery, (), (override));
83 MOCK_METHOD(bool,
84 PrepareDynamicPartitionsForUpdate,
85 (uint32_t, uint32_t, const DeltaArchiveManifest&, bool),
86 (override));
Kelvin Zhang34618522020-09-28 09:21:02 -040087 MOCK_METHOD(std::unique_ptr<android::snapshot::ISnapshotWriter>,
88 OpenCowWriter,
89 (const std::string& unsuffixed_partition_name,
90 const std::optional<std::string>& source_path,
91 bool is_append),
92 (override));
Kelvin Zhang9d87d6d2020-10-23 17:03:59 -040093 MOCK_METHOD(bool, MapAllPartitions, (), (override));
94 MOCK_METHOD(bool, UnmapAllPartitions, (), (override));
Yifan Hong6eec9952019-12-04 13:12:01 -080095
96 void set_fake_mapped_devices(const std::set<std::string>& fake) override {
97 DynamicPartitionControlAndroid::set_fake_mapped_devices(fake);
98 }
Yifan Hong29692902020-03-26 12:47:05 -070099
100 bool RealGetSystemOtherPath(uint32_t source_slot,
101 uint32_t target_slot,
102 const std::string& partition_name_suffix,
103 std::string* path,
104 bool* should_unmap) {
105 return DynamicPartitionControlAndroid::GetSystemOtherPath(
106 source_slot, target_slot, partition_name_suffix, path, should_unmap);
107 }
108
109 bool RealEraseSystemOtherAvbFooter(uint32_t source_slot,
110 uint32_t target_slot) {
111 return DynamicPartitionControlAndroid::EraseSystemOtherAvbFooter(
112 source_slot, target_slot);
113 }
114
115 std::optional<bool> RealIsAvbEnabledInFstab(const std::string& path) {
116 return DynamicPartitionControlAndroid::IsAvbEnabledInFstab(path);
117 }
Yifan Hong302fa702020-04-16 09:48:29 -0700118
119 bool RealPrepareDynamicPartitionsForUpdate(
120 uint32_t source_slot,
121 uint32_t target_slot,
122 const DeltaArchiveManifest& manifest,
123 bool delete_source) {
124 return DynamicPartitionControlAndroid::PrepareDynamicPartitionsForUpdate(
125 source_slot, target_slot, manifest, delete_source);
126 }
Yifan Hong537802d2018-08-15 13:15:42 -0700127};
128
129} // namespace chromeos_update_engine