Skip to content

Commit 332370d

Browse files
AlanStokesGerrit Code Review
authored and
Gerrit Code Review
committed
Merge "Small liblog test fixes & readability improvements."
2 parents 974ab46 + 81e63d0 commit 332370d

File tree

2 files changed

+37
-29
lines changed

2 files changed

+37
-29
lines changed

liblog/tests/log_id_test.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ TEST(liblog, concurrent_name(__android_log_buf_print, NUM_CONCURRENT)) {
8989
ASSERT_EQ(0, pthread_create(&t[i], NULL, ConcurrentPrintFn,
9090
reinterpret_cast<void*>(i)));
9191
}
92-
int ret = 0;
92+
int ret = 1;
9393
for (i = 0; i < NUM_CONCURRENT; i++) {
9494
void* result;
9595
ASSERT_EQ(0, pthread_join(t[i], &result));
9696
int this_result = reinterpret_cast<uintptr_t>(result);
97-
if ((0 == ret) && (0 != this_result)) {
97+
if ((0 < ret) && (ret != this_result)) {
9898
ret = this_result;
9999
}
100100
}

logd/tests/logd_test.cpp

+35-27
Original file line numberDiff line numberDiff line change
@@ -646,16 +646,20 @@ void timeout_negative(const char* command) {
646646
recv(fd, msg_timeout.buf, sizeof(msg_timeout), 0) > 0;
647647
}
648648

649-
alarm_timeout =
650-
alarm((old_alarm <= 0) ? old_alarm
651-
: (old_alarm > (1 + 3 - alarm_wrap))
652-
? old_alarm - 3 + alarm_wrap
653-
: 2);
649+
if (old_alarm > 0) {
650+
unsigned int time_spent = 3 - alarm_wrap;
651+
if (old_alarm > time_spent + 1) {
652+
old_alarm -= time_spent;
653+
} else {
654+
old_alarm = 2;
655+
}
656+
}
657+
alarm_timeout = alarm(old_alarm);
654658
sigaction(SIGALRM, &old_sigaction, nullptr);
655659

656660
close(fd);
657661

658-
if (!content_wrap && !alarm_wrap && content_timeout && alarm_timeout) {
662+
if (content_wrap && alarm_wrap && content_timeout && alarm_timeout) {
659663
break;
660664
}
661665
}
@@ -710,8 +714,8 @@ TEST(logd, timeout) {
710714
// A few tries to get it right just in case wrap kicks in due to
711715
// content providers being active during the test.
712716
int i = 5;
713-
log_time now(android_log_clockid());
714-
now.tv_sec -= 30; // reach back a moderate period of time
717+
log_time start(android_log_clockid());
718+
start.tv_sec -= 30; // reach back a moderate period of time
715719

716720
while (--i) {
717721
int fd = socket_local_client("logdr", ANDROID_SOCKET_NAMESPACE_RESERVED,
@@ -726,7 +730,7 @@ TEST(logd, timeout) {
726730
std::string ask = android::base::StringPrintf(
727731
"dumpAndClose lids=0,1,2,3,4,5 timeout=6 start=%" PRIu32
728732
".%09" PRIu32,
729-
now.tv_sec, now.tv_nsec);
733+
start.tv_sec, start.tv_nsec);
730734

731735
struct sigaction ignore, old_sigaction;
732736
memset(&ignore, 0, sizeof(ignore));
@@ -756,11 +760,15 @@ TEST(logd, timeout) {
756760
recv(fd, msg_timeout.buf, sizeof(msg_timeout), 0) > 0;
757761
}
758762

759-
alarm_timeout =
760-
alarm((old_alarm <= 0) ? old_alarm
761-
: (old_alarm > (1 + 3 - alarm_wrap))
762-
? old_alarm - 3 + alarm_wrap
763-
: 2);
763+
if (old_alarm > 0) {
764+
unsigned int time_spent = 3 - alarm_wrap;
765+
if (old_alarm > time_spent + 1) {
766+
old_alarm -= time_spent;
767+
} else {
768+
old_alarm = 2;
769+
}
770+
}
771+
alarm_timeout = alarm(old_alarm);
764772
sigaction(SIGALRM, &old_sigaction, nullptr);
765773

766774
close(fd);
@@ -773,23 +781,23 @@ TEST(logd, timeout) {
773781
// active _or_ inactive during the test.
774782
if (content_timeout) {
775783
log_time msg(msg_timeout.entry.sec, msg_timeout.entry.nsec);
776-
if (msg < now) {
784+
if (msg < start) {
777785
fprintf(stderr, "%u.%09u < %u.%09u\n", msg_timeout.entry.sec,
778-
msg_timeout.entry.nsec, (unsigned)now.tv_sec,
779-
(unsigned)now.tv_nsec);
786+
msg_timeout.entry.nsec, (unsigned)start.tv_sec,
787+
(unsigned)start.tv_nsec);
780788
_exit(-1);
781789
}
782-
if (msg > now) {
783-
now = msg;
784-
now.tv_sec += 30;
785-
msg = log_time(android_log_clockid());
786-
if (now > msg) {
787-
now = msg;
788-
--now.tv_sec;
790+
if (msg > start) {
791+
start = msg;
792+
start.tv_sec += 30;
793+
log_time now = log_time(android_log_clockid());
794+
if (start > now) {
795+
start = now;
796+
--start.tv_sec;
789797
}
790798
}
791799
} else {
792-
now.tv_sec -= 120; // inactive, reach further back!
800+
start.tv_sec -= 120; // inactive, reach further back!
793801
}
794802
}
795803

@@ -802,8 +810,8 @@ TEST(logd, timeout) {
802810
}
803811

804812
if (content_wrap || !content_timeout) {
805-
fprintf(stderr, "now=%" PRIu32 ".%09" PRIu32 "\n", now.tv_sec,
806-
now.tv_nsec);
813+
fprintf(stderr, "start=%" PRIu32 ".%09" PRIu32 "\n", start.tv_sec,
814+
start.tv_nsec);
807815
}
808816

809817
EXPECT_TRUE(written);

0 commit comments

Comments
 (0)