From 504031d850fd0b73ff36cfe61592ad11518b8d67 Mon Sep 17 00:00:00 2001 From: Mao Jiang Date: Thu, 4 Feb 2021 16:21:05 +0800 Subject: [PATCH] test/nvme_transport: build nvme transport unittest file Change-Id: I0ac4e9afdd69a933522e2cada54b891ab3fbd78c Signed-off-by: Mao Jiang Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6458 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Reviewed-by: Aleksey Marchuk Reviewed-by: Shuhei Matsumoto Reviewed-by: Changpeng Liu Tested-by: SPDK CI Jenkins --- test/unit/lib/nvme/Makefile | 2 +- .../unit/lib/nvme/nvme_transport.c/.gitignore | 1 + test/unit/lib/nvme/nvme_transport.c/Makefile | 38 ++++++++ .../nvme/nvme_transport.c/nvme_transport_ut.c | 89 +++++++++++++++++++ test/unit/unittest.sh | 1 + 5 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 test/unit/lib/nvme/nvme_transport.c/.gitignore create mode 100644 test/unit/lib/nvme/nvme_transport.c/Makefile create mode 100644 test/unit/lib/nvme/nvme_transport.c/nvme_transport_ut.c diff --git a/test/unit/lib/nvme/Makefile b/test/unit/lib/nvme/Makefile index 5f74579d2..ebba5eaa9 100644 --- a/test/unit/lib/nvme/Makefile +++ b/test/unit/lib/nvme/Makefile @@ -35,7 +35,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../../..) include $(SPDK_ROOT_DIR)/mk/spdk.common.mk DIRS-y = nvme.c nvme_ctrlr.c nvme_ctrlr_cmd.c nvme_ctrlr_ocssd_cmd.c nvme_ns.c nvme_ns_cmd.c nvme_ns_ocssd_cmd.c nvme_pcie.c nvme_poll_group.c nvme_qpair.c \ - nvme_quirks.c nvme_tcp.c nvme_uevent.c \ + nvme_quirks.c nvme_tcp.c nvme_uevent.c nvme_transport.c \ DIRS-$(CONFIG_RDMA) += nvme_rdma.c diff --git a/test/unit/lib/nvme/nvme_transport.c/.gitignore b/test/unit/lib/nvme/nvme_transport.c/.gitignore new file mode 100644 index 000000000..ef70323ab --- /dev/null +++ b/test/unit/lib/nvme/nvme_transport.c/.gitignore @@ -0,0 +1 @@ +nvme_transport_ut diff --git a/test/unit/lib/nvme/nvme_transport.c/Makefile b/test/unit/lib/nvme/nvme_transport.c/Makefile new file mode 100644 index 000000000..b34f25624 --- /dev/null +++ b/test/unit/lib/nvme/nvme_transport.c/Makefile @@ -0,0 +1,38 @@ +# +# BSD LICENSE +# +# Copyright (c) Intel Corporation. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Intel Corporation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../../../..) + +TEST_FILE = nvme_transport_ut.c + +include $(SPDK_ROOT_DIR)/mk/spdk.unittest.mk diff --git a/test/unit/lib/nvme/nvme_transport.c/nvme_transport_ut.c b/test/unit/lib/nvme/nvme_transport.c/nvme_transport_ut.c new file mode 100644 index 000000000..b31d8c219 --- /dev/null +++ b/test/unit/lib/nvme/nvme_transport.c/nvme_transport_ut.c @@ -0,0 +1,89 @@ +/*- + * BSD LICENSE + * + * Copyright (c) Intel Corporation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "spdk/stdinc.h" +#include "spdk_cunit.h" +#include "nvme/nvme_transport.c" +#include "common/lib/test_env.c" + +SPDK_LOG_REGISTER_COMPONENT(nvme) + +DEFINE_STUB(nvme_poll_group_connect_qpair, int, (struct spdk_nvme_qpair *qpair), 0); +DEFINE_STUB_V(nvme_qpair_abort_reqs, (struct spdk_nvme_qpair *qpair, uint32_t dnr)); +DEFINE_STUB(nvme_poll_group_disconnect_qpair, int, (struct spdk_nvme_qpair *qpair), 0); +DEFINE_STUB(spdk_nvme_ctrlr_free_io_qpair, int, (struct spdk_nvme_qpair *qpair), 0); +DEFINE_STUB(spdk_nvme_transport_id_trtype_str, const char *, + (enum spdk_nvme_transport_type trtype), NULL); + +static void +ut_construct_transport(struct spdk_nvme_transport *transport, const char name[]) +{ + memcpy(transport->ops.name, name, strlen(name)); + TAILQ_INSERT_TAIL(&g_spdk_nvme_transports, transport, link); +} + +static void +test_nvme_get_transport(void) +{ + const struct spdk_nvme_transport *nvme_transport = NULL; + struct spdk_nvme_transport new_transport = {}; + + ut_construct_transport(&new_transport, "new_transport"); + + nvme_transport = nvme_get_transport("new_transport"); + CU_ASSERT(nvme_transport == &new_transport); + TAILQ_REMOVE(&g_spdk_nvme_transports, nvme_transport, link); + CU_ASSERT(TAILQ_EMPTY(&g_spdk_nvme_transports)); + + /* Unavailable transport entry */ + nvme_transport = nvme_get_transport("new_transport"); + SPDK_CU_ASSERT_FATAL(nvme_transport == NULL); +} + +int main(int argc, char **argv) +{ + CU_pSuite suite = NULL; + unsigned int num_failures; + + CU_set_error_action(CUEA_ABORT); + CU_initialize_registry(); + + suite = CU_add_suite("nvme_transport", NULL, NULL); + CU_ADD_TEST(suite, test_nvme_get_transport); + + CU_basic_set_mode(CU_BRM_VERBOSE); + CU_basic_run_tests(); + num_failures = CU_get_number_of_failures(); + CU_cleanup_registry(); + return num_failures; +} diff --git a/test/unit/unittest.sh b/test/unit/unittest.sh index 46bc4db1a..90eac5fb1 100755 --- a/test/unit/unittest.sh +++ b/test/unit/unittest.sh @@ -84,6 +84,7 @@ function unittest_nvme() { $valgrind $testdir/lib/nvme/nvme_quirks.c/nvme_quirks_ut $valgrind $testdir/lib/nvme/nvme_tcp.c/nvme_tcp_ut $valgrind $testdir/lib/nvme/nvme_uevent.c/nvme_uevent_ut + $valgrind $testdir/lib/nvme/nvme_transport.c/nvme_transport_ut } function unittest_nvmf() {