am 65fd5412: am fd5231d7: am ccae68e4: Merge "liblog: logcat: Move library print test into gTest"
* commit '65fd5412d7fe053cb28f8e39e7753d86c333be22': liblog: logcat: Move library print test into gTest
This commit is contained in:
commit
955ebf70b7
|
@ -938,88 +938,3 @@ done:
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void logprint_run_tests()
|
||||
{
|
||||
#if 0
|
||||
|
||||
fprintf(stderr, "tests disabled\n");
|
||||
|
||||
#else
|
||||
|
||||
int err;
|
||||
const char *tag;
|
||||
AndroidLogFormat *p_format;
|
||||
|
||||
p_format = android_log_format_new();
|
||||
|
||||
fprintf(stderr, "running tests\n");
|
||||
|
||||
tag = "random";
|
||||
|
||||
android_log_addFilterRule(p_format,"*:i");
|
||||
|
||||
assert (ANDROID_LOG_INFO == filterPriForTag(p_format, "random"));
|
||||
assert(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) == 0);
|
||||
android_log_addFilterRule(p_format, "*");
|
||||
assert (ANDROID_LOG_DEBUG == filterPriForTag(p_format, "random"));
|
||||
assert(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) > 0);
|
||||
android_log_addFilterRule(p_format, "*:v");
|
||||
assert (ANDROID_LOG_VERBOSE == filterPriForTag(p_format, "random"));
|
||||
assert(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) > 0);
|
||||
android_log_addFilterRule(p_format, "*:i");
|
||||
assert (ANDROID_LOG_INFO == filterPriForTag(p_format, "random"));
|
||||
assert(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) == 0);
|
||||
|
||||
android_log_addFilterRule(p_format, "random");
|
||||
assert (ANDROID_LOG_VERBOSE == filterPriForTag(p_format, "random"));
|
||||
assert(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) > 0);
|
||||
android_log_addFilterRule(p_format, "random:v");
|
||||
assert (ANDROID_LOG_VERBOSE == filterPriForTag(p_format, "random"));
|
||||
assert(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) > 0);
|
||||
android_log_addFilterRule(p_format, "random:d");
|
||||
assert (ANDROID_LOG_DEBUG == filterPriForTag(p_format, "random"));
|
||||
assert(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) > 0);
|
||||
android_log_addFilterRule(p_format, "random:w");
|
||||
assert (ANDROID_LOG_WARN == filterPriForTag(p_format, "random"));
|
||||
assert(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) == 0);
|
||||
|
||||
android_log_addFilterRule(p_format, "crap:*");
|
||||
assert (ANDROID_LOG_VERBOSE== filterPriForTag(p_format, "crap"));
|
||||
assert(android_log_shouldPrintLine(p_format, "crap", ANDROID_LOG_VERBOSE) > 0);
|
||||
|
||||
// invalid expression
|
||||
err = android_log_addFilterRule(p_format, "random:z");
|
||||
assert (err < 0);
|
||||
assert (ANDROID_LOG_WARN == filterPriForTag(p_format, "random"));
|
||||
assert(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) == 0);
|
||||
|
||||
// Issue #550946
|
||||
err = android_log_addFilterString(p_format, " ");
|
||||
assert(err == 0);
|
||||
assert(ANDROID_LOG_WARN == filterPriForTag(p_format, "random"));
|
||||
|
||||
// note trailing space
|
||||
err = android_log_addFilterString(p_format, "*:s random:d ");
|
||||
assert(err == 0);
|
||||
assert(ANDROID_LOG_DEBUG == filterPriForTag(p_format, "random"));
|
||||
|
||||
err = android_log_addFilterString(p_format, "*:s random:z");
|
||||
assert(err < 0);
|
||||
|
||||
|
||||
#if 0
|
||||
char *ret;
|
||||
char defaultBuffer[512];
|
||||
|
||||
ret = android_log_formatLogLine(p_format,
|
||||
defaultBuffer, sizeof(defaultBuffer), 0, ANDROID_LOG_ERROR, 123,
|
||||
123, 123, "random", "nofile", strlen("Hello"), "Hello", NULL);
|
||||
#endif
|
||||
|
||||
|
||||
fprintf(stderr, "tests complete\n");
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <log/log.h>
|
||||
#include <log/logger.h>
|
||||
#include <log/log_read.h>
|
||||
#include <log/logprint.h>
|
||||
|
||||
// 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
|
||||
|
@ -612,3 +613,72 @@ TEST(liblog, android_logger_get_) {
|
|||
|
||||
android_logger_list_close(logger_list);
|
||||
}
|
||||
|
||||
static bool checkPriForTag(AndroidLogFormat *p_format, const char *tag, android_LogPriority pri) {
|
||||
return android_log_shouldPrintLine(p_format, tag, pri)
|
||||
&& !android_log_shouldPrintLine(p_format, tag, (android_LogPriority)(pri - 1));
|
||||
}
|
||||
|
||||
TEST(liblog, filterRule) {
|
||||
static const char tag[] = "random";
|
||||
|
||||
AndroidLogFormat *p_format = android_log_format_new();
|
||||
|
||||
android_log_addFilterRule(p_format,"*:i");
|
||||
|
||||
EXPECT_TRUE(checkPriForTag(p_format, tag, ANDROID_LOG_INFO));
|
||||
EXPECT_TRUE(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) == 0);
|
||||
android_log_addFilterRule(p_format, "*");
|
||||
EXPECT_TRUE (checkPriForTag(p_format, tag, ANDROID_LOG_DEBUG));
|
||||
EXPECT_TRUE(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) > 0);
|
||||
android_log_addFilterRule(p_format, "*:v");
|
||||
EXPECT_TRUE (checkPriForTag(p_format, tag, ANDROID_LOG_VERBOSE));
|
||||
EXPECT_TRUE(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) > 0);
|
||||
android_log_addFilterRule(p_format, "*:i");
|
||||
EXPECT_TRUE (checkPriForTag(p_format, tag, ANDROID_LOG_INFO));
|
||||
EXPECT_TRUE(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) == 0);
|
||||
|
||||
android_log_addFilterRule(p_format, tag);
|
||||
EXPECT_TRUE (checkPriForTag(p_format, tag, ANDROID_LOG_VERBOSE));
|
||||
EXPECT_TRUE(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) > 0);
|
||||
android_log_addFilterRule(p_format, "random:v");
|
||||
EXPECT_TRUE (checkPriForTag(p_format, tag, ANDROID_LOG_VERBOSE));
|
||||
EXPECT_TRUE(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) > 0);
|
||||
android_log_addFilterRule(p_format, "random:d");
|
||||
EXPECT_TRUE (checkPriForTag(p_format, tag, ANDROID_LOG_DEBUG));
|
||||
EXPECT_TRUE(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) > 0);
|
||||
android_log_addFilterRule(p_format, "random:w");
|
||||
EXPECT_TRUE (checkPriForTag(p_format, tag, ANDROID_LOG_WARN));
|
||||
EXPECT_TRUE(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) == 0);
|
||||
|
||||
android_log_addFilterRule(p_format, "crap:*");
|
||||
EXPECT_TRUE (checkPriForTag(p_format, "crap", ANDROID_LOG_VERBOSE));
|
||||
EXPECT_TRUE(android_log_shouldPrintLine(p_format, "crap", ANDROID_LOG_VERBOSE) > 0);
|
||||
|
||||
// invalid expression
|
||||
EXPECT_TRUE (android_log_addFilterRule(p_format, "random:z") < 0);
|
||||
EXPECT_TRUE (checkPriForTag(p_format, tag, ANDROID_LOG_WARN));
|
||||
EXPECT_TRUE(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) == 0);
|
||||
|
||||
// Issue #550946
|
||||
EXPECT_TRUE(android_log_addFilterString(p_format, " ") == 0);
|
||||
EXPECT_TRUE(checkPriForTag(p_format, tag, ANDROID_LOG_WARN));
|
||||
|
||||
// note trailing space
|
||||
EXPECT_TRUE(android_log_addFilterString(p_format, "*:s random:d ") == 0);
|
||||
EXPECT_TRUE(checkPriForTag(p_format, tag, ANDROID_LOG_DEBUG));
|
||||
|
||||
EXPECT_TRUE(android_log_addFilterString(p_format, "*:s random:z") < 0);
|
||||
|
||||
#if 0 // bitrot, seek update
|
||||
char defaultBuffer[512];
|
||||
|
||||
android_log_formatLogLine(p_format,
|
||||
defaultBuffer, sizeof(defaultBuffer), 0, ANDROID_LOG_ERROR, 123,
|
||||
123, 123, tag, "nofile", strlen("Hello"), "Hello", NULL);
|
||||
|
||||
fprintf(stderr, "%s\n", defaultBuffer);
|
||||
#endif
|
||||
|
||||
android_log_format_free(p_format);
|
||||
}
|
||||
|
|
|
@ -281,8 +281,6 @@ static int setLogFormat(const char * formatString)
|
|||
return 0;
|
||||
}
|
||||
|
||||
extern "C" void logprint_run_tests(void);
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int err;
|
||||
|
@ -306,11 +304,6 @@ int main(int argc, char **argv)
|
|||
|
||||
g_logformat = android_log_format_new();
|
||||
|
||||
if (argc == 2 && 0 == strcmp(argv[1], "--test")) {
|
||||
logprint_run_tests();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (argc == 2 && 0 == strcmp(argv[1], "--help")) {
|
||||
android::show_help(argv[0]);
|
||||
exit(0);
|
||||
|
|
Loading…
Reference in New Issue