diff options
| author | David Anderson <dvander@google.com> | 2018-08-14 17:49:43 -0700 |
|---|---|---|
| committer | David Anderson <dvander@google.com> | 2018-08-22 10:03:09 -0700 |
| commit | ee4075d84de16af1b14a195185226b33911a8d55 (patch) | |
| tree | 8c46fca343281d4e47cd69337e59ca3346a45fcb /fs_mgr/liblp/io_test.cpp | |
| parent | 1eb3ea37dcbad0265d5eac8c6cfc57fdcd2edc16 (diff) | |
| download | system_core-ee4075d84de16af1b14a195185226b33911a8d55.tar.gz system_core-ee4075d84de16af1b14a195185226b33911a8d55.tar.bz2 system_core-ee4075d84de16af1b14a195185226b33911a8d55.zip | |
liblp: Add ReadImageFromBlob.
This change enables reading metadata images from memory, for situations
where using file descriptors is not practical (such as fastbootd flash).
Bug: 78793464
Test: liblp_test gtest
Change-Id: I9ad08b0ddd4cbb96e87583237a90785e0f4befa4
Diffstat (limited to 'fs_mgr/liblp/io_test.cpp')
| -rw-r--r-- | fs_mgr/liblp/io_test.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/fs_mgr/liblp/io_test.cpp b/fs_mgr/liblp/io_test.cpp index a8d6d7051..329a9016a 100644 --- a/fs_mgr/liblp/io_test.cpp +++ b/fs_mgr/liblp/io_test.cpp @@ -394,6 +394,27 @@ TEST(liblp, ImageFiles) { ASSERT_NE(imported, nullptr); } +// Test that we can read images from buffers. +TEST(liblp, ImageFilesInMemory) { + unique_ptr<MetadataBuilder> builder = CreateDefaultBuilder(); + ASSERT_NE(builder, nullptr); + ASSERT_TRUE(AddDefaultPartitions(builder.get())); + unique_ptr<LpMetadata> exported = builder->Export(); + + unique_fd fd(syscall(__NR_memfd_create, "image_file", 0)); + ASSERT_GE(fd, 0); + ASSERT_TRUE(WriteToImageFile(fd, *exported.get())); + + int64_t offset = SeekFile64(fd, 0, SEEK_CUR); + ASSERT_GE(offset, 0); + ASSERT_EQ(SeekFile64(fd, 0, SEEK_SET), 0); + + size_t bytes = static_cast<size_t>(offset); + std::unique_ptr<char[]> buffer = std::make_unique<char[]>(bytes); + ASSERT_TRUE(android::base::ReadFully(fd, buffer.get(), bytes)); + ASSERT_NE(ReadFromImageBlob(buffer.get(), bytes), nullptr); +} + class BadWriter { public: // When requested, write garbage instead of the requested bytes, then |
