net/sfc: fix MTU change to check Rx scatter consistency
[dpdk.git] / app / test / test_malloc.c
index 6b6c6fe..f0e608c 100644 (file)
@@ -1,5 +1,5 @@
 /* SPDX-License-Identifier: BSD-3-Clause
- * Copyright(c) 2010-2014 Intel Corporation
+ * Copyright(c) 2010-2019 Intel Corporation
  */
 
 #include <stdio.h>
 
 #define N 10000
 
+
+static int
+is_mem_on_socket(int32_t socket);
+
+static int32_t
+addr_to_socket(void *addr);
+
 /*
  * Malloc
  * ======
@@ -542,7 +549,49 @@ test_realloc(void)
                return -1;
        }
        rte_free(ptr12);
-       return 0;
+
+       /* check realloc_socket part */
+       int32_t socket_count = 0, socket_allocated, socket;
+       int ret = -1;
+       size_t size = 1024;
+
+       ptr1 = NULL;
+       for (socket = 0; socket < RTE_MAX_NUMA_NODES; socket++) {
+               if (is_mem_on_socket(socket)) {
+                       int j = 2;
+
+                       socket_count++;
+                       while (j--) {
+                               /* j == 1 -> resizing */
+                               ptr2 = rte_realloc_socket(ptr1, size,
+                                                         RTE_CACHE_LINE_SIZE,
+                                                         socket);
+                               if (ptr2 == NULL) {
+                                       printf("NULL pointer returned from rte_realloc_socket\n");
+                                       goto end;
+                               }
+
+                               ptr1 = ptr2;
+                               socket_allocated = addr_to_socket(ptr2);
+                               if (socket_allocated != socket) {
+                                       printf("Requested socket (%d) doesn't mach allocated one (%d)\n",
+                                              socket, socket_allocated);
+                                       goto end;
+                               }
+                               size += RTE_CACHE_LINE_SIZE;
+                       }
+               }
+       }
+
+       /* Print warnign if only a single socket, but don't fail the test */
+       if (socket_count < 2)
+               printf("WARNING: realloc_socket test needs memory on multiple sockets!\n");
+
+       ret = 0;
+end:
+       rte_free(ptr1);
+
+       return ret;
 }
 
 static int