diff --git a/fs_mgr/libsnapshot/cow_snapuserd_test.cpp b/fs_mgr/libsnapshot/cow_snapuserd_test.cpp index 3888eb168..767cd049e 100644 --- a/fs_mgr/libsnapshot/cow_snapuserd_test.cpp +++ b/fs_mgr/libsnapshot/cow_snapuserd_test.cpp @@ -103,6 +103,7 @@ class CowSnapuserdTest final { void ReadSnapshotDeviceAndValidate(); void Shutdown(); void MergeInterrupt(); + void ReadDmUserBlockWithoutDaemon(); std::string snapshot_dev() const { return snapshot_dev_->path(); } @@ -481,6 +482,36 @@ void CowSnapuserdTest::CreateDmUserDevice() { ASSERT_TRUE(android::fs_mgr::WaitForFile(misc_device, 10s)); } +void CowSnapuserdTest::ReadDmUserBlockWithoutDaemon() { + DmTable dmuser_table; + std::string dm_user_name = "dm-test-device"; + unique_fd fd; + + // Create a dm-user block device + ASSERT_TRUE(dmuser_table.AddTarget(std::make_unique(0, 123456, dm_user_name))); + ASSERT_TRUE(dmuser_table.valid()); + + dmuser_dev_ = std::make_unique(dm_user_name, dmuser_table); + ASSERT_TRUE(dmuser_dev_->valid()); + ASSERT_FALSE(dmuser_dev_->path().empty()); + + fd.reset(open(dmuser_dev_->path().c_str(), O_RDONLY)); + ASSERT_GE(fd, 0); + + std::unique_ptr buffer = std::make_unique(1_MiB); + + loff_t offset = 0; + // Every IO should fail as there is no daemon to process the IO + for (size_t j = 0; j < 10; j++) { + ASSERT_EQ(ReadFullyAtOffset(fd, (char*)buffer.get() + offset, BLOCK_SZ, offset), false); + + offset += BLOCK_SZ; + } + + fd = {}; + ASSERT_TRUE(dmuser_dev_->Destroy()); +} + void CowSnapuserdTest::InitDaemon() { bool ok = client_->AttachDmUser(system_device_ctrl_name_); ASSERT_TRUE(ok); @@ -909,6 +940,11 @@ TEST(Snapuserd_Test, Snapshot_COPY_Overlap_Merge_Resume_TEST) { harness.Shutdown(); } +TEST(Snapuserd_Test, ReadDmUserBlockWithoutDaemon) { + CowSnapuserdTest harness; + harness.ReadDmUserBlockWithoutDaemon(); +} + } // namespace snapshot } // namespace android