@@ -48,8 +48,23 @@ using testing::SetArgPointee;
48
48
namespace chromeos_update_engine {
49
49
50
50
class FilesystemVerifierActionTest : public ::testing::Test {
51
+ public:
52
+ static constexpr size_t BLOCK_SIZE = 4096 ;
53
+ static constexpr size_t PARTITION_SIZE = BLOCK_SIZE * 1024 ;
54
+
51
55
protected:
52
- void SetUp () override { loop_.SetAsCurrent (); }
56
+ void SetUp () override {
57
+ brillo::Blob part_data (PARTITION_SIZE);
58
+ test_utils::FillWithData (&part_data);
59
+ ASSERT_TRUE (utils::WriteFile (
60
+ source_part.path ().c_str (), part_data.data (), part_data.size ()));
61
+ // FillWithData() will will with different data next call. We want
62
+ // source/target partitions to contain different data for testing.
63
+ test_utils::FillWithData (&part_data);
64
+ ASSERT_TRUE (utils::WriteFile (
65
+ target_part.path ().c_str (), part_data.data (), part_data.size ()));
66
+ loop_.SetAsCurrent ();
67
+ }
53
68
54
69
void TearDown () override {
55
70
EXPECT_EQ (0 , brillo::MessageLoopRunMaxIterations (&loop_, 1 ));
@@ -62,11 +77,34 @@ class FilesystemVerifierActionTest : public ::testing::Test {
62
77
void BuildActions (const InstallPlan& install_plan,
63
78
DynamicPartitionControlInterface* dynamic_control);
64
79
80
+ InstallPlan::Partition* AddFakePartition (InstallPlan* install_plan,
81
+ std::string name = " fake_part" ) {
82
+ InstallPlan::Partition& part = install_plan->partitions .emplace_back ();
83
+ part.name = name;
84
+ part.target_path = target_part.path ();
85
+ part.readonly_target_path = part.target_path ;
86
+ part.target_size = PARTITION_SIZE;
87
+ part.block_size = BLOCK_SIZE;
88
+ part.source_path = source_part.path ();
89
+ EXPECT_TRUE (
90
+ HashCalculator::RawHashOfFile (source_part.path (), &part.source_hash ));
91
+ EXPECT_TRUE (
92
+ HashCalculator::RawHashOfFile (target_part.path (), &part.target_hash ));
93
+ return ∂
94
+ }
95
+
65
96
brillo::FakeMessageLoop loop_{nullptr };
66
97
ActionProcessor processor_;
67
98
DynamicPartitionControlStub dynamic_control_stub_;
99
+ static ScopedTempFile source_part;
100
+ static ScopedTempFile target_part;
68
101
};
69
102
103
+ ScopedTempFile FilesystemVerifierActionTest::source_part{
104
+ " source_part.XXXXXX" , false , PARTITION_SIZE};
105
+ ScopedTempFile FilesystemVerifierActionTest::target_part{
106
+ " target_part.XXXXXX" , false , PARTITION_SIZE};
107
+
70
108
class FilesystemVerifierActionTestDelegate : public ActionProcessorDelegate {
71
109
public:
72
110
FilesystemVerifierActionTestDelegate ()
@@ -406,32 +444,27 @@ TEST_F(FilesystemVerifierActionTest, RunAsRootSkipWriteVerityTest) {
406
444
407
445
TEST_F (FilesystemVerifierActionTest, RunWithVABCNoVerity) {
408
446
InstallPlan install_plan;
409
- InstallPlan::Partition& part = install_plan.partitions .emplace_back ();
410
- part.name = " fake_part" ;
411
- part.target_path = " /dev/fake_target_path" ;
412
- part.target_size = 4096 * 4096 ;
413
- part.block_size = 4096 ;
414
- part.source_path = " /dev/fake_source_path" ;
415
- part.fec_size = 0 ;
416
- part.hash_tree_size = 0 ;
417
- part.target_hash .clear ();
418
- part.source_hash .clear ();
447
+ auto part_ptr = AddFakePartition (&install_plan);
448
+ ASSERT_NE (part_ptr, nullptr );
449
+ InstallPlan::Partition& part = *part_ptr;
450
+ part.target_path = " Shouldn't attempt to open this path" ;
419
451
420
452
NiceMock<MockDynamicPartitionControl> dynamic_control;
421
- auto fake_fd = std::make_shared<FakeFileDescriptor>();
422
453
423
454
ON_CALL (dynamic_control, GetDynamicPartitionsFeatureFlag ())
424
455
.WillByDefault (Return (FeatureFlag (FeatureFlag::Value::LAUNCH)));
425
456
ON_CALL (dynamic_control, UpdateUsesSnapshotCompression ())
426
457
.WillByDefault (Return (true ));
427
- ON_CALL (dynamic_control, OpenCowFd (_, _, _)).WillByDefault (Return (fake_fd));
428
458
ON_CALL (dynamic_control, IsDynamicPartition (part.name , _))
429
459
.WillByDefault (Return (true ));
430
460
431
461
EXPECT_CALL (dynamic_control, UpdateUsesSnapshotCompression ())
432
462
.Times (AtLeast (1 ));
463
+ // Since we are not writing verity, we should not attempt to OpenCowFd()
464
+ // reads should go through regular file descriptors on mapped partitions.
433
465
EXPECT_CALL (dynamic_control, OpenCowFd (part.name , {part.source_path }, _))
434
- .Times (1 );
466
+ .Times (0 );
467
+ EXPECT_CALL (dynamic_control, MapAllPartitions ()).Times (AtLeast (1 ));
435
468
EXPECT_CALL (dynamic_control, ListDynamicPartitionsForSlot (_, _, _))
436
469
.WillRepeatedly (
437
470
DoAll (SetArgPointee<2 , std::vector<std::string>>({part.name }),
@@ -451,16 +484,7 @@ TEST_F(FilesystemVerifierActionTest, RunWithVABCNoVerity) {
451
484
452
485
ASSERT_FALSE (processor_.IsRunning ());
453
486
ASSERT_TRUE (delegate.ran ());
454
- // Filesystem verifier will fail, because we set an empty hash
455
- ASSERT_EQ (ErrorCode::kNewRootfsVerificationError , delegate.code ());
456
- const auto & read_pos = fake_fd->GetReadOps ();
457
- size_t expected_offset = 0 ;
458
- for (const auto & [off, size] : read_pos) {
459
- ASSERT_EQ (off, expected_offset);
460
- expected_offset += size;
461
- }
462
- const auto actual_read_size = expected_offset;
463
- ASSERT_EQ (actual_read_size, part.target_size );
487
+ ASSERT_EQ (ErrorCode::kSuccess , delegate.code ());
464
488
}
465
489
466
490
TEST_F (FilesystemVerifierActionTest, ReadAfterWrite) {
0 commit comments