Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 453665b5 authored by Akilesh Kailash's avatar Akilesh Kailash
Browse files

snapuserd_test: Create dup of fd before passing it to cow writer



Bug: 352085551
Test: snapuserd_test - atest 10 iterations passed
Change-Id: I25549e546cb3ce234fcf92533effb124793f1953
Signed-off-by: default avatarAkilesh Kailash <akailash@google.com>
parent 73c43fd5
Loading
Loading
Loading
Loading
+7 −9
Original line number Original line Diff line number Diff line
@@ -79,6 +79,8 @@ class SnapuserdTestBase : public ::testing::TestWithParam<TestParam> {
    std::unique_ptr<ICowWriter> CreateCowDeviceInternal();
    std::unique_ptr<ICowWriter> CreateCowDeviceInternal();
    std::unique_ptr<ICowWriter> CreateV3Cow();
    std::unique_ptr<ICowWriter> CreateV3Cow();


    unique_fd GetCowFd() { return unique_fd{dup(cow_system_->fd)}; }

    std::unique_ptr<ITestHarness> harness_;
    std::unique_ptr<ITestHarness> harness_;
    size_t size_ = 10_MiB;
    size_t size_ = 10_MiB;
    int total_base_size_ = 0;
    int total_base_size_ = 0;
@@ -101,7 +103,9 @@ void SnapuserdTestBase::SetUp() {
#endif
#endif
}
}


void SnapuserdTestBase::TearDown() {}
void SnapuserdTestBase::TearDown() {
    cow_system_ = nullptr;
}


void SnapuserdTestBase::CreateBaseDevice() {
void SnapuserdTestBase::CreateBaseDevice() {
    total_base_size_ = (size_ * 5);
    total_base_size_ = (size_ * 5);
@@ -132,10 +136,7 @@ std::unique_ptr<ICowWriter> SnapuserdTestBase::CreateCowDeviceInternal() {
    CowOptions options;
    CowOptions options;
    options.compression = "gz";
    options.compression = "gz";


    unique_fd fd(cow_system_->fd);
    return CreateCowWriter(2, options, GetCowFd());
    cow_system_->fd = -1;

    return CreateCowWriter(2, options, std::move(fd));
}
}


std::unique_ptr<ICowWriter> SnapuserdTestBase::CreateV3Cow() {
std::unique_ptr<ICowWriter> SnapuserdTestBase::CreateV3Cow() {
@@ -151,10 +152,7 @@ std::unique_ptr<ICowWriter> SnapuserdTestBase::CreateV3Cow() {
    std::string path = android::base::GetExecutableDirectory();
    std::string path = android::base::GetExecutableDirectory();
    cow_system_ = std::make_unique<TemporaryFile>(path);
    cow_system_ = std::make_unique<TemporaryFile>(path);


    unique_fd fd(cow_system_->fd);
    return CreateCowWriter(3, options, GetCowFd());
    cow_system_->fd = -1;

    return CreateCowWriter(3, options, std::move(fd));
}
}


void SnapuserdTestBase::CreateCowDevice() {
void SnapuserdTestBase::CreateCowDevice() {