diff --git a/test/unit/lib/vhost/Makefile b/test/unit/lib/vhost/Makefile index baabb6d39..0f569f6d2 100644 --- a/test/unit/lib/vhost/Makefile +++ b/test/unit/lib/vhost/Makefile @@ -34,7 +34,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../../..) include $(SPDK_ROOT_DIR)/mk/spdk.common.mk -DIRS-y = vhost.c vhost_scsi.c vhost_blk.c vhost_nvme.c +DIRS-y = vhost.c .PHONY: all clean $(DIRS-y) diff --git a/test/unit/lib/vhost/vhost_blk.c/.gitignore b/test/unit/lib/vhost/vhost_blk.c/.gitignore deleted file mode 100644 index 85cd88dfc..000000000 --- a/test/unit/lib/vhost/vhost_blk.c/.gitignore +++ /dev/null @@ -1 +0,0 @@ -vhost_blk_ut diff --git a/test/unit/lib/vhost/vhost_blk.c/Makefile b/test/unit/lib/vhost/vhost_blk.c/Makefile deleted file mode 100644 index 359e71975..000000000 --- a/test/unit/lib/vhost/vhost_blk.c/Makefile +++ /dev/null @@ -1,42 +0,0 @@ -# -# 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)/../../../../..) -include $(SPDK_ROOT_DIR)/mk/spdk.common.mk -include $(SPDK_ROOT_DIR)/mk/spdk.app.mk - -CFLAGS += -I$(SPDK_ROOT_DIR)/lib/vhost/rte_vhost -CFLAGS += $(ENV_CFLAGS) -TEST_FILE = vhost_blk_ut.c - -include $(SPDK_ROOT_DIR)/mk/spdk.unittest.mk diff --git a/test/unit/lib/vhost/vhost_blk.c/vhost_blk_ut.c b/test/unit/lib/vhost/vhost_blk.c/vhost_blk_ut.c deleted file mode 100644 index 483bb02da..000000000 --- a/test/unit/lib/vhost/vhost_blk.c/vhost_blk_ut.c +++ /dev/null @@ -1,198 +0,0 @@ -/*- - * BSD LICENSE - * - * Copyright(c) Intel Corporation. All rights reserved. - * 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 "CUnit/Basic.h" -#include "spdk_cunit.h" -#include "spdk_internal/mock.h" -#include "common/lib/test_env.c" - -#include "vhost/vhost_blk.c" -#include "unit/lib/vhost/test_vhost.c" - -#include "spdk/bdev_module.h" -#include "spdk/env.h" - -DEFINE_STUB_V(spdk_bdev_free_io, (struct spdk_bdev_io *bdev_io)); -DEFINE_STUB(spdk_bdev_readv, int, (struct spdk_bdev_desc *desc, struct spdk_io_channel *ch, - struct iovec *iov, int iovcnt, uint64_t offset, uint64_t nbytes, spdk_bdev_io_completion_cb cb, - void *cb_arg), 0); -DEFINE_STUB(spdk_bdev_writev, int, (struct spdk_bdev_desc *desc, struct spdk_io_channel *ch, - struct iovec *iov, int iovcnt, uint64_t offset, uint64_t len, spdk_bdev_io_completion_cb cb, - void *cb_arg), 0); -DEFINE_STUB_P(spdk_bdev_get_product_name, const char, (const struct spdk_bdev *bdev), {0}); -DEFINE_STUB_P(spdk_bdev_get_name, const char, (const struct spdk_bdev *bdev), {0}); -DEFINE_STUB_P(spdk_conf_section_get_val, char, (struct spdk_conf_section *sp, const char *key), {0}); -DEFINE_STUB_P(spdk_bdev_get_by_name, struct spdk_bdev, (const char *bdev_name), {0}); -DEFINE_STUB(spdk_bdev_open, int, (struct spdk_bdev *bdev, bool write, - spdk_bdev_remove_cb_t remove_cb, void *remove_ctx, struct spdk_bdev_desc **desc), 0); -DEFINE_STUB_V(spdk_bdev_close, (struct spdk_bdev_desc *desc)); -DEFINE_STUB(rte_vhost_driver_enable_features, int, (const char *path, uint64_t features), 0); -DEFINE_STUB_P(spdk_bdev_get_io_channel, struct spdk_io_channel, (struct spdk_bdev_desc *desc), {0}); -DEFINE_STUB(spdk_bdev_get_block_size, uint32_t, (const struct spdk_bdev *bdev), 512); -DEFINE_STUB(spdk_bdev_get_num_blocks, uint64_t, (const struct spdk_bdev *bdev), 0x1); -DEFINE_STUB(spdk_bdev_has_write_cache, bool, (const struct spdk_bdev *bdev), false); - -SPDK_LOG_REGISTER_COMPONENT("vhost", SPDK_LOG_VHOST) - -static void -vhost_blk_controller_construct_test(void) -{ - int rc; - - MOCK_SET_P(spdk_conf_next_section, struct spdk_conf_section *, NULL); - - /* VhostBlk section has non numeric suffix */ - MOCK_SET(spdk_conf_section_match_prefix, bool, true); - MOCK_SET_P(spdk_conf_section_get_name, const char *, "VhostBlkx"); - rc = spdk_vhost_blk_controller_construct(); - CU_ASSERT(rc != 0); - - /* Device has no name */ - MOCK_SET_P(spdk_conf_section_get_name, const char *, "VhostBlk0"); - MOCK_SET_P(spdk_conf_section_get_val, char *, NULL); - rc = spdk_vhost_blk_controller_construct(); - CU_ASSERT(rc != 0); -} - -static struct spdk_vhost_blk_dev * -alloc_bvdev(void) -{ - struct spdk_vhost_blk_dev *bvdev = spdk_dma_zmalloc(sizeof(struct spdk_vhost_blk_dev), - SPDK_CACHE_LINE_SIZE, NULL); - - SPDK_CU_ASSERT_FATAL(bvdev != NULL); - bvdev->vdev.backend = &vhost_blk_device_backend; - return bvdev; -} - -static void -vhost_blk_construct_test(void) -{ - int rc; - struct spdk_bdev *ut_p_spdk_bdev = MOCK_PASS_THRU_P; - - MOCK_SET(spdk_vhost_dev_unregister_fail, bool, false); - MOCK_SET(spdk_vhost_dev_register_fail, bool, false); - - /* Create device with invalid name */ - MOCK_SET_P(spdk_bdev_get_by_name, struct spdk_bdev *, NULL); - rc = spdk_vhost_blk_construct("vhost.0", "0x1", NULL, true); - CU_ASSERT(rc != 0); - - /* Device could not be opened */ - MOCK_SET_P(spdk_bdev_get_by_name, struct spdk_bdev *, ut_p_spdk_bdev); - MOCK_SET(spdk_bdev_open, int, -ENOMEM); - rc = spdk_vhost_blk_construct("vhost.0", "0x1", "Malloc0", true); - CU_ASSERT(rc != 0); - - /* Failed to construct controller */ - MOCK_SET(spdk_bdev_open, int, 0); - MOCK_SET(spdk_vhost_dev_register_fail, bool, true); - rc = spdk_vhost_blk_construct("vhost.0", "0x1", "Malloc0", true); - CU_ASSERT(rc != 0); - - /* Failed to set readonly as a feature */ - MOCK_SET(rte_vhost_driver_enable_features, int, -1); - rc = spdk_vhost_blk_construct("vhost.0", "0x1", "Malloc0", true); - CU_ASSERT(rc != 0); - - /* Failed to set readonly as a feature and failed to remove controller */ - MOCK_SET(spdk_vhost_dev_unregister_fail, bool, true); - rc = spdk_vhost_blk_construct("vhost.0", "0x1", "Malloc0", true); - CU_ASSERT(rc != 0); -} - -static void -vhost_blk_destroy_test(void) -{ - int rc; - struct spdk_vhost_blk_dev *bvdev = NULL; - - bvdev = alloc_bvdev(); - - /* Device has an incorrect type */ - bvdev->vdev.backend = NULL;; - rc = spdk_vhost_blk_destroy(&bvdev->vdev); - CU_ASSERT(rc == -EINVAL); - - /* Failed to remove device */ - bvdev->vdev.backend = &vhost_blk_device_backend; - MOCK_SET(spdk_vhost_dev_unregister_fail, bool, true); - rc = spdk_vhost_blk_destroy(&bvdev->vdev); - CU_ASSERT(rc == -1); - - if (rc != 0) { - free(bvdev); - } -} - -static int -test_setup(void) -{ - return 0; -} - -int -main(int argc, char **argv) -{ - CU_pSuite suite = NULL; - unsigned int num_failures; - - if (CU_initialize_registry() != CUE_SUCCESS) { - return CU_get_error(); - } - - suite = CU_add_suite("vhost_blk_suite", test_setup, NULL); - if (suite == NULL) { - CU_cleanup_registry(); - return CU_get_error(); - } - - if ( - CU_add_test(suite, "vhost_blk_controller_construct", vhost_blk_controller_construct_test) == NULL || - CU_add_test(suite, "vhost_blk_construct_test", vhost_blk_construct_test) == NULL || - CU_add_test(suite, "vhost_blk_destroy", vhost_blk_destroy_test) == NULL - ) { - CU_cleanup_registry(); - return CU_get_error(); - } - - 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/lib/vhost/vhost_nvme.c/.gitignore b/test/unit/lib/vhost/vhost_nvme.c/.gitignore deleted file mode 100644 index abc3a09cc..000000000 --- a/test/unit/lib/vhost/vhost_nvme.c/.gitignore +++ /dev/null @@ -1 +0,0 @@ -vhost_nvme_ut diff --git a/test/unit/lib/vhost/vhost_nvme.c/Makefile b/test/unit/lib/vhost/vhost_nvme.c/Makefile deleted file mode 100644 index 5f91f580e..000000000 --- a/test/unit/lib/vhost/vhost_nvme.c/Makefile +++ /dev/null @@ -1,42 +0,0 @@ -# -# 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)/../../../../..) -include $(SPDK_ROOT_DIR)/mk/spdk.common.mk -include $(SPDK_ROOT_DIR)/mk/spdk.app.mk - -CFLAGS += -I$(SPDK_ROOT_DIR)/lib/vhost/rte_vhost -CFLAGS += $(ENV_CFLAGS) -TEST_FILE = vhost_nvme_ut.c - -include $(SPDK_ROOT_DIR)/mk/spdk.unittest.mk diff --git a/test/unit/lib/vhost/vhost_nvme.c/vhost_nvme_ut.c b/test/unit/lib/vhost/vhost_nvme.c/vhost_nvme_ut.c deleted file mode 100644 index 4cee930c0..000000000 --- a/test/unit/lib/vhost/vhost_nvme.c/vhost_nvme_ut.c +++ /dev/null @@ -1,151 +0,0 @@ -/*- - * BSD LICENSE - * - * Copyright(c) Intel Corporation. All rights reserved. - * 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 "CUnit/Basic.h" -#include "spdk_cunit.h" -#include "spdk_internal/mock.h" -#include "common/lib/test_env.c" - -#include "vhost/vhost_nvme.c" -#include "unit/lib/vhost/test_vhost.c" - -#include "spdk/bdev_module.h" -#include "spdk/env.h" - - -DEFINE_STUB_V(spdk_bdev_free_io, (struct spdk_bdev_io *bdev_io)); -DEFINE_STUB(spdk_bdev_readv, int, (struct spdk_bdev_desc *desc, struct spdk_io_channel *ch, - struct iovec *iov, int iovcnt, uint64_t offset, uint64_t nbytes, spdk_bdev_io_completion_cb cb, - void *cb_arg), 0); -DEFINE_STUB(spdk_bdev_writev, int, (struct spdk_bdev_desc *desc, struct spdk_io_channel *ch, - struct iovec *iov, int iovcnt, uint64_t offset, uint64_t len, spdk_bdev_io_completion_cb cb, - void *cb_arg), 0); -DEFINE_STUB_P(spdk_bdev_get_product_name, const char, (const struct spdk_bdev *bdev), {0}); -DEFINE_STUB_P(spdk_bdev_get_name, const char, (const struct spdk_bdev *bdev), {0}); -DEFINE_STUB_P(spdk_conf_section_get_val, char, (struct spdk_conf_section *sp, const char *key), {0}); -DEFINE_STUB_P(spdk_bdev_get_by_name, struct spdk_bdev, (const char *bdev_name), {0}); -DEFINE_STUB(spdk_bdev_open, int, (struct spdk_bdev *bdev, bool write, - spdk_bdev_remove_cb_t remove_cb, void *remove_ctx, struct spdk_bdev_desc **desc), 0); -DEFINE_STUB_V(spdk_bdev_close, (struct spdk_bdev_desc *desc)); -DEFINE_STUB(rte_vhost_driver_enable_features, int, (const char *path, uint64_t features), 0); -DEFINE_STUB_P(spdk_bdev_get_io_channel, struct spdk_io_channel, (struct spdk_bdev_desc *desc), {0}); -DEFINE_STUB(spdk_bdev_get_block_size, uint32_t, (const struct spdk_bdev *bdev), 512); -DEFINE_STUB(spdk_bdev_get_num_blocks, uint64_t, (const struct spdk_bdev *bdev), 0x1); -DEFINE_STUB(spdk_bdev_has_write_cache, bool, (const struct spdk_bdev *bdev), false); -DEFINE_STUB(spdk_bdev_unmap, int, (struct spdk_bdev_desc *desc, struct spdk_io_channel *ch, - uint64_t offset, uint64_t nbytes, spdk_bdev_io_completion_cb cb, void *cb_arg), 0); -DEFINE_STUB(spdk_bdev_flush, int, (struct spdk_bdev_desc *desc, struct spdk_io_channel *ch, - uint64_t offset, uint64_t length, spdk_bdev_io_completion_cb cb, void *cb_arg), 0); -DEFINE_STUB(spdk_bdev_get_optimal_io_boundary, uint32_t, (const struct spdk_bdev *bdev), 512); -DEFINE_STUB(spdk_conf_section_get_intval, int, (struct spdk_conf_section *sp, const char *key), 0); -DEFINE_STUB_V(spdk_bdev_io_get_nvme_status, (const struct spdk_bdev_io *bdev_io, int *sct, int *sc)) -DEFINE_STUB(spdk_conf_section_get_nval, char *, - (struct spdk_conf_section *sp, const char *key, int idx), NULL); - -SPDK_LOG_REGISTER_COMPONENT("vhost", SPDK_LOG_VHOST) - -static void -vhost_nvme_controller_construct_test(void) -{ - int rc; - - MOCK_SET_P(spdk_conf_next_section, struct spdk_conf_section *, NULL); - - /* VhostNvme section has non numeric suffix */ - MOCK_SET(spdk_conf_section_match_prefix, bool, true); - MOCK_SET_P(spdk_conf_section_get_name, const char *, "VhostNvmex"); - rc = spdk_vhost_nvme_controller_construct(); - CU_ASSERT(rc != 0); - - /* Device has no name */ - MOCK_SET_P(spdk_conf_section_get_name, const char *, "VhostNvme0"); - MOCK_SET_P(spdk_conf_section_get_val, char *, NULL); - rc = spdk_vhost_nvme_controller_construct(); - CU_ASSERT(rc != 0); -} - -static void -vhost_nvme_dev_construct_test(void) -{ - int rc; - - /* Failed to construct vhost device */ - MOCK_SET(spdk_vhost_dev_register_fail, bool, true); - rc = spdk_vhost_nvme_dev_construct("vhost.0", "0x1", 4); - CU_ASSERT(rc != 0); - - /* Bigger num_io_queues */ - rc = spdk_vhost_nvme_dev_construct("vhost.0", "0x1", MAX_IO_QUEUES + 1); - CU_ASSERT(rc != 0); -} - -static int -test_setup(void) -{ - return 0; -} - -int -main(int argc, char **argv) -{ - CU_pSuite suite = NULL; - unsigned int num_failures; - - if (CU_initialize_registry() != CUE_SUCCESS) { - return CU_get_error(); - } - - suite = CU_add_suite("vhost_nvme_suite", test_setup, NULL); - if (suite == NULL) { - CU_cleanup_registry(); - return CU_get_error(); - } - - if ( - CU_add_test(suite, "vhost_nvme_controller_construct", - vhost_nvme_controller_construct_test) == NULL || - CU_add_test(suite, "vhost_nvme_dev_construct", vhost_nvme_dev_construct_test) == NULL - ) { - CU_cleanup_registry(); - return CU_get_error(); - } - - 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/lib/vhost/vhost_scsi.c/.gitignore b/test/unit/lib/vhost/vhost_scsi.c/.gitignore deleted file mode 100644 index dc775ea32..000000000 --- a/test/unit/lib/vhost/vhost_scsi.c/.gitignore +++ /dev/null @@ -1 +0,0 @@ -vhost_scsi_ut diff --git a/test/unit/lib/vhost/vhost_scsi.c/Makefile b/test/unit/lib/vhost/vhost_scsi.c/Makefile deleted file mode 100644 index 3b8a59b08..000000000 --- a/test/unit/lib/vhost/vhost_scsi.c/Makefile +++ /dev/null @@ -1,42 +0,0 @@ -# -# 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)/../../../../..) -include $(SPDK_ROOT_DIR)/mk/spdk.common.mk -include $(SPDK_ROOT_DIR)/mk/spdk.app.mk - -CFLAGS += -I$(SPDK_ROOT_DIR)/lib/vhost/rte_vhost -CFLAGS += $(ENV_CFLAGS) -TEST_FILE = vhost_scsi_ut.c - -include $(SPDK_ROOT_DIR)/mk/spdk.unittest.mk diff --git a/test/unit/lib/vhost/vhost_scsi.c/vhost_scsi_ut.c b/test/unit/lib/vhost/vhost_scsi.c/vhost_scsi_ut.c deleted file mode 100644 index 0865dc2d5..000000000 --- a/test/unit/lib/vhost/vhost_scsi.c/vhost_scsi_ut.c +++ /dev/null @@ -1,307 +0,0 @@ -/*- - * BSD LICENSE - * - * Copyright(c) Intel Corporation. All rights reserved. - * 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 "CUnit/Basic.h" -#include "spdk_cunit.h" -#include "spdk_internal/mock.h" -#include "common/lib/test_env.c" - -#include "spdk/scsi.h" -#include "vhost/vhost_scsi.c" -#include "scsi/scsi_internal.h" -#include "unit/lib/vhost/test_vhost.c" - -#include "spdk/env.h" - -DEFINE_STUB_V(spdk_scsi_task_put, (struct spdk_scsi_task *task)); -DEFINE_STUB(spdk_scsi_dev_allocate_io_channels, int, (struct spdk_scsi_dev *dev), 0); -DEFINE_STUB_P(spdk_scsi_lun_get_bdev_name, const char, (const struct spdk_scsi_lun *lun), {0}); -DEFINE_STUB(spdk_scsi_lun_get_id, int, (const struct spdk_scsi_lun *lun), 0); -DEFINE_STUB(spdk_scsi_dev_has_pending_tasks, bool, (const struct spdk_scsi_dev *dev), false); -DEFINE_STUB_V(spdk_scsi_dev_free_io_channels, (struct spdk_scsi_dev *dev)); -DEFINE_STUB_V(spdk_scsi_dev_destruct, (struct spdk_scsi_dev *dev)); -DEFINE_STUB_V(spdk_scsi_dev_queue_task, (struct spdk_scsi_dev *dev, struct spdk_scsi_task *task)); -DEFINE_STUB_V(spdk_scsi_dev_queue_mgmt_task, (struct spdk_scsi_dev *dev, - struct spdk_scsi_task *task, enum spdk_scsi_task_func func)); -DEFINE_STUB_P(spdk_scsi_dev_find_port_by_id, struct spdk_scsi_port, (struct spdk_scsi_dev *dev, - uint64_t id), {0}); -DEFINE_STUB_V(spdk_scsi_task_construct, (struct spdk_scsi_task *task, spdk_scsi_task_cpl cpl_fn, - spdk_scsi_task_free free_fn)); -DEFINE_STUB_P(spdk_scsi_dev_get_lun, struct spdk_scsi_lun, (struct spdk_scsi_dev *dev, int lun_id), {0}); -DEFINE_STUB_V(spdk_scsi_task_process_null_lun, (struct spdk_scsi_task *task)); -DEFINE_STUB_P(spdk_scsi_lun_get_dev, const struct spdk_scsi_dev, (const struct spdk_scsi_lun *lun), {0}); -DEFINE_STUB_P(spdk_scsi_dev_get_name, const char, (const struct spdk_scsi_dev *dev), {0}); -DEFINE_STUB_P(spdk_scsi_dev_construct, struct spdk_scsi_dev, (const char *name, - const char *bdev_name_list[], int *lun_id_list, int num_luns, uint8_t protocol_id, - void (*hotremove_cb)(const struct spdk_scsi_lun *, void *), void *hotremove_ctx), {0}); -DEFINE_STUB(spdk_scsi_dev_add_port, int, (struct spdk_scsi_dev *dev, uint64_t id, const char *name), - 0); - -SPDK_LOG_REGISTER_COMPONENT("vhost", SPDK_LOG_VHOST) - -char * -spdk_conf_section_get_nval(struct spdk_conf_section *sp, const char *key, int idx) -{ - if (idx == 0) { - return "0"; - } - - return NULL; -} - -char * -spdk_conf_section_get_val(struct spdk_conf_section *sp, const char *key) -{ - if (strcmp(key, "Name") == 0) { - return "Vhost.0"; - } else if (strcmp(key, "Cpumask") == 0) { - return "0x1"; - } - - return NULL; -} - -static int -test_setup(void) -{ - return 0; -} - -static struct spdk_vhost_scsi_dev * -alloc_svdev(void) -{ - struct spdk_vhost_scsi_dev *svdev = spdk_dma_zmalloc(sizeof(struct spdk_vhost_scsi_dev), - SPDK_CACHE_LINE_SIZE, NULL); - - SPDK_CU_ASSERT_FATAL(svdev != NULL); - svdev->vdev.registered = true; - svdev->vdev.backend = &spdk_vhost_scsi_device_backend; - return svdev; -} - -static struct spdk_scsi_dev * -alloc_scsi_dev(void) -{ - struct spdk_scsi_dev *sdev; - - sdev = calloc(1, sizeof(*sdev)); - return sdev; -} - -static void -vhost_scsi_controller_construct_test(void) -{ - int rc; - - MOCK_SET_P(spdk_conf_next_section, struct spdk_conf_section *, NULL); - - /* VhostScsi section has non numeric suffix */ - MOCK_SET(spdk_conf_section_match_prefix, bool, true); - MOCK_SET_P(spdk_conf_section_get_name, const char *, "VhostScsix"); - rc = spdk_vhost_scsi_controller_construct(); - CU_ASSERT(rc != 0); - - /* Dev number has no value */ - MOCK_SET_P(spdk_conf_section_get_name, const char *, "VhostScsi0"); - MOCK_SET_P(spdk_conf_section_get_nmval, char *, NULL); - rc = spdk_vhost_scsi_controller_construct(); - CU_ASSERT(rc != 0); - /* - * Expecting that device has been created during the test but wasn't initialized as - * spdk_vhost_scsi_controller_construct failed after creating device - */ - CU_ASSERT(g_spdk_vhost_device != NULL); - - /* Remove created device */ - MOCK_SET(spdk_vhost_dev_unregister_fail, bool, false); - rc = spdk_vhost_scsi_dev_remove(g_spdk_vhost_device); - CU_ASSERT(rc == 0); -} - -static void -vhost_scsi_dev_remove_test(void) -{ - int rc; - struct spdk_vhost_scsi_dev *svdev = NULL; - struct spdk_scsi_dev *scsi_dev; - - MOCK_SET(spdk_vhost_dev_unregister_fail, bool, false); - - /* Try to remove controller which is occupied */ - svdev = alloc_svdev(); - scsi_dev = alloc_scsi_dev(); - svdev->scsi_dev[0] = scsi_dev; - rc = spdk_vhost_scsi_dev_remove(&svdev->vdev); - CU_ASSERT(rc == -EBUSY); - free(scsi_dev); - svdev->scsi_dev[0] = NULL; - - /* Failed to remove device */ - MOCK_SET(spdk_vhost_dev_unregister_fail, bool, true); - rc = spdk_vhost_scsi_dev_remove(&svdev->vdev); - CU_ASSERT(rc == -1); - - free(svdev); -} - -static void -vhost_scsi_dev_construct_test(void) -{ - int rc; - - /* Failed to construct vhost device */ - MOCK_SET(spdk_vhost_dev_register_fail, bool, true); - rc = spdk_vhost_scsi_dev_construct("vhost.0", "0x1"); - CU_ASSERT(rc != 0); -} - -static void -vhost_scsi_dev_remove_dev_test(void) -{ - int rc; - struct spdk_vhost_scsi_dev *svdev; - struct spdk_scsi_dev *scsi_dev; - - svdev = alloc_svdev(); - svdev->vdev.name = strdup("vhost.0"); - - /* Invalid device number */ - rc = spdk_vhost_scsi_dev_remove_tgt(&svdev->vdev, SPDK_VHOST_SCSI_CTRLR_MAX_DEVS + 1, NULL, - NULL); - CU_ASSERT(rc == -EINVAL); - - /* Try to remove nonexistent device */ - rc = spdk_vhost_scsi_dev_remove_tgt(&svdev->vdev, 0, NULL, NULL); - CU_ASSERT(rc == -ENODEV); - - /* Try to remove device when controller is in use */ - svdev->vdev.lcore = 0; - scsi_dev = alloc_scsi_dev(); - svdev->scsi_dev[0] = scsi_dev; - rc = spdk_vhost_scsi_dev_remove_tgt(&svdev->vdev, 0, NULL, NULL); - CU_ASSERT(rc == -ENOTSUP); - free(scsi_dev); - free(svdev->vdev.name); - free(svdev); -} - -static void -vhost_scsi_dev_add_dev_test(void) -{ - int rc; - char long_name[SPDK_SCSI_DEV_MAX_NAME + 1]; - struct spdk_vhost_scsi_dev *svdev; - struct spdk_vhost_dev *vdev; - struct spdk_scsi_dev *scsi_dev; - - /* Add device to controller without name */ - rc = spdk_vhost_scsi_dev_add_tgt(NULL, 0, "Malloc0"); - CU_ASSERT(rc == -EINVAL); - - svdev = alloc_svdev(); - vdev = &svdev->vdev; - - /* Add device when max devices is reached */ - rc = spdk_vhost_scsi_dev_add_tgt(vdev, - SPDK_VHOST_SCSI_CTRLR_MAX_DEVS + 1, "Malloc0"); - CU_ASSERT(rc == -EINVAL); - - /* Add device but lun has no name */ - rc = spdk_vhost_scsi_dev_add_tgt(vdev, 0, NULL); - CU_ASSERT(rc == -EINVAL); - - /* Add device but lun has too long name */ - memset(long_name, 'x', sizeof(long_name)); - long_name[SPDK_SCSI_DEV_MAX_NAME] = 0; - rc = spdk_vhost_scsi_dev_add_tgt(vdev, 0, long_name); - CU_ASSERT(rc != 0); - - /* Add device to a controller which is in use */ - svdev->vdev.lcore = 0; - rc = spdk_vhost_scsi_dev_add_tgt(vdev, 0, "Malloc0"); - CU_ASSERT(rc == -ENOTSUP); - - /* Add device to controller with already occupied device */ - vdev->lcore = -1; - scsi_dev = alloc_scsi_dev(); - svdev->scsi_dev[0] = scsi_dev; - rc = spdk_vhost_scsi_dev_add_tgt(vdev, 0, "Malloc0"); - CU_ASSERT(rc == -EEXIST); - free(scsi_dev); - svdev->scsi_dev[0] = NULL; - - /* Failed to create device */ - MOCK_SET_P(spdk_scsi_dev_construct, struct spdk_scsi_dev *, NULL); - rc = spdk_vhost_scsi_dev_add_tgt(vdev, 0, "Malloc0"); - CU_ASSERT(rc == -EINVAL); - - free(svdev); -} - -int -main(int argc, char **argv) -{ - CU_pSuite suite = NULL; - unsigned int num_failures; - - if (CU_initialize_registry() != CUE_SUCCESS) { - return CU_get_error(); - } - - suite = CU_add_suite("vhost_scsi_suite", test_setup, NULL); - if (suite == NULL) { - CU_cleanup_registry(); - return CU_get_error(); - } - - if ( - CU_add_test(suite, "vhost_scsi_controller_construct", - vhost_scsi_controller_construct_test) == NULL || - CU_add_test(suite, "vhost_scsi_dev_remove_dev", vhost_scsi_dev_remove_dev_test) == NULL || - CU_add_test(suite, "vhost_scsi_dev_remove", vhost_scsi_dev_remove_test) == NULL || - CU_add_test(suite, "vhost_scsi_dev_construct", vhost_scsi_dev_construct_test) == NULL || - CU_add_test(suite, "vhost_scsi_dev_add_dev", vhost_scsi_dev_add_dev_test) == NULL - ) { - CU_cleanup_registry(); - return CU_get_error(); - } - - 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 20c4942f7..7cd0a98da 100755 --- a/test/unit/unittest.sh +++ b/test/unit/unittest.sh @@ -119,9 +119,6 @@ $valgrind $testdir/lib/util/string.c/string_ut if [ $(uname -s) = Linux ]; then $valgrind $testdir/lib/vhost/vhost.c/vhost_ut -$valgrind $testdir/lib/vhost/vhost_scsi.c/vhost_scsi_ut -$valgrind $testdir/lib/vhost/vhost_blk.c/vhost_blk_ut -$valgrind $testdir/lib/vhost/vhost_nvme.c/vhost_nvme_ut fi # local unit test coverage