From 911c042df86fff52a1e6d189f0332c994062a001 Mon Sep 17 00:00:00 2001 From: Paul Luse Date: Sat, 21 Jul 2018 11:39:05 -0700 Subject: [PATCH] test: add mock and new function to test_env.c Need to mock spdk_mempool_get() to test code path when it fails. Also added spdk_mempool_get_bulk() to test env. Change-Id: I7f64230c9841215a404149e9a48ad4bf8a63822c Signed-off-by: Paul Luse Reviewed-on: https://review.gerrithub.io/420110 Chandler-Test-Pool: SPDK Automated Test System Tested-by: SPDK CI Jenkins Reviewed-by: Shuhei Matsumoto Reviewed-by: Ben Walker Reviewed-by: Jim Harris --- test/common/lib/test_env.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/common/lib/test_env.c b/test/common/lib/test_env.c index 66c0b9410..4cba6fea0 100644 --- a/test/common/lib/test_env.c +++ b/test/common/lib/test_env.c @@ -203,12 +203,17 @@ spdk_mempool_free(struct spdk_mempool *_mp) free(mp); } +bool ut_spdk_mempool_get = false; void * spdk_mempool_get(struct spdk_mempool *_mp) { struct test_mempool *mp = (struct test_mempool *)_mp; void *buf; + if (ut_spdk_mempool_get) { + return NULL; + } + if (mp && mp->count == 0) { return NULL; } @@ -223,6 +228,18 @@ spdk_mempool_get(struct spdk_mempool *_mp) } } +int +spdk_mempool_get_bulk(struct spdk_mempool *mp, void **ele_arr, size_t count) +{ + for (size_t i = 0; i < count; i++) { + ele_arr[i] = spdk_mempool_get(mp); + if (ele_arr[i] == NULL) { + return -1; + } + } + return 0; +} + void spdk_mempool_put(struct spdk_mempool *_mp, void *ele) {