summaryrefslogtreecommitdiffstats
path: root/tests/component
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2017-05-03 00:48:54 +0200
committerTao Bao <tbao@google.com>2017-05-08 21:16:45 +0200
commit00d5757186c279ba5e8a52a6f5209be3e7152025 (patch)
treeef219b66bb8ac8f7a20a182a91292213131505aa /tests/component
parentMerge "recovery: update mkfs.f2fs args to match f2fs-tools 1.8.0" (diff)
downloadandroid_bootable_recovery-00d5757186c279ba5e8a52a6f5209be3e7152025.tar
android_bootable_recovery-00d5757186c279ba5e8a52a6f5209be3e7152025.tar.gz
android_bootable_recovery-00d5757186c279ba5e8a52a6f5209be3e7152025.tar.bz2
android_bootable_recovery-00d5757186c279ba5e8a52a6f5209be3e7152025.tar.lz
android_bootable_recovery-00d5757186c279ba5e8a52a6f5209be3e7152025.tar.xz
android_bootable_recovery-00d5757186c279ba5e8a52a6f5209be3e7152025.tar.zst
android_bootable_recovery-00d5757186c279ba5e8a52a6f5209be3e7152025.zip
Diffstat (limited to 'tests/component')
-rw-r--r--tests/component/install_test.cpp84
1 files changed, 74 insertions, 10 deletions
diff --git a/tests/component/install_test.cpp b/tests/component/install_test.cpp
index 40201d76f..968196fc0 100644
--- a/tests/component/install_test.cpp
+++ b/tests/component/install_test.cpp
@@ -15,6 +15,8 @@
*/
#include <stdio.h>
+#include <sys/stat.h>
+#include <sys/types.h>
#include <unistd.h>
#include <string>
@@ -225,18 +227,62 @@ TEST(InstallTest, update_binary_command_smoke) {
ZipArchiveHandle zip;
ASSERT_EQ(0, OpenArchive(temp_file.path, &zip));
+ ZipString payload_name("payload.bin");
+ ZipEntry payload_entry;
+ ASSERT_EQ(0, FindEntry(zip, payload_name, &payload_entry));
int status_fd = 10;
- std::string path = "/path/to/update.zip";
+ std::string package = "/path/to/update.zip";
+ std::string binary_path = "/sbin/update_engine_sideload";
std::vector<std::string> cmd;
- ASSERT_EQ(0, update_binary_command(path, zip, 0, status_fd, &cmd));
- ASSERT_EQ("/sbin/update_engine_sideload", cmd[0]);
- ASSERT_EQ("--payload=file://" + path, cmd[1]);
+ ASSERT_EQ(0, update_binary_command(package, zip, binary_path, 0, status_fd, &cmd));
+ ASSERT_EQ(5U, cmd.size());
+ ASSERT_EQ(binary_path, cmd[0]);
+ ASSERT_EQ("--payload=file://" + package, cmd[1]);
+ ASSERT_EQ("--offset=" + std::to_string(payload_entry.offset), cmd[2]);
ASSERT_EQ("--headers=" + properties, cmd[3]);
ASSERT_EQ("--status_fd=" + std::to_string(status_fd), cmd[4]);
CloseArchive(zip);
#else
- // Cannot test update_binary_command() because it tries to extract update-binary to /tmp.
- GTEST_LOG_(INFO) << "Test skipped on non-A/B device.";
+ TemporaryFile temp_file;
+ FILE* zip_file = fdopen(temp_file.fd, "w");
+ ZipWriter writer(zip_file);
+ static constexpr const char* UPDATE_BINARY_NAME = "META-INF/com/google/android/update-binary";
+ ASSERT_EQ(0, writer.StartEntry(UPDATE_BINARY_NAME, kCompressStored));
+ ASSERT_EQ(0, writer.FinishEntry());
+ ASSERT_EQ(0, writer.Finish());
+ ASSERT_EQ(0, fclose(zip_file));
+
+ ZipArchiveHandle zip;
+ ASSERT_EQ(0, OpenArchive(temp_file.path, &zip));
+ int status_fd = 10;
+ std::string package = "/path/to/update.zip";
+ TemporaryDir td;
+ std::string binary_path = std::string(td.path) + "/update_binary";
+ std::vector<std::string> cmd;
+ ASSERT_EQ(0, update_binary_command(package, zip, binary_path, 0, status_fd, &cmd));
+ ASSERT_EQ(4U, cmd.size());
+ ASSERT_EQ(binary_path, cmd[0]);
+ ASSERT_EQ("3", cmd[1]); // RECOVERY_API_VERSION
+ ASSERT_EQ(std::to_string(status_fd), cmd[2]);
+ ASSERT_EQ(package, cmd[3]);
+ struct stat sb;
+ ASSERT_EQ(0, stat(binary_path.c_str(), &sb));
+ ASSERT_EQ(static_cast<mode_t>(0755), sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO));
+
+ // With non-zero retry count. update_binary will be removed automatically.
+ cmd.clear();
+ ASSERT_EQ(0, update_binary_command(package, zip, binary_path, 2, status_fd, &cmd));
+ ASSERT_EQ(5U, cmd.size());
+ ASSERT_EQ(binary_path, cmd[0]);
+ ASSERT_EQ("3", cmd[1]); // RECOVERY_API_VERSION
+ ASSERT_EQ(std::to_string(status_fd), cmd[2]);
+ ASSERT_EQ(package, cmd[3]);
+ ASSERT_EQ("retry", cmd[4]);
+ sb = {};
+ ASSERT_EQ(0, stat(binary_path.c_str(), &sb));
+ ASSERT_EQ(static_cast<mode_t>(0755), sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO));
+
+ CloseArchive(zip);
#endif // AB_OTA_UPDATER
}
@@ -267,12 +313,30 @@ TEST(InstallTest, update_binary_command_invalid) {
ZipArchiveHandle zip;
ASSERT_EQ(0, OpenArchive(temp_file.path, &zip));
int status_fd = 10;
- std::string path = "/path/to/update.zip";
+ std::string package = "/path/to/update.zip";
+ std::string binary_path = "/sbin/update_engine_sideload";
std::vector<std::string> cmd;
- ASSERT_EQ(INSTALL_CORRUPT, update_binary_command(path, zip, 0, status_fd, &cmd));
+ ASSERT_EQ(INSTALL_CORRUPT, update_binary_command(package, zip, binary_path, 0, status_fd, &cmd));
CloseArchive(zip);
#else
- // Cannot test update_binary_command() because it tries to extract update-binary to /tmp.
- GTEST_LOG_(INFO) << "Test skipped on non-A/B device.";
+ TemporaryFile temp_file;
+ FILE* zip_file = fdopen(temp_file.fd, "w");
+ ZipWriter writer(zip_file);
+ // The archive must have something to be opened correctly.
+ ASSERT_EQ(0, writer.StartEntry("dummy_entry", 0));
+ ASSERT_EQ(0, writer.FinishEntry());
+ ASSERT_EQ(0, writer.Finish());
+ ASSERT_EQ(0, fclose(zip_file));
+
+ // Missing update binary.
+ ZipArchiveHandle zip;
+ ASSERT_EQ(0, OpenArchive(temp_file.path, &zip));
+ int status_fd = 10;
+ std::string package = "/path/to/update.zip";
+ TemporaryDir td;
+ std::string binary_path = std::string(td.path) + "/update_binary";
+ std::vector<std::string> cmd;
+ ASSERT_EQ(INSTALL_CORRUPT, update_binary_command(package, zip, binary_path, 0, status_fd, &cmd));
+ CloseArchive(zip);
#endif // AB_OTA_UPDATER
}