diff options
Diffstat (limited to 'tests/component/install_test.cpp')
-rw-r--r-- | tests/component/install_test.cpp | 71 |
1 files changed, 58 insertions, 13 deletions
diff --git a/tests/component/install_test.cpp b/tests/component/install_test.cpp index 968196fc..7bb49606 100644 --- a/tests/component/install_test.cpp +++ b/tests/component/install_test.cpp | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <sys/types.h> | 19 | #include <sys/types.h> |
20 | #include <unistd.h> | 20 | #include <unistd.h> |
21 | 21 | ||
22 | #include <algorithm> | ||
22 | #include <string> | 23 | #include <string> |
23 | #include <vector> | 24 | #include <vector> |
24 | 25 | ||
@@ -198,8 +199,8 @@ TEST(InstallTest, verify_package_compatibility_with_libvintf_system_manifest_xml | |||
198 | CloseArchive(zip); | 199 | CloseArchive(zip); |
199 | } | 200 | } |
200 | 201 | ||
201 | TEST(InstallTest, update_binary_command_smoke) { | ||
202 | #ifdef AB_OTA_UPDATER | 202 | #ifdef AB_OTA_UPDATER |
203 | static void VerifyAbUpdateBinaryCommand(const std::string& serialno, bool success = true) { | ||
203 | TemporaryFile temp_file; | 204 | TemporaryFile temp_file; |
204 | FILE* zip_file = fdopen(temp_file.fd, "w"); | 205 | FILE* zip_file = fdopen(temp_file.fd, "w"); |
205 | ZipWriter writer(zip_file); | 206 | ZipWriter writer(zip_file); |
@@ -215,11 +216,13 @@ TEST(InstallTest, update_binary_command_smoke) { | |||
215 | ASSERT_NE("", device); | 216 | ASSERT_NE("", device); |
216 | std::string timestamp = android::base::GetProperty("ro.build.date.utc", ""); | 217 | std::string timestamp = android::base::GetProperty("ro.build.date.utc", ""); |
217 | ASSERT_NE("", timestamp); | 218 | ASSERT_NE("", timestamp); |
218 | std::string metadata = android::base::Join( | 219 | |
219 | std::vector<std::string>{ | 220 | std::vector<std::string> meta{ "ota-type=AB", "pre-device=" + device, |
220 | "ota-type=AB", "pre-device=" + device, "post-timestamp=" + timestamp, | 221 | "post-timestamp=" + timestamp }; |
221 | }, | 222 | if (!serialno.empty()) { |
222 | "\n"); | 223 | meta.push_back("serialno=" + serialno); |
224 | } | ||
225 | std::string metadata = android::base::Join(meta, "\n"); | ||
223 | ASSERT_EQ(0, writer.WriteBytes(metadata.data(), metadata.size())); | 226 | ASSERT_EQ(0, writer.WriteBytes(metadata.data(), metadata.size())); |
224 | ASSERT_EQ(0, writer.FinishEntry()); | 227 | ASSERT_EQ(0, writer.FinishEntry()); |
225 | ASSERT_EQ(0, writer.Finish()); | 228 | ASSERT_EQ(0, writer.Finish()); |
@@ -234,14 +237,25 @@ TEST(InstallTest, update_binary_command_smoke) { | |||
234 | std::string package = "/path/to/update.zip"; | 237 | std::string package = "/path/to/update.zip"; |
235 | std::string binary_path = "/sbin/update_engine_sideload"; | 238 | std::string binary_path = "/sbin/update_engine_sideload"; |
236 | std::vector<std::string> cmd; | 239 | std::vector<std::string> cmd; |
237 | ASSERT_EQ(0, update_binary_command(package, zip, binary_path, 0, status_fd, &cmd)); | 240 | if (success) { |
238 | ASSERT_EQ(5U, cmd.size()); | 241 | ASSERT_EQ(0, update_binary_command(package, zip, binary_path, 0, status_fd, &cmd)); |
239 | ASSERT_EQ(binary_path, cmd[0]); | 242 | ASSERT_EQ(5U, cmd.size()); |
240 | ASSERT_EQ("--payload=file://" + package, cmd[1]); | 243 | ASSERT_EQ(binary_path, cmd[0]); |
241 | ASSERT_EQ("--offset=" + std::to_string(payload_entry.offset), cmd[2]); | 244 | ASSERT_EQ("--payload=file://" + package, cmd[1]); |
242 | ASSERT_EQ("--headers=" + properties, cmd[3]); | 245 | ASSERT_EQ("--offset=" + std::to_string(payload_entry.offset), cmd[2]); |
243 | ASSERT_EQ("--status_fd=" + std::to_string(status_fd), cmd[4]); | 246 | ASSERT_EQ("--headers=" + properties, cmd[3]); |
247 | ASSERT_EQ("--status_fd=" + std::to_string(status_fd), cmd[4]); | ||
248 | } else { | ||
249 | ASSERT_EQ(INSTALL_ERROR, update_binary_command(package, zip, binary_path, 0, status_fd, &cmd)); | ||
250 | } | ||
244 | CloseArchive(zip); | 251 | CloseArchive(zip); |
252 | } | ||
253 | #endif // AB_OTA_UPDATER | ||
254 | |||
255 | TEST(InstallTest, update_binary_command_smoke) { | ||
256 | #ifdef AB_OTA_UPDATER | ||
257 | // Empty serialno will pass the verification. | ||
258 | VerifyAbUpdateBinaryCommand({}); | ||
245 | #else | 259 | #else |
246 | TemporaryFile temp_file; | 260 | TemporaryFile temp_file; |
247 | FILE* zip_file = fdopen(temp_file.fd, "w"); | 261 | FILE* zip_file = fdopen(temp_file.fd, "w"); |
@@ -340,3 +354,34 @@ TEST(InstallTest, update_binary_command_invalid) { | |||
340 | CloseArchive(zip); | 354 | CloseArchive(zip); |
341 | #endif // AB_OTA_UPDATER | 355 | #endif // AB_OTA_UPDATER |
342 | } | 356 | } |
357 | |||
358 | #ifdef AB_OTA_UPDATER | ||
359 | TEST(InstallTest, update_binary_command_multiple_serialno) { | ||
360 | std::string serialno = android::base::GetProperty("ro.serialno", ""); | ||
361 | ASSERT_NE("", serialno); | ||
362 | |||
363 | // Single matching serialno will pass the verification. | ||
364 | VerifyAbUpdateBinaryCommand(serialno); | ||
365 | |||
366 | static constexpr char alphabet[] = | ||
367 | "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; | ||
368 | auto generator = []() { return alphabet[rand() % (sizeof(alphabet) - 1)]; }; | ||
369 | |||
370 | // Generate 900 random serial numbers. | ||
371 | std::string random_serial; | ||
372 | for (size_t i = 0; i < 900; i++) { | ||
373 | generate_n(back_inserter(random_serial), serialno.size(), generator); | ||
374 | random_serial.append("|"); | ||
375 | } | ||
376 | // Random serialnos should fail the verification. | ||
377 | VerifyAbUpdateBinaryCommand(random_serial, false); | ||
378 | |||
379 | std::string long_serial = random_serial + serialno + "|"; | ||
380 | for (size_t i = 0; i < 99; i++) { | ||
381 | generate_n(back_inserter(long_serial), serialno.size(), generator); | ||
382 | long_serial.append("|"); | ||
383 | } | ||
384 | // String with the matching serialno should pass the verification. | ||
385 | VerifyAbUpdateBinaryCommand(long_serial); | ||
386 | } | ||
387 | #endif // AB_OTA_UPDATER | ||