Merge changes I7ebb6146,I0b42736c,I5331acde
* changes: logcat: expand -n, -r and -b logcat: allow comma-separate list of buffers logcat: Adjust help to make it more meaningful
This commit is contained in:
commit
df7c1ed3a0
3 changed files with 218 additions and 165 deletions
|
|
@ -27,6 +27,7 @@
|
||||||
|
|
||||||
#include <android-base/file.h>
|
#include <android-base/file.h>
|
||||||
#include <android-base/strings.h>
|
#include <android-base/strings.h>
|
||||||
|
#include <cutils/properties.h>
|
||||||
#include <cutils/sched_policy.h>
|
#include <cutils/sched_policy.h>
|
||||||
#include <cutils/sockets.h>
|
#include <cutils/sockets.h>
|
||||||
#include <log/event_tag_map.h>
|
#include <log/event_tag_map.h>
|
||||||
|
|
@ -278,66 +279,68 @@ static void show_help(const char *cmd)
|
||||||
fprintf(stderr,"Usage: %s [options] [filterspecs]\n", cmd);
|
fprintf(stderr,"Usage: %s [options] [filterspecs]\n", cmd);
|
||||||
|
|
||||||
fprintf(stderr, "options include:\n"
|
fprintf(stderr, "options include:\n"
|
||||||
" -s Set default filter to silent.\n"
|
" -s Set default filter to silent. Equivalent to filterspec '*:S'\n"
|
||||||
" Like specifying filterspec '*:S'\n"
|
" -f <file>, --file=<file> Log to file. Default is stdout\n"
|
||||||
" -f <filename> Log to file. Default is stdout\n"
|
" -r <kbytes>, --rotate-kbytes=<kbytes> Rotate log every kbytes. Requires -f\n"
|
||||||
" --file=<filename>\n"
|
" option. Permits property expansion.\n"
|
||||||
" -r <kbytes> Rotate log every kbytes. Requires -f\n"
|
" -n <count>, --rotate-count=<count> Sets max number of rotated logs to\n"
|
||||||
" --rotate-kbytes=<kbytes>\n"
|
" <count>, default 4. Permits property expansion.\n"
|
||||||
" -n <count> Sets max number of rotated logs to <count>, default 4\n"
|
" -v <format>, --format=<format>\n"
|
||||||
" --rotate-count=<count>\n"
|
" Sets the log print format, where <format> is:\n"
|
||||||
" -v <format> Sets the log print format, where <format> is:\n"
|
" brief color epoch long monotonic printable process raw\n"
|
||||||
" --format=<format>\n"
|
" tag thread threadtime time uid usec UTC year zone\n"
|
||||||
" brief color epoch long monotonic printable process raw\n"
|
" -D, --dividers Print dividers between each log buffer\n"
|
||||||
" tag thread threadtime time uid usec UTC year zone\n\n"
|
" -c, --clear Clear (flush) the entire log and exit\n"
|
||||||
" -D print dividers between each log buffer\n"
|
" -d Dump the log and then exit (don't block)\n"
|
||||||
" --dividers\n"
|
" -e <expr>, --regex=<expr>\n"
|
||||||
" -c clear (flush) the entire log and exit\n"
|
" Only print lines where the log message matches <expr>\n"
|
||||||
" --clear\n"
|
" where <expr> is a regular expression\n"
|
||||||
" -d dump the log and then exit (don't block)\n"
|
// Leave --head undocumented as alias for -m
|
||||||
" -e <expr> only print lines where the log message matches <expr>\n"
|
" -m <count>, --max-count=<count>\n"
|
||||||
" --regex <expr> where <expr> is a regular expression\n"
|
" Quit after printing <count> lines. This is meant to be\n"
|
||||||
" -m <count> quit after printing <count> lines. This is meant to be\n"
|
" paired with --regex, but will work on its own.\n"
|
||||||
" --max-count=<count> paired with --regex, but will work on its own.\n"
|
" --print Paired with --regex and --max-count to let content bypass\n"
|
||||||
" --print paired with --regex and --max-count to let content bypass\n"
|
|
||||||
" regex filter but still stop at number of matches.\n"
|
" regex filter but still stop at number of matches.\n"
|
||||||
" -t <count> print only the most recent <count> lines (implies -d)\n"
|
// Leave --tail undocumented as alias for -t
|
||||||
" -t '<time>' print most recent lines since specified time (implies -d)\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"
|
" -t '<time>' Print most recent lines since specified time (implies -d)\n"
|
||||||
" -T '<time>' print most recent lines since specified time (not imply -d)\n"
|
" -T <count> Print only the most recent <count> lines (does not imply -d)\n"
|
||||||
|
" -T '<time>' Print most recent lines since specified time (not imply -d)\n"
|
||||||
" count is pure numerical, time is 'MM-DD hh:mm:ss.mmm...'\n"
|
" count is pure numerical, time is 'MM-DD hh:mm:ss.mmm...'\n"
|
||||||
" 'YYYY-MM-DD hh:mm:ss.mmm...' or 'sssss.mmm...' format\n"
|
" 'YYYY-MM-DD hh:mm:ss.mmm...' or 'sssss.mmm...' format\n"
|
||||||
" -g get the size of the log's ring buffer and exit\n"
|
" -g, --buffer-size Get the size of the ring buffer.\n"
|
||||||
" --buffer-size\n"
|
" -G <size>, --buffer-size=<size>\n"
|
||||||
" -G <size> set size of log ring buffer, may suffix with K or M.\n"
|
" Set size of log ring buffer, may suffix with K or M.\n"
|
||||||
" --buffer-size=<size>\n"
|
" -L, -last Dump logs from prior to last reboot\n"
|
||||||
" -L dump logs from prior to last reboot\n"
|
|
||||||
" --last\n"
|
|
||||||
// Leave security (Device Owner only installations) and
|
// Leave security (Device Owner only installations) and
|
||||||
// kernel (userdebug and eng) buffers undocumented.
|
// kernel (userdebug and eng) buffers undocumented.
|
||||||
" -b <buffer> Request alternate ring buffer, 'main', 'system', 'radio',\n"
|
" -b <buffer>, --buffer=<buffer> Request alternate ring buffer, 'main',\n"
|
||||||
" --buffer=<buffer> 'events', 'crash', 'default' or 'all'. Multiple -b\n"
|
" 'system', 'radio', 'events', 'crash', 'default' or 'all'.\n"
|
||||||
" parameters are allowed and results are interleaved. The\n"
|
" Multiple -b parameters or comma separated list of buffers are\n"
|
||||||
" default is -b main -b system -b crash.\n"
|
" allowed. Buffers interleaved. Default -b main,system,crash.\n"
|
||||||
" -B output the log in binary.\n"
|
" Permits property expansion.\n"
|
||||||
" --binary\n"
|
" -B, --binary Output the log in binary.\n"
|
||||||
" -S output statistics.\n"
|
" -S, --statistics Output statistics.\n"
|
||||||
" --statistics\n"
|
" -p, --prune Print prune white and ~black list. Service is specified as\n"
|
||||||
" -p print prune white and ~black list. Service is specified as\n"
|
" UID, UID/PID or /PID. Weighed for quicker pruning if prefix\n"
|
||||||
" --prune UID, UID/PID or /PID. Weighed for quicker pruning if prefix\n"
|
|
||||||
" with ~, otherwise weighed for longevity if unadorned. All\n"
|
" with ~, otherwise weighed for longevity if unadorned. All\n"
|
||||||
" other pruning activity is oldest first. Special case ~!\n"
|
" other pruning activity is oldest first. Special case ~!\n"
|
||||||
" represents an automatic quicker pruning for the noisiest\n"
|
" represents an automatic quicker pruning for the noisiest\n"
|
||||||
" UID as determined by the current statistics.\n"
|
" UID as determined by the current statistics.\n"
|
||||||
" -P '<list> ...' set prune white and ~black list, using same format as\n"
|
" -P '<list> ...', --prune='<list> ...'\n"
|
||||||
" --prune='<list> ...' printed above. Must be quoted.\n"
|
" Set prune white and ~black list, using same format as\n"
|
||||||
|
" listed above. Must be quoted.\n"
|
||||||
" --pid=<pid> Only prints logs from the given pid.\n"
|
" --pid=<pid> Only prints logs from the given pid.\n"
|
||||||
// Check ANDROID_LOG_WRAP_DEFAULT_TIMEOUT value
|
// Check ANDROID_LOG_WRAP_DEFAULT_TIMEOUT value for match to 2 hours
|
||||||
" --wrap Sleep for 2 hours or when buffer about to wrap whichever\n"
|
" --wrap Sleep for 2 hours or when buffer about to wrap whichever\n"
|
||||||
" comes first. Improves efficiency of polling by providing\n"
|
" comes first. Improves efficiency of polling by providing\n"
|
||||||
" an about-to-wrap wakeup.\n");
|
" an about-to-wrap wakeup.\n");
|
||||||
|
|
||||||
fprintf(stderr,"\nfilterspecs are a series of \n"
|
fprintf(stderr,"\nProperty expansion where available, may need to be single quoted to prevent\n"
|
||||||
|
"shell expansion:\n"
|
||||||
|
" ${key} - Expand string with property value associated with key\n"
|
||||||
|
" ${key:-default} - Expand, if property key value clear, use default\n"
|
||||||
|
"\nfilterspecs are a series of \n"
|
||||||
" <tag>[:priority]\n\n"
|
" <tag>[:priority]\n\n"
|
||||||
"where <tag> is a log component tag (or * for all) and priority is:\n"
|
"where <tag> is a log component tag (or * for all) and priority is:\n"
|
||||||
" V Verbose (default for <tag>)\n"
|
" V Verbose (default for <tag>)\n"
|
||||||
|
|
@ -394,7 +397,7 @@ static const char *multiplier_of_size(unsigned long value)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*String to unsigned int, returns -1 if it fails*/
|
/*String to unsigned int, returns -1 if it fails*/
|
||||||
static bool getSizeTArg(char *ptr, size_t *val, size_t min = 0,
|
static bool getSizeTArg(const char *ptr, size_t *val, size_t min = 0,
|
||||||
size_t max = SIZE_MAX)
|
size_t max = SIZE_MAX)
|
||||||
{
|
{
|
||||||
if (!ptr) {
|
if (!ptr) {
|
||||||
|
|
@ -535,6 +538,49 @@ static log_time lastLogTime(char *outputFileName) {
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Expand multiple flat property references ${<tag>:-default} or ${tag}.
|
||||||
|
//
|
||||||
|
// ToDo: Do we permit nesting?
|
||||||
|
// ${persist.logcat.something:-${ro.logcat.something:-maybesomething}}
|
||||||
|
// For now this will result in a syntax error for caller and is acceptable.
|
||||||
|
//
|
||||||
|
std::string expand(const char *str)
|
||||||
|
{
|
||||||
|
std::string retval(str);
|
||||||
|
|
||||||
|
// Caller has no use for ${, } or :- as literals so no use for escape
|
||||||
|
// character. Result expectations are a number or a string, with validity
|
||||||
|
// checking for both in caller. Recursive expansion or other syntax errors
|
||||||
|
// will result in content caller can not obviously tolerate, error must
|
||||||
|
// report substring if applicable, expanded and original content (if
|
||||||
|
// different) so that it will be clear to user what they did wrong.
|
||||||
|
for (size_t pos; (pos = retval.find("${")) != std::string::npos; ) {
|
||||||
|
size_t epos = retval.find("}", pos + 2);
|
||||||
|
if (epos == std::string::npos) {
|
||||||
|
break; // Caller will error out, showing this unexpanded.
|
||||||
|
}
|
||||||
|
size_t def = retval.find(":-", pos + 2);
|
||||||
|
if (def >= epos) {
|
||||||
|
def = std::string::npos;
|
||||||
|
}
|
||||||
|
std::string default_value("");
|
||||||
|
std::string key;
|
||||||
|
if (def == std::string::npos) {
|
||||||
|
key = retval.substr(pos + 2, epos - (pos + 2));
|
||||||
|
} else {
|
||||||
|
key = retval.substr(pos + 2, def - (pos + 2));
|
||||||
|
default_value = retval.substr(def + 2, epos - (def + 2));
|
||||||
|
}
|
||||||
|
char value[PROPERTY_VALUE_MAX];
|
||||||
|
property_get(key.c_str(), value, default_value.c_str());
|
||||||
|
// Caller will error out, syntactically empty content at this point
|
||||||
|
// will not be tolerated as expected.
|
||||||
|
retval.replace(pos, epos - pos + 1, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
} /* namespace android */
|
} /* namespace android */
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -765,111 +811,75 @@ int main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'b': {
|
case 'b': {
|
||||||
if (strcmp(optarg, "default") == 0) {
|
unsigned idMask = 0;
|
||||||
for (int i = LOG_ID_MIN; i < LOG_ID_MAX; ++i) {
|
std::string expanded = expand(optarg);
|
||||||
switch (i) {
|
std::istringstream copy(expanded);
|
||||||
case LOG_ID_SECURITY:
|
std::string token;
|
||||||
case LOG_ID_EVENTS:
|
// wish for strtok and ",:; \t\n\r\f" for hidden flexibility
|
||||||
continue;
|
while (std::getline(copy, token, ',')) { // settle for ","
|
||||||
case LOG_ID_MAIN:
|
if (token.compare("default") == 0) {
|
||||||
case LOG_ID_SYSTEM:
|
idMask |= (1 << LOG_ID_MAIN) |
|
||||||
case LOG_ID_CRASH:
|
(1 << LOG_ID_SYSTEM) |
|
||||||
break;
|
(1 << LOG_ID_CRASH);
|
||||||
default:
|
} else if (token.compare("all") == 0) {
|
||||||
continue;
|
idMask = (unsigned)-1;
|
||||||
}
|
} else {
|
||||||
|
log_id_t log_id = android_name_to_log_id(token.c_str());
|
||||||
|
const char *name = android_log_id_to_name(log_id);
|
||||||
|
|
||||||
const char *name = android_log_id_to_name((log_id_t)i);
|
if (token.compare(name) != 0) {
|
||||||
log_id_t log_id = android_name_to_log_id(name);
|
bool strDifferent = expanded.compare(token);
|
||||||
|
if (expanded.compare(optarg)) {
|
||||||
if (log_id != (log_id_t)i) {
|
expanded += " expanded from ";
|
||||||
continue;
|
expanded += optarg;
|
||||||
}
|
|
||||||
|
|
||||||
bool found = false;
|
|
||||||
for (dev = devices; dev; dev = dev->next) {
|
|
||||||
if (!strcmp(optarg, dev->device)) {
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if (!dev->next) {
|
if (strDifferent) {
|
||||||
break;
|
expanded = token + " within " + expanded;
|
||||||
}
|
}
|
||||||
|
logcat_panic(true, "unknown buffer -b %s\n",
|
||||||
|
expanded.c_str());
|
||||||
}
|
}
|
||||||
if (found) {
|
idMask |= (1 << log_id);
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
log_device_t* d = new log_device_t(name, false);
|
|
||||||
|
|
||||||
if (dev) {
|
|
||||||
dev->next = d;
|
|
||||||
dev = d;
|
|
||||||
} else {
|
|
||||||
devices = dev = d;
|
|
||||||
}
|
|
||||||
g_devCount++;
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(optarg, "all") == 0) {
|
for (int i = LOG_ID_MIN; i < LOG_ID_MAX; ++i) {
|
||||||
for (int i = LOG_ID_MIN; i < LOG_ID_MAX; ++i) {
|
const char *name = android_log_id_to_name((log_id_t)i);
|
||||||
const char *name = android_log_id_to_name((log_id_t)i);
|
log_id_t log_id = android_name_to_log_id(name);
|
||||||
log_id_t log_id = android_name_to_log_id(name);
|
|
||||||
|
|
||||||
if (log_id != (log_id_t)i) {
|
if (log_id != (log_id_t)i) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if ((idMask & (1 << i)) == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (dev = devices; dev; dev = dev->next) {
|
for (dev = devices; dev; dev = dev->next) {
|
||||||
if (!strcmp(optarg, dev->device)) {
|
if (!strcmp(name, dev->device)) {
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (!dev->next) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (found) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (!dev->next) {
|
||||||
bool binary = !strcmp(name, "events") ||
|
|
||||||
!strcmp(name, "security");
|
|
||||||
log_device_t* d = new log_device_t(name, binary);
|
|
||||||
|
|
||||||
if (dev) {
|
|
||||||
dev->next = d;
|
|
||||||
dev = d;
|
|
||||||
} else {
|
|
||||||
devices = dev = d;
|
|
||||||
}
|
|
||||||
g_devCount++;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool binary = !(strcmp(optarg, "events") &&
|
|
||||||
strcmp(optarg, "security"));
|
|
||||||
|
|
||||||
if (devices) {
|
|
||||||
dev = devices;
|
|
||||||
while (dev->next) {
|
|
||||||
if (!strcmp(optarg, dev->device)) {
|
|
||||||
dev = NULL;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
dev = dev->next;
|
|
||||||
}
|
}
|
||||||
|
if (found) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool binary = !strcmp(name, "events") ||
|
||||||
|
!strcmp(name, "security");
|
||||||
|
log_device_t* d = new log_device_t(name, binary);
|
||||||
|
|
||||||
if (dev) {
|
if (dev) {
|
||||||
dev->next = new log_device_t(optarg, binary);
|
dev->next = d;
|
||||||
|
dev = d;
|
||||||
|
} else {
|
||||||
|
devices = dev = d;
|
||||||
}
|
}
|
||||||
} else {
|
g_devCount++;
|
||||||
devices = new log_device_t(optarg, binary);
|
|
||||||
}
|
}
|
||||||
g_devCount++;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -885,22 +895,36 @@ int main(int argc, char **argv)
|
||||||
g_outputFileName = optarg;
|
g_outputFileName = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'r':
|
case 'r': {
|
||||||
if (!getSizeTArg(optarg, &g_logRotateSizeKBytes, 1)) {
|
std::string expanded = expand(optarg);
|
||||||
logcat_panic(true, "Invalid parameter %s to -r\n", optarg);
|
if (!getSizeTArg(expanded.c_str(), &g_logRotateSizeKBytes, 1)) {
|
||||||
|
if (expanded.compare(optarg)) {
|
||||||
|
expanded += " expanded from ";
|
||||||
|
expanded += optarg;
|
||||||
|
}
|
||||||
|
logcat_panic(true, "Invalid parameter -r %s\n",
|
||||||
|
expanded.c_str());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'n':
|
case 'n': {
|
||||||
if (!getSizeTArg(optarg, &g_maxRotatedLogs, 1)) {
|
std::string expanded = expand(optarg);
|
||||||
logcat_panic(true, "Invalid parameter %s to -n\n", optarg);
|
if (!getSizeTArg(expanded.c_str(), &g_maxRotatedLogs, 1)) {
|
||||||
|
if (expanded.compare(optarg)) {
|
||||||
|
expanded += " expanded from ";
|
||||||
|
expanded += optarg;
|
||||||
|
}
|
||||||
|
logcat_panic(true, "Invalid parameter -n %s\n",
|
||||||
|
expanded.c_str());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
err = setLogFormat (optarg);
|
err = setLogFormat (optarg);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
logcat_panic(true, "Invalid parameter %s to -v\n", optarg);
|
logcat_panic(true, "Invalid parameter -v %s\n", optarg);
|
||||||
}
|
}
|
||||||
hasSetLogFormat |= err;
|
hasSetLogFormat |= err;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,6 @@ include $(CLEAR_VARS)
|
||||||
LOCAL_MODULE := $(test_module_prefix)unit-tests
|
LOCAL_MODULE := $(test_module_prefix)unit-tests
|
||||||
LOCAL_MODULE_TAGS := $(test_tags)
|
LOCAL_MODULE_TAGS := $(test_tags)
|
||||||
LOCAL_CFLAGS += $(test_c_flags)
|
LOCAL_CFLAGS += $(test_c_flags)
|
||||||
LOCAL_SHARED_LIBRARIES := liblog
|
LOCAL_SHARED_LIBRARIES := liblog libcutils
|
||||||
LOCAL_SRC_FILES := $(test_src_files)
|
LOCAL_SRC_FILES := $(test_src_files)
|
||||||
include $(BUILD_NATIVE_TEST)
|
include $(BUILD_NATIVE_TEST)
|
||||||
|
|
|
||||||
|
|
@ -25,11 +25,14 @@
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#include <cutils/properties.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <log/log.h>
|
#include <log/log.h>
|
||||||
#include <log/logger.h>
|
#include <log/logger.h>
|
||||||
#include <log/log_read.h>
|
#include <log/log_read.h>
|
||||||
|
|
||||||
|
#define BIG_BUFFER (5 * 1024)
|
||||||
|
|
||||||
// enhanced version of LOG_FAILURE_RETRY to add support for EAGAIN and
|
// enhanced version of LOG_FAILURE_RETRY to add support for EAGAIN and
|
||||||
// non-syscall libs. Since we are only using this in the emergency of
|
// non-syscall libs. Since we are only using this in the emergency of
|
||||||
// a signal to stuff a terminating code into the logs, we will spin rather
|
// a signal to stuff a terminating code into the logs, we will spin rather
|
||||||
|
|
@ -54,7 +57,7 @@ TEST(logcat, buckets) {
|
||||||
"logcat -b radio -b events -b system -b main -d 2>/dev/null",
|
"logcat -b radio -b events -b system -b main -d 2>/dev/null",
|
||||||
"r")));
|
"r")));
|
||||||
|
|
||||||
char buffer[5120];
|
char buffer[BIG_BUFFER];
|
||||||
|
|
||||||
int ids = 0;
|
int ids = 0;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
@ -102,7 +105,7 @@ TEST(logcat, year) {
|
||||||
"logcat -v long -v year -b all -t 3 2>/dev/null",
|
"logcat -v long -v year -b all -t 3 2>/dev/null",
|
||||||
"r")));
|
"r")));
|
||||||
|
|
||||||
char buffer[5120];
|
char buffer[BIG_BUFFER];
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
|
|
@ -165,7 +168,7 @@ TEST(logcat, tz) {
|
||||||
"logcat -v long -v America/Los_Angeles -b all -t 3 2>/dev/null",
|
"logcat -v long -v America/Los_Angeles -b all -t 3 2>/dev/null",
|
||||||
"r")));
|
"r")));
|
||||||
|
|
||||||
char buffer[5120];
|
char buffer[BIG_BUFFER];
|
||||||
|
|
||||||
count = 0;
|
count = 0;
|
||||||
|
|
||||||
|
|
@ -189,7 +192,7 @@ TEST(logcat, ntz) {
|
||||||
"logcat -v long -v America/Los_Angeles -v zone -b all -t 3 2>/dev/null",
|
"logcat -v long -v America/Los_Angeles -v zone -b all -t 3 2>/dev/null",
|
||||||
"r")));
|
"r")));
|
||||||
|
|
||||||
char buffer[5120];
|
char buffer[BIG_BUFFER];
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
|
|
@ -209,7 +212,7 @@ void do_tail(int num) {
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
char buffer[5120];
|
char buffer[BIG_BUFFER];
|
||||||
|
|
||||||
snprintf(buffer, sizeof(buffer),
|
snprintf(buffer, sizeof(buffer),
|
||||||
"logcat -v long -b radio -b events -b system -b main -t %d 2>/dev/null",
|
"logcat -v long -b radio -b events -b system -b main -t %d 2>/dev/null",
|
||||||
|
|
@ -252,7 +255,7 @@ TEST(logcat, tail_time) {
|
||||||
|
|
||||||
ASSERT_TRUE(NULL != (fp = popen("logcat -v long -b all -t 10 2>&1", "r")));
|
ASSERT_TRUE(NULL != (fp = popen("logcat -v long -b all -t 10 2>&1", "r")));
|
||||||
|
|
||||||
char buffer[5120];
|
char buffer[BIG_BUFFER];
|
||||||
char *last_timestamp = NULL;
|
char *last_timestamp = NULL;
|
||||||
char *first_timestamp = NULL;
|
char *first_timestamp = NULL;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
@ -315,7 +318,7 @@ TEST(logcat, End_to_End) {
|
||||||
"logcat -v brief -b events -t 100 2>/dev/null",
|
"logcat -v brief -b events -t 100 2>/dev/null",
|
||||||
"r")));
|
"r")));
|
||||||
|
|
||||||
char buffer[5120];
|
char buffer[BIG_BUFFER];
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
|
|
@ -339,15 +342,17 @@ TEST(logcat, End_to_End) {
|
||||||
ASSERT_EQ(1, count);
|
ASSERT_EQ(1, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(logcat, get_size) {
|
int get_groups(const char *cmd) {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
// NB: crash log only available in user space
|
// NB: crash log only available in user space
|
||||||
ASSERT_TRUE(NULL != (fp = popen(
|
EXPECT_TRUE(NULL != (fp = popen(cmd, "r")));
|
||||||
"logcat -v brief -b radio -b events -b system -b main -g 2>/dev/null",
|
|
||||||
"r")));
|
|
||||||
|
|
||||||
char buffer[5120];
|
if (fp == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
char buffer[BIG_BUFFER];
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
|
|
@ -407,7 +412,31 @@ TEST(logcat, get_size) {
|
||||||
|
|
||||||
pclose(fp);
|
pclose(fp);
|
||||||
|
|
||||||
ASSERT_EQ(4, count);
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(logcat, get_size) {
|
||||||
|
ASSERT_EQ(4, get_groups(
|
||||||
|
"logcat -v brief -b radio -b events -b system -b main -g 2>/dev/null"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// duplicate test for get_size, but use comma-separated list of buffers
|
||||||
|
TEST(logcat, multiple_buffer) {
|
||||||
|
ASSERT_EQ(4, get_groups(
|
||||||
|
"logcat -v brief -b radio,events,system,main -g 2>/dev/null"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// duplicate test for get_size, but use test.logcat.buffer property
|
||||||
|
TEST(logcat, property_expand) {
|
||||||
|
property_set("test.logcat.buffer", "radio,events");
|
||||||
|
EXPECT_EQ(4, get_groups(
|
||||||
|
"logcat -v brief -b 'system,${test.logcat.buffer:-bogo},main' -g 2>/dev/null"));
|
||||||
|
property_set("test.logcat.buffer", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(logcat, bad_buffer) {
|
||||||
|
ASSERT_EQ(0, get_groups(
|
||||||
|
"logcat -v brief -b radio,events,bogo,system,main -g 2>/dev/null"));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void caught_blocking(int /*signum*/)
|
static void caught_blocking(int /*signum*/)
|
||||||
|
|
@ -436,7 +465,7 @@ TEST(logcat, blocking) {
|
||||||
" logcat -v brief -b events 2>&1",
|
" logcat -v brief -b events 2>&1",
|
||||||
"r")));
|
"r")));
|
||||||
|
|
||||||
char buffer[5120];
|
char buffer[BIG_BUFFER];
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
|
|
@ -505,7 +534,7 @@ TEST(logcat, blocking_tail) {
|
||||||
" logcat -v brief -b events -T 5 2>&1",
|
" logcat -v brief -b events -T 5 2>&1",
|
||||||
"r")));
|
"r")));
|
||||||
|
|
||||||
char buffer[5120];
|
char buffer[BIG_BUFFER];
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
|
|
@ -568,7 +597,7 @@ TEST(logcat, logrotate) {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
EXPECT_TRUE(NULL != (fp = popen(command, "r")));
|
EXPECT_TRUE(NULL != (fp = popen(command, "r")));
|
||||||
if (fp) {
|
if (fp) {
|
||||||
char buffer[5120];
|
char buffer[BIG_BUFFER];
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
while (fgets(buffer, sizeof(buffer), fp)) {
|
while (fgets(buffer, sizeof(buffer), fp)) {
|
||||||
|
|
@ -611,7 +640,7 @@ TEST(logcat, logrotate_suffix) {
|
||||||
|
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
EXPECT_TRUE(NULL != (fp = popen(command, "r")));
|
EXPECT_TRUE(NULL != (fp = popen(command, "r")));
|
||||||
char buffer[5120];
|
char buffer[BIG_BUFFER];
|
||||||
int log_file_count = 0;
|
int log_file_count = 0;
|
||||||
|
|
||||||
while (fgets(buffer, sizeof(buffer), fp)) {
|
while (fgets(buffer, sizeof(buffer), fp)) {
|
||||||
|
|
@ -784,7 +813,7 @@ TEST(logcat, blocking_clear) {
|
||||||
" logcat -v brief -b events 2>&1",
|
" logcat -v brief -b events 2>&1",
|
||||||
"r")));
|
"r")));
|
||||||
|
|
||||||
char buffer[5120];
|
char buffer[BIG_BUFFER];
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
|
|
@ -845,7 +874,7 @@ static bool get_white_black(char **list) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char buffer[5120];
|
char buffer[BIG_BUFFER];
|
||||||
|
|
||||||
while (fgets(buffer, sizeof(buffer), fp)) {
|
while (fgets(buffer, sizeof(buffer), fp)) {
|
||||||
char *hold = *list;
|
char *hold = *list;
|
||||||
|
|
@ -874,7 +903,7 @@ static bool get_white_black(char **list) {
|
||||||
static bool set_white_black(const char *list) {
|
static bool set_white_black(const char *list) {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
char buffer[5120];
|
char buffer[BIG_BUFFER];
|
||||||
|
|
||||||
snprintf(buffer, sizeof(buffer), "logcat -P '%s' 2>&1", list ? list : "");
|
snprintf(buffer, sizeof(buffer), "logcat -P '%s' 2>&1", list ? list : "");
|
||||||
fp = popen(buffer, "r");
|
fp = popen(buffer, "r");
|
||||||
|
|
@ -936,7 +965,7 @@ TEST(logcat, regex) {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
char buffer[5120];
|
char buffer[BIG_BUFFER];
|
||||||
|
|
||||||
snprintf(buffer, sizeof(buffer), "logcat --pid %d -d -e logcat_test_a+b", getpid());
|
snprintf(buffer, sizeof(buffer), "logcat --pid %d -d -e logcat_test_a+b", getpid());
|
||||||
|
|
||||||
|
|
@ -969,7 +998,7 @@ TEST(logcat, maxcount) {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
char buffer[5120];
|
char buffer[BIG_BUFFER];
|
||||||
|
|
||||||
snprintf(buffer, sizeof(buffer), "logcat --pid %d -d --max-count 3", getpid());
|
snprintf(buffer, sizeof(buffer), "logcat --pid %d -d --max-count 3", getpid());
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue