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
This commit is contained in:
Mark Salyzyn 2016-02-25 09:02:09 -08:00
parent 67d7eafd56
commit 5cecedc6e8
1 changed files with 36 additions and 4 deletions

View File

@ -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;