diff options
author | Alan Stokes | 2017-08-25 11:42:37 -0500 |
---|---|---|
committer | android-build-merger | 2017-08-25 11:42:37 -0500 |
commit | 511cc676331b3bdf9fdd68b8641ac39e01cbc824 (patch) | |
tree | 6b66406f5f85c3c9b47299e874ecf906008e8370 /logd | |
parent | 9181fe642740cf4d7fe7fd774d61d45aad73ada9 (diff) | |
parent | 332370d14d0948308f9c467f81c23d6e06cb38bf (diff) | |
download | platform-system-core-511cc676331b3bdf9fdd68b8641ac39e01cbc824.tar.gz platform-system-core-511cc676331b3bdf9fdd68b8641ac39e01cbc824.tar.xz platform-system-core-511cc676331b3bdf9fdd68b8641ac39e01cbc824.zip |
Merge "Small liblog test fixes & readability improvements."
am: 332370d14d
Change-Id: Id3ba8e43ac60fdfe33b40e0f78629ae3312afb50
Diffstat (limited to 'logd')
-rw-r--r-- | logd/tests/logd_test.cpp | 62 |
1 files changed, 35 insertions, 27 deletions
diff --git a/logd/tests/logd_test.cpp b/logd/tests/logd_test.cpp index 4397b144c..8ee5ea10d 100644 --- a/logd/tests/logd_test.cpp +++ b/logd/tests/logd_test.cpp | |||
@@ -646,16 +646,20 @@ void timeout_negative(const char* command) { | |||
646 | recv(fd, msg_timeout.buf, sizeof(msg_timeout), 0) > 0; | 646 | recv(fd, msg_timeout.buf, sizeof(msg_timeout), 0) > 0; |
647 | } | 647 | } |
648 | 648 | ||
649 | alarm_timeout = | 649 | if (old_alarm > 0) { |
650 | alarm((old_alarm <= 0) ? old_alarm | 650 | unsigned int time_spent = 3 - alarm_wrap; |
651 | : (old_alarm > (1 + 3 - alarm_wrap)) | 651 | if (old_alarm > time_spent + 1) { |
652 | ? old_alarm - 3 + alarm_wrap | 652 | old_alarm -= time_spent; |
653 | : 2); | 653 | } else { |
654 | old_alarm = 2; | ||
655 | } | ||
656 | } | ||
657 | alarm_timeout = alarm(old_alarm); | ||
654 | sigaction(SIGALRM, &old_sigaction, nullptr); | 658 | sigaction(SIGALRM, &old_sigaction, nullptr); |
655 | 659 | ||
656 | close(fd); | 660 | close(fd); |
657 | 661 | ||
658 | if (!content_wrap && !alarm_wrap && content_timeout && alarm_timeout) { | 662 | if (content_wrap && alarm_wrap && content_timeout && alarm_timeout) { |
659 | break; | 663 | break; |
660 | } | 664 | } |
661 | } | 665 | } |
@@ -710,8 +714,8 @@ TEST(logd, timeout) { | |||
710 | // A few tries to get it right just in case wrap kicks in due to | 714 | // A few tries to get it right just in case wrap kicks in due to |
711 | // content providers being active during the test. | 715 | // content providers being active during the test. |
712 | int i = 5; | 716 | int i = 5; |
713 | log_time now(android_log_clockid()); | 717 | log_time start(android_log_clockid()); |
714 | now.tv_sec -= 30; // reach back a moderate period of time | 718 | start.tv_sec -= 30; // reach back a moderate period of time |
715 | 719 | ||
716 | while (--i) { | 720 | while (--i) { |
717 | int fd = socket_local_client("logdr", ANDROID_SOCKET_NAMESPACE_RESERVED, | 721 | int fd = socket_local_client("logdr", ANDROID_SOCKET_NAMESPACE_RESERVED, |
@@ -726,7 +730,7 @@ TEST(logd, timeout) { | |||
726 | std::string ask = android::base::StringPrintf( | 730 | std::string ask = android::base::StringPrintf( |
727 | "dumpAndClose lids=0,1,2,3,4,5 timeout=6 start=%" PRIu32 | 731 | "dumpAndClose lids=0,1,2,3,4,5 timeout=6 start=%" PRIu32 |
728 | ".%09" PRIu32, | 732 | ".%09" PRIu32, |
729 | now.tv_sec, now.tv_nsec); | 733 | start.tv_sec, start.tv_nsec); |
730 | 734 | ||
731 | struct sigaction ignore, old_sigaction; | 735 | struct sigaction ignore, old_sigaction; |
732 | memset(&ignore, 0, sizeof(ignore)); | 736 | memset(&ignore, 0, sizeof(ignore)); |
@@ -756,11 +760,15 @@ TEST(logd, timeout) { | |||
756 | recv(fd, msg_timeout.buf, sizeof(msg_timeout), 0) > 0; | 760 | recv(fd, msg_timeout.buf, sizeof(msg_timeout), 0) > 0; |
757 | } | 761 | } |
758 | 762 | ||
759 | alarm_timeout = | 763 | if (old_alarm > 0) { |
760 | alarm((old_alarm <= 0) ? old_alarm | 764 | unsigned int time_spent = 3 - alarm_wrap; |
761 | : (old_alarm > (1 + 3 - alarm_wrap)) | 765 | if (old_alarm > time_spent + 1) { |
762 | ? old_alarm - 3 + alarm_wrap | 766 | old_alarm -= time_spent; |
763 | : 2); | 767 | } else { |
768 | old_alarm = 2; | ||
769 | } | ||
770 | } | ||
771 | alarm_timeout = alarm(old_alarm); | ||
764 | sigaction(SIGALRM, &old_sigaction, nullptr); | 772 | sigaction(SIGALRM, &old_sigaction, nullptr); |
765 | 773 | ||
766 | close(fd); | 774 | close(fd); |
@@ -773,23 +781,23 @@ TEST(logd, timeout) { | |||
773 | // active _or_ inactive during the test. | 781 | // active _or_ inactive during the test. |
774 | if (content_timeout) { | 782 | if (content_timeout) { |
775 | log_time msg(msg_timeout.entry.sec, msg_timeout.entry.nsec); | 783 | log_time msg(msg_timeout.entry.sec, msg_timeout.entry.nsec); |
776 | if (msg < now) { | 784 | if (msg < start) { |
777 | fprintf(stderr, "%u.%09u < %u.%09u\n", msg_timeout.entry.sec, | 785 | fprintf(stderr, "%u.%09u < %u.%09u\n", msg_timeout.entry.sec, |
778 | msg_timeout.entry.nsec, (unsigned)now.tv_sec, | 786 | msg_timeout.entry.nsec, (unsigned)start.tv_sec, |
779 | (unsigned)now.tv_nsec); | 787 | (unsigned)start.tv_nsec); |
780 | _exit(-1); | 788 | _exit(-1); |
781 | } | 789 | } |
782 | if (msg > now) { | 790 | if (msg > start) { |
783 | now = msg; | 791 | start = msg; |
784 | now.tv_sec += 30; | 792 | start.tv_sec += 30; |
785 | msg = log_time(android_log_clockid()); | 793 | log_time now = log_time(android_log_clockid()); |
786 | if (now > msg) { | 794 | if (start > now) { |
787 | now = msg; | 795 | start = now; |
788 | --now.tv_sec; | 796 | --start.tv_sec; |
789 | } | 797 | } |
790 | } | 798 | } |
791 | } else { | 799 | } else { |
792 | now.tv_sec -= 120; // inactive, reach further back! | 800 | start.tv_sec -= 120; // inactive, reach further back! |
793 | } | 801 | } |
794 | } | 802 | } |
795 | 803 | ||
@@ -802,8 +810,8 @@ TEST(logd, timeout) { | |||
802 | } | 810 | } |
803 | 811 | ||
804 | if (content_wrap || !content_timeout) { | 812 | if (content_wrap || !content_timeout) { |
805 | fprintf(stderr, "now=%" PRIu32 ".%09" PRIu32 "\n", now.tv_sec, | 813 | fprintf(stderr, "start=%" PRIu32 ".%09" PRIu32 "\n", start.tv_sec, |
806 | now.tv_nsec); | 814 | start.tv_nsec); |
807 | } | 815 | } |
808 | 816 | ||
809 | EXPECT_TRUE(written); | 817 | EXPECT_TRUE(written); |