diff options
author | Christopher Ferris <cferris@google.com> | 2019-04-01 19:31:26 -0700 |
---|---|---|
committer | Christopher Ferris <cferris@google.com> | 2019-04-02 10:55:21 -0700 |
commit | c328e4465d12d760f5fbcb2daddf5fa4138f50b1 (patch) | |
tree | fd91c386332bbe1198cb0bedc11505b76d146057 /libc/malloc_debug/tests/malloc_debug_unit_tests.cpp | |
parent | 4699cf61746d37fc11c8eb8bdfc7eb296a476e4b (diff) |
Disable info messages by default for malloc debug.
Add a new option verbose for malloc debug that is not enabled by default.
This disables all of the info log messages. It turns out these log
messages can add a measurable amount of time and can change the boot up.
Bug: 129239269
Test: Adjusted unit tests pass.
Test: Verified no messages unless verbose option used.
Change-Id: I805cb7c8ecb44de88119574e59d784877cacc383
Diffstat (limited to 'libc/malloc_debug/tests/malloc_debug_unit_tests.cpp')
-rw-r--r-- | libc/malloc_debug/tests/malloc_debug_unit_tests.cpp | 136 |
1 files changed, 67 insertions, 69 deletions
diff --git a/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp b/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp index 66955db59..f611f3da7 100644 --- a/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp +++ b/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp @@ -154,7 +154,7 @@ std::string ShowDiffs(uint8_t* a, uint8_t* b, size_t size) { return diff; } -void VerifyAllocCalls(bool backtrace_enabled) { +void VerifyAllocCalls(bool all_options) { size_t alloc_size = 1024; // Verify debug_malloc. @@ -209,21 +209,28 @@ void VerifyAllocCalls(bool backtrace_enabled) { ASSERT_STREQ("", getFakeLogBuf().c_str()); std::string expected_log; - if (backtrace_enabled) { + if (all_options) { + expected_log += android::base::StringPrintf( + "4 malloc_debug malloc_testing: Run: 'kill -%d %d' to enable backtracing.\n", + SIGRTMAX - 19, getpid()); expected_log += android::base::StringPrintf( "4 malloc_debug malloc_testing: Run: 'kill -%d %d' to dump the backtrace.\n", SIGRTMAX - 17, getpid()); + expected_log += android::base::StringPrintf( + "4 malloc_debug malloc_testing: Run: 'kill -%d %d' to dump the allocation records.\n", + SIGRTMAX - 18, getpid()); } + expected_log += "4 malloc_debug malloc_testing: malloc debug enabled\n"; ASSERT_STREQ(expected_log.c_str(), getFakeLogPrint().c_str()); } TEST_F(MallocDebugTest, fill_generic) { - Init("fill"); + Init("verbose fill"); VerifyAllocCalls(false); } TEST_F(MallocDebugTest, fill_on_alloc_generic) { - Init("fill_on_alloc"); + Init("verbose fill_on_alloc"); VerifyAllocCalls(false); } @@ -241,6 +248,46 @@ TEST_F(MallocDebugTest, fill_on_alloc_partial) { ASSERT_STREQ("", getFakeLogPrint().c_str()); } +TEST_F(MallocDebugTest, verbose_only) { + Init("verbose"); + + ASSERT_STREQ("", getFakeLogBuf().c_str()); + ASSERT_STREQ("4 malloc_debug malloc_testing: malloc debug enabled\n", getFakeLogPrint().c_str()); +} + +TEST_F(MallocDebugTest, verbose_backtrace_enable_on_signal) { + Init("verbose backtrace_enable_on_signal"); + + std::string expected_log = android::base::StringPrintf( + "4 malloc_debug malloc_testing: Run: 'kill -%d %d' to enable backtracing.\n", + SIGRTMAX - 19, getpid()); + expected_log += android::base::StringPrintf( + "4 malloc_debug malloc_testing: Run: 'kill -%d %d' to dump the backtrace.\n", + SIGRTMAX - 17, getpid()); + expected_log += "4 malloc_debug malloc_testing: malloc debug enabled\n"; + ASSERT_STREQ(expected_log.c_str(), getFakeLogPrint().c_str()); +} + +TEST_F(MallocDebugTest, verbose_backtrace) { + Init("verbose backtrace"); + + std::string expected_log = android::base::StringPrintf( + "4 malloc_debug malloc_testing: Run: 'kill -%d %d' to dump the backtrace.\n", + SIGRTMAX - 17, getpid()); + expected_log += "4 malloc_debug malloc_testing: malloc debug enabled\n"; + ASSERT_STREQ(expected_log.c_str(), getFakeLogPrint().c_str()); +} + +TEST_F(MallocDebugTest, verbose_record_allocs) { + Init("verbose record_allocs"); + + std::string expected_log = android::base::StringPrintf( + "4 malloc_debug malloc_testing: Run: 'kill -%d %d' to dump the allocation records.\n", + SIGRTMAX - 18, getpid()); + expected_log += "4 malloc_debug malloc_testing: malloc debug enabled\n"; + ASSERT_STREQ(expected_log.c_str(), getFakeLogPrint().c_str()); +} + TEST_F(MallocDebugTest, fill_on_free) { Init("fill_on_free free_track free_track_backtrace_num_frames=0"); @@ -302,7 +349,9 @@ TEST_F(MallocDebugTest, free_track_partial) { } TEST_F(MallocDebugTest, all_options) { - Init("guard backtrace fill expand_alloc free_track leak_track"); + Init( + "guard backtrace backtrace_enable_on_signal fill expand_alloc free_track leak_track " + "record_allocs verify_pointers abort_on_error verbose"); VerifyAllocCalls(true); } @@ -667,9 +716,6 @@ TEST_F(MallocDebugTest, leak_track_no_frees_with_backtrace) { ASSERT_STREQ("", getFakeLogBuf().c_str()); std::string expected_log = android::base::StringPrintf( - "4 malloc_debug malloc_testing: Run: 'kill -%d %d' to dump the backtrace.\n", - SIGRTMAX - 17, getpid()); - expected_log += android::base::StringPrintf( "6 malloc_debug +++ malloc_testing leaked block of size 1024 at %p (leak 1 of 3)\n", pointer3); expected_log += "6 malloc_debug Backtrace at time of allocation:\n"; @@ -1096,10 +1142,7 @@ TEST_F(MallocDebugTest, get_malloc_leak_info_empty) { ASSERT_EQ(0U, backtrace_size); ASSERT_STREQ("", getFakeLogBuf().c_str()); - std::string expected_log = android::base::StringPrintf( - "4 malloc_debug malloc_testing: Run: 'kill -%d %d' to dump the backtrace.\n", - SIGRTMAX - 17, getpid()); - ASSERT_STREQ(expected_log.c_str(), getFakeLogPrint().c_str()); + ASSERT_STREQ("", getFakeLogPrint().c_str()); } TEST_F(MallocDebugTest, get_malloc_leak_info_single) { @@ -1143,10 +1186,7 @@ TEST_F(MallocDebugTest, get_malloc_leak_info_single) { debug_free(pointer); ASSERT_STREQ("", getFakeLogBuf().c_str()); - std::string expected_log = android::base::StringPrintf( - "4 malloc_debug malloc_testing: Run: 'kill -%d %d' to dump the backtrace.\n", - SIGRTMAX - 17, getpid()); - ASSERT_STREQ(expected_log.c_str(), getFakeLogPrint().c_str()); + ASSERT_STREQ("", getFakeLogPrint().c_str()); } TEST_F(MallocDebugTest, get_malloc_leak_info_multi) { @@ -1226,10 +1266,7 @@ TEST_F(MallocDebugTest, get_malloc_leak_info_multi) { debug_free(pointers[2]); ASSERT_STREQ("", getFakeLogBuf().c_str()); - std::string expected_log = android::base::StringPrintf( - "4 malloc_debug malloc_testing: Run: 'kill -%d %d' to dump the backtrace.\n", - SIGRTMAX - 17, getpid()); - ASSERT_STREQ(expected_log.c_str(), getFakeLogPrint().c_str()); + ASSERT_STREQ("", getFakeLogPrint().c_str()); } TEST_F(MallocDebugTest, get_malloc_backtrace_with_header) { @@ -1261,10 +1298,7 @@ TEST_F(MallocDebugTest, get_malloc_backtrace_with_header) { initialized = false; ASSERT_STREQ("", getFakeLogBuf().c_str()); - std::string expected_log = android::base::StringPrintf( - "4 malloc_debug malloc_testing: Run: 'kill -%d %d' to dump the backtrace.\n", - SIGRTMAX - 17, getpid()); - ASSERT_STREQ(expected_log.c_str(), getFakeLogPrint().c_str()); + ASSERT_STREQ("", getFakeLogPrint().c_str()); } static std::string SanitizeHeapData(const std::string& data) { @@ -1375,9 +1409,6 @@ END ASSERT_STREQ("", getFakeLogBuf().c_str()); std::string expected_log = android::base::StringPrintf( - "4 malloc_debug malloc_testing: Run: 'kill -%d %d' to dump the backtrace.\n", - SIGRTMAX - 17, getpid()); - expected_log += android::base::StringPrintf( "6 malloc_debug Dumping to file: /data/local/tmp/backtrace_heap.%d.txt\n\n", getpid()); ASSERT_STREQ(expected_log.c_str(), getFakeLogPrint().c_str()); } @@ -1649,13 +1680,7 @@ TEST_F(MallocDebugTest, backtrace_enable_on_signal) { debug_free_malloc_leak_info(info); ASSERT_STREQ("", getFakeLogBuf().c_str()); - std::string expected_log = android::base::StringPrintf( - "4 malloc_debug malloc_testing: Run: 'kill -%d %d' to enable backtracing.\n", - SIGRTMAX - 19, getpid()); - expected_log += android::base::StringPrintf( - "4 malloc_debug malloc_testing: Run: 'kill -%d %d' to dump the backtrace.\n", - SIGRTMAX - 17, getpid()); - ASSERT_STREQ(expected_log.c_str(), getFakeLogPrint().c_str()); + ASSERT_STREQ("", getFakeLogPrint().c_str()); } TEST_F(MallocDebugTest, backtrace_same_stack) { @@ -1712,10 +1737,7 @@ TEST_F(MallocDebugTest, backtrace_same_stack) { debug_free(pointers[3]); ASSERT_STREQ("", getFakeLogBuf().c_str()); - std::string expected_log = android::base::StringPrintf( - "4 malloc_debug malloc_testing: Run: 'kill -%d %d' to dump the backtrace.\n", - SIGRTMAX - 17, getpid()); - ASSERT_STREQ(expected_log.c_str(), getFakeLogPrint().c_str()); + ASSERT_STREQ("", getFakeLogPrint().c_str()); } TEST_F(MallocDebugTest, backtrace_same_stack_zygote) { @@ -1774,10 +1796,7 @@ TEST_F(MallocDebugTest, backtrace_same_stack_zygote) { debug_free(pointers[3]); ASSERT_STREQ("", getFakeLogBuf().c_str()); - std::string expected_log = android::base::StringPrintf( - "4 malloc_debug malloc_testing: Run: 'kill -%d %d' to dump the backtrace.\n", - SIGRTMAX - 17, getpid()); - ASSERT_STREQ(expected_log.c_str(), getFakeLogPrint().c_str()); + ASSERT_STREQ("", getFakeLogPrint().c_str()); } TEST_F(MallocDebugTest, backtrace_same_stack_mix_zygote) { @@ -1844,10 +1863,7 @@ TEST_F(MallocDebugTest, backtrace_same_stack_mix_zygote) { debug_free(pointers[3]); ASSERT_STREQ("", getFakeLogBuf().c_str()); - std::string expected_log = android::base::StringPrintf( - "4 malloc_debug malloc_testing: Run: 'kill -%d %d' to dump the backtrace.\n", - SIGRTMAX - 17, getpid()); - ASSERT_STREQ(expected_log.c_str(), getFakeLogPrint().c_str()); + ASSERT_STREQ("", getFakeLogPrint().c_str()); } TEST_F(MallocDebugTest, backtrace_frame_data_nullptr_same_size) { @@ -1891,10 +1907,7 @@ TEST_F(MallocDebugTest, backtrace_frame_data_nullptr_same_size) { debug_free(pointers[3]); ASSERT_STREQ("", getFakeLogBuf().c_str()); - std::string expected_log = android::base::StringPrintf( - "4 malloc_debug malloc_testing: Run: 'kill -%d %d' to dump the backtrace.\n", - SIGRTMAX - 17, getpid()); - ASSERT_STREQ(expected_log.c_str(), getFakeLogPrint().c_str()); + ASSERT_STREQ("", getFakeLogPrint().c_str()); } TEST_F(MallocDebugTest, overflow) { @@ -2022,10 +2035,7 @@ TEST_F(MallocDebugTest, zygote_set) { debug_free(pointer); ASSERT_STREQ("", getFakeLogBuf().c_str()); - std::string expected_log = android::base::StringPrintf( - "4 malloc_debug malloc_testing: Run: 'kill -%d %d' to dump the backtrace.\n", - SIGRTMAX - 17, getpid()); - ASSERT_STREQ(expected_log.c_str(), getFakeLogPrint().c_str()); + ASSERT_STREQ("", getFakeLogPrint().c_str()); } TEST_F(MallocDebugTest, max_size) { @@ -2193,10 +2203,7 @@ void VerifyRecordAllocs() { ASSERT_STREQ(expected.c_str(), actual.c_str()); ASSERT_STREQ("", getFakeLogBuf().c_str()); - std::string expected_log = android::base::StringPrintf( - "4 malloc_debug malloc_testing: Run: 'kill -%d %d' to dump the allocation records.\n", - SIGRTMAX - 18, getpid()); - ASSERT_STREQ(expected_log.c_str(), getFakeLogPrint().c_str()); + ASSERT_STREQ("", getFakeLogPrint().c_str()); debug_free(pointer); } @@ -2251,10 +2258,7 @@ TEST_F(MallocDebugTest, record_allocs_max) { ASSERT_STREQ(expected.c_str(), actual.c_str()); ASSERT_STREQ("", getFakeLogBuf().c_str()); - std::string expected_log = android::base::StringPrintf( - "4 malloc_debug malloc_testing: Run: 'kill -%d %d' to dump the allocation records.\n", - SIGRTMAX - 18, getpid()); - ASSERT_STREQ(expected_log.c_str(), getFakeLogPrint().c_str()); + ASSERT_STREQ("", getFakeLogPrint().c_str()); debug_free(pointer); } @@ -2293,10 +2297,7 @@ TEST_F(MallocDebugTest, record_allocs_thread_done) { ASSERT_STREQ(expected.c_str(), actual.c_str()); ASSERT_STREQ("", getFakeLogBuf().c_str()); - std::string expected_log = android::base::StringPrintf( - "4 malloc_debug malloc_testing: Run: 'kill -%d %d' to dump the allocation records.\n", - SIGRTMAX - 18, getpid()); - ASSERT_STREQ(expected_log.c_str(), getFakeLogPrint().c_str()); + ASSERT_STREQ("", getFakeLogPrint().c_str()); debug_free(pointer); } @@ -2348,9 +2349,6 @@ TEST_F(MallocDebugTest, record_allocs_file_name_fail) { ASSERT_STREQ("", getFakeLogBuf().c_str()); std::string expected_log = android::base::StringPrintf( - "4 malloc_debug malloc_testing: Run: 'kill -%d %d' to dump the allocation records.\n", - SIGRTMAX - 18, getpid()); - expected_log += android::base::StringPrintf( "6 malloc_debug Cannot create record alloc file %s: Too many symbolic links encountered\n", RECORD_ALLOCS_FILE); ASSERT_STREQ(expected_log.c_str(), getFakeLogPrint().c_str()); |