diff options
author | Dmitry Vyukov <dvyukov@google.com> | 2013-01-24 09:08:03 +0000 |
---|---|---|
committer | Dmitry Vyukov <dvyukov@google.com> | 2013-01-24 09:08:03 +0000 |
commit | bdd844cb41718c27ef727a99a236191bc29a3df8 (patch) | |
tree | 5ade9022b178bd4c6b130c7a2cc9cb6085d7b56b /lib/tsan/tests | |
parent | f0c846b8ef61a5f4bc664c463d643bb8dedc3768 (diff) | |
download | compiler-rt-bdd844cb41718c27ef727a99a236191bc29a3df8.tar.gz compiler-rt-bdd844cb41718c27ef727a99a236191bc29a3df8.tar.bz2 compiler-rt-bdd844cb41718c27ef727a99a236191bc29a3df8.tar.xz |
tsan: implement malloc stats querying
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@173332 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/tsan/tests')
-rw-r--r-- | lib/tsan/tests/unit/tsan_mman_test.cc | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/tsan/tests/unit/tsan_mman_test.cc b/lib/tsan/tests/unit/tsan_mman_test.cc index 1a9a88f6..988918ff 100644 --- a/lib/tsan/tests/unit/tsan_mman_test.cc +++ b/lib/tsan/tests/unit/tsan_mman_test.cc @@ -14,6 +14,16 @@ #include "tsan_rtl.h" #include "gtest/gtest.h" +extern "C" { +uptr __tsan_get_current_allocated_bytes(); +uptr __tsan_get_heap_size(); +uptr __tsan_get_free_bytes(); +uptr __tsan_get_unmapped_bytes(); +uptr __tsan_get_estimated_allocated_size(uptr size); +bool __tsan_get_ownership(void *p); +uptr __tsan_get_allocated_size(void *p); +} + namespace __tsan { TEST(Mman, Internal) { @@ -106,4 +116,33 @@ TEST(Mman, UserRealloc) { } } +TEST(Mman, Stats) { + ScopedInRtl in_rtl; + ThreadState *thr = cur_thread(); + + uptr alloc0 = __tsan_get_current_allocated_bytes(); + uptr heap0 = __tsan_get_heap_size(); + uptr free0 = __tsan_get_free_bytes(); + uptr unmapped0 = __tsan_get_unmapped_bytes(); + + EXPECT_EQ(__tsan_get_estimated_allocated_size(10), (uptr)10); + EXPECT_EQ(__tsan_get_estimated_allocated_size(20), (uptr)20); + EXPECT_EQ(__tsan_get_estimated_allocated_size(100), (uptr)100); + + char *p = (char*)user_alloc(thr, 0, 10); + EXPECT_EQ(__tsan_get_ownership(p), true); + EXPECT_EQ(__tsan_get_allocated_size(p), (uptr)10); + + EXPECT_EQ(__tsan_get_current_allocated_bytes(), alloc0 + 16); + EXPECT_GE(__tsan_get_heap_size(), heap0); + EXPECT_EQ(__tsan_get_free_bytes(), free0); + EXPECT_EQ(__tsan_get_unmapped_bytes(), unmapped0); + + user_free(thr, 0, p); + + EXPECT_EQ(__tsan_get_current_allocated_bytes(), alloc0); + EXPECT_GE(__tsan_get_heap_size(), heap0); + EXPECT_EQ(__tsan_get_free_bytes(), free0); + EXPECT_EQ(__tsan_get_unmapped_bytes(), unmapped0); +} } // namespace __tsan |