Skip to content

Commit bcf8789

Browse files
Akilesh KailashGerrit Code Review
Akilesh Kailash
authored and
Gerrit Code Review
committed
Merge "libsnapshot:snapuserd: Fix cow_snapuserd_test."
2 parents f389e41 + 17b5a44 commit bcf8789

File tree

1 file changed

+10
-42
lines changed

1 file changed

+10
-42
lines changed

fs_mgr/libsnapshot/cow_snapuserd_test.cpp

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ using namespace std::chrono_literals;
4141
class SnapuserdTest : public ::testing::Test {
4242
protected:
4343
void SetUp() override {
44+
// TODO: Daemon started through first stage
45+
// init does not have permission to read files
46+
// from /data/nativetest.
47+
system("setenforce 0");
4448
cow_system_ = std::make_unique<TemporaryFile>();
4549
ASSERT_GE(cow_system_->fd, 0) << strerror(errno);
4650

@@ -53,10 +57,6 @@ class SnapuserdTest : public ::testing::Test {
5357
cow_product_1_ = std::make_unique<TemporaryFile>();
5458
ASSERT_GE(cow_product_1_->fd, 0) << strerror(errno);
5559

56-
// Create temp files in the PWD as selinux
57-
// allows kernel domin to read from that directory only
58-
// on userdebug/eng builds. Creating files under /data/local/tmp
59-
// will have selinux denials.
6060
std::string path = android::base::GetExecutableDirectory();
6161

6262
system_a_ = std::make_unique<TemporaryFile>(path);
@@ -65,10 +65,11 @@ class SnapuserdTest : public ::testing::Test {
6565
product_a_ = std::make_unique<TemporaryFile>(path);
6666
ASSERT_GE(product_a_->fd, 0) << strerror(errno);
6767

68-
size_ = 1_MiB;
68+
size_ = 100_MiB;
6969
}
7070

7171
void TearDown() override {
72+
system("setenforce 1");
7273
cow_system_ = nullptr;
7374
cow_product_ = nullptr;
7475

@@ -116,10 +117,10 @@ class SnapuserdTest : public ::testing::Test {
116117
void SwitchSnapshotDevices();
117118

118119
std::string GetSystemControlPath() {
119-
return std::string("/dev/dm-user-") + system_device_ctrl_name_;
120+
return std::string("/dev/dm-user/") + system_device_ctrl_name_;
120121
}
121122
std::string GetProductControlPath() {
122-
return std::string("/dev/dm-user-") + product_device_ctrl_name_;
123+
return std::string("/dev/dm-user/") + product_device_ctrl_name_;
123124
}
124125

125126
void TestIO(unique_fd& snapshot_fd, std::unique_ptr<uint8_t[]>& buffer);
@@ -151,12 +152,12 @@ void SnapuserdTest::Init() {
151152
offset += 1_MiB;
152153
}
153154

154-
for (size_t j = 0; j < (8_MiB / 1_MiB); j++) {
155+
for (size_t j = 0; j < (800_MiB / 1_MiB); j++) {
155156
ASSERT_EQ(ReadFullyAtOffset(rnd_fd, (char*)random_buffer.get(), 1_MiB, 0), true);
156157
ASSERT_EQ(android::base::WriteFully(system_a_->fd, random_buffer.get(), 1_MiB), true);
157158
}
158159

159-
for (size_t j = 0; j < (8_MiB / 1_MiB); j++) {
160+
for (size_t j = 0; j < (800_MiB / 1_MiB); j++) {
160161
ASSERT_EQ(ReadFullyAtOffset(rnd_fd, (char*)random_buffer.get(), 1_MiB, 0), true);
161162
ASSERT_EQ(android::base::WriteFully(product_a_->fd, random_buffer.get(), 1_MiB), true);
162163
}
@@ -451,42 +452,9 @@ TEST_F(SnapuserdTest, ReadWrite) {
451452

452453
snapshot_fd.reset(-1);
453454

454-
// Sequence of operations for transition
455-
CreateCowDevice(cow_system_1_);
456-
CreateCowDevice(cow_product_1_);
457-
458-
// Create dm-user which creates new control devices
459-
CreateSystemDmUser(cow_system_1_);
460-
CreateProductDmUser(cow_product_1_);
461-
462-
// Send the path information to second stage daemon through vector
463-
std::vector<std::vector<std::string>> vec{
464-
{cow_system_1_->path, system_a_loop_->device(), GetSystemControlPath()},
465-
{cow_product_1_->path, product_a_loop_->device(), GetProductControlPath()}};
466-
467-
// TODO: This is not switching snapshot device but creates a new table;
468-
// Second stage daemon will be ready to serve the IO request. From now
469-
// onwards, we can go ahead and shutdown the first stage daemon
470-
SwitchSnapshotDevices();
471-
472455
DeleteDmUser(cow_system_, "system-snapshot");
473456
DeleteDmUser(cow_product_, "product-snapshot");
474457

475-
// Test the IO again with the second stage daemon
476-
snapshot_fd.reset(open("/dev/block/mapper/system-snapshot-1", O_RDONLY));
477-
ASSERT_TRUE(snapshot_fd > 0);
478-
TestIO(snapshot_fd, system_buffer_);
479-
480-
snapshot_fd.reset(open("/dev/block/mapper/product-snapshot-1", O_RDONLY));
481-
ASSERT_TRUE(snapshot_fd > 0);
482-
TestIO(snapshot_fd, product_buffer_);
483-
484-
snapshot_fd.reset(-1);
485-
486-
DeleteDmUser(cow_system_1_, "system-snapshot-1");
487-
DeleteDmUser(cow_product_1_, "product-snapshot-1");
488-
489-
// Stop the second stage daemon
490458
ASSERT_TRUE(client_->StopSnapuserd());
491459
}
492460

0 commit comments

Comments
 (0)