+ return ret;
+}
+
+static int
+test_realloc(void)
+{
+ const char *heap_name = "realloc_heap";
+ int realloc_heap_socket;
+ unsigned int mem_sz = 1U << 13; /* 8K */
+ unsigned int page_sz = sysconf(_SC_PAGESIZE);
+ void *mem;
+ int ret;
+
+ /* page size may be bigger than total mem size, so adjust */
+ mem_sz = RTE_MAX(mem_sz, page_sz);
+
+ /*
+ * the realloc tests depend on specific layout of underlying memory, so
+ * to prevent accidental failures to do fragmented main heap, we will
+ * do all of our tests on an artificially created memory.
+ */
+ if (rte_malloc_heap_create(heap_name) != 0) {
+ printf("Failed to create external heap\n");
+ ret = -1;
+ goto end;
+ }
+ realloc_heap_socket = rte_malloc_heap_get_socket(heap_name);
+
+ mem = mmap(NULL, mem_sz, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ if (mem == MAP_FAILED) {
+ printf("Failed to allocate memory for external heap\n");
+ ret = -1;
+ goto heap_destroy;
+ }
+
+ if (rte_malloc_heap_memory_add(
+ heap_name, mem, mem_sz, NULL, 0, page_sz) != 0) {
+ printf("Failed to add memory to external heap\n");
+ ret = -1;
+ goto mem_free;
+ }