From 01c284ecf81d34d027161e822ecde23f81fd9f48 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Thu, 26 Oct 2017 10:25:12 +0200 Subject: [PATCH 1/1] Try to improve coverage for mrealloc. --- teshsuite/xbt/mmalloc/mmalloc_32.tesh | 1 + teshsuite/xbt/mmalloc/mmalloc_64.tesh | 1 + teshsuite/xbt/mmalloc/mmalloc_test.cpp | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/teshsuite/xbt/mmalloc/mmalloc_32.tesh b/teshsuite/xbt/mmalloc/mmalloc_32.tesh index 449049d43b..e40a03f31b 100644 --- a/teshsuite/xbt/mmalloc/mmalloc_32.tesh +++ b/teshsuite/xbt/mmalloc/mmalloc_32.tesh @@ -106,4 +106,5 @@ $ ${bindir:=.}/mmalloc_test --log=root.fmt:%m%n > Re-allocate every second block > free all blocks (each one twice, to check that double free are correctly catched) > free again all blocks (to really check that double free are correctly catched) +> Let's try different codepaths for mrealloc > Damnit, I cannot break mmalloc this time. That's SO disappointing. diff --git a/teshsuite/xbt/mmalloc/mmalloc_64.tesh b/teshsuite/xbt/mmalloc/mmalloc_64.tesh index 343e2a4a98..90e01ff2f1 100644 --- a/teshsuite/xbt/mmalloc/mmalloc_64.tesh +++ b/teshsuite/xbt/mmalloc/mmalloc_64.tesh @@ -106,4 +106,5 @@ $ ${bindir:=.}/mmalloc_test --log=root.fmt:%m%n > Re-allocate every second block > free all blocks (each one twice, to check that double free are correctly catched) > free again all blocks (to really check that double free are correctly catched) +> Let's try different codepaths for mrealloc > Damnit, I cannot break mmalloc this time. That's SO disappointing. diff --git a/teshsuite/xbt/mmalloc/mmalloc_test.cpp b/teshsuite/xbt/mmalloc/mmalloc_test.cpp index 759f09e473..a20ee38dbf 100644 --- a/teshsuite/xbt/mmalloc/mmalloc_test.cpp +++ b/teshsuite/xbt/mmalloc/mmalloc_test.cpp @@ -22,6 +22,15 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(test,"this test"); #define TESTSIZE 100 #define size_of_block(i) (((i % 50)+1)* 100) +static void check_block(const void* s, int c, int n) +{ + const unsigned char* p = static_cast(s); + unsigned char b = static_cast(c); + for (int i = 0; i < n; i++) + if (p[i] != b) + xbt_die("value mismatch: %p[%d] = %#hhx, expected %#hhx", p, i, p[i], b); +} + int main(int argc, char**argv) { xbt_mheap_t heapA = nullptr; @@ -87,6 +96,21 @@ int main(int argc, char**argv) xbt_die("FAIL: A double-free went undetected (for size:%d)",size_of_block(i)); } + XBT_INFO("Let's try different codepaths for mrealloc"); + for (i = 0; i < TESTSIZE; i++) { + const std::vector> requests = { + {size_of_block(i) / 2, 0x77}, {size_of_block(i) * 2, 0xaa}, {1, 0xc0}, {0, 0}}; + pointers[i] = nullptr; + for (unsigned k = 0; k < requests.size(); ++k) { + size = requests[k].first; + pointers[i] = mrealloc(heapA, pointers[i], size); + if (k > 0) + check_block(pointers[i], requests[k - 1].second, std::min(size, requests[k - 1].first)); + if (size > 0) + memset(pointers[i], requests[k].second, size); + } + } + XBT_INFO("Damnit, I cannot break mmalloc this time. That's SO disappointing."); return 0; } -- 2.20.1