unit test: add new mock macro and use macros in nvme_ut.c
No new coverage added, just used the STUB macros in nvme UT to make sure they cover all the cases and discovered a few small tweaks needed: (1) added _V variant to declare void stubs (if someone sees an easy way to make DECLARE_STUB handle this case that'd be cleaner but I don't think its a big deal) and (2) updated DECLARE_STUB so that it can set a struct return value by adding {} to the ut_ variable set statement. Also ordered the declarations simply for readability, the _V first, the regular stubs next, the _P next and then the stubs that don't have a macro to cover them because they do something other than return a specific value. Change-Id: Idd8919d2b9e9daa76dd629364ea1d0285657fa81 Signed-off-by: Paul Luse <paul.e.luse@intel.com> Reviewed-on: https://review.gerrithub.io/368420 Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
4f7210f664
commit
ca2931227e
@ -39,14 +39,18 @@
|
||||
/* used to signify pass through */
|
||||
#define MOCK_PASS_THRU (0xdeadbeef)
|
||||
|
||||
/* helper for initializing struct value with mock macros */
|
||||
#define MOCK_STRUCT_INIT(...) \
|
||||
{ __VA_ARGS__ }
|
||||
|
||||
/* for controlling mocked function behavior, setting */
|
||||
/* and getting values from the stub, the _P macros are */
|
||||
/* for mocking functions that return pointer values */
|
||||
#define MOCK_SET(fn, ret, val) \
|
||||
ut_ ## fn = (ret){val}
|
||||
ut_ ## fn = (ret)val
|
||||
|
||||
#define MOCK_SET_P(fn, ret, val) \
|
||||
ut_p_ ## fn = (ret){val}
|
||||
ut_p_ ## fn = (ret)val
|
||||
|
||||
#define MOCK_GET(fn) \
|
||||
ut_ ## fn
|
||||
|
@ -41,64 +41,59 @@
|
||||
|
||||
#include "spdk_internal/mock.h"
|
||||
|
||||
int
|
||||
spdk_pci_nvme_enumerate(spdk_pci_enum_cb enum_cb, void *enum_ctx)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
DEFINE_STUB_V(nvme_ctrlr_destruct, (struct spdk_nvme_ctrlr *ctrlr))
|
||||
|
||||
struct spdk_pci_id
|
||||
spdk_pci_device_get_id(struct spdk_pci_device *pci_dev)
|
||||
{
|
||||
struct spdk_pci_id pci_id;
|
||||
DEFINE_STUB_V(nvme_ctrlr_fail,
|
||||
(struct spdk_nvme_ctrlr *ctrlr, bool hot_remove))
|
||||
|
||||
memset(&pci_id, 0xFF, sizeof(pci_id));
|
||||
DEFINE_STUB_V(nvme_ctrlr_proc_get_ref, (struct spdk_nvme_ctrlr *ctrlr))
|
||||
|
||||
return pci_id;
|
||||
}
|
||||
DEFINE_STUB_V(nvme_ctrlr_proc_put_ref, (struct spdk_nvme_ctrlr *ctrlr))
|
||||
|
||||
bool
|
||||
spdk_nvme_transport_available(enum spdk_nvme_transport_type trtype)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
DEFINE_STUB(spdk_pci_nvme_enumerate, int,
|
||||
(spdk_pci_enum_cb enum_cb, void *enum_ctx), -1)
|
||||
|
||||
int
|
||||
nvme_transport_ctrlr_scan(const struct spdk_nvme_transport_id *trid,
|
||||
void *cb_ctx,
|
||||
spdk_nvme_probe_cb probe_cb,
|
||||
spdk_nvme_remove_cb remove_cb)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
DEFINE_STUB(spdk_pci_device_get_id, struct spdk_pci_id,
|
||||
(struct spdk_pci_device *pci_dev),
|
||||
MOCK_STRUCT_INIT(.vendor_id = 0xffff, .device_id = 0xffff,
|
||||
.subvendor_id = 0xffff, .subdevice_id = 0xffff))
|
||||
|
||||
void
|
||||
nvme_ctrlr_destruct(struct spdk_nvme_ctrlr *ctrlr)
|
||||
{
|
||||
}
|
||||
DEFINE_STUB(spdk_nvme_transport_available, bool,
|
||||
(enum spdk_nvme_transport_type trtype), true)
|
||||
|
||||
int
|
||||
nvme_ctrlr_add_process(struct spdk_nvme_ctrlr *ctrlr, void *devhandle)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
DEFINE_STUB(nvme_transport_ctrlr_scan, int,
|
||||
(const struct spdk_nvme_transport_id *trid,
|
||||
void *cb_ctx,
|
||||
spdk_nvme_probe_cb probe_cb,
|
||||
spdk_nvme_remove_cb remove_c), 0)
|
||||
|
||||
int
|
||||
nvme_ctrlr_process_init(struct spdk_nvme_ctrlr *ctrlr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
DEFINE_STUB(nvme_ctrlr_add_process, int,
|
||||
(struct spdk_nvme_ctrlr *ctrlr, void *devhandle), 0)
|
||||
|
||||
int
|
||||
nvme_ctrlr_start(struct spdk_nvme_ctrlr *ctrlr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
DEFINE_STUB(nvme_ctrlr_process_init, int,
|
||||
(struct spdk_nvme_ctrlr *ctrlr), 0)
|
||||
|
||||
void
|
||||
nvme_ctrlr_fail(struct spdk_nvme_ctrlr *ctrlr, bool hot_remove)
|
||||
{
|
||||
}
|
||||
DEFINE_STUB(nvme_ctrlr_start, int,
|
||||
(struct spdk_nvme_ctrlr *ctrlr), 0)
|
||||
|
||||
DEFINE_STUB(spdk_pci_device_get_addr, struct spdk_pci_addr,
|
||||
(struct spdk_pci_device *pci_dev), {0})
|
||||
|
||||
DEFINE_STUB(spdk_pci_addr_compare, int,
|
||||
(const struct spdk_pci_addr *a1,
|
||||
const struct spdk_pci_addr *a2), 1)
|
||||
|
||||
DEFINE_STUB(nvme_ctrlr_get_ref_count, int,
|
||||
(struct spdk_nvme_ctrlr *ctrlr), 0)
|
||||
|
||||
DEFINE_STUB(dummy_probe_cb, bool,
|
||||
(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
|
||||
struct spdk_nvme_ctrlr_opts *opts), false)
|
||||
|
||||
DEFINE_STUB_P(nvme_transport_ctrlr_construct, struct spdk_nvme_ctrlr,
|
||||
(const struct spdk_nvme_transport_id *trid,
|
||||
const struct spdk_nvme_ctrlr_opts *opts,
|
||||
void *devhandle), {0})
|
||||
|
||||
void
|
||||
spdk_nvme_ctrlr_opts_set_defaults(struct spdk_nvme_ctrlr_opts *opts)
|
||||
@ -106,39 +101,6 @@ spdk_nvme_ctrlr_opts_set_defaults(struct spdk_nvme_ctrlr_opts *opts)
|
||||
memset(opts, 0, sizeof(*opts));
|
||||
}
|
||||
|
||||
struct spdk_pci_addr
|
||||
spdk_pci_device_get_addr(struct spdk_pci_device *pci_dev)
|
||||
{
|
||||
struct spdk_pci_addr pci_addr;
|
||||
|
||||
memset(&pci_addr, 0, sizeof(pci_addr));
|
||||
return pci_addr;
|
||||
}
|
||||
|
||||
int
|
||||
spdk_pci_addr_compare(const struct spdk_pci_addr *a1, const struct spdk_pci_addr *a2)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
nvme_ctrlr_proc_get_ref(struct spdk_nvme_ctrlr *ctrlr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
nvme_ctrlr_proc_put_ref(struct spdk_nvme_ctrlr *ctrlr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int
|
||||
nvme_ctrlr_get_ref_count(struct spdk_nvme_ctrlr *ctrlr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
memset_trid(struct spdk_nvme_transport_id *trid1, struct spdk_nvme_transport_id *trid2)
|
||||
{
|
||||
@ -146,15 +108,6 @@ memset_trid(struct spdk_nvme_transport_id *trid1, struct spdk_nvme_transport_id
|
||||
memset(trid2, 0, sizeof(struct spdk_nvme_transport_id));
|
||||
}
|
||||
|
||||
DEFINE_STUB_P(nvme_transport_ctrlr_construct, struct spdk_nvme_ctrlr,
|
||||
(const struct spdk_nvme_transport_id *trid,
|
||||
const struct spdk_nvme_ctrlr_opts *opts,
|
||||
void *devhandle), {0})
|
||||
|
||||
DEFINE_STUB(dummy_probe_cb, bool,
|
||||
(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
|
||||
struct spdk_nvme_ctrlr_opts *opts), false)
|
||||
|
||||
static void
|
||||
test_nvme_ctrlr_probe(void)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user