ut/nvme: add coverage for spdk_nvme_probe()
Change-Id: I8662806c462a47ec389c96c5a233cce48cc11944 Signed-off-by: Paul Luse <paul.e.luse@intel.com> Reviewed-on: https://review.gerrithub.io/372554 Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
parent
fca11f1519
commit
bd5ce60f82
@ -59,12 +59,6 @@ DEFINE_STUB(spdk_pci_device_get_id, struct spdk_pci_id,
|
|||||||
DEFINE_STUB(spdk_nvme_transport_available, bool,
|
DEFINE_STUB(spdk_nvme_transport_available, bool,
|
||||||
(enum spdk_nvme_transport_type trtype), true)
|
(enum spdk_nvme_transport_type trtype), true)
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
DEFINE_STUB(nvme_ctrlr_add_process, int,
|
DEFINE_STUB(nvme_ctrlr_add_process, int,
|
||||||
(struct spdk_nvme_ctrlr *ctrlr, void *devhandle), 0)
|
(struct spdk_nvme_ctrlr *ctrlr, void *devhandle), 0)
|
||||||
|
|
||||||
@ -113,6 +107,19 @@ memset_trid(struct spdk_nvme_transport_id *trid1, struct spdk_nvme_transport_id
|
|||||||
memset(trid2, 0, sizeof(struct spdk_nvme_transport_id));
|
memset(trid2, 0, sizeof(struct spdk_nvme_transport_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool ut_check_trtype = false;
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
if (ut_check_trtype == true) {
|
||||||
|
CU_ASSERT(trid->trtype == SPDK_NVME_TRANSPORT_PCIE);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static bool ut_attach_cb_called = false;
|
static bool ut_attach_cb_called = false;
|
||||||
static void
|
static void
|
||||||
dummy_attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
|
dummy_attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
|
||||||
@ -121,6 +128,67 @@ dummy_attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
|
|||||||
ut_attach_cb_called = true;
|
ut_attach_cb_called = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_spdk_nvme_probe(void)
|
||||||
|
{
|
||||||
|
int rc = 0;
|
||||||
|
const struct spdk_nvme_transport_id *trid = NULL;
|
||||||
|
void *cb_ctx = NULL;
|
||||||
|
spdk_nvme_probe_cb probe_cb = NULL;
|
||||||
|
spdk_nvme_attach_cb attach_cb = dummy_attach_cb;
|
||||||
|
spdk_nvme_remove_cb remove_cb = NULL;
|
||||||
|
struct spdk_nvme_ctrlr ctrlr;
|
||||||
|
pthread_mutexattr_t attr;
|
||||||
|
struct nvme_driver dummy;
|
||||||
|
g_spdk_nvme_driver = &dummy;
|
||||||
|
|
||||||
|
/* driver init fails */
|
||||||
|
MOCK_SET(spdk_process_is_primary, bool, false);
|
||||||
|
MOCK_SET_P(spdk_memzone_lookup, void *, NULL);
|
||||||
|
rc = spdk_nvme_probe(trid, cb_ctx, probe_cb, attach_cb, remove_cb);
|
||||||
|
CU_ASSERT(rc == -1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For secondary processes, the attach_cb should automatically get
|
||||||
|
* called for any controllers already initialized by the primary
|
||||||
|
* process.
|
||||||
|
*/
|
||||||
|
MOCK_SET(spdk_nvme_transport_available, bool, false);
|
||||||
|
MOCK_SET(spdk_process_is_primary, bool, true);
|
||||||
|
dummy.initialized = true;
|
||||||
|
g_spdk_nvme_driver = &dummy;
|
||||||
|
rc = spdk_nvme_probe(trid, cb_ctx, probe_cb, attach_cb, remove_cb);
|
||||||
|
CU_ASSERT(rc == -1);
|
||||||
|
|
||||||
|
/* driver init passes, transport available, secondary call attach_cb */
|
||||||
|
MOCK_SET(spdk_nvme_transport_available, bool, true);
|
||||||
|
MOCK_SET(spdk_process_is_primary, bool, false);
|
||||||
|
MOCK_SET_P(spdk_memzone_lookup, void *, g_spdk_nvme_driver);
|
||||||
|
dummy.initialized = true;
|
||||||
|
memset(&ctrlr, 0, sizeof(struct spdk_nvme_ctrlr));
|
||||||
|
CU_ASSERT(pthread_mutexattr_init(&attr) == 0);
|
||||||
|
CU_ASSERT(pthread_mutex_init(&dummy.lock, &attr) == 0);
|
||||||
|
TAILQ_INIT(&dummy.attached_ctrlrs);
|
||||||
|
TAILQ_INSERT_TAIL(&dummy.attached_ctrlrs, &ctrlr, tailq);
|
||||||
|
MOCK_SET(attach_cb_called, bool, false);
|
||||||
|
/* setup nvme_transport_ctrlr_scan() stub to also check the trype */
|
||||||
|
MOCK_SET(check_trtype, bool, true);
|
||||||
|
rc = spdk_nvme_probe(trid, cb_ctx, probe_cb, attach_cb, remove_cb);
|
||||||
|
CU_ASSERT(rc == 0);
|
||||||
|
CU_ASSERT(ut_attach_cb_called == true);
|
||||||
|
|
||||||
|
/* driver init passes, transport available, we are primary */
|
||||||
|
MOCK_SET(spdk_process_is_primary, bool, true);
|
||||||
|
TAILQ_INIT(&dummy.init_ctrlrs);
|
||||||
|
rc = spdk_nvme_probe(trid, cb_ctx, probe_cb, attach_cb, remove_cb);
|
||||||
|
CU_ASSERT(rc == 0);
|
||||||
|
|
||||||
|
g_spdk_nvme_driver = NULL;
|
||||||
|
/* reset to pre-test values */
|
||||||
|
MOCK_SET_P(spdk_memzone_lookup, void *, MOCK_PASS_THRU_P);
|
||||||
|
MOCK_SET(check_trtype, bool, false);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_nvme_init_controllers(void)
|
test_nvme_init_controllers(void)
|
||||||
{
|
{
|
||||||
@ -878,6 +946,8 @@ int main(int argc, char **argv)
|
|||||||
test_trid_adrfam_str) == NULL ||
|
test_trid_adrfam_str) == NULL ||
|
||||||
CU_add_test(suite, "test_nvme_ctrlr_probe",
|
CU_add_test(suite, "test_nvme_ctrlr_probe",
|
||||||
test_nvme_ctrlr_probe) == NULL ||
|
test_nvme_ctrlr_probe) == NULL ||
|
||||||
|
CU_add_test(suite, "test_spdk_nvme_probe",
|
||||||
|
test_spdk_nvme_probe) == NULL ||
|
||||||
CU_add_test(suite, "test_nvme_init_controllers",
|
CU_add_test(suite, "test_nvme_init_controllers",
|
||||||
test_nvme_init_controllers) == NULL ||
|
test_nvme_init_controllers) == NULL ||
|
||||||
CU_add_test(suite, "test_nvme_driver_init",
|
CU_add_test(suite, "test_nvme_driver_init",
|
||||||
|
Loading…
Reference in New Issue
Block a user