>From 475eac69463f384419a3b5a8bd449a6876123fab Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 25 Oct 2020 18:18:06 +0100 Subject: [PATCH 5/5] ssfmalloc tests: Small tweaks. * tests/test-ssfmalloc.c: Add comments. (alloc_pages): Don't require PROT_EXEC bits. (block_sizes): Add more small sizes, for better coverage of ssfmalloc-bitmap.h. --- ChangeLog | 6 ++++++ tests/test-ssfmalloc.c | 25 ++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 26ba40c..bb838bc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2020-10-25 Bruno Haible + ssfmalloc tests: Small tweaks. + * tests/test-ssfmalloc.c: Add comments. + (alloc_pages): Don't require PROT_EXEC bits. + (block_sizes): Add more small sizes, for better coverage of + ssfmalloc-bitmap.h. + ssfmalloc tests: Portability to Minix. * modules/ssfmalloc-tests (Files): Add m4/mmap-anon.m4. (configure.ac): Invoke gl_FUNC_MMAP_ANON. diff --git a/tests/test-ssfmalloc.c b/tests/test-ssfmalloc.c index 09427c7..9699e6b 100644 --- a/tests/test-ssfmalloc.c +++ b/tests/test-ssfmalloc.c @@ -92,7 +92,7 @@ alloc_pages (size_t size) return (uintptr_t) mem; #else /* Use mmap with the MAP_ANONYMOUS or MAP_ANON flag. */ - void *mem = mmap (NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC, + void *mem = mmap (NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_VARIABLE, -1, 0); if (mem == (void *)(-1)) return 0; @@ -143,6 +143,7 @@ free_pages (uintptr_t pages, size_t size) #include "macros.h" +/* Fills a block of a given size with some contents. */ static void fill_block (uintptr_t block, size_t size) { @@ -150,6 +151,8 @@ fill_block (uintptr_t block, size_t size) memset ((char *) block, code, size); } +/* Verifies that the contents of a block is still present + (i.e. has not accidentally been overwritten by other operations). */ static void verify_block (uintptr_t block, size_t size) { @@ -187,12 +190,29 @@ static size_t block_sizes[] = 64, 65, 71, + 77, 83, + 96, 99, 110, + 119, 127, 128, + 130, + 144, + 150, + 157, + 161, 169, + 180, + 192, + 199, + 204, + 210, + 224, + 225, + 236, + 241, 249, 255, 256, @@ -266,6 +286,9 @@ main (int argc, char *argv[]) init_pagesize (); + /* Randomly allocate and deallocate blocks. + Also verify that there are no unexpected modifications to the contents of + these blocks. */ { unsigned int repeat; char *blocks[SIZEOF (block_sizes)]; -- 2.7.4