From 84b2933ff55e8ebf97bfd04283d3e07c66f5183b Mon Sep 17 00:00:00 2001 From: Paul Luse Date: Thu, 3 Aug 2017 09:51:36 -0700 Subject: [PATCH] ut/nvme: add coverage for nvme_allocate_request_null() Change-Id: I39757052a7458ff1520b2cc13face2db1fafbf75 Signed-off-by: Paul Luse Reviewed-on: https://review.gerrithub.io/372542 Tested-by: SPDK Automated Test System Reviewed-by: Daniel Verkamp Reviewed-by: Jim Harris Reviewed-by: Ben Walker --- test/unit/lib/nvme/nvme.c/nvme_ut.c | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/unit/lib/nvme/nvme.c/nvme_ut.c b/test/unit/lib/nvme/nvme.c/nvme_ut.c index f6e0f8875..94f319fe2 100644 --- a/test/unit/lib/nvme/nvme.c/nvme_ut.c +++ b/test/unit/lib/nvme/nvme.c/nvme_ut.c @@ -108,6 +108,38 @@ memset_trid(struct spdk_nvme_transport_id *trid1, struct spdk_nvme_transport_id memset(trid2, 0, sizeof(struct spdk_nvme_transport_id)); } +static void +test_nvme_allocate_request_null(void) +{ + struct spdk_nvme_qpair qpair; + spdk_nvme_cmd_cb cb_fn = (spdk_nvme_cmd_cb)0x1234; + void *cb_arg = (void *)0x5678; + struct nvme_request *req = NULL; + struct nvme_request dummy_req; + + STAILQ_INIT(&qpair.free_req); + STAILQ_INIT(&qpair.queued_req); + + /* + * Put a dummy on the queue so we can make a request + * and confirm that what comes back is what we expect. + */ + STAILQ_INSERT_HEAD(&qpair.free_req, &dummy_req, stailq); + + req = nvme_allocate_request_null(&qpair, cb_fn, cb_arg); + + /* + * Compare the req with the parmaters that we passed in + * as well as what the function is supposed to update. + */ + CU_ASSERT(req->cb_fn == cb_fn); + CU_ASSERT(req->cb_arg == cb_arg); + CU_ASSERT(req->pid == getpid()); + CU_ASSERT(req->payload.type == NVME_PAYLOAD_TYPE_CONTIG); + CU_ASSERT(req->payload.md == NULL); + CU_ASSERT(req->payload.u.contig == NULL); +} + static void test_nvme_allocate_request(void) { @@ -576,6 +608,8 @@ int main(int argc, char **argv) test_trid_adrfam_str) == NULL || CU_add_test(suite, "test_nvme_ctrlr_probe", test_nvme_ctrlr_probe) == NULL || + CU_add_test(suite, "test_nvme_allocate_request_null", + test_nvme_allocate_request_null) == NULL || CU_add_test(suite, "test_nvme_allocate_request", test_nvme_allocate_request) == NULL || CU_add_test(suite, "test_nvme_free_request",