Loading fs_mgr/libdm/dm_test.cpp +0 −44 Original line number Diff line number Diff line Loading @@ -47,50 +47,6 @@ TEST(libdm, HasMinimumTargets) { ASSERT_TRUE(dm.GetTargetByName("linear", &info)); } // Helper to ensure that device mapper devices are released. class TempDevice { public: TempDevice(const std::string& name, const DmTable& table) : dm_(DeviceMapper::Instance()), name_(name), valid_(false) { valid_ = dm_.CreateDevice(name, table, &path_, 5s); } TempDevice(TempDevice&& other) noexcept : dm_(other.dm_), name_(other.name_), path_(other.path_), valid_(other.valid_) { other.valid_ = false; } ~TempDevice() { if (valid_) { dm_.DeleteDevice(name_); } } bool Destroy() { if (!valid_) { return false; } valid_ = false; return dm_.DeleteDevice(name_); } std::string path() const { return path_; } const std::string& name() const { return name_; } bool valid() const { return valid_; } TempDevice(const TempDevice&) = delete; TempDevice& operator=(const TempDevice&) = delete; TempDevice& operator=(TempDevice&& other) noexcept { name_ = other.name_; valid_ = other.valid_; other.valid_ = false; return *this; } private: DeviceMapper& dm_; std::string name_; std::string path_; bool valid_; }; TEST(libdm, DmLinear) { unique_fd tmp1(CreateTempFile("file_1", 4096)); ASSERT_GE(tmp1, 0); Loading fs_mgr/libdm/test_util.h +48 −0 Original line number Diff line number Diff line Loading @@ -20,8 +20,12 @@ #include <android-base/unique_fd.h> #include <stddef.h> #include <chrono> #include <string> #include <libdm/dm.h> #include <libdm/dm_table.h> namespace android { namespace dm { Loading @@ -29,6 +33,50 @@ namespace dm { // created with a fixed size. android::base::unique_fd CreateTempFile(const std::string& name, size_t size); // Helper to ensure that device mapper devices are released. class TempDevice { public: TempDevice(const std::string& name, const DmTable& table) : dm_(DeviceMapper::Instance()), name_(name), valid_(false) { valid_ = dm_.CreateDevice(name, table, &path_, std::chrono::seconds(5)); } TempDevice(TempDevice&& other) noexcept : dm_(other.dm_), name_(other.name_), path_(other.path_), valid_(other.valid_) { other.valid_ = false; } ~TempDevice() { if (valid_) { dm_.DeleteDevice(name_); } } bool Destroy() { if (!valid_) { return false; } valid_ = false; return dm_.DeleteDevice(name_); } std::string path() const { return path_; } const std::string& name() const { return name_; } bool valid() const { return valid_; } TempDevice(const TempDevice&) = delete; TempDevice& operator=(const TempDevice&) = delete; TempDevice& operator=(TempDevice&& other) noexcept { name_ = other.name_; valid_ = other.valid_; other.valid_ = false; return *this; } private: DeviceMapper& dm_; std::string name_; std::string path_; bool valid_; }; } // namespace dm } // namespace android Loading Loading
fs_mgr/libdm/dm_test.cpp +0 −44 Original line number Diff line number Diff line Loading @@ -47,50 +47,6 @@ TEST(libdm, HasMinimumTargets) { ASSERT_TRUE(dm.GetTargetByName("linear", &info)); } // Helper to ensure that device mapper devices are released. class TempDevice { public: TempDevice(const std::string& name, const DmTable& table) : dm_(DeviceMapper::Instance()), name_(name), valid_(false) { valid_ = dm_.CreateDevice(name, table, &path_, 5s); } TempDevice(TempDevice&& other) noexcept : dm_(other.dm_), name_(other.name_), path_(other.path_), valid_(other.valid_) { other.valid_ = false; } ~TempDevice() { if (valid_) { dm_.DeleteDevice(name_); } } bool Destroy() { if (!valid_) { return false; } valid_ = false; return dm_.DeleteDevice(name_); } std::string path() const { return path_; } const std::string& name() const { return name_; } bool valid() const { return valid_; } TempDevice(const TempDevice&) = delete; TempDevice& operator=(const TempDevice&) = delete; TempDevice& operator=(TempDevice&& other) noexcept { name_ = other.name_; valid_ = other.valid_; other.valid_ = false; return *this; } private: DeviceMapper& dm_; std::string name_; std::string path_; bool valid_; }; TEST(libdm, DmLinear) { unique_fd tmp1(CreateTempFile("file_1", 4096)); ASSERT_GE(tmp1, 0); Loading
fs_mgr/libdm/test_util.h +48 −0 Original line number Diff line number Diff line Loading @@ -20,8 +20,12 @@ #include <android-base/unique_fd.h> #include <stddef.h> #include <chrono> #include <string> #include <libdm/dm.h> #include <libdm/dm_table.h> namespace android { namespace dm { Loading @@ -29,6 +33,50 @@ namespace dm { // created with a fixed size. android::base::unique_fd CreateTempFile(const std::string& name, size_t size); // Helper to ensure that device mapper devices are released. class TempDevice { public: TempDevice(const std::string& name, const DmTable& table) : dm_(DeviceMapper::Instance()), name_(name), valid_(false) { valid_ = dm_.CreateDevice(name, table, &path_, std::chrono::seconds(5)); } TempDevice(TempDevice&& other) noexcept : dm_(other.dm_), name_(other.name_), path_(other.path_), valid_(other.valid_) { other.valid_ = false; } ~TempDevice() { if (valid_) { dm_.DeleteDevice(name_); } } bool Destroy() { if (!valid_) { return false; } valid_ = false; return dm_.DeleteDevice(name_); } std::string path() const { return path_; } const std::string& name() const { return name_; } bool valid() const { return valid_; } TempDevice(const TempDevice&) = delete; TempDevice& operator=(const TempDevice&) = delete; TempDevice& operator=(TempDevice&& other) noexcept { name_ = other.name_; valid_ = other.valid_; other.valid_ = false; return *this; } private: DeviceMapper& dm_; std::string name_; std::string path_; bool valid_; }; } // namespace dm } // namespace android Loading