]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-10167: Added test to identify issue with ks_pool_realloc
authorShane Bryldt <astaelan@gmail.com>
Mon, 3 Apr 2017 20:49:37 +0000 (15:49 -0500)
committerShane Bryldt <astaelan@gmail.com>
Mon, 3 Apr 2017 20:50:00 +0000 (15:50 -0500)
libs/libks/test/Makefile.am
libs/libks/test/testrealloc.c [new file with mode: 0644]

index 17bd30d05e8fb6541f37a0304c508f47b95e9fbc..8d6e0843ec1364b46e1d7d753f03e67681a4c864 100644 (file)
@@ -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 (file)
index 0000000..6f2924a
--- /dev/null
@@ -0,0 +1,47 @@
+#include "ks.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#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();
+}