|
@@ -15,6 +15,8 @@
|
15
|
15
|
*/
|
16
|
16
|
|
17
|
17
|
#include <stdio.h>
|
|
18
|
+#include <sys/stat.h>
|
|
19
|
+#include <sys/types.h>
|
18
|
20
|
#include <unistd.h>
|
19
|
21
|
|
20
|
22
|
#include <string>
|
|
@@ -225,18 +227,62 @@ TEST(InstallTest, update_binary_command_smoke) {
|
225
|
227
|
|
226
|
228
|
ZipArchiveHandle zip;
|
227
|
229
|
ASSERT_EQ(0, OpenArchive(temp_file.path, &zip));
|
|
230
|
+ ZipString payload_name("payload.bin");
|
|
231
|
+ ZipEntry payload_entry;
|
|
232
|
+ ASSERT_EQ(0, FindEntry(zip, payload_name, &payload_entry));
|
228
|
233
|
int status_fd = 10;
|
229
|
|
- std::string path = "/path/to/update.zip";
|
|
234
|
+ std::string package = "/path/to/update.zip";
|
|
235
|
+ std::string binary_path = "/sbin/update_engine_sideload";
|
230
|
236
|
std::vector<std::string> cmd;
|
231
|
|
- ASSERT_EQ(0, update_binary_command(path, zip, 0, status_fd, &cmd));
|
232
|
|
- ASSERT_EQ("/sbin/update_engine_sideload", cmd[0]);
|
233
|
|
- ASSERT_EQ("--payload=file://" + path, cmd[1]);
|
|
237
|
+ ASSERT_EQ(0, update_binary_command(package, zip, binary_path, 0, status_fd, &cmd));
|
|
238
|
+ ASSERT_EQ(5U, cmd.size());
|
|
239
|
+ ASSERT_EQ(binary_path, cmd[0]);
|
|
240
|
+ ASSERT_EQ("--payload=file://" + package, cmd[1]);
|
|
241
|
+ ASSERT_EQ("--offset=" + std::to_string(payload_entry.offset), cmd[2]);
|
234
|
242
|
ASSERT_EQ("--headers=" + properties, cmd[3]);
|
235
|
243
|
ASSERT_EQ("--status_fd=" + std::to_string(status_fd), cmd[4]);
|
236
|
244
|
CloseArchive(zip);
|
237
|
245
|
#else
|
238
|
|
- // Cannot test update_binary_command() because it tries to extract update-binary to /tmp.
|
239
|
|
- GTEST_LOG_(INFO) << "Test skipped on non-A/B device.";
|
|
246
|
+ TemporaryFile temp_file;
|
|
247
|
+ FILE* zip_file = fdopen(temp_file.fd, "w");
|
|
248
|
+ ZipWriter writer(zip_file);
|
|
249
|
+ static constexpr const char* UPDATE_BINARY_NAME = "META-INF/com/google/android/update-binary";
|
|
250
|
+ ASSERT_EQ(0, writer.StartEntry(UPDATE_BINARY_NAME, kCompressStored));
|
|
251
|
+ ASSERT_EQ(0, writer.FinishEntry());
|
|
252
|
+ ASSERT_EQ(0, writer.Finish());
|
|
253
|
+ ASSERT_EQ(0, fclose(zip_file));
|
|
254
|
+
|
|
255
|
+ ZipArchiveHandle zip;
|
|
256
|
+ ASSERT_EQ(0, OpenArchive(temp_file.path, &zip));
|
|
257
|
+ int status_fd = 10;
|
|
258
|
+ std::string package = "/path/to/update.zip";
|
|
259
|
+ TemporaryDir td;
|
|
260
|
+ std::string binary_path = std::string(td.path) + "/update_binary";
|
|
261
|
+ std::vector<std::string> cmd;
|
|
262
|
+ ASSERT_EQ(0, update_binary_command(package, zip, binary_path, 0, status_fd, &cmd));
|
|
263
|
+ ASSERT_EQ(4U, cmd.size());
|
|
264
|
+ ASSERT_EQ(binary_path, cmd[0]);
|
|
265
|
+ ASSERT_EQ("3", cmd[1]); // RECOVERY_API_VERSION
|
|
266
|
+ ASSERT_EQ(std::to_string(status_fd), cmd[2]);
|
|
267
|
+ ASSERT_EQ(package, cmd[3]);
|
|
268
|
+ struct stat sb;
|
|
269
|
+ ASSERT_EQ(0, stat(binary_path.c_str(), &sb));
|
|
270
|
+ ASSERT_EQ(static_cast<mode_t>(0755), sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO));
|
|
271
|
+
|
|
272
|
+ // With non-zero retry count. update_binary will be removed automatically.
|
|
273
|
+ cmd.clear();
|
|
274
|
+ ASSERT_EQ(0, update_binary_command(package, zip, binary_path, 2, status_fd, &cmd));
|
|
275
|
+ ASSERT_EQ(5U, cmd.size());
|
|
276
|
+ ASSERT_EQ(binary_path, cmd[0]);
|
|
277
|
+ ASSERT_EQ("3", cmd[1]); // RECOVERY_API_VERSION
|
|
278
|
+ ASSERT_EQ(std::to_string(status_fd), cmd[2]);
|
|
279
|
+ ASSERT_EQ(package, cmd[3]);
|
|
280
|
+ ASSERT_EQ("retry", cmd[4]);
|
|
281
|
+ sb = {};
|
|
282
|
+ ASSERT_EQ(0, stat(binary_path.c_str(), &sb));
|
|
283
|
+ ASSERT_EQ(static_cast<mode_t>(0755), sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO));
|
|
284
|
+
|
|
285
|
+ CloseArchive(zip);
|
240
|
286
|
#endif // AB_OTA_UPDATER
|
241
|
287
|
}
|
242
|
288
|
|
|
@@ -267,12 +313,30 @@ TEST(InstallTest, update_binary_command_invalid) {
|
267
|
313
|
ZipArchiveHandle zip;
|
268
|
314
|
ASSERT_EQ(0, OpenArchive(temp_file.path, &zip));
|
269
|
315
|
int status_fd = 10;
|
270
|
|
- std::string path = "/path/to/update.zip";
|
|
316
|
+ std::string package = "/path/to/update.zip";
|
|
317
|
+ std::string binary_path = "/sbin/update_engine_sideload";
|
271
|
318
|
std::vector<std::string> cmd;
|
272
|
|
- ASSERT_EQ(INSTALL_CORRUPT, update_binary_command(path, zip, 0, status_fd, &cmd));
|
|
319
|
+ ASSERT_EQ(INSTALL_CORRUPT, update_binary_command(package, zip, binary_path, 0, status_fd, &cmd));
|
273
|
320
|
CloseArchive(zip);
|
274
|
321
|
#else
|
275
|
|
- // Cannot test update_binary_command() because it tries to extract update-binary to /tmp.
|
276
|
|
- GTEST_LOG_(INFO) << "Test skipped on non-A/B device.";
|
|
322
|
+ TemporaryFile temp_file;
|
|
323
|
+ FILE* zip_file = fdopen(temp_file.fd, "w");
|
|
324
|
+ ZipWriter writer(zip_file);
|
|
325
|
+ // The archive must have something to be opened correctly.
|
|
326
|
+ ASSERT_EQ(0, writer.StartEntry("dummy_entry", 0));
|
|
327
|
+ ASSERT_EQ(0, writer.FinishEntry());
|
|
328
|
+ ASSERT_EQ(0, writer.Finish());
|
|
329
|
+ ASSERT_EQ(0, fclose(zip_file));
|
|
330
|
+
|
|
331
|
+ // Missing update binary.
|
|
332
|
+ ZipArchiveHandle zip;
|
|
333
|
+ ASSERT_EQ(0, OpenArchive(temp_file.path, &zip));
|
|
334
|
+ int status_fd = 10;
|
|
335
|
+ std::string package = "/path/to/update.zip";
|
|
336
|
+ TemporaryDir td;
|
|
337
|
+ std::string binary_path = std::string(td.path) + "/update_binary";
|
|
338
|
+ std::vector<std::string> cmd;
|
|
339
|
+ ASSERT_EQ(INSTALL_CORRUPT, update_binary_command(package, zip, binary_path, 0, status_fd, &cmd));
|
|
340
|
+ CloseArchive(zip);
|
277
|
341
|
#endif // AB_OTA_UPDATER
|
278
|
342
|
}
|