[RFC] malloc: Fix test for malloc_usable_size

Message ID 20191216191742.1035-1-msc@linux.ibm.com
State New
Headers show
Series
  • [RFC] malloc: Fix test for malloc_usable_size
Related show

Commit Message

Matheus Castanho Dec. 16, 2019, 7:17 p.m.
Hi,

We have seen some tests on recent builds on ppc64le failing with
the following:

  ---=== ./malloc/tst-malloc-usable-tunables.out ===---
  malloc_usable_size: expected 7 but got 24
  FAIL: malloc/tst-malloc-usable-tunables.c

After taking a look at the contents of that test, the check failing
actually comes from tst-malloc-usable.c, which tests if the value
returned by malloc_usable_size() is different than the number of bytes
requested for allocation by a previous call to malloc. However, per
malloc/malloc.c:

  malloc_usable_size(void* p);

  Returns the number of bytes you can actually use in
  an allocated chunk, which may be more than you requested (although
  often not) due to alignment and minimum size constraints.
  You can use this many bytes without worrying about
  overwriting other allocated objects. 

Based on that, is there any special reason why the comparison on
tst-malloc-usable.c is a != instead of a <, since the size of the
allocated chunk may be greater than what was requested?

Matheus Castanho

---
Currently malloc/tst-malloc-usable.c fails if the return value of
malloc_usable_size() is different than the number of bytes requested
for allocation by a previous call to malloc(), which may not always
be the case. This commit changes that check to avoid false positives
when running this test.
---
 malloc/tst-malloc-usable.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

-- 
2.21.0

Patch

diff --git a/malloc/tst-malloc-usable.c b/malloc/tst-malloc-usable.c
index aa572fa06a..767f4ac6ef 100644
--- a/malloc/tst-malloc-usable.c
+++ b/malloc/tst-malloc-usable.c
@@ -34,9 +34,9 @@  do_test (void)
     }
 
   usable_size = malloc_usable_size (p);
-  if (usable_size != 7)
+  if (usable_size < 7)
     {
-      printf ("malloc_usable_size: expected 7 but got %zu\n", usable_size);
+      printf ("malloc_usable_size: expected at least 7 but got %zu\n", usable_size);
       return 1;
     }