logcat: test: add clear and blocking check

Change-Id: I243b1338c4a5935a297a0519c03697fd828e47e6
This commit is contained in:
Mark Salyzyn 2014-01-22 10:30:09 -08:00
parent 0f18bb1fe0
commit 1beb2ab6f6

View file

@ -319,12 +319,16 @@ static void caught_blocking(int signum)
TEST(logcat, blocking) {
FILE *fp;
unsigned long long v = 0xDEADBEEFA55A0000ULL;
unsigned long long v = 0xDEADBEEFA55F0000ULL;
pid_t pid = getpid();
v += pid & 0xFFFF;
LOG_FAILURE_RETRY(__android_log_btwrite(0, EVENT_TYPE_LONG, &v, sizeof(v)));
v &= 0xFFFFFFFFFFFAFFFFULL;
ASSERT_EQ(0, NULL == (fp = popen(
"( trap exit HUP QUIT INT PIPE KILL ; sleep 6; echo DONE )&"
" logcat -b events 2>&1",
@ -341,12 +345,12 @@ TEST(logcat, blocking) {
while (fgets(buffer, sizeof(buffer), fp)) {
alarm(2);
++count;
if (!strncmp(buffer, "DONE", 4)) {
break;
}
++count;
int p;
unsigned long long l;
@ -369,7 +373,7 @@ TEST(logcat, blocking) {
pclose(fp);
ASSERT_LT(10, count);
ASSERT_LE(2, count);
ASSERT_EQ(1, signals);
}
@ -385,12 +389,16 @@ static void caught_blocking_tail(int signum)
TEST(logcat, blocking_tail) {
FILE *fp;
unsigned long long v = 0xA55ADEADBEEF0000ULL;
unsigned long long v = 0xA55FDEADBEEF0000ULL;
pid_t pid = getpid();
v += pid & 0xFFFF;
LOG_FAILURE_RETRY(__android_log_btwrite(0, EVENT_TYPE_LONG, &v, sizeof(v)));
v &= 0xFFFAFFFFFFFFFFFFULL;
ASSERT_EQ(0, NULL == (fp = popen(
"( trap exit HUP QUIT INT PIPE KILL ; sleep 6; echo DONE )&"
" logcat -b events -T 5 2>&1",
@ -407,12 +415,12 @@ TEST(logcat, blocking_tail) {
while (fgets(buffer, sizeof(buffer), fp)) {
alarm(2);
++count;
if (!strncmp(buffer, "DONE", 4)) {
break;
}
++count;
int p;
unsigned long long l;
@ -431,13 +439,91 @@ TEST(logcat, blocking_tail) {
alarm(0);
signal(SIGALRM, SIG_DFL);
/* Generate SIGPIPE */
// Generate SIGPIPE
fclose(fp);
caught_blocking_tail(0);
pclose(fp);
ASSERT_LT(5, count);
ASSERT_LE(2, count);
ASSERT_EQ(1, signals);
}
static void caught_blocking_clear(int signum)
{
unsigned long long v = 0xDEADBEEFA55C0000ULL;
v += getpid() & 0xFFFF;
LOG_FAILURE_RETRY(__android_log_btwrite(0, EVENT_TYPE_LONG, &v, sizeof(v)));
}
TEST(logcat, blocking_clear) {
FILE *fp;
unsigned long long v = 0xDEADBEEFA55C0000ULL;
pid_t pid = getpid();
v += pid & 0xFFFF;
// This test is racey; an event occurs between clear and dump.
// We accept that we will get a false positive, but never a false negative.
ASSERT_EQ(0, NULL == (fp = popen(
"( trap exit HUP QUIT INT PIPE KILL ; sleep 6; echo DONE )&"
" logcat -b events -c 2>&1 ;"
" logcat -b events 2>&1",
"r")));
char buffer[5120];
int count = 0;
int signals = 0;
signal(SIGALRM, caught_blocking_clear);
alarm(2);
while (fgets(buffer, sizeof(buffer), fp)) {
alarm(2);
if (!strncmp(buffer, "clearLog: ", 10)) {
fprintf(stderr, "WARNING: Test lacks permission to run :-(\n");
count = signals = 1;
break;
}
if (!strncmp(buffer, "DONE", 4)) {
break;
}
++count;
int p;
unsigned long long l;
if ((2 != sscanf(buffer, "I/[0] ( %u): %lld", &p, &l))
|| (p != pid)) {
continue;
}
if (l == v) {
if (count > 1) {
fprintf(stderr, "WARNING: Possible false positive\n");
}
++signals;
break;
}
}
alarm(0);
signal(SIGALRM, SIG_DFL);
// Generate SIGPIPE
fclose(fp);
caught_blocking_clear(0);
pclose(fp);
ASSERT_LE(1, count);
ASSERT_EQ(1, signals);
}