@@ -41,6 +41,10 @@ using namespace std::chrono_literals;
41
41
class SnapuserdTest : public ::testing::Test {
42
42
protected:
43
43
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" );
44
48
cow_system_ = std::make_unique<TemporaryFile>();
45
49
ASSERT_GE (cow_system_->fd , 0 ) << strerror (errno);
46
50
@@ -53,10 +57,6 @@ class SnapuserdTest : public ::testing::Test {
53
57
cow_product_1_ = std::make_unique<TemporaryFile>();
54
58
ASSERT_GE (cow_product_1_->fd , 0 ) << strerror (errno);
55
59
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.
60
60
std::string path = android::base::GetExecutableDirectory ();
61
61
62
62
system_a_ = std::make_unique<TemporaryFile>(path);
@@ -65,10 +65,11 @@ class SnapuserdTest : public ::testing::Test {
65
65
product_a_ = std::make_unique<TemporaryFile>(path);
66
66
ASSERT_GE (product_a_->fd , 0 ) << strerror (errno);
67
67
68
- size_ = 1_MiB ;
68
+ size_ = 100_MiB ;
69
69
}
70
70
71
71
void TearDown () override {
72
+ system (" setenforce 1" );
72
73
cow_system_ = nullptr ;
73
74
cow_product_ = nullptr ;
74
75
@@ -116,10 +117,10 @@ class SnapuserdTest : public ::testing::Test {
116
117
void SwitchSnapshotDevices ();
117
118
118
119
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_;
120
121
}
121
122
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_;
123
124
}
124
125
125
126
void TestIO (unique_fd& snapshot_fd, std::unique_ptr<uint8_t []>& buffer);
@@ -151,12 +152,12 @@ void SnapuserdTest::Init() {
151
152
offset += 1_MiB;
152
153
}
153
154
154
- for (size_t j = 0 ; j < (8_MiB / 1_MiB); j++) {
155
+ for (size_t j = 0 ; j < (800_MiB / 1_MiB); j++) {
155
156
ASSERT_EQ (ReadFullyAtOffset (rnd_fd, (char *)random_buffer.get (), 1_MiB, 0 ), true );
156
157
ASSERT_EQ (android::base::WriteFully (system_a_->fd , random_buffer.get (), 1_MiB), true );
157
158
}
158
159
159
- for (size_t j = 0 ; j < (8_MiB / 1_MiB); j++) {
160
+ for (size_t j = 0 ; j < (800_MiB / 1_MiB); j++) {
160
161
ASSERT_EQ (ReadFullyAtOffset (rnd_fd, (char *)random_buffer.get (), 1_MiB, 0 ), true );
161
162
ASSERT_EQ (android::base::WriteFully (product_a_->fd , random_buffer.get (), 1_MiB), true );
162
163
}
@@ -451,42 +452,9 @@ TEST_F(SnapuserdTest, ReadWrite) {
451
452
452
453
snapshot_fd.reset (-1 );
453
454
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
-
472
455
DeleteDmUser (cow_system_, " system-snapshot" );
473
456
DeleteDmUser (cow_product_, " product-snapshot" );
474
457
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
490
458
ASSERT_TRUE (client_->StopSnapuserd ());
491
459
}
492
460
0 commit comments