From 58d8a4564b8ef71c5ced1b00759cead056865e75 Mon Sep 17 00:00:00 2001 From: Paul Luse Date: Sat, 7 Jul 2018 15:16:18 -0700 Subject: [PATCH] test: add ability to mock spdk_dma_malloc() Used in crypto unit tests. Change-Id: I7d7e31e9030c238cb539b9fcf0936e588c1a4211 Signed-off-by: Paul Luse Reviewed-on: https://review.gerrithub.io/418320 Tested-by: SPDK Automated Test System Reviewed-by: Ben Walker Reviewed-by: Jim Harris --- test/common/lib/test_env.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/test/common/lib/test_env.c b/test/common/lib/test_env.c index deda18564..66c0b9410 100644 --- a/test/common/lib/test_env.c +++ b/test/common/lib/test_env.c @@ -89,17 +89,24 @@ spdk_memzone_reserve_aligned(const char *name, size_t len, int socket_id, } } +int ut_spdk_dma_malloc = (int)MOCK_PASS_THRU; +void *ut_p_spdk_dma_malloc = &ut_spdk_dma_malloc; void * spdk_dma_malloc(size_t size, size_t align, uint64_t *phys_addr) { - void *buf = NULL; - if (posix_memalign(&buf, align, size)) { - return NULL; + if (ut_p_spdk_dma_malloc && + ut_spdk_dma_malloc == (int)MOCK_PASS_THRU) { + void *buf = NULL; + if (posix_memalign(&buf, align, size)) { + return NULL; + } + if (phys_addr) { + *phys_addr = (uint64_t)buf; + } + return buf; + } else { + return ut_p_spdk_dma_malloc; } - if (phys_addr) { - *phys_addr = (uint64_t)buf; - } - return buf; } int ut_spdk_dma_zmalloc = (int)MOCK_PASS_THRU;