mock: add MOCK_CLEARED_ASSERT macro

This is useful for proving to scan-build that we are not using a mocked
function. Sometimes it needs to be called repeatedly every time any mock
variables are called.

Change-Id: Id0ef196620c2984252f792a7e40162e10b989748
Signed-off-by: Seth Howell <seth.howell@intel.com>
Reviewed-on: https://review.gerrithub.io/c/437997
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: yidong0635 <dongx.yi@intel.com>
This commit is contained in:
Seth Howell 2018-12-20 12:50:06 -07:00 committed by Jim Harris
parent baea123097
commit 1ed1f968ae
2 changed files with 9 additions and 0 deletions

View File

@ -62,6 +62,10 @@
ut_ ## fn ## _mocked = false; \
ut_ ## fn = NULL;
/* for proving to *certain* static analysis tools that we didn't reset the mock function. */
#define MOCK_CLEARED_ASSERT(fn) \
SPDK_CU_ASSERT_FATAL(ut_ ## fn ## _mocked == false)
/* for declaring function protoypes for wrappers */
#define DECLARE_WRAPPER(fn, ret, args) \
extern bool ut_ ## fn ## _mocked; \

View File

@ -742,6 +742,7 @@ test_initdrivers(void)
MOCK_SET(rte_crypto_op_pool_create, (struct rte_mempool *)1);
/* Check resources are sufficient failure. */
MOCK_CLEARED_ASSERT(spdk_mempool_create);
rc = vbdev_crypto_init_crypto_drivers();
CU_ASSERT(rc == -EINVAL);
@ -749,6 +750,7 @@ test_initdrivers(void)
MOCK_SET(rte_cryptodev_device_count_by_driver, 2);
MOCK_SET(rte_cryptodev_info_get, 1);
MOCK_SET(rte_cryptodev_configure, -1);
MOCK_CLEARED_ASSERT(spdk_mempool_create);
rc = vbdev_crypto_init_crypto_drivers();
MOCK_SET(rte_cryptodev_configure, 0);
CU_ASSERT(g_mbuf_mp == NULL);
@ -757,6 +759,7 @@ test_initdrivers(void)
/* Test failure of qp setup. */
MOCK_SET(rte_cryptodev_queue_pair_setup, -1);
MOCK_CLEARED_ASSERT(spdk_mempool_create);
rc = vbdev_crypto_init_crypto_drivers();
CU_ASSERT(rc == -EINVAL);
CU_ASSERT(g_mbuf_mp == NULL);
@ -765,6 +768,7 @@ test_initdrivers(void)
/* Test failure of dev start. */
MOCK_SET(rte_cryptodev_start, -1);
MOCK_CLEARED_ASSERT(spdk_mempool_create);
rc = vbdev_crypto_init_crypto_drivers();
CU_ASSERT(rc == -EINVAL);
CU_ASSERT(g_mbuf_mp == NULL);
@ -772,6 +776,7 @@ test_initdrivers(void)
MOCK_SET(rte_cryptodev_start, 0);
/* Test happy path. */
MOCK_CLEARED_ASSERT(spdk_mempool_create);
rc = vbdev_crypto_init_crypto_drivers();
/* We don't have spdk_mempool_create mocked right now, so make sure to free the mempools. */
CU_ASSERT(g_mbuf_mp != NULL);