Merge "Small liblog test fixes & readability improvements."

am: 332370d14d

Change-Id: Id3ba8e43ac60fdfe33b40e0f78629ae3312afb50
This commit is contained in:
Alan Stokes 2017-08-25 16:42:37 +00:00 committed by android-build-merger
commit 511cc67633
2 changed files with 37 additions and 29 deletions

View file

@ -89,12 +89,12 @@ TEST(liblog, concurrent_name(__android_log_buf_print, NUM_CONCURRENT)) {
ASSERT_EQ(0, pthread_create(&t[i], NULL, ConcurrentPrintFn, ASSERT_EQ(0, pthread_create(&t[i], NULL, ConcurrentPrintFn,
reinterpret_cast<void*>(i))); reinterpret_cast<void*>(i)));
} }
int ret = 0; int ret = 1;
for (i = 0; i < NUM_CONCURRENT; i++) { for (i = 0; i < NUM_CONCURRENT; i++) {
void* result; void* result;
ASSERT_EQ(0, pthread_join(t[i], &result)); ASSERT_EQ(0, pthread_join(t[i], &result));
int this_result = reinterpret_cast<uintptr_t>(result); int this_result = reinterpret_cast<uintptr_t>(result);
if ((0 == ret) && (0 != this_result)) { if ((0 < ret) && (ret != this_result)) {
ret = this_result; ret = this_result;
} }
} }

View file

@ -646,16 +646,20 @@ void timeout_negative(const char* command) {
recv(fd, msg_timeout.buf, sizeof(msg_timeout), 0) > 0; recv(fd, msg_timeout.buf, sizeof(msg_timeout), 0) > 0;
} }
alarm_timeout = if (old_alarm > 0) {
alarm((old_alarm <= 0) ? old_alarm unsigned int time_spent = 3 - alarm_wrap;
: (old_alarm > (1 + 3 - alarm_wrap)) if (old_alarm > time_spent + 1) {
? old_alarm - 3 + alarm_wrap old_alarm -= time_spent;
: 2); } else {
old_alarm = 2;
}
}
alarm_timeout = alarm(old_alarm);
sigaction(SIGALRM, &old_sigaction, nullptr); sigaction(SIGALRM, &old_sigaction, nullptr);
close(fd); close(fd);
if (!content_wrap && !alarm_wrap && content_timeout && alarm_timeout) { if (content_wrap && alarm_wrap && content_timeout && alarm_timeout) {
break; break;
} }
} }
@ -710,8 +714,8 @@ TEST(logd, timeout) {
// A few tries to get it right just in case wrap kicks in due to // A few tries to get it right just in case wrap kicks in due to
// content providers being active during the test. // content providers being active during the test.
int i = 5; int i = 5;
log_time now(android_log_clockid()); log_time start(android_log_clockid());
now.tv_sec -= 30; // reach back a moderate period of time start.tv_sec -= 30; // reach back a moderate period of time
while (--i) { while (--i) {
int fd = socket_local_client("logdr", ANDROID_SOCKET_NAMESPACE_RESERVED, int fd = socket_local_client("logdr", ANDROID_SOCKET_NAMESPACE_RESERVED,
@ -726,7 +730,7 @@ TEST(logd, timeout) {
std::string ask = android::base::StringPrintf( std::string ask = android::base::StringPrintf(
"dumpAndClose lids=0,1,2,3,4,5 timeout=6 start=%" PRIu32 "dumpAndClose lids=0,1,2,3,4,5 timeout=6 start=%" PRIu32
".%09" PRIu32, ".%09" PRIu32,
now.tv_sec, now.tv_nsec); start.tv_sec, start.tv_nsec);
struct sigaction ignore, old_sigaction; struct sigaction ignore, old_sigaction;
memset(&ignore, 0, sizeof(ignore)); memset(&ignore, 0, sizeof(ignore));
@ -756,11 +760,15 @@ TEST(logd, timeout) {
recv(fd, msg_timeout.buf, sizeof(msg_timeout), 0) > 0; recv(fd, msg_timeout.buf, sizeof(msg_timeout), 0) > 0;
} }
alarm_timeout = if (old_alarm > 0) {
alarm((old_alarm <= 0) ? old_alarm unsigned int time_spent = 3 - alarm_wrap;
: (old_alarm > (1 + 3 - alarm_wrap)) if (old_alarm > time_spent + 1) {
? old_alarm - 3 + alarm_wrap old_alarm -= time_spent;
: 2); } else {
old_alarm = 2;
}
}
alarm_timeout = alarm(old_alarm);
sigaction(SIGALRM, &old_sigaction, nullptr); sigaction(SIGALRM, &old_sigaction, nullptr);
close(fd); close(fd);
@ -773,23 +781,23 @@ TEST(logd, timeout) {
// active _or_ inactive during the test. // active _or_ inactive during the test.
if (content_timeout) { if (content_timeout) {
log_time msg(msg_timeout.entry.sec, msg_timeout.entry.nsec); log_time msg(msg_timeout.entry.sec, msg_timeout.entry.nsec);
if (msg < now) { if (msg < start) {
fprintf(stderr, "%u.%09u < %u.%09u\n", msg_timeout.entry.sec, fprintf(stderr, "%u.%09u < %u.%09u\n", msg_timeout.entry.sec,
msg_timeout.entry.nsec, (unsigned)now.tv_sec, msg_timeout.entry.nsec, (unsigned)start.tv_sec,
(unsigned)now.tv_nsec); (unsigned)start.tv_nsec);
_exit(-1); _exit(-1);
} }
if (msg > now) { if (msg > start) {
now = msg; start = msg;
now.tv_sec += 30; start.tv_sec += 30;
msg = log_time(android_log_clockid()); log_time now = log_time(android_log_clockid());
if (now > msg) { if (start > now) {
now = msg; start = now;
--now.tv_sec; --start.tv_sec;
} }
} }
} else { } else {
now.tv_sec -= 120; // inactive, reach further back! start.tv_sec -= 120; // inactive, reach further back!
} }
} }
@ -802,8 +810,8 @@ TEST(logd, timeout) {
} }
if (content_wrap || !content_timeout) { if (content_wrap || !content_timeout) {
fprintf(stderr, "now=%" PRIu32 ".%09" PRIu32 "\n", now.tv_sec, fprintf(stderr, "start=%" PRIu32 ".%09" PRIu32 "\n", start.tv_sec,
now.tv_nsec); start.tv_nsec);
} }
EXPECT_TRUE(written); EXPECT_TRUE(written);