diff options
author | Tianjie Xu <xunchang@google.com> | 2019-03-27 00:09:33 +0100 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-03-27 00:09:33 +0100 |
commit | 67a3ffc22fb3ef3fba87d1e91c352660beaab1ba (patch) | |
tree | 303b8ebc0cdc324d4f8ecdd49249b2c2171c1f7b /tests | |
parent | Merge "Move librecovery_ui to a sub-directory" (diff) | |
parent | Merge "Move out the code to parse block map in MemMap" (diff) | |
download | android_bootable_recovery-67a3ffc22fb3ef3fba87d1e91c352660beaab1ba.tar android_bootable_recovery-67a3ffc22fb3ef3fba87d1e91c352660beaab1ba.tar.gz android_bootable_recovery-67a3ffc22fb3ef3fba87d1e91c352660beaab1ba.tar.bz2 android_bootable_recovery-67a3ffc22fb3ef3fba87d1e91c352660beaab1ba.tar.lz android_bootable_recovery-67a3ffc22fb3ef3fba87d1e91c352660beaab1ba.tar.xz android_bootable_recovery-67a3ffc22fb3ef3fba87d1e91c352660beaab1ba.tar.zst android_bootable_recovery-67a3ffc22fb3ef3fba87d1e91c352660beaab1ba.zip |
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/sysutil_test.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/unit/sysutil_test.cpp b/tests/unit/sysutil_test.cpp index 77625dbe9..3466e8eec 100644 --- a/tests/unit/sysutil_test.cpp +++ b/tests/unit/sysutil_test.cpp @@ -17,8 +17,10 @@ #include <string> #include <android-base/file.h> +#include <android-base/strings.h> #include <gtest/gtest.h> +#include "otautil/rangeset.h" #include "otautil/sysutil.h" TEST(SysUtilTest, InvalidArgs) { @@ -28,6 +30,65 @@ TEST(SysUtilTest, InvalidArgs) { ASSERT_FALSE(mapping.MapFile("")); } +TEST(SysUtilTest, ParseBlockMapFile_smoke) { + std::vector<std::string> content = { + "/dev/abc", "49652 4096", "3", "1000 1008", "2100 2102", "30 33", + }; + + TemporaryFile temp_file; + ASSERT_TRUE(android::base::WriteStringToFile(android::base::Join(content, '\n'), temp_file.path)); + + auto block_map_data = BlockMapData::ParseBlockMapFile(temp_file.path); + ASSERT_EQ("/dev/abc", block_map_data.path()); + ASSERT_EQ(49652, block_map_data.file_size()); + ASSERT_EQ(4096, block_map_data.block_size()); + ASSERT_EQ(RangeSet(std::vector<Range>{ + { 1000, 1008 }, + { 2100, 2102 }, + { 30, 33 }, + }), + block_map_data.block_ranges()); +} + +TEST(SysUtilTest, ParseBlockMapFile_invalid_line_count) { + std::vector<std::string> content = { + "/dev/abc", "49652 4096", "2", "1000 1008", "2100 2102", "30 33", + }; + + TemporaryFile temp_file; + ASSERT_TRUE(android::base::WriteStringToFile(android::base::Join(content, '\n'), temp_file.path)); + + auto block_map_data1 = BlockMapData::ParseBlockMapFile(temp_file.path); + ASSERT_FALSE(block_map_data1); +} + +TEST(SysUtilTest, ParseBlockMapFile_invalid_size) { + std::vector<std::string> content = { + "/dev/abc", + "42949672950 4294967295", + "1", + "0 9", + }; + + TemporaryFile temp_file; + ASSERT_TRUE(android::base::WriteStringToFile(android::base::Join(content, '\n'), temp_file.path)); + + auto block_map_data = BlockMapData::ParseBlockMapFile(temp_file.path); + ASSERT_EQ("/dev/abc", block_map_data.path()); + ASSERT_EQ(42949672950, block_map_data.file_size()); + ASSERT_EQ(4294967295, block_map_data.block_size()); + + content[1] = "42949672950 4294967296"; + ASSERT_TRUE(android::base::WriteStringToFile(android::base::Join(content, '\n'), temp_file.path)); + auto large_block_size = BlockMapData::ParseBlockMapFile(temp_file.path); + ASSERT_FALSE(large_block_size); + + content[1] = "4294967296 1"; + ASSERT_TRUE(android::base::WriteStringToFile(android::base::Join(content, '\n'), temp_file.path)); + auto too_many_blocks = BlockMapData::ParseBlockMapFile(temp_file.path); + ASSERT_FALSE(too_many_blocks); +} + TEST(SysUtilTest, MapFileRegularFile) { TemporaryFile temp_file1; std::string content = "abc"; |