From bc72197b33bb97cdbb4227d66b2b38d889179c08 Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Wed, 22 Jul 2020 15:30:02 -0700 Subject: logd: use the compressed (serialized) log buffer by default The serialized log buffer along with compression results in: * ~3.5x more logs than chatty * Less CPU usage * Less memory usage * Equivalent log range Also, delete tests that assume that the device logd implementation is chatty. There are actual unit tests for this same behavior that don't rely on the device logd. Test: serialized log buffer is used Change-Id: Ie12898617429a75b6caff92725aa7145650f8fc6 --- logd/logd_test.cpp | 124 ----------------------------------------------------- 1 file changed, 124 deletions(-) (limited to 'logd/logd_test.cpp') diff --git a/logd/logd_test.cpp b/logd/logd_test.cpp index ed34ea413..307610ec5 100644 --- a/logd/logd_test.cpp +++ b/logd/logd_test.cpp @@ -832,127 +832,3 @@ TEST(logd, getEventTag_newentry) { GTEST_LOG_(INFO) << "This test does nothing.\n"; #endif } - -#ifdef __ANDROID__ -static inline uint32_t get4LE(const uint8_t* src) { - return src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24); -} - -static inline uint32_t get4LE(const char* src) { - return get4LE(reinterpret_cast(src)); -} -#endif - -void __android_log_btwrite_multiple__helper(int count) { -#ifdef __ANDROID__ - log_time ts(CLOCK_MONOTONIC); - usleep(100); - log_time ts1(CLOCK_MONOTONIC); - - // We fork to create a unique pid for the submitted log messages - // so that we do not collide with the other _multiple_ tests. - - pid_t pid = fork(); - - if (pid == 0) { - // child - for (int i = count; i; --i) { - ASSERT_LT( - 0, __android_log_btwrite(0, EVENT_TYPE_LONG, &ts, sizeof(ts))); - usleep(100); - } - ASSERT_LT(0, - __android_log_btwrite(0, EVENT_TYPE_LONG, &ts1, sizeof(ts1))); - usleep(1000000); - - _exit(0); - } - - siginfo_t info = {}; - ASSERT_EQ(0, TEMP_FAILURE_RETRY(waitid(P_PID, pid, &info, WEXITED))); - ASSERT_EQ(0, info.si_status); - - struct logger_list* logger_list; - ASSERT_TRUE(nullptr != (logger_list = android_logger_list_open(LOG_ID_EVENTS, - ANDROID_LOG_NONBLOCK, 0, pid))); - - int expected_count = (count < 2) ? count : 2; - int expected_chatty_count = (count <= 2) ? 0 : 1; - int expected_identical_count = (count < 2) ? 0 : (count - 2); - static const int expected_expire_count = 0; - - count = 0; - int second_count = 0; - int chatty_count = 0; - int identical_count = 0; - int expire_count = 0; - - for (;;) { - log_msg log_msg; - if (android_logger_list_read(logger_list, &log_msg) <= 0) break; - - if ((log_msg.entry.pid != pid) || (log_msg.entry.len < (4 + 1 + 8)) || - (log_msg.id() != LOG_ID_EVENTS)) - continue; - - char* eventData = log_msg.msg(); - if (!eventData) continue; - - uint32_t tag = get4LE(eventData); - - if ((eventData[4] == EVENT_TYPE_LONG) && - (log_msg.entry.len == (4 + 1 + 8))) { - if (tag != 0) continue; - - log_time* tx = reinterpret_cast(eventData + 4 + 1); - if (ts == *tx) { - ++count; - } else if (ts1 == *tx) { - ++second_count; - } - } else if (eventData[4] == EVENT_TYPE_STRING) { - if (tag != CHATTY_LOG_TAG) continue; - ++chatty_count; - // int len = get4LE(eventData + 4 + 1); - log_msg.buf[LOGGER_ENTRY_MAX_LEN] = '\0'; - const char* cp; - if ((cp = strstr(eventData + 4 + 1 + 4, " identical "))) { - unsigned val = 0; - sscanf(cp, " identical %u lines", &val); - identical_count += val; - } else if ((cp = strstr(eventData + 4 + 1 + 4, " expire "))) { - unsigned val = 0; - sscanf(cp, " expire %u lines", &val); - expire_count += val; - } - } - } - - android_logger_list_close(logger_list); - - EXPECT_EQ(expected_count, count); - EXPECT_EQ(1, second_count); - EXPECT_EQ(expected_chatty_count, chatty_count); - EXPECT_EQ(expected_identical_count, identical_count); - EXPECT_EQ(expected_expire_count, expire_count); -#else - count = 0; - GTEST_LOG_(INFO) << "This test does nothing.\n"; -#endif -} - -TEST(logd, multiple_test_1) { - __android_log_btwrite_multiple__helper(1); -} - -TEST(logd, multiple_test_2) { - __android_log_btwrite_multiple__helper(2); -} - -TEST(logd, multiple_test_3) { - __android_log_btwrite_multiple__helper(3); -} - -TEST(logd, multiple_test_10) { - __android_log_btwrite_multiple__helper(10); -} -- cgit v1.2.3 From bd5a283ccd8181d28bc4b4a026abf8c9b9d9bbcb Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Fri, 31 Jul 2020 11:48:33 -0700 Subject: logd: disable flaky tests Bug: 162600780 Test: build Change-Id: I1da7531ab1c64d77ba228096913fc23d36ef5793 --- logd/logd_test.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'logd/logd_test.cpp') diff --git a/logd/logd_test.cpp b/logd/logd_test.cpp index 307610ec5..5a0585a73 100644 --- a/logd/logd_test.cpp +++ b/logd/logd_test.cpp @@ -162,6 +162,7 @@ static char* find_benchmark_spam(char* cp) { } #endif +#ifdef LOGD_ENABLE_FLAKY_TESTS TEST(logd, statistics) { #ifdef __ANDROID__ size_t len; @@ -237,6 +238,7 @@ TEST(logd, statistics) { GTEST_LOG_(INFO) << "This test does nothing.\n"; #endif } +#endif #ifdef __ANDROID__ static void caught_signal(int /* signum */) { @@ -720,6 +722,7 @@ TEST(logd, timeout) { } #endif +#ifdef LOGD_ENABLE_FLAKY_TESTS // b/27242723 confirmed fixed TEST(logd, SNDTIMEO) { #ifdef __ANDROID__ @@ -777,6 +780,7 @@ TEST(logd, SNDTIMEO) { GTEST_LOG_(INFO) << "This test does nothing.\n"; #endif } +#endif TEST(logd, getEventTag_list) { #ifdef __ANDROID__ -- cgit v1.2.3 From 9b77d73744852adddbb0871dd2a5691738886f10 Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Fri, 7 Aug 2020 10:27:37 -0700 Subject: logd: add a test that logd ignores SIGPIPE Now that libsysutils sockets do not ignore SIGPIPE, logd itself must ignore it and we therefore add a test that it is ignored properly. Test: this test passes Test: this test fails if logd doesn't ignore SIGPIPE Change-Id: I65474967f40291a7abd11cfd279c8cde2d2bca14 --- logd/logd_test.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'logd/logd_test.cpp') diff --git a/logd/logd_test.cpp b/logd/logd_test.cpp index 5a0585a73..202ab062b 100644 --- a/logd/logd_test.cpp +++ b/logd/logd_test.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -41,6 +42,8 @@ #include "LogReader.h" // pickup LOGD_SNDTIMEO +using android::base::unique_fd; + #ifdef __ANDROID__ static void send_to_control(char* buf, size_t len) { int sock = socket_local_client("logd", ANDROID_SOCKET_NAMESPACE_RESERVED, @@ -836,3 +839,34 @@ TEST(logd, getEventTag_newentry) { GTEST_LOG_(INFO) << "This test does nothing.\n"; #endif } + +TEST(logd, no_epipe) { +#ifdef __ANDROID__ + // Actually generating SIGPIPE in logd is racy, since we need to close the socket quicker than + // logd finishes writing the data to it, so we try 10 times, which should be enough to trigger + // SIGPIPE if logd isn't ignoring SIGPIPE + for (int i = 0; i < 10; ++i) { + unique_fd sock1( + socket_local_client("logd", ANDROID_SOCKET_NAMESPACE_RESERVED, SOCK_STREAM)); + ASSERT_GT(sock1, 0); + unique_fd sock2( + socket_local_client("logd", ANDROID_SOCKET_NAMESPACE_RESERVED, SOCK_STREAM)); + ASSERT_GT(sock2, 0); + + std::string message = "getStatistics 0 1 2 3 4 5 6 7"; + + ASSERT_GT(write(sock1, message.c_str(), message.length()), 0); + sock1.reset(); + ASSERT_GT(write(sock2, message.c_str(), message.length()), 0); + + struct pollfd p = {.fd = sock2, .events = POLLIN, .revents = 0}; + + int ret = poll(&p, 1, 20); + EXPECT_EQ(ret, 1); + EXPECT_TRUE(p.revents & POLLIN); + EXPECT_FALSE(p.revents & POLL_ERR); + } +#else + GTEST_LOG_(INFO) << "This test does nothing.\n"; +#endif +} -- cgit v1.2.3 From 0fe3b67024bfb4dfe4062c722532f20e35242238 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 20 Aug 2020 15:40:57 -0700 Subject: Fix logd's implicit dependency on libsysutils. We're trying to remove the implicit dependency on libsysutils that *all* code has via the symlink in system/core/include/, but netd and logd have code that #includes the headers without declaring the dependency (which works out in the end because their executables declare the dependency). Bug: http://b/165825252 Test: treehugger Change-Id: I8c582e427d9dbe7d9f8172c445f38ae2737a9049 --- logd/logd_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'logd/logd_test.cpp') diff --git a/logd/logd_test.cpp b/logd/logd_test.cpp index 202ab062b..828f58056 100644 --- a/logd/logd_test.cpp +++ b/logd/logd_test.cpp @@ -40,7 +40,7 @@ #include #endif -#include "LogReader.h" // pickup LOGD_SNDTIMEO +#include "LogUtils.h" // For LOGD_SNDTIMEO. using android::base::unique_fd; -- cgit v1.2.3