summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--logcat/tests/logcat_test.cpp49
1 files changed, 29 insertions, 20 deletions
diff --git a/logcat/tests/logcat_test.cpp b/logcat/tests/logcat_test.cpp
index 9c9043eb3..66800b15e 100644
--- a/logcat/tests/logcat_test.cpp
+++ b/logcat/tests/logcat_test.cpp
@@ -570,6 +570,14 @@ TEST(logcat, blocking_tail) {
570 EXPECT_EQ(1, signals); 570 EXPECT_EQ(1, signals);
571} 571}
572 572
573// meant to be handed to ASSERT_FALSE / EXPECT_FALSE to expand the message
574static testing::AssertionResult IsFalse(int ret, const char* command) {
575 return ret ?
576 (testing::AssertionSuccess() <<
577 "ret=" << ret << " command=\"" << command << "\"") :
578 testing::AssertionFailure();
579}
580
573TEST(logcat, logrotate) { 581TEST(logcat, logrotate) {
574 static const char form[] = "/data/local/tmp/logcat.logrotate.XXXXXX"; 582 static const char form[] = "/data/local/tmp/logcat.logrotate.XXXXXX";
575 char buf[sizeof(form)]; 583 char buf[sizeof(form)];
@@ -581,7 +589,7 @@ TEST(logcat, logrotate) {
581 snprintf(command, sizeof(command), comm, buf); 589 snprintf(command, sizeof(command), comm, buf);
582 590
583 int ret; 591 int ret;
584 EXPECT_FALSE((ret = system(command))); 592 EXPECT_FALSE(IsFalse(ret = system(command), command));
585 if (!ret) { 593 if (!ret) {
586 snprintf(command, sizeof(command), "ls -s %s 2>/dev/null", buf); 594 snprintf(command, sizeof(command), "ls -s %s 2>/dev/null", buf);
587 595
@@ -611,7 +619,7 @@ TEST(logcat, logrotate) {
611 } 619 }
612 } 620 }
613 snprintf(command, sizeof(command), "rm -rf %s", buf); 621 snprintf(command, sizeof(command), "rm -rf %s", buf);
614 EXPECT_FALSE(system(command)); 622 EXPECT_FALSE(IsFalse(system(command), command));
615} 623}
616 624
617TEST(logcat, logrotate_suffix) { 625TEST(logcat, logrotate_suffix) {
@@ -625,7 +633,7 @@ TEST(logcat, logrotate_suffix) {
625 snprintf(command, sizeof(command), logcat_cmd, tmp_out_dir); 633 snprintf(command, sizeof(command), logcat_cmd, tmp_out_dir);
626 634
627 int ret; 635 int ret;
628 EXPECT_FALSE((ret = system(command))); 636 EXPECT_FALSE(IsFalse(ret = system(command), command));
629 if (!ret) { 637 if (!ret) {
630 snprintf(command, sizeof(command), "ls %s 2>/dev/null", tmp_out_dir); 638 snprintf(command, sizeof(command), "ls %s 2>/dev/null", tmp_out_dir);
631 639
@@ -664,7 +672,7 @@ TEST(logcat, logrotate_suffix) {
664 EXPECT_EQ(11, log_file_count); 672 EXPECT_EQ(11, log_file_count);
665 } 673 }
666 snprintf(command, sizeof(command), "rm -rf %s", tmp_out_dir); 674 snprintf(command, sizeof(command), "rm -rf %s", tmp_out_dir);
667 EXPECT_FALSE(system(command)); 675 EXPECT_FALSE(IsFalse(system(command), command));
668} 676}
669 677
670TEST(logcat, logrotate_continue) { 678TEST(logcat, logrotate_continue) {
@@ -679,10 +687,10 @@ TEST(logcat, logrotate_continue) {
679 snprintf(command, sizeof(command), logcat_cmd, tmp_out_dir, log_filename); 687 snprintf(command, sizeof(command), logcat_cmd, tmp_out_dir, log_filename);
680 688
681 int ret; 689 int ret;
682 EXPECT_FALSE((ret = system(command))); 690 EXPECT_FALSE(IsFalse(ret = system(command), command));
683 if (ret) { 691 if (ret) {
684 snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir); 692 snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir);
685 EXPECT_FALSE(system(command)); 693 EXPECT_FALSE(IsFalse(system(command), command));
686 return; 694 return;
687 } 695 }
688 FILE *fp; 696 FILE *fp;
@@ -690,7 +698,7 @@ TEST(logcat, logrotate_continue) {
690 EXPECT_TRUE(NULL != ((fp = fopen(command, "r")))); 698 EXPECT_TRUE(NULL != ((fp = fopen(command, "r"))));
691 if (!fp) { 699 if (!fp) {
692 snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir); 700 snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir);
693 EXPECT_FALSE(system(command)); 701 EXPECT_FALSE(IsFalse(system(command), command));
694 return; 702 return;
695 } 703 }
696 char *line = NULL; 704 char *line = NULL;
@@ -714,23 +722,23 @@ TEST(logcat, logrotate_continue) {
714 EXPECT_TRUE(NULL != second_last_line); 722 EXPECT_TRUE(NULL != second_last_line);
715 if (!second_last_line) { 723 if (!second_last_line) {
716 snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir); 724 snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir);
717 EXPECT_FALSE(system(command)); 725 EXPECT_FALSE(IsFalse(system(command), command));
718 return; 726 return;
719 } 727 }
720 // re-run the command, it should only add a few lines more content if it 728 // re-run the command, it should only add a few lines more content if it
721 // continues where it left off. 729 // continues where it left off.
722 snprintf(command, sizeof(command), logcat_cmd, tmp_out_dir, log_filename); 730 snprintf(command, sizeof(command), logcat_cmd, tmp_out_dir, log_filename);
723 EXPECT_FALSE((ret = system(command))); 731 EXPECT_FALSE(IsFalse(ret = system(command), command));
724 if (ret) { 732 if (ret) {
725 snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir); 733 snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir);
726 EXPECT_FALSE(system(command)); 734 EXPECT_FALSE(IsFalse(system(command), command));
727 return; 735 return;
728 } 736 }
729 std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(tmp_out_dir), closedir); 737 std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(tmp_out_dir), closedir);
730 EXPECT_NE(nullptr, dir); 738 EXPECT_NE(nullptr, dir);
731 if (!dir) { 739 if (!dir) {
732 snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir); 740 snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir);
733 EXPECT_FALSE(system(command)); 741 EXPECT_FALSE(IsFalse(system(command), command));
734 return; 742 return;
735 } 743 }
736 struct dirent *entry; 744 struct dirent *entry;
@@ -769,7 +777,7 @@ TEST(logcat, logrotate_continue) {
769 free(second_last_line); 777 free(second_last_line);
770 778
771 snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir); 779 snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir);
772 EXPECT_FALSE(system(command)); 780 EXPECT_FALSE(IsFalse(system(command), command));
773} 781}
774 782
775TEST(logcat, logrotate_clear) { 783TEST(logcat, logrotate_clear) {
@@ -790,17 +798,17 @@ TEST(logcat, logrotate_clear) {
790 logcat_cmd, tmp_out_dir, log_filename, num_val); 798 logcat_cmd, tmp_out_dir, log_filename, num_val);
791 799
792 int ret; 800 int ret;
793 EXPECT_FALSE((ret = system(command))); 801 EXPECT_FALSE(IsFalse(ret = system(command), command));
794 if (ret) { 802 if (ret) {
795 snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir); 803 snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir);
796 EXPECT_FALSE(system(command)); 804 EXPECT_FALSE(IsFalse(system(command), command));
797 return; 805 return;
798 } 806 }
799 std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(tmp_out_dir), closedir); 807 std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(tmp_out_dir), closedir);
800 EXPECT_NE(nullptr, dir); 808 EXPECT_NE(nullptr, dir);
801 if (!dir) { 809 if (!dir) {
802 snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir); 810 snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir);
803 EXPECT_FALSE(system(command)); 811 EXPECT_FALSE(IsFalse(system(command), command));
804 return; 812 return;
805 } 813 }
806 struct dirent *entry; 814 struct dirent *entry;
@@ -819,17 +827,18 @@ TEST(logcat, logrotate_clear) {
819 strcat(command, clear_cmd); 827 strcat(command, clear_cmd);
820 828
821 int ret; 829 int ret;
822 EXPECT_FALSE((ret = system(command))); 830 EXPECT_FALSE(IsFalse(ret = system(command), command));
823 if (ret) { 831 if (ret) {
824 snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir); 832 snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir);
825 EXPECT_FALSE(system(command)); 833 EXPECT_FALSE(system(command));
834 EXPECT_FALSE(IsFalse(system(command), command));
826 return; 835 return;
827 } 836 }
828 std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(tmp_out_dir), closedir); 837 std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(tmp_out_dir), closedir);
829 EXPECT_NE(nullptr, dir); 838 EXPECT_NE(nullptr, dir);
830 if (!dir) { 839 if (!dir) {
831 snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir); 840 snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir);
832 EXPECT_FALSE(system(command)); 841 EXPECT_FALSE(IsFalse(system(command), command));
833 return; 842 return;
834 } 843 }
835 struct dirent *entry; 844 struct dirent *entry;
@@ -845,7 +854,7 @@ TEST(logcat, logrotate_clear) {
845 } 854 }
846 855
847 snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir); 856 snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir);
848 EXPECT_FALSE(system(command)); 857 EXPECT_FALSE(IsFalse(system(command), command));
849} 858}
850 859
851static int logrotate_count_id(const char *logcat_cmd, const char *tmp_out_dir) { 860static int logrotate_count_id(const char *logcat_cmd, const char *tmp_out_dir) {
@@ -856,7 +865,7 @@ static int logrotate_count_id(const char *logcat_cmd, const char *tmp_out_dir) {
856 snprintf(command, sizeof(command), logcat_cmd, tmp_out_dir, log_filename); 865 snprintf(command, sizeof(command), logcat_cmd, tmp_out_dir, log_filename);
857 866
858 int ret; 867 int ret;
859 EXPECT_FALSE((ret = system(command))); 868 EXPECT_FALSE(IsFalse(ret = system(command), command));
860 if (ret) { 869 if (ret) {
861 return -1; 870 return -1;
862 } 871 }
@@ -914,7 +923,7 @@ TEST(logcat, logrotate_id) {
914 static const char cleanup_cmd[] = "rm -rf %s"; 923 static const char cleanup_cmd[] = "rm -rf %s";
915 char command[strlen(cleanup_cmd) + strlen(tmp_out_dir_form)]; 924 char command[strlen(cleanup_cmd) + strlen(tmp_out_dir_form)];
916 snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir); 925 snprintf(command, sizeof(command), cleanup_cmd, tmp_out_dir);
917 EXPECT_FALSE(system(command)); 926 EXPECT_FALSE(IsFalse(system(command), command));
918} 927}
919 928
920TEST(logcat, logrotate_nodir) { 929TEST(logcat, logrotate_nodir) {