blob: e8ef1f980ff3e32742123afe6bfbed4834f8670c [file] [log] [blame]
Yifan Hongc049f932019-07-23 15:06:05 -07001//
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 "update_engine/dynamic_partition_control_android.h"
18
19#include <set>
20#include <vector>
21
22#include <base/logging.h>
23#include <base/strings/string_util.h>
24#include <gmock/gmock.h>
25#include <gtest/gtest.h>
26
27#include "update_engine/dynamic_partition_test_utils.h"
28#include "update_engine/mock_dynamic_partition_control.h"
29
30using std::string;
31using testing::_;
32using testing::AnyNumber;
33using testing::Invoke;
34using testing::NiceMock;
35using testing::Not;
36using testing::Return;
37
38namespace chromeos_update_engine {
39
40class DynamicPartitionControlAndroidTest : public ::testing::Test {
41 public:
42 void SetUp() override {
43 module_ = std::make_unique<NiceMock<MockDynamicPartitionControlAndroid>>();
44
45 ON_CALL(dynamicControl(), GetDynamicPartitionsFeatureFlag())
46 .WillByDefault(Return(FeatureFlag(FeatureFlag::Value::LAUNCH)));
Yifan Hong413d5722019-07-23 14:21:09 -070047 ON_CALL(dynamicControl(), GetVirtualAbFeatureFlag())
48 .WillByDefault(Return(FeatureFlag(FeatureFlag::Value::NONE)));
Yifan Hongc049f932019-07-23 15:06:05 -070049
50 ON_CALL(dynamicControl(), GetDeviceDir(_))
51 .WillByDefault(Invoke([](auto path) {
52 *path = kFakeDevicePath;
53 return true;
54 }));
Yifan Hong700d7c12019-07-23 20:49:16 -070055
56 ON_CALL(dynamicControl(), GetSuperPartitionName(_))
57 .WillByDefault(Return(kFakeSuper));
Yifan Hongc049f932019-07-23 15:06:05 -070058 }
59
60 // Return the mocked DynamicPartitionControlInterface.
61 NiceMock<MockDynamicPartitionControlAndroid>& dynamicControl() {
62 return static_cast<NiceMock<MockDynamicPartitionControlAndroid>&>(*module_);
63 }
64
Yifan Hong700d7c12019-07-23 20:49:16 -070065 std::string GetSuperDevice(uint32_t slot) {
66 return GetDevice(dynamicControl().GetSuperPartitionName(slot));
67 }
68
Yifan Hongc049f932019-07-23 15:06:05 -070069 uint32_t source() { return slots_.source; }
70 uint32_t target() { return slots_.target; }
71
72 // Return partition names with suffix of source().
73 std::string S(const std::string& name) {
74 return name + kSlotSuffixes[source()];
75 }
76
77 // Return partition names with suffix of target().
78 std::string T(const std::string& name) {
79 return name + kSlotSuffixes[target()];
80 }
81
82 // Set the fake metadata to return when LoadMetadataBuilder is called on
83 // |slot|.
84 void SetMetadata(uint32_t slot, const PartitionSuffixSizes& sizes) {
85 EXPECT_CALL(dynamicControl(),
86 LoadMetadataBuilder(GetSuperDevice(slot), slot, _))
87 .Times(AnyNumber())
88 .WillRepeatedly(Invoke([sizes](auto, auto, auto) {
Yifan Hong13d41cb2019-09-16 13:18:22 -070089 return NewFakeMetadata(PartitionSuffixSizesToManifest(sizes));
Yifan Hongc049f932019-07-23 15:06:05 -070090 }));
91 }
92
93 void ExpectStoreMetadata(const PartitionSuffixSizes& partition_sizes) {
94 EXPECT_CALL(dynamicControl(),
95 StoreMetadata(GetSuperDevice(target()),
96 MetadataMatches(partition_sizes),
97 target()))
98 .WillOnce(Return(true));
99 }
100
101 // Expect that UnmapPartitionOnDeviceMapper is called on target() metadata
102 // slot with each partition in |partitions|.
103 void ExpectUnmap(const std::set<std::string>& partitions) {
104 // Error when UnmapPartitionOnDeviceMapper is called on unknown arguments.
105 ON_CALL(dynamicControl(), UnmapPartitionOnDeviceMapper(_))
106 .WillByDefault(Return(false));
107
108 for (const auto& partition : partitions) {
109 EXPECT_CALL(dynamicControl(), UnmapPartitionOnDeviceMapper(partition))
110 .WillOnce(Return(true));
111 }
112 }
113 bool PreparePartitionsForUpdate(const PartitionSizes& partition_sizes) {
114 return dynamicControl().PreparePartitionsForUpdate(
Yifan Hongf0f4a912019-09-26 17:51:33 -0700115 source(), target(), PartitionSizesToManifest(partition_sizes), true);
Yifan Hongc049f932019-07-23 15:06:05 -0700116 }
117 void SetSlots(const TestParam& slots) { slots_ = slots; }
118
119 struct Listener : public ::testing::MatchResultListener {
120 explicit Listener(std::ostream* os) : MatchResultListener(os) {}
121 };
122
123 testing::AssertionResult UpdatePartitionMetadata(
124 const PartitionSuffixSizes& source_metadata,
125 const PartitionSizes& update_metadata,
126 const PartitionSuffixSizes& expected) {
127 return UpdatePartitionMetadata(
Yifan Hong13d41cb2019-09-16 13:18:22 -0700128 PartitionSuffixSizesToManifest(source_metadata),
129 PartitionSizesToManifest(update_metadata),
130 PartitionSuffixSizesToManifest(expected));
Yifan Hongc049f932019-07-23 15:06:05 -0700131 }
132 testing::AssertionResult UpdatePartitionMetadata(
Yifan Hong13d41cb2019-09-16 13:18:22 -0700133 const DeltaArchiveManifest& source_manifest,
134 const DeltaArchiveManifest& update_manifest,
135 const DeltaArchiveManifest& expected) {
Yifan Hongc049f932019-07-23 15:06:05 -0700136 return UpdatePartitionMetadata(
Yifan Hong13d41cb2019-09-16 13:18:22 -0700137 source_manifest, update_manifest, MetadataMatches(expected));
Yifan Hongc049f932019-07-23 15:06:05 -0700138 }
139 testing::AssertionResult UpdatePartitionMetadata(
Yifan Hong13d41cb2019-09-16 13:18:22 -0700140 const DeltaArchiveManifest& source_manifest,
141 const DeltaArchiveManifest& update_manifest,
Yifan Hongc049f932019-07-23 15:06:05 -0700142 const Matcher<MetadataBuilder*>& matcher) {
Yifan Hong13d41cb2019-09-16 13:18:22 -0700143 auto super_metadata = NewFakeMetadata(source_manifest);
Yifan Hongc049f932019-07-23 15:06:05 -0700144 if (!module_->UpdatePartitionMetadata(
Yifan Hong13d41cb2019-09-16 13:18:22 -0700145 super_metadata.get(), target(), update_manifest)) {
Yifan Hongc049f932019-07-23 15:06:05 -0700146 return testing::AssertionFailure()
147 << "UpdatePartitionMetadataInternal failed";
148 }
149 std::stringstream ss;
150 Listener listener(&ss);
151 if (matcher.MatchAndExplain(super_metadata.get(), &listener)) {
152 return testing::AssertionSuccess() << ss.str();
153 } else {
154 return testing::AssertionFailure() << ss.str();
155 }
156 }
157
158 std::unique_ptr<DynamicPartitionControlAndroid> module_;
159 TestParam slots_;
160};
161
162class DynamicPartitionControlAndroidTestP
163 : public DynamicPartitionControlAndroidTest,
164 public ::testing::WithParamInterface<TestParam> {
165 public:
166 void SetUp() override {
167 DynamicPartitionControlAndroidTest::SetUp();
168 SetSlots(GetParam());
169 }
170};
171
172// Test resize case. Grow if target metadata contains a partition with a size
173// less than expected.
174TEST_P(DynamicPartitionControlAndroidTestP,
175 NeedGrowIfSizeNotMatchWhenResizing) {
176 PartitionSuffixSizes source_metadata{{S("system"), 2_GiB},
177 {S("vendor"), 1_GiB},
178 {T("system"), 2_GiB},
179 {T("vendor"), 1_GiB}};
180 PartitionSuffixSizes expected{{S("system"), 2_GiB},
181 {S("vendor"), 1_GiB},
182 {T("system"), 3_GiB},
183 {T("vendor"), 1_GiB}};
184 PartitionSizes update_metadata{{"system", 3_GiB}, {"vendor", 1_GiB}};
185 EXPECT_TRUE(
186 UpdatePartitionMetadata(source_metadata, update_metadata, expected));
187}
188
189// Test resize case. Shrink if target metadata contains a partition with a size
190// greater than expected.
191TEST_P(DynamicPartitionControlAndroidTestP,
192 NeedShrinkIfSizeNotMatchWhenResizing) {
193 PartitionSuffixSizes source_metadata{{S("system"), 2_GiB},
194 {S("vendor"), 1_GiB},
195 {T("system"), 2_GiB},
196 {T("vendor"), 1_GiB}};
197 PartitionSuffixSizes expected{{S("system"), 2_GiB},
198 {S("vendor"), 1_GiB},
199 {T("system"), 2_GiB},
200 {T("vendor"), 150_MiB}};
201 PartitionSizes update_metadata{{"system", 2_GiB}, {"vendor", 150_MiB}};
202 EXPECT_TRUE(
203 UpdatePartitionMetadata(source_metadata, update_metadata, expected));
204}
205
206// Test adding partitions on the first run.
207TEST_P(DynamicPartitionControlAndroidTestP, AddPartitionToEmptyMetadata) {
208 PartitionSuffixSizes source_metadata{};
209 PartitionSuffixSizes expected{{T("system"), 2_GiB}, {T("vendor"), 1_GiB}};
210 PartitionSizes update_metadata{{"system", 2_GiB}, {"vendor", 1_GiB}};
211 EXPECT_TRUE(
212 UpdatePartitionMetadata(source_metadata, update_metadata, expected));
213}
214
215// Test subsequent add case.
216TEST_P(DynamicPartitionControlAndroidTestP, AddAdditionalPartition) {
217 PartitionSuffixSizes source_metadata{{S("system"), 2_GiB},
218 {T("system"), 2_GiB}};
219 PartitionSuffixSizes expected{
220 {S("system"), 2_GiB}, {T("system"), 2_GiB}, {T("vendor"), 1_GiB}};
221 PartitionSizes update_metadata{{"system", 2_GiB}, {"vendor", 1_GiB}};
222 EXPECT_TRUE(
223 UpdatePartitionMetadata(source_metadata, update_metadata, expected));
224}
225
226// Test delete one partition.
227TEST_P(DynamicPartitionControlAndroidTestP, DeletePartition) {
228 PartitionSuffixSizes source_metadata{{S("system"), 2_GiB},
229 {S("vendor"), 1_GiB},
230 {T("system"), 2_GiB},
231 {T("vendor"), 1_GiB}};
232 // No T("vendor")
233 PartitionSuffixSizes expected{
234 {S("system"), 2_GiB}, {S("vendor"), 1_GiB}, {T("system"), 2_GiB}};
235 PartitionSizes update_metadata{{"system", 2_GiB}};
236 EXPECT_TRUE(
237 UpdatePartitionMetadata(source_metadata, update_metadata, expected));
238}
239
240// Test delete all partitions.
241TEST_P(DynamicPartitionControlAndroidTestP, DeleteAll) {
242 PartitionSuffixSizes source_metadata{{S("system"), 2_GiB},
243 {S("vendor"), 1_GiB},
244 {T("system"), 2_GiB},
245 {T("vendor"), 1_GiB}};
246 PartitionSuffixSizes expected{{S("system"), 2_GiB}, {S("vendor"), 1_GiB}};
247 PartitionSizes update_metadata{};
248 EXPECT_TRUE(
249 UpdatePartitionMetadata(source_metadata, update_metadata, expected));
250}
251
252// Test corrupt source metadata case.
253TEST_P(DynamicPartitionControlAndroidTestP, CorruptedSourceMetadata) {
254 EXPECT_CALL(dynamicControl(),
255 LoadMetadataBuilder(GetSuperDevice(source()), source(), _))
256 .WillOnce(Invoke([](auto, auto, auto) { return nullptr; }));
257 ExpectUnmap({T("system")});
258
259 EXPECT_FALSE(PreparePartitionsForUpdate({{"system", 1_GiB}}))
260 << "Should not be able to continue with corrupt source metadata";
261}
262
263// Test that UpdatePartitionMetadata fails if there is not enough space on the
264// device.
265TEST_P(DynamicPartitionControlAndroidTestP, NotEnoughSpace) {
266 PartitionSuffixSizes source_metadata{{S("system"), 3_GiB},
267 {S("vendor"), 2_GiB},
268 {T("system"), 0},
269 {T("vendor"), 0}};
270 PartitionSizes update_metadata{{"system", 3_GiB}, {"vendor", 3_GiB}};
271
272 EXPECT_FALSE(UpdatePartitionMetadata(source_metadata, update_metadata, {}))
273 << "Should not be able to fit 11GiB data into 10GiB space";
274}
275
276TEST_P(DynamicPartitionControlAndroidTestP, NotEnoughSpaceForSlot) {
277 PartitionSuffixSizes source_metadata{{S("system"), 1_GiB},
278 {S("vendor"), 1_GiB},
279 {T("system"), 0},
280 {T("vendor"), 0}};
281 PartitionSizes update_metadata{{"system", 3_GiB}, {"vendor", 3_GiB}};
282 EXPECT_FALSE(UpdatePartitionMetadata(source_metadata, update_metadata, {}))
283 << "Should not be able to grow over size of super / 2";
284}
285
286INSTANTIATE_TEST_CASE_P(DynamicPartitionControlAndroidTest,
287 DynamicPartitionControlAndroidTestP,
288 testing::Values(TestParam{0, 1}, TestParam{1, 0}));
289
290class DynamicPartitionControlAndroidGroupTestP
291 : public DynamicPartitionControlAndroidTestP {
292 public:
Yifan Hong13d41cb2019-09-16 13:18:22 -0700293 DeltaArchiveManifest source_manifest;
Yifan Hongc049f932019-07-23 15:06:05 -0700294 void SetUp() override {
295 DynamicPartitionControlAndroidTestP::SetUp();
Yifan Hong13d41cb2019-09-16 13:18:22 -0700296 AddGroupAndPartition(
297 &source_manifest, S("android"), 3_GiB, S("system"), 2_GiB);
298 AddGroupAndPartition(&source_manifest, S("oem"), 2_GiB, S("vendor"), 1_GiB);
299 AddGroupAndPartition(&source_manifest, T("android"), 3_GiB, T("system"), 0);
300 AddGroupAndPartition(&source_manifest, T("oem"), 2_GiB, T("vendor"), 0);
Yifan Hongc049f932019-07-23 15:06:05 -0700301 }
302
Yifan Hong13d41cb2019-09-16 13:18:22 -0700303 void AddGroupAndPartition(DeltaArchiveManifest* manifest,
304 const string& group,
305 uint64_t group_size,
306 const string& partition,
307 uint64_t partition_size) {
308 auto* g = AddGroup(manifest, group, group_size);
309 AddPartition(manifest, g, partition, partition_size);
Yifan Hongc049f932019-07-23 15:06:05 -0700310 }
311};
312
313// Allow to resize within group.
314TEST_P(DynamicPartitionControlAndroidGroupTestP, ResizeWithinGroup) {
Yifan Hong13d41cb2019-09-16 13:18:22 -0700315 DeltaArchiveManifest expected;
316 AddGroupAndPartition(&expected, T("android"), 3_GiB, T("system"), 3_GiB);
317 AddGroupAndPartition(&expected, T("oem"), 2_GiB, T("vendor"), 2_GiB);
Yifan Hongc049f932019-07-23 15:06:05 -0700318
Yifan Hong13d41cb2019-09-16 13:18:22 -0700319 DeltaArchiveManifest update_manifest;
320 AddGroupAndPartition(&update_manifest, "android", 3_GiB, "system", 3_GiB);
321 AddGroupAndPartition(&update_manifest, "oem", 2_GiB, "vendor", 2_GiB);
Yifan Hongc049f932019-07-23 15:06:05 -0700322
323 EXPECT_TRUE(
Yifan Hong13d41cb2019-09-16 13:18:22 -0700324 UpdatePartitionMetadata(source_manifest, update_manifest, expected));
Yifan Hongc049f932019-07-23 15:06:05 -0700325}
326
327TEST_P(DynamicPartitionControlAndroidGroupTestP, NotEnoughSpaceForGroup) {
Yifan Hong13d41cb2019-09-16 13:18:22 -0700328 DeltaArchiveManifest update_manifest;
329 AddGroupAndPartition(&update_manifest, "android", 3_GiB, "system", 1_GiB),
330 AddGroupAndPartition(&update_manifest, "oem", 2_GiB, "vendor", 3_GiB);
331 EXPECT_FALSE(UpdatePartitionMetadata(source_manifest, update_manifest, {}))
Yifan Hongc049f932019-07-23 15:06:05 -0700332 << "Should not be able to grow over maximum size of group";
333}
334
335TEST_P(DynamicPartitionControlAndroidGroupTestP, GroupTooBig) {
Yifan Hong13d41cb2019-09-16 13:18:22 -0700336 DeltaArchiveManifest update_manifest;
337 AddGroup(&update_manifest, "android", 3_GiB);
338 AddGroup(&update_manifest, "oem", 3_GiB);
339 EXPECT_FALSE(UpdatePartitionMetadata(source_manifest, update_manifest, {}))
Yifan Hongc049f932019-07-23 15:06:05 -0700340 << "Should not be able to grow over size of super / 2";
341}
342
343TEST_P(DynamicPartitionControlAndroidGroupTestP, AddPartitionToGroup) {
Yifan Hong13d41cb2019-09-16 13:18:22 -0700344 DeltaArchiveManifest expected;
345 auto* g = AddGroup(&expected, T("android"), 3_GiB);
346 AddPartition(&expected, g, T("system"), 2_GiB);
347 AddPartition(&expected, g, T("system_ext"), 1_GiB);
348
349 DeltaArchiveManifest update_manifest;
350 g = AddGroup(&update_manifest, "android", 3_GiB);
351 AddPartition(&update_manifest, g, "system", 2_GiB);
352 AddPartition(&update_manifest, g, "system_ext", 1_GiB);
353 AddGroupAndPartition(&update_manifest, "oem", 2_GiB, "vendor", 2_GiB);
354
Yifan Hongc049f932019-07-23 15:06:05 -0700355 EXPECT_TRUE(
Yifan Hong13d41cb2019-09-16 13:18:22 -0700356 UpdatePartitionMetadata(source_manifest, update_manifest, expected));
Yifan Hongc049f932019-07-23 15:06:05 -0700357}
358
359TEST_P(DynamicPartitionControlAndroidGroupTestP, RemovePartitionFromGroup) {
Yifan Hong13d41cb2019-09-16 13:18:22 -0700360 DeltaArchiveManifest expected;
361 AddGroup(&expected, T("android"), 3_GiB);
362
363 DeltaArchiveManifest update_manifest;
364 AddGroup(&update_manifest, "android", 3_GiB);
365 AddGroupAndPartition(&update_manifest, "oem", 2_GiB, "vendor", 2_GiB);
366
Yifan Hongc049f932019-07-23 15:06:05 -0700367 EXPECT_TRUE(
Yifan Hong13d41cb2019-09-16 13:18:22 -0700368 UpdatePartitionMetadata(source_manifest, update_manifest, expected));
Yifan Hongc049f932019-07-23 15:06:05 -0700369}
370
371TEST_P(DynamicPartitionControlAndroidGroupTestP, AddGroup) {
Yifan Hong13d41cb2019-09-16 13:18:22 -0700372 DeltaArchiveManifest expected;
373 AddGroupAndPartition(
374 &expected, T("new_group"), 2_GiB, T("new_partition"), 2_GiB);
375
376 DeltaArchiveManifest update_manifest;
377 AddGroupAndPartition(&update_manifest, "android", 2_GiB, "system", 2_GiB);
378 AddGroupAndPartition(&update_manifest, "oem", 1_GiB, "vendor", 1_GiB);
379 AddGroupAndPartition(
380 &update_manifest, "new_group", 2_GiB, "new_partition", 2_GiB);
Yifan Hongc049f932019-07-23 15:06:05 -0700381 EXPECT_TRUE(
Yifan Hong13d41cb2019-09-16 13:18:22 -0700382 UpdatePartitionMetadata(source_manifest, update_manifest, expected));
Yifan Hongc049f932019-07-23 15:06:05 -0700383}
384
385TEST_P(DynamicPartitionControlAndroidGroupTestP, RemoveGroup) {
Yifan Hong13d41cb2019-09-16 13:18:22 -0700386 DeltaArchiveManifest update_manifest;
387 AddGroupAndPartition(&update_manifest, "android", 2_GiB, "system", 2_GiB);
Yifan Hongc049f932019-07-23 15:06:05 -0700388
389 EXPECT_TRUE(UpdatePartitionMetadata(
Yifan Hong13d41cb2019-09-16 13:18:22 -0700390 source_manifest, update_manifest, Not(HasGroup(T("oem")))));
Yifan Hongc049f932019-07-23 15:06:05 -0700391}
392
393TEST_P(DynamicPartitionControlAndroidGroupTestP, ResizeGroup) {
Yifan Hong13d41cb2019-09-16 13:18:22 -0700394 DeltaArchiveManifest expected;
395 AddGroupAndPartition(&expected, T("android"), 2_GiB, T("system"), 2_GiB);
396 AddGroupAndPartition(&expected, T("oem"), 3_GiB, T("vendor"), 3_GiB);
397 DeltaArchiveManifest update_manifest;
398 AddGroupAndPartition(&update_manifest, "android", 2_GiB, "system", 2_GiB),
399 AddGroupAndPartition(&update_manifest, "oem", 3_GiB, "vendor", 3_GiB);
Yifan Hongc049f932019-07-23 15:06:05 -0700400 EXPECT_TRUE(
Yifan Hong13d41cb2019-09-16 13:18:22 -0700401 UpdatePartitionMetadata(source_manifest, update_manifest, expected));
Yifan Hongc049f932019-07-23 15:06:05 -0700402}
403
404INSTANTIATE_TEST_CASE_P(DynamicPartitionControlAndroidTest,
405 DynamicPartitionControlAndroidGroupTestP,
406 testing::Values(TestParam{0, 1}, TestParam{1, 0}));
407
408const PartitionSuffixSizes update_sizes_0() {
409 // Initial state is 0 for "other" slot.
410 return {
411 {"grown_a", 2_GiB},
412 {"shrunk_a", 1_GiB},
413 {"same_a", 100_MiB},
414 {"deleted_a", 150_MiB},
415 // no added_a
416 {"grown_b", 200_MiB},
417 // simulate system_other
418 {"shrunk_b", 0},
419 {"same_b", 0},
420 {"deleted_b", 0},
421 // no added_b
422 };
423}
424
425const PartitionSuffixSizes update_sizes_1() {
426 return {
427 {"grown_a", 2_GiB},
428 {"shrunk_a", 1_GiB},
429 {"same_a", 100_MiB},
430 {"deleted_a", 150_MiB},
431 // no added_a
432 {"grown_b", 3_GiB},
433 {"shrunk_b", 150_MiB},
434 {"same_b", 100_MiB},
435 {"added_b", 150_MiB},
436 // no deleted_b
437 };
438}
439
440const PartitionSuffixSizes update_sizes_2() {
441 return {
442 {"grown_a", 4_GiB},
443 {"shrunk_a", 100_MiB},
444 {"same_a", 100_MiB},
445 {"deleted_a", 64_MiB},
446 // no added_a
447 {"grown_b", 3_GiB},
448 {"shrunk_b", 150_MiB},
449 {"same_b", 100_MiB},
450 {"added_b", 150_MiB},
451 // no deleted_b
452 };
453}
454
455// Test case for first update after the device is manufactured, in which
456// case the "other" slot is likely of size "0" (except system, which is
457// non-zero because of system_other partition)
458TEST_F(DynamicPartitionControlAndroidTest, SimulatedFirstUpdate) {
459 SetSlots({0, 1});
460
461 SetMetadata(source(), update_sizes_0());
462 SetMetadata(target(), update_sizes_0());
463 ExpectStoreMetadata(update_sizes_1());
464 ExpectUnmap({"grown_b", "shrunk_b", "same_b", "added_b"});
465
466 EXPECT_TRUE(PreparePartitionsForUpdate({{"grown", 3_GiB},
467 {"shrunk", 150_MiB},
468 {"same", 100_MiB},
469 {"added", 150_MiB}}));
470}
471
472// After first update, test for the second update. In the second update, the
473// "added" partition is deleted and "deleted" partition is re-added.
474TEST_F(DynamicPartitionControlAndroidTest, SimulatedSecondUpdate) {
475 SetSlots({1, 0});
476
477 SetMetadata(source(), update_sizes_1());
478 SetMetadata(target(), update_sizes_0());
479
480 ExpectStoreMetadata(update_sizes_2());
481 ExpectUnmap({"grown_a", "shrunk_a", "same_a", "deleted_a"});
482
483 EXPECT_TRUE(PreparePartitionsForUpdate({{"grown", 4_GiB},
484 {"shrunk", 100_MiB},
485 {"same", 100_MiB},
486 {"deleted", 64_MiB}}));
487}
488
489} // namespace chromeos_update_engine