summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--liblog/logprint.c85
-rw-r--r--liblog/tests/liblog_test.cpp70
-rw-r--r--logcat/logcat.cpp7
3 files changed, 70 insertions, 92 deletions
diff --git a/liblog/logprint.c b/liblog/logprint.c
index a7480d51e..3bc9f5a67 100644
--- a/liblog/logprint.c
+++ b/liblog/logprint.c
@@ -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
-}
diff --git a/liblog/tests/liblog_test.cpp b/liblog/tests/liblog_test.cpp
index 92b68acee..c6f981f58 100644
--- a/liblog/tests/liblog_test.cpp
+++ b/liblog/tests/liblog_test.cpp
@@ -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);
+}
diff --git a/logcat/logcat.cpp b/logcat/logcat.cpp
index 41a4fae42..ea4634586 100644
--- a/logcat/logcat.cpp
+++ b/logcat/logcat.cpp
@@ -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);