summaryrefslogtreecommitdiffstats
path: root/fs_mgr/liblp/io_test.cpp
diff options
context:
space:
mode:
authorDavid Anderson <dvander@google.com>2018-11-09 15:58:09 -0800
committerDavid Anderson <dvander@google.com>2018-11-09 16:03:40 -0800
commit140d053c021dc70cdec909b8962b849d06bdf0fa (patch)
tree7c47e6e56327a9c0c191ec9d4392784b7176b9a0 /fs_mgr/liblp/io_test.cpp
parent3d086369344eb63e876f7fcac23dfcfab258264a (diff)
downloadsystem_core-140d053c021dc70cdec909b8962b849d06bdf0fa.tar.gz
system_core-140d053c021dc70cdec909b8962b849d06bdf0fa.tar.bz2
system_core-140d053c021dc70cdec909b8962b849d06bdf0fa.zip
liblp: Add a helper method for upgrading metadata on retrofit devices.
This adds a new MetadataBuilder constructor, NewForUpdate, that can be used by update_engine to simplify upgrading metadata. It is safe to call whether or not the device is a retrofit. If the metadata has block devices assigned to a specific slot, and that slot matches the slot suffix, it will ensure that an equivalent entry exists for the alternate slot. Thus, if the source slot is _a and the target slot is _b, and the metadata has "system_a" as a block device but not "system_b", this will automatically add "system_b" as a block device. Bug: 116802789 Test: liblp_test gtest Change-Id: Ie89d4dbf4c708b5705e658220227ebf33fcb1930
Diffstat (limited to 'fs_mgr/liblp/io_test.cpp')
-rw-r--r--fs_mgr/liblp/io_test.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/fs_mgr/liblp/io_test.cpp b/fs_mgr/liblp/io_test.cpp
index 5f0d9c812..9acf23e8e 100644
--- a/fs_mgr/liblp/io_test.cpp
+++ b/fs_mgr/liblp/io_test.cpp
@@ -649,3 +649,42 @@ TEST(liblp, AutoSlotSuffixing) {
ASSERT_EQ(metadata->block_devices.size(), static_cast<size_t>(1));
EXPECT_EQ(GetBlockDevicePartitionName(metadata->block_devices[0]), "super_a");
}
+
+TEST(liblp, UpdateRetrofit) {
+ unique_ptr<MetadataBuilder> builder = CreateDefaultBuilder();
+ ASSERT_NE(builder, nullptr);
+ ASSERT_TRUE(AddDefaultPartitions(builder.get()));
+ builder->SetAutoSlotSuffixing();
+
+ auto fd = CreateFakeDisk();
+ ASSERT_GE(fd, 0);
+
+ // Note: we bind the same fd to both names, since we want to make sure the
+ // exact same bits are getting read back in each test.
+ TestPartitionOpener opener({{"super_a", fd}, {"super_b", fd}},
+ {{"super_a", kSuperInfo}, {"super_b", kSuperInfo}});
+ auto exported = builder->Export();
+ ASSERT_NE(exported, nullptr);
+ ASSERT_TRUE(FlashPartitionTable(opener, "super_a", *exported.get()));
+
+ builder = MetadataBuilder::NewForUpdate(opener, "super_a", 0, 1);
+ ASSERT_NE(builder, nullptr);
+ auto updated = builder->Export();
+ ASSERT_NE(updated, nullptr);
+ ASSERT_EQ(updated->block_devices.size(), static_cast<size_t>(2));
+ EXPECT_EQ(GetBlockDevicePartitionName(updated->block_devices[0]), "super_a");
+ EXPECT_EQ(GetBlockDevicePartitionName(updated->block_devices[1]), "super_b");
+}
+
+TEST(liblp, UpdateNonRetrofit) {
+ unique_fd fd = CreateFlashedDisk();
+ ASSERT_GE(fd, 0);
+
+ DefaultPartitionOpener opener(fd);
+ auto builder = MetadataBuilder::NewForUpdate(opener, "super", 0, 1);
+ ASSERT_NE(builder, nullptr);
+ auto updated = builder->Export();
+ ASSERT_NE(updated, nullptr);
+ ASSERT_EQ(updated->block_devices.size(), static_cast<size_t>(1));
+ EXPECT_EQ(GetBlockDevicePartitionName(updated->block_devices[0]), "super");
+}