Commit 911c042d authored by Paul Luse's avatar Paul Luse Committed by Ben Walker
Browse files

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: default avatarPaul Luse <paul.e.luse@intel.com>
Reviewed-on: https://review.gerrithub.io/420110


Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 6397392e
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -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)
{