aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTianjie Xu2017-09-08 19:09:10 -0500
committerTianjie Xu2017-09-11 16:38:49 -0500
commit79327ac21dcc58830845c99470873c5967504cbd (patch)
treeab8276c70101279a1dcad9c9bde2f1de34f89c45 /tests/component
parentfa4f0140637ea2d2c24e9d8739ab3a573fbd22fe (diff)
downloadplatform-bootable-recovery-79327ac21dcc58830845c99470873c5967504cbd.tar.gz
platform-bootable-recovery-79327ac21dcc58830845c99470873c5967504cbd.tar.xz
platform-bootable-recovery-79327ac21dcc58830845c99470873c5967504cbd.zip
Close cmd_pipe properly after updater test finishes
Otherwise the test may fail after a large number of iterations due to file open failure. Bug: 65430057 Test: run recovery_component_test on sailfish for 2000 iterations. Change-Id: I0d456284d6064467038911d63eade95740cbec2c
Diffstat (limited to 'tests/component')
-rw-r--r--tests/component/updater_test.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/tests/component/updater_test.cpp b/tests/component/updater_test.cpp
index 6c341c11..2a0575a3 100644
--- a/tests/component/updater_test.cpp
+++ b/tests/component/updater_test.cpp
@@ -383,7 +383,7 @@ TEST_F(UpdaterTest, set_progress) {
383 383
384 TemporaryFile tf; 384 TemporaryFile tf;
385 UpdaterInfo updater_info; 385 UpdaterInfo updater_info;
386 updater_info.cmd_pipe = fdopen(tf.fd, "w"); 386 updater_info.cmd_pipe = fdopen(tf.release(), "w");
387 expect(".52", "set_progress(\".52\")", kNoCause, &updater_info); 387 expect(".52", "set_progress(\".52\")", kNoCause, &updater_info);
388 fflush(updater_info.cmd_pipe); 388 fflush(updater_info.cmd_pipe);
389 389
@@ -392,6 +392,7 @@ TEST_F(UpdaterTest, set_progress) {
392 ASSERT_EQ(android::base::StringPrintf("set_progress %f\n", .52), cmd); 392 ASSERT_EQ(android::base::StringPrintf("set_progress %f\n", .52), cmd);
393 // recovery-updater protocol expects 2 tokens ("set_progress <frac>"). 393 // recovery-updater protocol expects 2 tokens ("set_progress <frac>").
394 ASSERT_EQ(2U, android::base::Split(cmd, " ").size()); 394 ASSERT_EQ(2U, android::base::Split(cmd, " ").size());
395 ASSERT_EQ(0, fclose(updater_info.cmd_pipe));
395} 396}
396 397
397TEST_F(UpdaterTest, show_progress) { 398TEST_F(UpdaterTest, show_progress) {
@@ -407,7 +408,7 @@ TEST_F(UpdaterTest, show_progress) {
407 408
408 TemporaryFile tf; 409 TemporaryFile tf;
409 UpdaterInfo updater_info; 410 UpdaterInfo updater_info;
410 updater_info.cmd_pipe = fdopen(tf.fd, "w"); 411 updater_info.cmd_pipe = fdopen(tf.release(), "w");
411 expect(".52", "show_progress(\".52\", \"10\")", kNoCause, &updater_info); 412 expect(".52", "show_progress(\".52\", \"10\")", kNoCause, &updater_info);
412 fflush(updater_info.cmd_pipe); 413 fflush(updater_info.cmd_pipe);
413 414
@@ -416,12 +417,13 @@ TEST_F(UpdaterTest, show_progress) {
416 ASSERT_EQ(android::base::StringPrintf("progress %f %d\n", .52, 10), cmd); 417 ASSERT_EQ(android::base::StringPrintf("progress %f %d\n", .52, 10), cmd);
417 // recovery-updater protocol expects 3 tokens ("progress <frac> <secs>"). 418 // recovery-updater protocol expects 3 tokens ("progress <frac> <secs>").
418 ASSERT_EQ(3U, android::base::Split(cmd, " ").size()); 419 ASSERT_EQ(3U, android::base::Split(cmd, " ").size());
420 ASSERT_EQ(0, fclose(updater_info.cmd_pipe));
419} 421}
420 422
421TEST_F(UpdaterTest, block_image_update) { 423TEST_F(UpdaterTest, block_image_update) {
422 // Create a zip file with new_data and patch_data. 424 // Create a zip file with new_data and patch_data.
423 TemporaryFile zip_file; 425 TemporaryFile zip_file;
424 FILE* zip_file_ptr = fdopen(zip_file.fd, "wb"); 426 FILE* zip_file_ptr = fdopen(zip_file.release(), "wb");
425 ZipWriter zip_writer(zip_file_ptr); 427 ZipWriter zip_writer(zip_file_ptr);
426 428
427 // Add a dummy new data. 429 // Add a dummy new data.
@@ -485,7 +487,7 @@ TEST_F(UpdaterTest, block_image_update) {
485 UpdaterInfo updater_info; 487 UpdaterInfo updater_info;
486 updater_info.package_zip = handle; 488 updater_info.package_zip = handle;
487 TemporaryFile temp_pipe; 489 TemporaryFile temp_pipe;
488 updater_info.cmd_pipe = fopen(temp_pipe.path, "wbe"); 490 updater_info.cmd_pipe = fdopen(temp_pipe.release(), "wbe");
489 updater_info.package_zip_addr = map.addr; 491 updater_info.package_zip_addr = map.addr;
490 updater_info.package_zip_len = map.length; 492 updater_info.package_zip_len = map.length;
491 493
@@ -518,7 +520,7 @@ TEST_F(UpdaterTest, block_image_update) {
518TEST_F(UpdaterTest, new_data_short_write) { 520TEST_F(UpdaterTest, new_data_short_write) {
519 // Create a zip file with new_data. 521 // Create a zip file with new_data.
520 TemporaryFile zip_file; 522 TemporaryFile zip_file;
521 FILE* zip_file_ptr = fdopen(zip_file.fd, "wb"); 523 FILE* zip_file_ptr = fdopen(zip_file.release(), "wb");
522 ZipWriter zip_writer(zip_file_ptr); 524 ZipWriter zip_writer(zip_file_ptr);
523 525
524 // Add the empty new data. 526 // Add the empty new data.
@@ -561,7 +563,7 @@ TEST_F(UpdaterTest, new_data_short_write) {
561 UpdaterInfo updater_info; 563 UpdaterInfo updater_info;
562 updater_info.package_zip = handle; 564 updater_info.package_zip = handle;
563 TemporaryFile temp_pipe; 565 TemporaryFile temp_pipe;
564 updater_info.cmd_pipe = fopen(temp_pipe.path, "wbe"); 566 updater_info.cmd_pipe = fdopen(temp_pipe.release(), "wbe");
565 updater_info.package_zip_addr = map.addr; 567 updater_info.package_zip_addr = map.addr;
566 updater_info.package_zip_len = map.length; 568 updater_info.package_zip_len = map.length;
567 569
@@ -579,13 +581,15 @@ TEST_F(UpdaterTest, new_data_short_write) {
579 std::string script_exact_data = "block_image_update(\"" + std::string(update_file.path) + 581 std::string script_exact_data = "block_image_update(\"" + std::string(update_file.path) +
580 R"(", package_extract_file("transfer_list"), "exact_new_data", "patch_data"))"; 582 R"(", package_extract_file("transfer_list"), "exact_new_data", "patch_data"))";
581 expect("t", script_exact_data.c_str(), kNoCause, &updater_info); 583 expect("t", script_exact_data.c_str(), kNoCause, &updater_info);
584
585 ASSERT_EQ(0, fclose(updater_info.cmd_pipe));
582 CloseArchive(handle); 586 CloseArchive(handle);
583} 587}
584 588
585TEST_F(UpdaterTest, brotli_new_data) { 589TEST_F(UpdaterTest, brotli_new_data) {
586 // Create a zip file with new_data. 590 // Create a zip file with new_data.
587 TemporaryFile zip_file; 591 TemporaryFile zip_file;
588 FILE* zip_file_ptr = fdopen(zip_file.fd, "wb"); 592 FILE* zip_file_ptr = fdopen(zip_file.release(), "wb");
589 ZipWriter zip_writer(zip_file_ptr); 593 ZipWriter zip_writer(zip_file_ptr);
590 594
591 // Add a brotli compressed new data entry. 595 // Add a brotli compressed new data entry.
@@ -639,7 +643,7 @@ TEST_F(UpdaterTest, brotli_new_data) {
639 UpdaterInfo updater_info; 643 UpdaterInfo updater_info;
640 updater_info.package_zip = handle; 644 updater_info.package_zip = handle;
641 TemporaryFile temp_pipe; 645 TemporaryFile temp_pipe;
642 updater_info.cmd_pipe = fopen(temp_pipe.path, "wb"); 646 updater_info.cmd_pipe = fdopen(temp_pipe.release(), "wb");
643 updater_info.package_zip_addr = map.addr; 647 updater_info.package_zip_addr = map.addr;
644 updater_info.package_zip_len = map.length; 648 updater_info.package_zip_len = map.length;
645 649
@@ -653,5 +657,7 @@ TEST_F(UpdaterTest, brotli_new_data) {
653 std::string updated_content; 657 std::string updated_content;
654 ASSERT_TRUE(android::base::ReadFileToString(update_file.path, &updated_content)); 658 ASSERT_TRUE(android::base::ReadFileToString(update_file.path, &updated_content));
655 ASSERT_EQ(brotli_new_data, updated_content); 659 ASSERT_EQ(brotli_new_data, updated_content);
660
661 ASSERT_EQ(0, fclose(updater_info.cmd_pipe));
656 CloseArchive(handle); 662 CloseArchive(handle);
657} 663}