MCPcopy Create free account
hub / github.com/F-Stack/f-stack / test_malloc_basic

Function test_malloc_basic

dpdk/app/test/test_external_mem.c:280–403  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

278}
279
280static int
281test_malloc_basic(void *addr, size_t len, size_t pgsz, rte_iova_t *iova,
282 int n_pages)
283{
284 const char *heap_name = "heap";
285 void *ptr = NULL;
286 int socket_id;
287 const struct rte_memzone *mz = NULL, *contig_mz = NULL;
288
289 /* create heap */
290 if (rte_malloc_heap_create(heap_name) != 0) {
291 printf("%s():%i: Failed to create malloc heap\n",
292 __func__, __LINE__);
293 goto fail;
294 }
295
296 /* get socket ID corresponding to this heap */
297 socket_id = rte_malloc_heap_get_socket(heap_name);
298 if (socket_id < 0) {
299 printf("%s():%i: cannot find socket for external heap\n",
300 __func__, __LINE__);
301 goto fail;
302 }
303
304 /* heap is empty, so any allocation should fail */
305 ptr = rte_malloc_socket("EXTMEM", 64, 0, socket_id);
306 if (ptr != NULL) {
307 printf("%s():%i: Allocated from empty heap\n", __func__,
308 __LINE__);
309 goto fail;
310 }
311
312 /* add memory to heap */
313 if (rte_malloc_heap_memory_add(heap_name, addr, len,
314 iova, n_pages, pgsz) != 0) {
315 printf("%s():%i: Failed to add memory to heap\n",
316 __func__, __LINE__);
317 goto fail;
318 }
319
320 /* check if memory is accessible from EAL */
321 if (check_mem(addr, iova, pgsz, n_pages) < 0)
322 goto fail;
323
324 /* allocate - this now should succeed */
325 ptr = rte_malloc_socket("EXTMEM", 64, 0, socket_id);
326 if (ptr == NULL) {
327 printf("%s():%i: Failed to allocate from external heap\n",
328 __func__, __LINE__);
329 goto fail;
330 }
331
332 /* check if address is in expected range */
333 if (ptr < addr || ptr >= RTE_PTR_ADD(addr, len)) {
334 printf("%s():%i: Allocated from unexpected address space\n",
335 __func__, __LINE__);
336 goto fail;
337 }

Callers 1

test_external_memFunction · 0.85

Calls 13

rte_malloc_heap_createFunction · 0.85
rte_malloc_socketFunction · 0.85
rte_malloc_heap_destroyFunction · 0.85
rte_memzone_reserveFunction · 0.85
rte_malloc_dump_statsFunction · 0.85
rte_malloc_dump_heapsFunction · 0.85
rte_freeFunction · 0.85
rte_memzone_freeFunction · 0.85
check_memFunction · 0.70

Tested by

no test coverage detected