diff options
author | Mark Salyzyn <salyzyn@google.com> | 2014-03-11 11:20:56 -0700 |
---|---|---|
committer | Mark Salyzyn <salyzyn@google.com> | 2014-03-14 10:24:42 -0700 |
commit | 95cfc7b8e2e6e5c6cdc97989563e49208915a583 (patch) | |
tree | ca35789ca24deeeece188403230b0bf632cb61f3 /logcat/tests | |
parent | a1c60cf80d0d1002576a6cf8aa395b295c6a272e (diff) | |
download | system_core-95cfc7b8e2e6e5c6cdc97989563e49208915a583.zip system_core-95cfc7b8e2e6e5c6cdc97989563e49208915a583.tar.gz system_core-95cfc7b8e2e6e5c6cdc97989563e49208915a583.tar.bz2 |
logcat: test White Black list
Change-Id: Ia9509ad09dd86e4d9169ed7d0b33911f1ca9eec6
Diffstat (limited to 'logcat/tests')
-rw-r--r-- | logcat/tests/Android.mk | 6 | ||||
-rw-r--r-- | logcat/tests/logcat_test.cpp | 97 |
2 files changed, 102 insertions, 1 deletions
diff --git a/logcat/tests/Android.mk b/logcat/tests/Android.mk index bdaec14..733af31 100644 --- a/logcat/tests/Android.mk +++ b/logcat/tests/Android.mk @@ -28,7 +28,11 @@ test_c_flags := \ -g \ -Wall -Wextra \ -Werror \ - -fno-builtin \ + -fno-builtin + +ifneq ($(filter userdebug eng,$(TARGET_BUILD_VARIANT)),) +test_c_flags += -DUSERDEBUG_BUILD=1 +endif test_src_files := \ logcat_test.cpp \ diff --git a/logcat/tests/logcat_test.cpp b/logcat/tests/logcat_test.cpp index fc696bb..818a978 100644 --- a/logcat/tests/logcat_test.cpp +++ b/logcat/tests/logcat_test.cpp @@ -527,3 +527,100 @@ TEST(logcat, blocking_clear) { ASSERT_EQ(1, signals); } + +#ifdef USERDEBUG_BUILD +static bool get_white_black(char **list) { + FILE *fp; + + fp = popen("logcat -p 2>/dev/null", "r"); + if (fp == NULL) { + fprintf(stderr, "ERROR: logcat -p 2>/dev/null\n"); + return false; + } + + char buffer[5120]; + + while (fgets(buffer, sizeof(buffer), fp)) { + char *hold = *list; + char *buf = buffer; + while (isspace(*buf)) { + ++buf; + } + char *end = buf + strlen(buf); + while (isspace(*--end) && (end >= buf)) { + *end = '\0'; + } + if (end < buf) { + continue; + } + if (hold) { + asprintf(list, "%s %s", hold, buf); + free(hold); + } else { + asprintf(list, "%s", buf); + } + } + pclose(fp); + return *list != NULL; +} + +static bool set_white_black(const char *list) { + FILE *fp; + + char buffer[5120]; + + snprintf(buffer, sizeof(buffer), "logcat -P '%s' 2>&1", list); + fp = popen(buffer, "r"); + if (fp == NULL) { + fprintf(stderr, "ERROR: %s\n", buffer); + return false; + } + + while (fgets(buffer, sizeof(buffer), fp)) { + char *buf = buffer; + while (isspace(*buf)) { + ++buf; + } + char *end = buf + strlen(buf); + while (isspace(*--end) && (end >= buf)) { + *end = '\0'; + } + if (end < buf) { + continue; + } + fprintf(stderr, "%s\n", buf); + pclose(fp); + return false; + } + return pclose(fp) == 0; +} + +TEST(logcat, white_black_adjust) { + char *list = NULL; + char *adjust = NULL; + + ASSERT_EQ(true, get_white_black(&list)); + + static const char adjustment[] = "~! ~1000"; + ASSERT_EQ(true, set_white_black(adjustment)); + ASSERT_EQ(true, get_white_black(&adjust)); + if (strcmp(adjustment, adjust)) { + fprintf(stderr, "ERROR: '%s' != '%s'\n", adjustment, adjust); + } + ASSERT_STREQ(adjustment, adjust); + free(adjust); + adjust = NULL; + + ASSERT_EQ(true, set_white_black(list)); + ASSERT_EQ(true, get_white_black(&adjust)); + if (strcmp(list, adjust)) { + fprintf(stderr, "ERROR: '%s' != '%s'\n", list, adjust); + } + ASSERT_STREQ(list, adjust); + free(adjust); + adjust = NULL; + + free(list); + list = NULL; +} +#endif // USERDEBUG_BUILD |