From: Shane Bryldt Date: Mon, 3 Apr 2017 20:49:37 +0000 (-0500) Subject: FS-10167: Added test to identify issue with ks_pool_realloc X-Git-Tag: v1.8.0~644 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7861bb0d4938c2fe74b7120b09ec6b73122b53c2;p=thirdparty%2Ffreeswitch.git FS-10167: Added test to identify issue with ks_pool_realloc --- diff --git a/libs/libks/test/Makefile.am b/libs/libks/test/Makefile.am index 17bd30d05e..8d6e0843ec 100644 --- a/libs/libks/test/Makefile.am +++ b/libs/libks/test/Makefile.am @@ -9,6 +9,11 @@ testpools_SOURCES = testpools.c tap.c testpools_CFLAGS = $(AM_CFLAGS) testpools_LDADD = $(TEST_LDADD) +check_PROGRAMS += testrealloc +testrealloc_SOURCES = testrealloc.c tap.c +testrealloc_CFLAGS = $(AM_CFLAGS) +testrealloc_LDADD = $(TEST_LDADD) + check_PROGRAMS += testacl testacl_SOURCES = testacl.c tap.c testacl_CFLAGS = $(AM_CFLAGS) diff --git a/libs/libks/test/testrealloc.c b/libs/libks/test/testrealloc.c new file mode 100644 index 0000000000..6f2924a385 --- /dev/null +++ b/libs/libks/test/testrealloc.c @@ -0,0 +1,47 @@ +#include "ks.h" + +#include +#include +#include +#include "tap.h" + +int main(int argc, char **argv) +{ + ks_pool_t *pool; + uint32_t *buf = NULL; + intptr_t ptr = 0; + + ks_init(); + + plan(3); + + ks_pool_open(&pool); + + buf = (uint32_t *)ks_pool_resize(pool, buf, sizeof(uint32_t) * 1); + ok(buf != NULL); + + ptr = (intptr_t)buf; + + buf = (uint32_t *)ks_pool_resize(pool, buf, sizeof(uint32_t) * 2); + ok(buf != NULL); + + ok((intptr_t)buf == ptr); + + buf = (uint32_t *)ks_pool_resize(pool, buf, sizeof(uint32_t) * 1); + ok(buf != NULL); + + ok((intptr_t)buf == ptr); + + buf = (uint32_t *)ks_pool_resize(pool, buf, sizeof(uint32_t) * 2); + ok(buf != NULL); + + ok((intptr_t)buf == ptr); + + ks_pool_free(pool, &buf); + + ks_pool_close(&pool); + + ks_shutdown(); + + done_testing(); +}