diff options
author | Amin Hassani <ahassani@google.com> | 2017-12-06 15:31:17 -0800 |
---|---|---|
committer | Amin Hassani <ahassani@google.com> | 2018-02-05 12:53:18 -0800 |
commit | b379d19c05c5128a7fa45b72dbe74a764d143b98 (patch) | |
tree | 4401a36d4174b68dfeff004d85f4ff3a1f45e5da /payload_consumer/file_descriptor_utils_unittest.cc | |
parent | 4e13cf4743d5c02dec7030c71a3c7e2fa8da7aa8 (diff) |
Restructure hash calculation in delta_performer
This patch moves DeltaPerformer::CalculateAndValidateHash to
fd_utils::ReadAndHashExtents and cleans up the code. It also adds
unittests for ReadAndHashExtents.
Bug: None
Test: unittest pass
Change-Id: I297cf79ef38a7495d5bcc0e6516a1ca783e505ea
Signed-off-by: Amin Hassani <ahassani@google.com>
Diffstat (limited to 'payload_consumer/file_descriptor_utils_unittest.cc')
-rw-r--r-- | payload_consumer/file_descriptor_utils_unittest.cc | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/payload_consumer/file_descriptor_utils_unittest.cc b/payload_consumer/file_descriptor_utils_unittest.cc index 8ba8ce69..79d21846 100644 --- a/payload_consumer/file_descriptor_utils_unittest.cc +++ b/payload_consumer/file_descriptor_utils_unittest.cc @@ -167,4 +167,32 @@ TEST_F(FileDescriptorUtilsTest, CopyAndHashExtentsManyToManyTest) { EXPECT_EQ(expected_hash, hash_out); } +// Failing to read from the source should fail the hash calculation. +TEST_F(FileDescriptorUtilsTest, ReadAndHashExtentsReadFailureTest) { + auto extents = CreateExtentList({{0, 5}}); + fake_source_->AddFailureRange(10, 5); + brillo::Blob hash_out; + EXPECT_FALSE(fd_utils::ReadAndHashExtents(source_, extents, 4, &hash_out)); +} + +// Test that if hash_out is null, then it should fail. +TEST_F(FileDescriptorUtilsTest, ReadAndHashExtentsWithoutHashingTest) { + auto extents = CreateExtentList({{0, 5}}); + EXPECT_FALSE(fd_utils::ReadAndHashExtents(source_, extents, 4, nullptr)); +} + +// Tests that it can calculate the hash properly. +TEST_F(FileDescriptorUtilsTest, ReadAndHashExtentsTest) { + // Reorder the input as 1 4 2 3 0. + auto extents = CreateExtentList({{1, 1}, {4, 1}, {2, 2}, {0, 1}}); + brillo::Blob hash_out; + EXPECT_TRUE(fd_utils::ReadAndHashExtents(source_, extents, 4, &hash_out)); + + const char kExpectedResult[] = "00010004000200030000"; + brillo::Blob expected_hash; + EXPECT_TRUE(HashCalculator::RawHashOfBytes( + kExpectedResult, strlen(kExpectedResult), &expected_hash)); + EXPECT_EQ(expected_hash, hash_out); +} + } // namespace chromeos_update_engine |