diff options
| author | David Anderson <dvander@google.com> | 2018-10-11 15:00:55 -0700 |
|---|---|---|
| committer | David Anderson <dvander@google.com> | 2018-10-11 17:49:50 -0700 |
| commit | f89838887faf27ebbe42fba75977a6badea81cde (patch) | |
| tree | b81026cec768b63b270fdabe3d759ca801773afd /fs_mgr/liblp/io_test.cpp | |
| parent | e8ab57765ba1ecc5ff66d0b5d6ef20caba77ec02 (diff) | |
| download | system_core-f89838887faf27ebbe42fba75977a6badea81cde.tar.gz system_core-f89838887faf27ebbe42fba75977a6badea81cde.tar.bz2 system_core-f89838887faf27ebbe42fba75977a6badea81cde.zip | |
liblp: Add a gtest for sparse image creation.
Note that this moves SparseBuilder into images.h, and splits
ReadLogicalPartitionGeometry into componenet methods for better
testability.
Bug: 116802789
Test: liblp_test gtest
Change-Id: Ib41a46b633c71623c136a10fcc8017e4de20884c
Diffstat (limited to 'fs_mgr/liblp/io_test.cpp')
| -rw-r--r-- | fs_mgr/liblp/io_test.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/fs_mgr/liblp/io_test.cpp b/fs_mgr/liblp/io_test.cpp index 01de3aca3..322219bc9 100644 --- a/fs_mgr/liblp/io_test.cpp +++ b/fs_mgr/liblp/io_test.cpp @@ -535,3 +535,36 @@ TEST(liblp, UpdateMetadataCleanFailure) { ASSERT_GE(new_table->partitions.size(), 1); ASSERT_EQ(GetPartitionName(new_table->partitions[0]), GetPartitionName(imported->partitions[0])); } + +// Test that writing a sparse image can be read back. +TEST(liblp, FlashSparseImage) { + unique_fd fd = CreateFakeDisk(); + ASSERT_GE(fd, 0); + + BlockDeviceInfo device_info(kDiskSize, 0, 0, 512); + unique_ptr<MetadataBuilder> builder = + MetadataBuilder::New(device_info, kMetadataSize, kMetadataSlots); + ASSERT_NE(builder, nullptr); + ASSERT_TRUE(AddDefaultPartitions(builder.get())); + + unique_ptr<LpMetadata> exported = builder->Export(); + ASSERT_NE(exported, nullptr); + + // Build the sparse file. + SparseBuilder sparse(*exported.get(), 512, {}); + ASSERT_TRUE(sparse.IsValid()); + sparse_file_verbose(sparse.file()); + ASSERT_TRUE(sparse.Build()); + + // Write it to the fake disk. + ASSERT_NE(lseek(fd.get(), 0, SEEK_SET), -1); + int ret = sparse_file_write(sparse.file(), fd.get(), false, false, false); + ASSERT_EQ(ret, 0); + + // Verify that we can read both sets of metadata. + LpMetadataGeometry geometry; + ASSERT_TRUE(ReadPrimaryGeometry(fd.get(), &geometry)); + ASSERT_TRUE(ReadBackupGeometry(fd.get(), &geometry)); + ASSERT_NE(ReadPrimaryMetadata(fd.get(), geometry, 0), nullptr); + ASSERT_NE(ReadBackupMetadata(fd.get(), geometry, 0), nullptr); +} |
