Commit 985ef53a authored by Konrad Sztyber's avatar Konrad Sztyber Committed by Jim Harris
Browse files

test/mock: introduce DEFINE_WRAPPER_MOCK() macro



This macro is intended to be used to define the mock variables (e.g.
ut_foo_mocked and ut_foo) for functions wrapped with DECLARE_WRAPPER().
Currently, it's identical to DEFINE_RETURN_MOCK(), but we'll be changing
them in the next patch, so we'll need two separate macros.

Signed-off-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Change-Id: I9d551f5c3f0659501e9937a25076818f4cbb62b1
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/22810


Community-CI: Mellanox Build Bot
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarBen Walker <ben@nvidia.com>
parent e622de2c
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -49,8 +49,7 @@
 * Avoid nested macro calls to prevent macro expansion of fn.
 */
#define DEFINE_WRAPPER(fn, ret, dargs, pargs) \
	bool ut_ ## fn ## _mocked = false; \
	ret ut_ ## fn; \
	DEFINE_WRAPPER_MOCK(fn, ret); \
	__attribute__((used)) ret __wrap_ ## fn dargs \
	{ \
		if (!ut_ ## fn ## _mocked) { \
@@ -60,6 +59,10 @@
		} \
	}

#define DEFINE_WRAPPER_MOCK(fn, ret) \
	bool ut_ ## fn ## _mocked = false;	\
	ret ut_ ## fn

/* DEFINE_STUB is for defining the implementation of stubs for SPDK funcs. */
#define DEFINE_STUB(fn, ret, dargs, val) \
	bool ut_ ## fn ## _mocked = true; \
+1 −1
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ DEFINE_STUB(spdk_nvme_dhchap_dhkey_derive_secret, int,
DECLARE_WRAPPER(RAND_bytes, int, (unsigned char *buf, int num));

static uint8_t g_rand_val;
DEFINE_RETURN_MOCK(RAND_bytes, int) = 1;
DEFINE_WRAPPER_MOCK(RAND_bytes, int) = 1;

int
__wrap_RAND_bytes(unsigned char *buf, int num)