summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTianjie Xu <xunchang@google.com>2019-03-26 22:52:40 +0100
committerGerrit Code Review <noreply-gerritcodereview@google.com>2019-03-26 22:52:40 +0100
commitf1cbd2f7f29e8f87631858959fa36ce84b495fc9 (patch)
tree303b8ebc0cdc324d4f8ecdd49249b2c2171c1f7b /tests
parentMerge "Move librecovery_ui to a sub-directory" (diff)
parentMove out the code to parse block map in MemMap (diff)
downloadandroid_bootable_recovery-f1cbd2f7f29e8f87631858959fa36ce84b495fc9.tar
android_bootable_recovery-f1cbd2f7f29e8f87631858959fa36ce84b495fc9.tar.gz
android_bootable_recovery-f1cbd2f7f29e8f87631858959fa36ce84b495fc9.tar.bz2
android_bootable_recovery-f1cbd2f7f29e8f87631858959fa36ce84b495fc9.tar.lz
android_bootable_recovery-f1cbd2f7f29e8f87631858959fa36ce84b495fc9.tar.xz
android_bootable_recovery-f1cbd2f7f29e8f87631858959fa36ce84b495fc9.tar.zst
android_bootable_recovery-f1cbd2f7f29e8f87631858959fa36ce84b495fc9.zip
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/sysutil_test.cpp61
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";