diff options
author | Mattias Andrée <maandree@kth.se> | 2018-12-15 18:32:50 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2018-12-15 18:32:50 +0100 |
commit | 519d9b72a68f074eb32f24fe8587716a768026b2 (patch) | |
tree | 2a0189f098bf5779a2cba89bcfb67dbef3c5dcea /libsimple.c | |
parent | More tests and fix attributes on wcsndup (diff) | |
download | libsimple-519d9b72a68f074eb32f24fe8587716a768026b2.tar.gz libsimple-519d9b72a68f074eb32f24fe8587716a768026b2.tar.bz2 libsimple-519d9b72a68f074eb32f24fe8587716a768026b2.tar.xz |
Add tests
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libsimple.c')
-rw-r--r-- | libsimple.c | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/libsimple.c b/libsimple.c index a2ae4bc..5232833 100644 --- a/libsimple.c +++ b/libsimple.c @@ -88,7 +88,7 @@ int main(void) { struct allocinfo *volatile info; - void *ptr; + void *ptr, *old; struct timespec ts, ts1, ts2; struct timeval tv1, tv2; const char *cs; @@ -2248,6 +2248,66 @@ main(void) assert_stderr("%s: libsimple_vmemalignz: %s\n", argv0, strerror(EINVAL)); libsimple_default_failure_exit = 1; +#ifdef LIBSIMPLE_HAVE_ALIGNED_REALLOC + assert((ptr = libsimple_aligned_realloc(NULL, 16, 5))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 5 || info->size == info->alignment); + assert(!info->zeroed); + ASSERT_ALIGNMENT(info, 16); + info->refcount += 1; + } + stpcpy(ptr, "test"); + assert((ptr = libsimple_aligned_realloc(old = ptr, 32, 10))); + assert(!strcmp(ptr, "test")); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 10 || info->size == info->alignment); + assert(!info->zeroed); + ASSERT_ALIGNMENT(info, 32); + assert(ptr != old); + free(old); + } + free(ptr); + if (have_custom_malloc()) { + alloc_fail_in = 1; + assert(!libsimple_aligned_realloc(NULL, 8, 1) && errno == ENOMEM); + assert(!alloc_fail_in); + } +#else + assert(libsimple_aligned_realloc(NULL, 8, 1) && errno == ENOSYS); +#endif + +#ifdef LIBSIMPLE_HAVE_ALIGNED_REALLOC + assert((ptr = libsimple_aligned_reallocarray(NULL, 16, 5, 3))); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 15 || info->size == info->alignment); + assert(!info->zeroed); + ASSERT_ALIGNMENT(info, 16); + info->refcount += 1; + } + stpcpy(ptr, "test"); + assert((ptr = libsimple_aligned_reallocarray(old = ptr, 32, 10, 2))); + assert(!strcmp(ptr, "test")); + if (have_custom_malloc()) { + assert((info = get_allocinfo(ptr))); + assert(info->size == 20 || info->size == info->alignment); + assert(!info->zeroed); + ASSERT_ALIGNMENT(info, 32); + assert(ptr != old); + free(old); + } + free(ptr); + if (have_custom_malloc()) { + alloc_fail_in = 1; + assert(!libsimple_aligned_reallocarray(NULL, 8, 1, 1) && errno == ENOMEM); + assert(!alloc_fail_in); + } +#else + assert(libsimple_aligned_reallocarray(NULL, 8, 1, 1) && errno == ENOSYS); +#endif + assert(libsimple_memeq("abcxyz", "abc123", 3)); assert(!libsimple_memeq("abcxyz", "abc123", 4)); assert(libsimple_memeq("abcxyz", "abcx23", 4)); |