From 5cecedc6e8d5559213220b4dae993f277801433a Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Thu, 25 Feb 2016 09:02:09 -0800 Subject: [PATCH] liblog: test: __android_log_error_write accuracy Add a test to confirm exact expected content using the testframe setup for the events log handler. Remove dependency on 512 truncation in liblog-> android_errorWriteWithInfoLog__android_logger_list_read__data_too_large to something more liberal. Bug: 27356456 Change-Id: I8a53ad3a16cf16b14856efe5b95417e857c7e09b --- liblog/tests/liblog_test.cpp | 40 ++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/liblog/tests/liblog_test.cpp b/liblog/tests/liblog_test.cpp index 13178539d..50ecd2dff 100644 --- a/liblog/tests/liblog_test.cpp +++ b/liblog/tests/liblog_test.cpp @@ -1429,7 +1429,7 @@ TEST(liblog, android_errorWriteWithInfoLog__android_logger_list_read__data_too_l const int TAG = 123456782; const char SUBTAG[] = "test-subtag"; const int UID = -1; - const int DATA_LEN = SIZEOF_MAX_PAYLOAD_BUF; + const int DATA_LEN = sizeof(max_payload_buf); struct logger_list *logger_list; pid_t pid = getpid(); @@ -1500,9 +1500,9 @@ TEST(liblog, android_errorWriteWithInfoLog__android_logger_list_read__data_too_l } eventData += dataLen; - // 4 bytes for the tag, and 512 bytes for the log since the - // max_payload_buf should be truncated. - ASSERT_EQ(4 + 512, eventData - original); + // 4 bytes for the tag, and max_payload_buf should be truncated. + ASSERT_LE(4 + 512, eventData - original); // worst expectations + ASSERT_GT(4 + DATA_LEN, eventData - original); // must be truncated ++count; } @@ -2123,6 +2123,30 @@ static const char *event_test_7_level_suffix(uint32_t tag, size_t &expected_len) return "[1,[2,[3,[4,[5,[6]]]]]]"; } +static const char *event_test_android_log_error_write(uint32_t tag, size_t &expected_len) { + EXPECT_LE(0, __android_log_error_write(tag, "Hello World", 42, "dlroW olleH", 11)); + + expected_len = sizeof(uint32_t) + + sizeof(uint8_t) + sizeof(uint8_t) + + sizeof(uint8_t) + sizeof(uint32_t) + sizeof("Hello World") - 1 + + sizeof(uint8_t) + sizeof(uint32_t) + + sizeof(uint8_t) + sizeof(uint32_t) + sizeof("dlroW olleH") - 1; + + return "[Hello World,42,dlroW olleH]"; +} + +static const char *event_test_android_log_error_write_null(uint32_t tag, size_t &expected_len) { + EXPECT_LE(0, __android_log_error_write(tag, "Hello World", 42, NULL, 0)); + + expected_len = sizeof(uint32_t) + + sizeof(uint8_t) + sizeof(uint8_t) + + sizeof(uint8_t) + sizeof(uint32_t) + sizeof("Hello World") - 1 + + sizeof(uint8_t) + sizeof(uint32_t) + + sizeof(uint8_t) + sizeof(uint32_t) + sizeof("") - 1; + + return "[Hello World,42,]"; +} + // make sure all user buffers are flushed static void print_barrier() { std::cout.flush(); @@ -2241,6 +2265,14 @@ TEST(liblog, create_android_logger_7_level_suffix) { create_android_logger(event_test_7_level_suffix); } +TEST(liblog, create_android_logger_android_log_error_write) { + create_android_logger(event_test_android_log_error_write); +} + +TEST(liblog, create_android_logger_android_log_error_write_null) { + create_android_logger(event_test_android_log_error_write_null); +} + TEST(liblog, create_android_logger_overflow) { android_log_context ctx;