Loading logcat/logcat.cpp +4 −1 Original line number Diff line number Diff line Loading @@ -223,6 +223,7 @@ static void show_help(const char *cmd) " -c clear (flush) the entire log and exit\n" " -d dump the log and then exit (don't block)\n" " -t <count> print only the most recent <count> lines (implies -d)\n" " -T <count> print only the most recent <count> lines (does not imply -d)\n" " -g get the size of the log's ring buffer and exit\n" " -b <buffer> Request alternate ring buffer, 'main', 'system', 'radio'\n" " or 'events'. Multiple -b parameters are allowed and the\n" Loading Loading @@ -302,7 +303,7 @@ int main(int argc, char **argv) for (;;) { int ret; ret = getopt(argc, argv, "cdt:gsQf:r::n:v:b:B"); ret = getopt(argc, argv, "cdt:T:gsQf:r::n:v:b:B"); if (ret < 0) { break; Loading @@ -325,6 +326,8 @@ int main(int argc, char **argv) case 't': mode = O_RDONLY | O_NDELAY; /* FALLTHRU */ case 'T': tail_lines = atoi(optarg); break; Loading logcat/tests/logcat_test.cpp +68 −0 Original line number Diff line number Diff line Loading @@ -373,3 +373,71 @@ TEST(logcat, blocking) { ASSERT_EQ(1, signals); } static void caught_blocking_tail(int signum) { unsigned long long v = 0xA55ADEADBEEF0000ULL; v += getpid() & 0xFFFF; LOG_FAILURE_RETRY(__android_log_btwrite(0, EVENT_TYPE_LONG, &v, sizeof(v))); } TEST(logcat, blocking_tail) { FILE *fp; unsigned long long v = 0xA55ADEADBEEF0000ULL; pid_t pid = getpid(); v += pid & 0xFFFF; ASSERT_EQ(0, NULL == (fp = popen( "( trap exit HUP QUIT INT PIPE KILL ; sleep 6; echo DONE )&" " logcat -b events -T 5 2>&1", "r"))); char buffer[5120]; int count = 0; int signals = 0; signal(SIGALRM, caught_blocking_tail); alarm(2); while (fgets(buffer, sizeof(buffer), fp)) { alarm(2); ++count; if (!strncmp(buffer, "DONE", 4)) { break; } int p; unsigned long long l; if ((2 != sscanf(buffer, "I/[0] ( %u): %lld", &p, &l)) || (p != pid)) { continue; } if (l == v) { if (count >= 5) { ++signals; } break; } } alarm(0); signal(SIGALRM, SIG_DFL); /* Generate SIGPIPE */ fclose(fp); caught_blocking_tail(0); pclose(fp); ASSERT_LT(5, count); ASSERT_EQ(1, signals); } Loading
logcat/logcat.cpp +4 −1 Original line number Diff line number Diff line Loading @@ -223,6 +223,7 @@ static void show_help(const char *cmd) " -c clear (flush) the entire log and exit\n" " -d dump the log and then exit (don't block)\n" " -t <count> print only the most recent <count> lines (implies -d)\n" " -T <count> print only the most recent <count> lines (does not imply -d)\n" " -g get the size of the log's ring buffer and exit\n" " -b <buffer> Request alternate ring buffer, 'main', 'system', 'radio'\n" " or 'events'. Multiple -b parameters are allowed and the\n" Loading Loading @@ -302,7 +303,7 @@ int main(int argc, char **argv) for (;;) { int ret; ret = getopt(argc, argv, "cdt:gsQf:r::n:v:b:B"); ret = getopt(argc, argv, "cdt:T:gsQf:r::n:v:b:B"); if (ret < 0) { break; Loading @@ -325,6 +326,8 @@ int main(int argc, char **argv) case 't': mode = O_RDONLY | O_NDELAY; /* FALLTHRU */ case 'T': tail_lines = atoi(optarg); break; Loading
logcat/tests/logcat_test.cpp +68 −0 Original line number Diff line number Diff line Loading @@ -373,3 +373,71 @@ TEST(logcat, blocking) { ASSERT_EQ(1, signals); } static void caught_blocking_tail(int signum) { unsigned long long v = 0xA55ADEADBEEF0000ULL; v += getpid() & 0xFFFF; LOG_FAILURE_RETRY(__android_log_btwrite(0, EVENT_TYPE_LONG, &v, sizeof(v))); } TEST(logcat, blocking_tail) { FILE *fp; unsigned long long v = 0xA55ADEADBEEF0000ULL; pid_t pid = getpid(); v += pid & 0xFFFF; ASSERT_EQ(0, NULL == (fp = popen( "( trap exit HUP QUIT INT PIPE KILL ; sleep 6; echo DONE )&" " logcat -b events -T 5 2>&1", "r"))); char buffer[5120]; int count = 0; int signals = 0; signal(SIGALRM, caught_blocking_tail); alarm(2); while (fgets(buffer, sizeof(buffer), fp)) { alarm(2); ++count; if (!strncmp(buffer, "DONE", 4)) { break; } int p; unsigned long long l; if ((2 != sscanf(buffer, "I/[0] ( %u): %lld", &p, &l)) || (p != pid)) { continue; } if (l == v) { if (count >= 5) { ++signals; } break; } } alarm(0); signal(SIGALRM, SIG_DFL); /* Generate SIGPIPE */ fclose(fp); caught_blocking_tail(0); pclose(fp); ASSERT_LT(5, count); ASSERT_EQ(1, signals); }