diff options
author | Mark Salyzyn <salyzyn@google.com> | 2014-04-09 10:02:23 -0700 |
---|---|---|
committer | Mark Salyzyn <salyzyn@google.com> | 2014-04-25 11:03:58 -0700 |
commit | e821dace4161c5fdf19d8af036381b850d0fb988 (patch) | |
tree | b184ec68b00092e07db7e6edd23db99ac7a7ba2d /logd | |
parent | c8a576c637ae00577273b778498019dd609fcd15 (diff) | |
download | core-e821dace4161c5fdf19d8af036381b850d0fb988.tar.gz core-e821dace4161c5fdf19d8af036381b850d0fb988.tar.bz2 core-e821dace4161c5fdf19d8af036381b850d0fb988.zip |
logd: enable UID spam filter and test
Change-Id: Ie9c7a744e341e6e64afa14973d4d095717c97933
Diffstat (limited to 'logd')
-rw-r--r-- | logd/LogWhiteBlackList.cpp | 2 | ||||
-rw-r--r-- | logd/tests/logd_test.cpp | 53 |
2 files changed, 52 insertions, 3 deletions
diff --git a/logd/LogWhiteBlackList.cpp b/logd/LogWhiteBlackList.cpp index f739865a5..c6c7b232a 100644 --- a/logd/LogWhiteBlackList.cpp +++ b/logd/LogWhiteBlackList.cpp @@ -47,7 +47,7 @@ void Prune::format(char **strp) { } PruneList::PruneList() - : mWorstUidEnabled(false) { + : mWorstUidEnabled(true) { mNaughty.clear(); mNice.clear(); } diff --git a/logd/tests/logd_test.cpp b/logd/tests/logd_test.cpp index 23e614668..731aff660 100644 --- a/logd/tests/logd_test.cpp +++ b/logd/tests/logd_test.cpp @@ -23,6 +23,7 @@ #include <gtest/gtest.h> #include "cutils/sockets.h" +#include "log/log.h" #include "log/logger.h" #define __unused __attribute__((__unused__)) @@ -96,8 +97,9 @@ static char *find_benchmark_spam(char *cp) // // main: UID/PID Total size/num Now UID/PID[?] Total // 0 7500306/304207 71608/3183 0/4225? 7454388/303656 + // <wrap> 93432/1012 // -or- - // 0/gone 7454388/303656 + // 0/gone 7454388/303656 93432/1012 // // basically if we see a *large* number of 0/????? entries unsigned long value; @@ -126,6 +128,15 @@ static char *find_benchmark_spam(char *cp) value = value * 10ULL + *cp - '0'; ++cp; } + if (*cp != '/') { + value = 0; + continue; + } + while (isdigit(*++cp)); + while (*cp == ' ') ++cp; + if (!isdigit(*cp)) { + value = 0; + } } } while ((value < 900000ULL) && *cp); return cp; @@ -624,7 +635,45 @@ TEST(logd, benchmark) { #endif ASSERT_TRUE(NULL != buf); - EXPECT_TRUE(find_benchmark_spam(buf) != NULL); + + char *benchmark_statistics_found = find_benchmark_spam(buf); + ASSERT_TRUE(benchmark_statistics_found != NULL); + + // Check how effective the SPAM filter is, parse out Now size. + // Total Now + // 0/4225? 7454388/303656 31488/755 + // ^-- benchmark_statistics_found + + unsigned long nowSize = atol(benchmark_statistics_found); delete [] buf; + + ASSERT_NE(0UL, nowSize); + + int sock = socket_local_client("logd", + ANDROID_SOCKET_NAMESPACE_RESERVED, + SOCK_STREAM); + static const unsigned long expected_absolute_minimum_log_size = 65536UL; + unsigned long totalSize = expected_absolute_minimum_log_size; + if (sock >= 0) { + static const char getSize[] = { + 'g', 'e', 't', 'L', 'o', 'g', 'S', 'i', 'z', 'e', ' ', + LOG_ID_MAIN + '0', '\0' + }; + if (write(sock, getSize, sizeof(getSize)) > 0) { + char buffer[80]; + memset(buffer, 0, sizeof(buffer)); + read(sock, buffer, sizeof(buffer)); + totalSize = atol(buffer); + if (totalSize < expected_absolute_minimum_log_size) { + totalSize = expected_absolute_minimum_log_size; + } + } + close(sock); + } + // logd allows excursions to 110% of total size + totalSize = (totalSize * 11 ) / 10; + + // 50% threshold for SPAM filter (<20% typical, lots of engineering margin) + ASSERT_GT(totalSize, nowSize * 2); } |