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 "update_engine/boot_control_android.h" |
| 18 | |
| 19 | #include <set> |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 20 | #include <vector> |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 21 | |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 22 | #include <base/logging.h> |
| 23 | #include <base/strings/string_util.h> |
David Anderson | d63cb3c | 2018-10-01 14:15:00 -0700 | [diff] [blame] | 24 | #include <fs_mgr.h> |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 25 | #include <gmock/gmock.h> |
| 26 | #include <gtest/gtest.h> |
| 27 | |
| 28 | #include "update_engine/mock_boot_control_hal.h" |
| 29 | #include "update_engine/mock_dynamic_partition_control.h" |
| 30 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 31 | using android::fs_mgr::MetadataBuilder; |
| 32 | using android::hardware::Void; |
| 33 | using testing::_; |
| 34 | using testing::AnyNumber; |
| 35 | using testing::Contains; |
| 36 | using testing::Eq; |
| 37 | using testing::Invoke; |
| 38 | using testing::Key; |
| 39 | using testing::MakeMatcher; |
| 40 | using testing::Matcher; |
| 41 | using testing::MatcherInterface; |
| 42 | using testing::MatchResultListener; |
| 43 | using testing::NiceMock; |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 44 | using testing::Not; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 45 | using testing::Return; |
| 46 | |
| 47 | namespace chromeos_update_engine { |
| 48 | |
| 49 | constexpr const uint32_t kMaxNumSlots = 2; |
| 50 | constexpr const char* kSlotSuffixes[kMaxNumSlots] = {"_a", "_b"}; |
| 51 | constexpr const char* kFakeDevicePath = "/fake/dev/path/"; |
| 52 | constexpr const char* kFakeMappedPath = "/fake/mapped/path/"; |
| 53 | constexpr const uint32_t kFakeMetadataSize = 65536; |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 54 | constexpr const char* kDefaultGroup = "foo"; |
| 55 | |
| 56 | // "vendor" |
| 57 | struct PartitionName : std::string { |
| 58 | using std::string::string; |
| 59 | }; |
| 60 | |
| 61 | // "vendor_a" |
| 62 | struct PartitionNameSuffix : std::string { |
| 63 | using std::string::string; |
| 64 | }; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 65 | |
| 66 | // A map describing the size of each partition. |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 67 | using PartitionSizes = std::map<PartitionName, uint64_t>; |
| 68 | using PartitionSuffixSizes = std::map<PartitionNameSuffix, uint64_t>; |
| 69 | |
| 70 | using PartitionMetadata = BootControlInterface::PartitionMetadata; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 71 | |
| 72 | // C++ standards do not allow uint64_t (aka unsigned long) to be the parameter |
| 73 | // of user-defined literal operators. |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 74 | constexpr unsigned long long operator"" _MiB(unsigned long long x) { // NOLINT |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 75 | return x << 20; |
| 76 | } |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 77 | constexpr unsigned long long operator"" _GiB(unsigned long long x) { // NOLINT |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 78 | return x << 30; |
| 79 | } |
| 80 | |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 81 | constexpr uint64_t kDefaultGroupSize = 5_GiB; |
| 82 | // Super device size. 1 MiB for metadata. |
| 83 | constexpr uint64_t kDefaultSuperSize = kDefaultGroupSize * 2 + 1_MiB; |
| 84 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 85 | template <typename U, typename V> |
| 86 | std::ostream& operator<<(std::ostream& os, const std::map<U, V>& param) { |
| 87 | os << "{"; |
| 88 | bool first = true; |
| 89 | for (const auto& pair : param) { |
| 90 | if (!first) |
| 91 | os << ", "; |
| 92 | os << pair.first << ":" << pair.second; |
| 93 | first = false; |
| 94 | } |
| 95 | return os << "}"; |
| 96 | } |
| 97 | |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 98 | template <typename T> |
| 99 | std::ostream& operator<<(std::ostream& os, const std::vector<T>& param) { |
| 100 | os << "["; |
| 101 | bool first = true; |
| 102 | for (const auto& e : param) { |
| 103 | if (!first) |
| 104 | os << ", "; |
| 105 | os << e; |
| 106 | first = false; |
| 107 | } |
| 108 | return os << "]"; |
| 109 | } |
| 110 | |
| 111 | std::ostream& operator<<(std::ostream& os, |
| 112 | const PartitionMetadata::Partition& p) { |
| 113 | return os << "{" << p.name << ", " << p.size << "}"; |
| 114 | } |
| 115 | |
| 116 | std::ostream& operator<<(std::ostream& os, const PartitionMetadata::Group& g) { |
| 117 | return os << "{" << g.name << ", " << g.size << ", " << g.partitions << "}"; |
| 118 | } |
| 119 | |
| 120 | std::ostream& operator<<(std::ostream& os, const PartitionMetadata& m) { |
| 121 | return os << m.groups; |
| 122 | } |
| 123 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 124 | inline std::string GetDevice(const std::string& name) { |
| 125 | return kFakeDevicePath + name; |
| 126 | } |
| 127 | inline std::string GetSuperDevice() { |
David Anderson | d63cb3c | 2018-10-01 14:15:00 -0700 | [diff] [blame] | 128 | return GetDevice(fs_mgr_get_super_partition_name()); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | struct TestParam { |
| 132 | uint32_t source; |
| 133 | uint32_t target; |
| 134 | }; |
| 135 | std::ostream& operator<<(std::ostream& os, const TestParam& param) { |
| 136 | return os << "{source: " << param.source << ", target:" << param.target |
| 137 | << "}"; |
| 138 | } |
| 139 | |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 140 | // To support legacy tests, auto-convert {name_a: size} map to |
| 141 | // PartitionMetadata. |
| 142 | PartitionMetadata toMetadata(const PartitionSuffixSizes& partition_sizes) { |
| 143 | PartitionMetadata metadata; |
| 144 | for (const char* suffix : kSlotSuffixes) { |
| 145 | metadata.groups.push_back( |
| 146 | {std::string(kDefaultGroup) + suffix, kDefaultGroupSize, {}}); |
| 147 | } |
| 148 | for (const auto& pair : partition_sizes) { |
| 149 | for (size_t suffix_idx = 0; suffix_idx < kMaxNumSlots; ++suffix_idx) { |
| 150 | if (base::EndsWith(pair.first, |
| 151 | kSlotSuffixes[suffix_idx], |
| 152 | base::CompareCase::SENSITIVE)) { |
| 153 | metadata.groups[suffix_idx].partitions.push_back( |
| 154 | {pair.first, pair.second}); |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | return metadata; |
| 159 | } |
| 160 | |
| 161 | // To support legacy tests, auto-convert {name: size} map to PartitionMetadata. |
| 162 | PartitionMetadata toMetadata(const PartitionSizes& partition_sizes) { |
| 163 | PartitionMetadata metadata; |
| 164 | metadata.groups.push_back( |
| 165 | {std::string{kDefaultGroup}, kDefaultGroupSize, {}}); |
| 166 | for (const auto& pair : partition_sizes) { |
| 167 | metadata.groups[0].partitions.push_back({pair.first, pair.second}); |
| 168 | } |
| 169 | return metadata; |
| 170 | } |
| 171 | |
| 172 | std::unique_ptr<MetadataBuilder> NewFakeMetadata( |
| 173 | const PartitionMetadata& metadata) { |
| 174 | auto builder = |
| 175 | MetadataBuilder::New(kDefaultSuperSize, kFakeMetadataSize, kMaxNumSlots); |
| 176 | EXPECT_GE(builder->AllocatableSpace(), kDefaultGroupSize * 2); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 177 | EXPECT_NE(nullptr, builder); |
| 178 | if (builder == nullptr) |
| 179 | return nullptr; |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 180 | for (const auto& group : metadata.groups) { |
| 181 | EXPECT_TRUE(builder->AddGroup(group.name, group.size)); |
| 182 | for (const auto& partition : group.partitions) { |
| 183 | auto p = builder->AddPartition(partition.name, group.name, 0 /* attr */); |
| 184 | EXPECT_TRUE(p && builder->ResizePartition(p, partition.size)); |
| 185 | } |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 186 | } |
| 187 | return builder; |
| 188 | } |
| 189 | |
| 190 | class MetadataMatcher : public MatcherInterface<MetadataBuilder*> { |
| 191 | public: |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 192 | explicit MetadataMatcher(const PartitionSuffixSizes& partition_sizes) |
| 193 | : partition_metadata_(toMetadata(partition_sizes)) {} |
| 194 | explicit MetadataMatcher(const PartitionMetadata& partition_metadata) |
| 195 | : partition_metadata_(partition_metadata) {} |
| 196 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 197 | bool MatchAndExplain(MetadataBuilder* metadata, |
| 198 | MatchResultListener* listener) const override { |
| 199 | bool success = true; |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 200 | for (const auto& group : partition_metadata_.groups) { |
| 201 | for (const auto& partition : group.partitions) { |
| 202 | auto p = metadata->FindPartition(partition.name); |
| 203 | if (p == nullptr) { |
| 204 | if (!success) |
| 205 | *listener << "; "; |
| 206 | *listener << "No partition " << partition.name; |
| 207 | success = false; |
| 208 | continue; |
| 209 | } |
| 210 | if (p->size() != partition.size) { |
| 211 | if (!success) |
| 212 | *listener << "; "; |
| 213 | *listener << "Partition " << partition.name << " has size " |
| 214 | << p->size() << ", expected " << partition.size; |
| 215 | success = false; |
| 216 | } |
| 217 | if (p->group_name() != group.name) { |
| 218 | if (!success) |
| 219 | *listener << "; "; |
| 220 | *listener << "Partition " << partition.name << " has group " |
| 221 | << p->group_name() << ", expected " << group.name; |
| 222 | success = false; |
| 223 | } |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 224 | } |
| 225 | } |
| 226 | return success; |
| 227 | } |
| 228 | |
| 229 | void DescribeTo(std::ostream* os) const override { |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 230 | *os << "expect: " << partition_metadata_; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | void DescribeNegationTo(std::ostream* os) const override { |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 234 | *os << "expect not: " << partition_metadata_; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | private: |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 238 | PartitionMetadata partition_metadata_; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 239 | }; |
| 240 | |
| 241 | inline Matcher<MetadataBuilder*> MetadataMatches( |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 242 | const PartitionSuffixSizes& partition_sizes) { |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 243 | return MakeMatcher(new MetadataMatcher(partition_sizes)); |
| 244 | } |
| 245 | |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 246 | inline Matcher<MetadataBuilder*> MetadataMatches( |
| 247 | const PartitionMetadata& partition_metadata) { |
| 248 | return MakeMatcher(new MetadataMatcher(partition_metadata)); |
| 249 | } |
| 250 | |
| 251 | MATCHER_P(HasGroup, group, " has group " + group) { |
| 252 | auto groups = arg->ListGroups(); |
| 253 | return std::find(groups.begin(), groups.end(), group) != groups.end(); |
| 254 | } |
| 255 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 256 | class BootControlAndroidTest : public ::testing::Test { |
| 257 | protected: |
| 258 | void SetUp() override { |
| 259 | // Fake init bootctl_ |
| 260 | bootctl_.module_ = new NiceMock<MockBootControlHal>(); |
| 261 | bootctl_.dynamic_control_ = |
| 262 | std::make_unique<NiceMock<MockDynamicPartitionControl>>(); |
| 263 | |
| 264 | ON_CALL(module(), getNumberSlots()).WillByDefault(Invoke([] { |
| 265 | return kMaxNumSlots; |
| 266 | })); |
| 267 | ON_CALL(module(), getSuffix(_, _)) |
| 268 | .WillByDefault(Invoke([](auto slot, auto cb) { |
| 269 | EXPECT_LE(slot, kMaxNumSlots); |
| 270 | cb(slot < kMaxNumSlots ? kSlotSuffixes[slot] : ""); |
| 271 | return Void(); |
| 272 | })); |
| 273 | |
| 274 | ON_CALL(dynamicControl(), IsDynamicPartitionsEnabled()) |
| 275 | .WillByDefault(Return(true)); |
| 276 | ON_CALL(dynamicControl(), GetDeviceDir(_)) |
| 277 | .WillByDefault(Invoke([](auto path) { |
| 278 | *path = kFakeDevicePath; |
| 279 | return true; |
| 280 | })); |
| 281 | } |
| 282 | |
| 283 | // Return the mocked HAL module. |
| 284 | NiceMock<MockBootControlHal>& module() { |
| 285 | return static_cast<NiceMock<MockBootControlHal>&>(*bootctl_.module_); |
| 286 | } |
| 287 | |
| 288 | // Return the mocked DynamicPartitionControlInterface. |
| 289 | NiceMock<MockDynamicPartitionControl>& dynamicControl() { |
| 290 | return static_cast<NiceMock<MockDynamicPartitionControl>&>( |
| 291 | *bootctl_.dynamic_control_); |
| 292 | } |
| 293 | |
| 294 | // Set the fake metadata to return when LoadMetadataBuilder is called on |
| 295 | // |slot|. |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 296 | void SetMetadata(uint32_t slot, const PartitionSuffixSizes& sizes) { |
| 297 | SetMetadata(slot, toMetadata(sizes)); |
| 298 | } |
| 299 | |
| 300 | void SetMetadata(uint32_t slot, const PartitionMetadata& metadata) { |
Yifan Hong | 6e706b1 | 2018-11-09 16:50:51 -0800 | [diff] [blame] | 301 | EXPECT_CALL(dynamicControl(), |
| 302 | LoadMetadataBuilder(GetSuperDevice(), slot, _)) |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 303 | .Times(AnyNumber()) |
Yifan Hong | 6e706b1 | 2018-11-09 16:50:51 -0800 | [diff] [blame] | 304 | .WillRepeatedly(Invoke([metadata](auto, auto, auto) { |
| 305 | return NewFakeMetadata(metadata); |
| 306 | })); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | // Expect that MapPartitionOnDeviceMapper is called on target() metadata slot |
| 310 | // with each partition in |partitions|. |
Yifan Hong | af65ef1 | 2018-10-29 11:09:06 -0700 | [diff] [blame] | 311 | void ExpectMap(const std::set<std::string>& partitions, |
| 312 | bool force_writable = true) { |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 313 | // Error when MapPartitionOnDeviceMapper is called on unknown arguments. |
Yifan Hong | af65ef1 | 2018-10-29 11:09:06 -0700 | [diff] [blame] | 314 | ON_CALL(dynamicControl(), MapPartitionOnDeviceMapper(_, _, _, _, _)) |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 315 | .WillByDefault(Return(false)); |
| 316 | |
| 317 | for (const auto& partition : partitions) { |
Yifan Hong | af65ef1 | 2018-10-29 11:09:06 -0700 | [diff] [blame] | 318 | EXPECT_CALL(dynamicControl(), |
| 319 | MapPartitionOnDeviceMapper( |
| 320 | GetSuperDevice(), partition, target(), force_writable, _)) |
| 321 | .WillOnce(Invoke([this](auto, auto partition, auto, auto, auto path) { |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 322 | auto it = mapped_devices_.find(partition); |
| 323 | if (it != mapped_devices_.end()) { |
| 324 | *path = it->second; |
| 325 | return true; |
| 326 | } |
| 327 | mapped_devices_[partition] = *path = kFakeMappedPath + partition; |
| 328 | return true; |
| 329 | })); |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | // Expect that UnmapPartitionOnDeviceMapper is called on target() metadata |
| 334 | // slot with each partition in |partitions|. |
| 335 | void ExpectUnmap(const std::set<std::string>& partitions) { |
| 336 | // Error when UnmapPartitionOnDeviceMapper is called on unknown arguments. |
| 337 | ON_CALL(dynamicControl(), UnmapPartitionOnDeviceMapper(_, _)) |
| 338 | .WillByDefault(Return(false)); |
| 339 | |
| 340 | for (const auto& partition : partitions) { |
| 341 | EXPECT_CALL(dynamicControl(), UnmapPartitionOnDeviceMapper(partition, _)) |
| 342 | .WillOnce(Invoke([this](auto partition, auto) { |
| 343 | mapped_devices_.erase(partition); |
| 344 | return true; |
| 345 | })); |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | void ExpectRemap(const std::set<std::string>& partitions) { |
| 350 | ExpectUnmap(partitions); |
| 351 | ExpectMap(partitions); |
| 352 | } |
| 353 | |
| 354 | void ExpectDevicesAreMapped(const std::set<std::string>& partitions) { |
| 355 | ASSERT_EQ(partitions.size(), mapped_devices_.size()); |
| 356 | for (const auto& partition : partitions) { |
| 357 | EXPECT_THAT(mapped_devices_, Contains(Key(Eq(partition)))) |
| 358 | << "Expect that " << partition << " is mapped, but it is not."; |
| 359 | } |
| 360 | } |
| 361 | |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 362 | void ExpectStoreMetadata(const PartitionSuffixSizes& partition_sizes) { |
Yifan Hong | 549eb36 | 2018-10-19 15:11:12 -0700 | [diff] [blame] | 363 | ExpectStoreMetadataMatch(MetadataMatches(partition_sizes)); |
| 364 | } |
| 365 | |
| 366 | virtual void ExpectStoreMetadataMatch( |
| 367 | const Matcher<MetadataBuilder*>& matcher) { |
| 368 | EXPECT_CALL(dynamicControl(), |
| 369 | StoreMetadata(GetSuperDevice(), matcher, target())) |
| 370 | .WillOnce(Return(true)); |
| 371 | } |
| 372 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 373 | uint32_t source() { return slots_.source; } |
| 374 | |
| 375 | uint32_t target() { return slots_.target; } |
| 376 | |
| 377 | // Return partition names with suffix of source(). |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 378 | PartitionNameSuffix S(const std::string& name) { |
| 379 | return PartitionNameSuffix(name + std::string(kSlotSuffixes[source()])); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | // Return partition names with suffix of target(). |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 383 | PartitionNameSuffix T(const std::string& name) { |
| 384 | return PartitionNameSuffix(name + std::string(kSlotSuffixes[target()])); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | // Set source and target slots to use before testing. |
| 388 | void SetSlots(const TestParam& slots) { |
| 389 | slots_ = slots; |
| 390 | |
| 391 | ON_CALL(module(), getCurrentSlot()).WillByDefault(Invoke([this] { |
| 392 | return source(); |
| 393 | })); |
| 394 | // Should not store metadata to source slot. |
| 395 | EXPECT_CALL(dynamicControl(), StoreMetadata(GetSuperDevice(), _, source())) |
| 396 | .Times(0); |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 397 | // Should not load metadata from target slot. |
| 398 | EXPECT_CALL(dynamicControl(), |
Yifan Hong | 6e706b1 | 2018-11-09 16:50:51 -0800 | [diff] [blame] | 399 | LoadMetadataBuilder(GetSuperDevice(), target(), _)) |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 400 | .Times(0); |
| 401 | } |
| 402 | |
| 403 | bool InitPartitionMetadata(uint32_t slot, PartitionSizes partition_sizes) { |
| 404 | auto m = toMetadata(partition_sizes); |
| 405 | LOG(INFO) << m; |
| 406 | return bootctl_.InitPartitionMetadata(slot, m); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | BootControlAndroid bootctl_; // BootControlAndroid under test. |
| 410 | TestParam slots_; |
| 411 | // mapped devices through MapPartitionOnDeviceMapper. |
| 412 | std::map<std::string, std::string> mapped_devices_; |
| 413 | }; |
| 414 | |
| 415 | class BootControlAndroidTestP |
| 416 | : public BootControlAndroidTest, |
| 417 | public ::testing::WithParamInterface<TestParam> { |
| 418 | public: |
| 419 | void SetUp() override { |
| 420 | BootControlAndroidTest::SetUp(); |
| 421 | SetSlots(GetParam()); |
| 422 | } |
| 423 | }; |
| 424 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 425 | // Test resize case. Grow if target metadata contains a partition with a size |
| 426 | // less than expected. |
| 427 | TEST_P(BootControlAndroidTestP, NeedGrowIfSizeNotMatchWhenResizing) { |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 428 | SetMetadata(source(), |
| 429 | {{S("system"), 2_GiB}, |
| 430 | {S("vendor"), 1_GiB}, |
| 431 | {T("system"), 2_GiB}, |
| 432 | {T("vendor"), 1_GiB}}); |
Yifan Hong | 549eb36 | 2018-10-19 15:11:12 -0700 | [diff] [blame] | 433 | ExpectStoreMetadata({{S("system"), 2_GiB}, |
| 434 | {S("vendor"), 1_GiB}, |
| 435 | {T("system"), 3_GiB}, |
| 436 | {T("vendor"), 1_GiB}}); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 437 | ExpectRemap({T("system"), T("vendor")}); |
| 438 | |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 439 | EXPECT_TRUE( |
| 440 | InitPartitionMetadata(target(), {{"system", 3_GiB}, {"vendor", 1_GiB}})); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 441 | ExpectDevicesAreMapped({T("system"), T("vendor")}); |
| 442 | } |
| 443 | |
| 444 | // Test resize case. Shrink if target metadata contains a partition with a size |
| 445 | // greater than expected. |
| 446 | TEST_P(BootControlAndroidTestP, NeedShrinkIfSizeNotMatchWhenResizing) { |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 447 | SetMetadata(source(), |
| 448 | {{S("system"), 2_GiB}, |
| 449 | {S("vendor"), 1_GiB}, |
| 450 | {T("system"), 2_GiB}, |
| 451 | {T("vendor"), 1_GiB}}); |
Yifan Hong | 549eb36 | 2018-10-19 15:11:12 -0700 | [diff] [blame] | 452 | ExpectStoreMetadata({{S("system"), 2_GiB}, |
| 453 | {S("vendor"), 1_GiB}, |
| 454 | {T("system"), 2_GiB}, |
| 455 | {T("vendor"), 150_MiB}}); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 456 | ExpectRemap({T("system"), T("vendor")}); |
| 457 | |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 458 | EXPECT_TRUE(InitPartitionMetadata(target(), |
| 459 | {{"system", 2_GiB}, {"vendor", 150_MiB}})); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 460 | ExpectDevicesAreMapped({T("system"), T("vendor")}); |
| 461 | } |
| 462 | |
| 463 | // Test adding partitions on the first run. |
| 464 | TEST_P(BootControlAndroidTestP, AddPartitionToEmptyMetadata) { |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 465 | SetMetadata(source(), PartitionSuffixSizes{}); |
Yifan Hong | 549eb36 | 2018-10-19 15:11:12 -0700 | [diff] [blame] | 466 | ExpectStoreMetadata({{T("system"), 2_GiB}, {T("vendor"), 1_GiB}}); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 467 | ExpectRemap({T("system"), T("vendor")}); |
| 468 | |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 469 | EXPECT_TRUE( |
| 470 | InitPartitionMetadata(target(), {{"system", 2_GiB}, {"vendor", 1_GiB}})); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 471 | ExpectDevicesAreMapped({T("system"), T("vendor")}); |
| 472 | } |
| 473 | |
| 474 | // Test subsequent add case. |
| 475 | TEST_P(BootControlAndroidTestP, AddAdditionalPartition) { |
| 476 | SetMetadata(source(), {{S("system"), 2_GiB}, {T("system"), 2_GiB}}); |
Yifan Hong | 549eb36 | 2018-10-19 15:11:12 -0700 | [diff] [blame] | 477 | ExpectStoreMetadata( |
| 478 | {{S("system"), 2_GiB}, {T("system"), 2_GiB}, {T("vendor"), 1_GiB}}); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 479 | ExpectRemap({T("system"), T("vendor")}); |
| 480 | |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 481 | EXPECT_TRUE( |
| 482 | InitPartitionMetadata(target(), {{"system", 2_GiB}, {"vendor", 1_GiB}})); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 483 | ExpectDevicesAreMapped({T("system"), T("vendor")}); |
| 484 | } |
| 485 | |
| 486 | // Test delete one partition. |
| 487 | TEST_P(BootControlAndroidTestP, DeletePartition) { |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 488 | SetMetadata(source(), |
| 489 | {{S("system"), 2_GiB}, |
| 490 | {S("vendor"), 1_GiB}, |
| 491 | {T("system"), 2_GiB}, |
| 492 | {T("vendor"), 1_GiB}}); |
| 493 | // No T("vendor") |
| 494 | ExpectStoreMetadata( |
| 495 | {{S("system"), 2_GiB}, {S("vendor"), 1_GiB}, {T("system"), 2_GiB}}); |
| 496 | ExpectRemap({T("system")}); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 497 | |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 498 | EXPECT_TRUE(InitPartitionMetadata(target(), {{"system", 2_GiB}})); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 499 | ExpectDevicesAreMapped({T("system")}); |
| 500 | } |
| 501 | |
| 502 | // Test delete all partitions. |
| 503 | TEST_P(BootControlAndroidTestP, DeleteAll) { |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 504 | SetMetadata(source(), |
| 505 | {{S("system"), 2_GiB}, |
| 506 | {S("vendor"), 1_GiB}, |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 507 | {T("system"), 2_GiB}, |
| 508 | {T("vendor"), 1_GiB}}); |
| 509 | ExpectStoreMetadata({{S("system"), 2_GiB}, {S("vendor"), 1_GiB}}); |
| 510 | |
| 511 | EXPECT_TRUE(InitPartitionMetadata(target(), {})); |
| 512 | ExpectDevicesAreMapped({}); |
| 513 | } |
| 514 | |
| 515 | // Test corrupt source metadata case. |
| 516 | TEST_P(BootControlAndroidTestP, CorruptedSourceMetadata) { |
Yifan Hong | 6e706b1 | 2018-11-09 16:50:51 -0800 | [diff] [blame] | 517 | EXPECT_CALL(dynamicControl(), |
| 518 | LoadMetadataBuilder(GetSuperDevice(), source(), _)) |
| 519 | .WillOnce(Invoke([](auto, auto, auto) { return nullptr; })); |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 520 | EXPECT_FALSE(InitPartitionMetadata(target(), {{"system", 1_GiB}})) |
| 521 | << "Should not be able to continue with corrupt source metadata"; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | // Test that InitPartitionMetadata fail if there is not enough space on the |
| 525 | // device. |
| 526 | TEST_P(BootControlAndroidTestP, NotEnoughSpace) { |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 527 | SetMetadata(source(), |
| 528 | {{S("system"), 3_GiB}, |
| 529 | {S("vendor"), 2_GiB}, |
| 530 | {T("system"), 0}, |
| 531 | {T("vendor"), 0}}); |
| 532 | EXPECT_FALSE( |
| 533 | InitPartitionMetadata(target(), {{"system", 3_GiB}, {"vendor", 3_GiB}})) |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 534 | << "Should not be able to fit 11GiB data into 10GiB space"; |
| 535 | } |
| 536 | |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 537 | TEST_P(BootControlAndroidTestP, NotEnoughSpaceForSlot) { |
| 538 | SetMetadata(source(), |
| 539 | {{S("system"), 1_GiB}, |
| 540 | {S("vendor"), 1_GiB}, |
| 541 | {T("system"), 0}, |
| 542 | {T("vendor"), 0}}); |
| 543 | EXPECT_FALSE( |
| 544 | InitPartitionMetadata(target(), {{"system", 3_GiB}, {"vendor", 3_GiB}})) |
| 545 | << "Should not be able to grow over size of super / 2"; |
| 546 | } |
| 547 | |
| 548 | INSTANTIATE_TEST_CASE_P(BootControlAndroidTest, |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 549 | BootControlAndroidTestP, |
| 550 | testing::Values(TestParam{0, 1}, TestParam{1, 0})); |
| 551 | |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 552 | const PartitionSuffixSizes update_sizes_0() { |
| 553 | // Initial state is 0 for "other" slot. |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 554 | return { |
| 555 | {"grown_a", 2_GiB}, |
| 556 | {"shrunk_a", 1_GiB}, |
| 557 | {"same_a", 100_MiB}, |
| 558 | {"deleted_a", 150_MiB}, |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 559 | // no added_a |
| 560 | {"grown_b", 200_MiB}, |
| 561 | // simulate system_other |
| 562 | {"shrunk_b", 0}, |
| 563 | {"same_b", 0}, |
| 564 | {"deleted_b", 0}, |
| 565 | // no added_b |
| 566 | }; |
| 567 | } |
| 568 | |
| 569 | const PartitionSuffixSizes update_sizes_1() { |
| 570 | return { |
| 571 | {"grown_a", 2_GiB}, |
| 572 | {"shrunk_a", 1_GiB}, |
| 573 | {"same_a", 100_MiB}, |
| 574 | {"deleted_a", 150_MiB}, |
| 575 | // no added_a |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 576 | {"grown_b", 3_GiB}, |
| 577 | {"shrunk_b", 150_MiB}, |
| 578 | {"same_b", 100_MiB}, |
| 579 | {"added_b", 150_MiB}, |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 580 | // no deleted_b |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 581 | }; |
| 582 | } |
| 583 | |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 584 | const PartitionSuffixSizes update_sizes_2() { |
| 585 | return { |
| 586 | {"grown_a", 4_GiB}, |
| 587 | {"shrunk_a", 100_MiB}, |
| 588 | {"same_a", 100_MiB}, |
| 589 | {"deleted_a", 64_MiB}, |
| 590 | // no added_a |
| 591 | {"grown_b", 3_GiB}, |
| 592 | {"shrunk_b", 150_MiB}, |
| 593 | {"same_b", 100_MiB}, |
| 594 | {"added_b", 150_MiB}, |
| 595 | // no deleted_b |
| 596 | }; |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | // Test case for first update after the device is manufactured, in which |
| 600 | // case the "other" slot is likely of size "0" (except system, which is |
| 601 | // non-zero because of system_other partition) |
| 602 | TEST_F(BootControlAndroidTest, SimulatedFirstUpdate) { |
| 603 | SetSlots({0, 1}); |
| 604 | |
| 605 | SetMetadata(source(), update_sizes_0()); |
| 606 | SetMetadata(target(), update_sizes_0()); |
Yifan Hong | 549eb36 | 2018-10-19 15:11:12 -0700 | [diff] [blame] | 607 | ExpectStoreMetadata(update_sizes_1()); |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 608 | ExpectRemap({"grown_b", "shrunk_b", "same_b", "added_b"}); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 609 | |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 610 | EXPECT_TRUE(InitPartitionMetadata(target(), |
| 611 | {{"grown", 3_GiB}, |
| 612 | {"shrunk", 150_MiB}, |
| 613 | {"same", 100_MiB}, |
| 614 | {"added", 150_MiB}})); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 615 | ExpectDevicesAreMapped({"grown_b", "shrunk_b", "same_b", "added_b"}); |
| 616 | } |
| 617 | |
| 618 | // After first update, test for the second update. In the second update, the |
| 619 | // "added" partition is deleted and "deleted" partition is re-added. |
| 620 | TEST_F(BootControlAndroidTest, SimulatedSecondUpdate) { |
| 621 | SetSlots({1, 0}); |
| 622 | |
| 623 | SetMetadata(source(), update_sizes_1()); |
| 624 | SetMetadata(target(), update_sizes_0()); |
| 625 | |
Yifan Hong | 549eb36 | 2018-10-19 15:11:12 -0700 | [diff] [blame] | 626 | ExpectStoreMetadata(update_sizes_2()); |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 627 | ExpectRemap({"grown_a", "shrunk_a", "same_a", "deleted_a"}); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 628 | |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 629 | EXPECT_TRUE(InitPartitionMetadata(target(), |
| 630 | {{"grown", 4_GiB}, |
| 631 | {"shrunk", 100_MiB}, |
| 632 | {"same", 100_MiB}, |
| 633 | {"deleted", 64_MiB}})); |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 634 | ExpectDevicesAreMapped({"grown_a", "shrunk_a", "same_a", "deleted_a"}); |
| 635 | } |
| 636 | |
| 637 | TEST_F(BootControlAndroidTest, ApplyingToCurrentSlot) { |
| 638 | SetSlots({1, 1}); |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 639 | EXPECT_FALSE(InitPartitionMetadata(target(), {})) |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 640 | << "Should not be able to apply to current slot."; |
| 641 | } |
| 642 | |
Yifan Hong | d4db07e | 2018-10-18 17:46:27 -0700 | [diff] [blame] | 643 | class BootControlAndroidGroupTestP : public BootControlAndroidTestP { |
| 644 | public: |
| 645 | void SetUp() override { |
| 646 | BootControlAndroidTestP::SetUp(); |
| 647 | SetMetadata( |
| 648 | source(), |
| 649 | {.groups = {SimpleGroup(S("android"), 3_GiB, S("system"), 2_GiB), |
| 650 | SimpleGroup(S("oem"), 2_GiB, S("vendor"), 1_GiB), |
| 651 | SimpleGroup(T("android"), 3_GiB, T("system"), 0), |
| 652 | SimpleGroup(T("oem"), 2_GiB, T("vendor"), 0)}}); |
| 653 | } |
| 654 | |
| 655 | // Return a simple group with only one partition. |
| 656 | PartitionMetadata::Group SimpleGroup(const std::string& group, |
| 657 | uint64_t group_size, |
| 658 | const std::string& partition, |
| 659 | uint64_t partition_size) { |
| 660 | return {.name = group, |
| 661 | .size = group_size, |
| 662 | .partitions = {{.name = partition, .size = partition_size}}}; |
| 663 | } |
| 664 | |
| 665 | void ExpectStoreMetadata(const PartitionMetadata& partition_metadata) { |
| 666 | ExpectStoreMetadataMatch(MetadataMatches(partition_metadata)); |
| 667 | } |
| 668 | |
| 669 | // Expect that target slot is stored with target groups. |
| 670 | void ExpectStoreMetadataMatch( |
| 671 | const Matcher<MetadataBuilder*>& matcher) override { |
| 672 | BootControlAndroidTestP::ExpectStoreMetadataMatch(AllOf( |
| 673 | MetadataMatches(PartitionMetadata{ |
| 674 | .groups = {SimpleGroup(S("android"), 3_GiB, S("system"), 2_GiB), |
| 675 | SimpleGroup(S("oem"), 2_GiB, S("vendor"), 1_GiB)}}), |
| 676 | matcher)); |
| 677 | } |
| 678 | }; |
| 679 | |
| 680 | // Allow to resize within group. |
| 681 | TEST_P(BootControlAndroidGroupTestP, ResizeWithinGroup) { |
| 682 | ExpectStoreMetadata(PartitionMetadata{ |
| 683 | .groups = {SimpleGroup(T("android"), 3_GiB, T("system"), 3_GiB), |
| 684 | SimpleGroup(T("oem"), 2_GiB, T("vendor"), 2_GiB)}}); |
| 685 | ExpectRemap({T("system"), T("vendor")}); |
| 686 | |
| 687 | EXPECT_TRUE(bootctl_.InitPartitionMetadata( |
| 688 | target(), |
| 689 | PartitionMetadata{ |
| 690 | .groups = {SimpleGroup("android", 3_GiB, "system", 3_GiB), |
| 691 | SimpleGroup("oem", 2_GiB, "vendor", 2_GiB)}})); |
| 692 | ExpectDevicesAreMapped({T("system"), T("vendor")}); |
| 693 | } |
| 694 | |
| 695 | TEST_P(BootControlAndroidGroupTestP, NotEnoughSpaceForGroup) { |
| 696 | EXPECT_FALSE(bootctl_.InitPartitionMetadata( |
| 697 | target(), |
| 698 | PartitionMetadata{ |
| 699 | .groups = {SimpleGroup("android", 3_GiB, "system", 1_GiB), |
| 700 | SimpleGroup("oem", 2_GiB, "vendor", 3_GiB)}})) |
| 701 | << "Should not be able to grow over maximum size of group"; |
| 702 | } |
| 703 | |
| 704 | TEST_P(BootControlAndroidGroupTestP, GroupTooBig) { |
| 705 | EXPECT_FALSE(bootctl_.InitPartitionMetadata( |
| 706 | target(), |
| 707 | PartitionMetadata{.groups = {{.name = "android", .size = 3_GiB}, |
| 708 | {.name = "oem", .size = 3_GiB}}})) |
| 709 | << "Should not be able to grow over size of super / 2"; |
| 710 | } |
| 711 | |
| 712 | TEST_P(BootControlAndroidGroupTestP, AddPartitionToGroup) { |
| 713 | ExpectStoreMetadata(PartitionMetadata{ |
| 714 | .groups = { |
| 715 | {.name = T("android"), |
| 716 | .size = 3_GiB, |
| 717 | .partitions = {{.name = T("system"), .size = 2_GiB}, |
| 718 | {.name = T("product_services"), .size = 1_GiB}}}}}); |
| 719 | ExpectRemap({T("system"), T("vendor"), T("product_services")}); |
| 720 | |
| 721 | EXPECT_TRUE(bootctl_.InitPartitionMetadata( |
| 722 | target(), |
| 723 | PartitionMetadata{ |
| 724 | .groups = { |
| 725 | {.name = "android", |
| 726 | .size = 3_GiB, |
| 727 | .partitions = {{.name = "system", .size = 2_GiB}, |
| 728 | {.name = "product_services", .size = 1_GiB}}}, |
| 729 | SimpleGroup("oem", 2_GiB, "vendor", 2_GiB)}})); |
| 730 | ExpectDevicesAreMapped({T("system"), T("vendor"), T("product_services")}); |
| 731 | } |
| 732 | |
| 733 | TEST_P(BootControlAndroidGroupTestP, RemovePartitionFromGroup) { |
| 734 | ExpectStoreMetadata(PartitionMetadata{ |
| 735 | .groups = {{.name = T("android"), .size = 3_GiB, .partitions = {}}}}); |
| 736 | ExpectRemap({T("vendor")}); |
| 737 | |
| 738 | EXPECT_TRUE(bootctl_.InitPartitionMetadata( |
| 739 | target(), |
| 740 | PartitionMetadata{ |
| 741 | .groups = {{.name = "android", .size = 3_GiB, .partitions = {}}, |
| 742 | SimpleGroup("oem", 2_GiB, "vendor", 2_GiB)}})); |
| 743 | ExpectDevicesAreMapped({T("vendor")}); |
| 744 | } |
| 745 | |
| 746 | TEST_P(BootControlAndroidGroupTestP, AddGroup) { |
| 747 | ExpectStoreMetadata(PartitionMetadata{ |
| 748 | .groups = { |
| 749 | SimpleGroup(T("new_group"), 2_GiB, T("new_partition"), 2_GiB)}}); |
| 750 | ExpectRemap({T("system"), T("vendor"), T("new_partition")}); |
| 751 | |
| 752 | EXPECT_TRUE(bootctl_.InitPartitionMetadata( |
| 753 | target(), |
| 754 | PartitionMetadata{ |
| 755 | .groups = { |
| 756 | SimpleGroup("android", 2_GiB, "system", 2_GiB), |
| 757 | SimpleGroup("oem", 1_GiB, "vendor", 1_GiB), |
| 758 | SimpleGroup("new_group", 2_GiB, "new_partition", 2_GiB)}})); |
| 759 | ExpectDevicesAreMapped({T("system"), T("vendor"), T("new_partition")}); |
| 760 | } |
| 761 | |
| 762 | TEST_P(BootControlAndroidGroupTestP, RemoveGroup) { |
| 763 | ExpectStoreMetadataMatch(Not(HasGroup(T("oem")))); |
| 764 | ExpectRemap({T("system")}); |
| 765 | EXPECT_TRUE(bootctl_.InitPartitionMetadata( |
| 766 | target(), |
| 767 | PartitionMetadata{ |
| 768 | .groups = {SimpleGroup("android", 2_GiB, "system", 2_GiB)}})); |
| 769 | ExpectDevicesAreMapped({T("system")}); |
| 770 | } |
| 771 | |
| 772 | TEST_P(BootControlAndroidGroupTestP, ResizeGroup) { |
| 773 | ExpectStoreMetadata(PartitionMetadata{ |
| 774 | .groups = {SimpleGroup(T("android"), 2_GiB, T("system"), 2_GiB), |
| 775 | SimpleGroup(T("oem"), 3_GiB, T("vendor"), 3_GiB)}}); |
| 776 | ExpectRemap({T("system"), T("vendor")}); |
| 777 | |
| 778 | EXPECT_TRUE(bootctl_.InitPartitionMetadata( |
| 779 | target(), |
| 780 | PartitionMetadata{ |
| 781 | .groups = {SimpleGroup("android", 2_GiB, "system", 2_GiB), |
| 782 | SimpleGroup("oem", 3_GiB, "vendor", 3_GiB)}})); |
| 783 | ExpectDevicesAreMapped({T("system"), T("vendor")}); |
| 784 | } |
| 785 | |
| 786 | INSTANTIATE_TEST_CASE_P(BootControlAndroidTest, |
| 787 | BootControlAndroidGroupTestP, |
| 788 | testing::Values(TestParam{0, 1}, TestParam{1, 0})); |
| 789 | |
Yifan Hong | 537802d | 2018-08-15 13:15:42 -0700 | [diff] [blame] | 790 | } // namespace chromeos_update_engine |