summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2019-05-21 15:41:07 +0200
committerGerrit Code Review <noreply-gerritcodereview@google.com>2019-05-21 15:41:07 +0200
commit962f7e0c0c93b8f6fbcd8254a12ea58a89ea7f41 (patch)
tree70ea4a53c7f20236f6388e1ebd1b5c933783f615 /tests
parentDO NOT MERGE - Skip pi-platform-release (PPRL.190505.001) in stage-aosp-master (diff)
parentAdd misc_writer. (diff)
downloadandroid_bootable_recovery-962f7e0c0c93b8f6fbcd8254a12ea58a89ea7f41.tar
android_bootable_recovery-962f7e0c0c93b8f6fbcd8254a12ea58a89ea7f41.tar.gz
android_bootable_recovery-962f7e0c0c93b8f6fbcd8254a12ea58a89ea7f41.tar.bz2
android_bootable_recovery-962f7e0c0c93b8f6fbcd8254a12ea58a89ea7f41.tar.lz
android_bootable_recovery-962f7e0c0c93b8f6fbcd8254a12ea58a89ea7f41.tar.xz
android_bootable_recovery-962f7e0c0c93b8f6fbcd8254a12ea58a89ea7f41.tar.zst
android_bootable_recovery-962f7e0c0c93b8f6fbcd8254a12ea58a89ea7f41.zip
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/bootloader_message_test.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/unit/bootloader_message_test.cpp b/tests/unit/bootloader_message_test.cpp
index b005d199c..95d875e69 100644
--- a/tests/unit/bootloader_message_test.cpp
+++ b/tests/unit/bootloader_message_test.cpp
@@ -15,6 +15,7 @@
*/
#include <string>
+#include <string_view>
#include <vector>
#include <android-base/file.h>
@@ -22,6 +23,10 @@
#include <bootloader_message/bootloader_message.h>
#include <gtest/gtest.h>
+using namespace std::string_literals;
+
+extern void SetMiscBlockDeviceForTest(std::string_view misc_device);
+
TEST(BootloaderMessageTest, read_and_write_bootloader_message) {
TemporaryFile temp_misc;
@@ -114,3 +119,36 @@ TEST(BootloaderMessageTest, update_bootloader_message_recovery_options_long) {
std::string(boot.reserved, sizeof(boot.reserved)));
}
+TEST(BootloaderMessageTest, WriteMiscPartitionVendorSpace) {
+ TemporaryFile temp_misc;
+ ASSERT_TRUE(android::base::WriteStringToFile(std::string(4096, '\x00'), temp_misc.path));
+ SetMiscBlockDeviceForTest(temp_misc.path);
+
+ constexpr std::string_view kTestMessage = "kTestMessage";
+ std::string err;
+ ASSERT_TRUE(WriteMiscPartitionVendorSpace(kTestMessage.data(), kTestMessage.size(), 0, &err));
+
+ std::string message;
+ message.resize(kTestMessage.size());
+ ASSERT_TRUE(ReadMiscPartitionVendorSpace(message.data(), message.size(), 0, &err));
+ ASSERT_EQ(kTestMessage, message);
+
+ // Write with an offset.
+ ASSERT_TRUE(WriteMiscPartitionVendorSpace("\x00\x00", 2, 5, &err));
+ ASSERT_TRUE(ReadMiscPartitionVendorSpace(message.data(), message.size(), 0, &err));
+ ASSERT_EQ("kTest\x00\x00ssage"s, message);
+
+ // Write with the right size.
+ auto start_offset =
+ WIPE_PACKAGE_OFFSET_IN_MISC - VENDOR_SPACE_OFFSET_IN_MISC - kTestMessage.size();
+ ASSERT_TRUE(
+ WriteMiscPartitionVendorSpace(kTestMessage.data(), kTestMessage.size(), start_offset, &err));
+
+ // Out-of-bound write.
+ ASSERT_FALSE(WriteMiscPartitionVendorSpace(kTestMessage.data(), kTestMessage.size(),
+ start_offset + 1, &err));
+
+ // Message won't fit.
+ std::string long_message(WIPE_PACKAGE_OFFSET_IN_MISC - VENDOR_SPACE_OFFSET_IN_MISC + 1, 'a');
+ ASSERT_FALSE(WriteMiscPartitionVendorSpace(long_message.data(), long_message.size(), 0, &err));
+}