/*- * 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 "spdk_internal/mock.h" #include "ctrlr.c" SPDK_LOG_REGISTER_COMPONENT("nvmf", SPDK_LOG_NVMF) DEFINE_STUB(spdk_nvmf_tgt_find_subsystem, struct spdk_nvmf_subsystem *, (struct spdk_nvmf_tgt *tgt, const char *subnqn), NULL) DEFINE_STUB(spdk_nvmf_poll_group_create, struct spdk_nvmf_poll_group *, (struct spdk_nvmf_tgt *tgt), NULL) DEFINE_STUB_V(spdk_nvmf_poll_group_destroy, (struct spdk_nvmf_poll_group *group)) DEFINE_STUB_V(spdk_nvmf_transport_qpair_fini, (struct spdk_nvmf_qpair *qpair)) DEFINE_STUB(spdk_nvmf_poll_group_add, int, (struct spdk_nvmf_poll_group *group, struct spdk_nvmf_qpair *qpair), 0) DEFINE_STUB(spdk_nvmf_poll_group_remove, int, (struct spdk_nvmf_poll_group *group, struct spdk_nvmf_qpair *qpair), 0) DEFINE_STUB(spdk_nvmf_subsystem_get_sn, const char *, (const struct spdk_nvmf_subsystem *subsystem), NULL) DEFINE_STUB(spdk_nvmf_subsystem_get_ns, struct spdk_nvmf_ns *, (struct spdk_nvmf_subsystem *subsystem, uint32_t nsid), NULL) DEFINE_STUB(spdk_nvmf_subsystem_get_first_ns, struct spdk_nvmf_ns *, (struct spdk_nvmf_subsystem *subsystem), NULL) DEFINE_STUB(spdk_nvmf_subsystem_get_next_ns, struct spdk_nvmf_ns *, (struct spdk_nvmf_subsystem *subsystem, struct spdk_nvmf_ns *prev_ns), NULL) DEFINE_STUB(spdk_nvmf_subsystem_host_allowed, bool, (struct spdk_nvmf_subsystem *subsystem, const char *hostnqn), true) DEFINE_STUB(spdk_nvmf_subsystem_add_ctrlr, int, (struct spdk_nvmf_subsystem *subsystem, struct spdk_nvmf_ctrlr *ctrlr), 0) DEFINE_STUB_V(spdk_nvmf_subsystem_remove_ctrlr, (struct spdk_nvmf_subsystem *subsystem, struct spdk_nvmf_ctrlr *ctrlr)) DEFINE_STUB(spdk_nvmf_subsystem_get_ctrlr, struct spdk_nvmf_ctrlr *, (struct spdk_nvmf_subsystem *subsystem, uint16_t cntlid), NULL) DEFINE_STUB(spdk_nvmf_ctrlr_dsm_supported, bool, (struct spdk_nvmf_ctrlr *ctrlr), false) DEFINE_STUB(spdk_nvmf_ctrlr_write_zeroes_supported, bool, (struct spdk_nvmf_ctrlr *ctrlr), false) DEFINE_STUB(spdk_nvmf_bdev_ctrlr_identify_ns, int, (struct spdk_bdev *bdev, struct spdk_nvme_ns_data *nsdata), -1) DEFINE_STUB_V(spdk_nvmf_get_discovery_log_page, (struct spdk_nvmf_tgt *tgt, void *buffer, uint64_t offset, uint32_t length)) DEFINE_STUB(spdk_nvmf_request_complete, int, (struct spdk_nvmf_request *req), -1) DEFINE_STUB(spdk_nvmf_request_abort, int, (struct spdk_nvmf_request *req), -1) static void test_get_log_page(void) { struct spdk_nvmf_subsystem subsystem = {}; struct spdk_nvmf_request req = {}; struct spdk_nvmf_qpair qpair = {}; struct spdk_nvmf_ctrlr ctrlr = {}; union nvmf_h2c_msg cmd = {}; union nvmf_c2h_msg rsp = {}; char data[4096]; subsystem.subtype = SPDK_NVMF_SUBTYPE_NVME; ctrlr.subsys = &subsystem; qpair.ctrlr = &ctrlr; req.qpair = &qpair; req.cmd = &cmd; req.rsp = &rsp; req.data = &data; req.length = sizeof(data); /* Get Log Page - all valid */ memset(&cmd, 0, sizeof(cmd)); memset(&rsp, 0, sizeof(rsp)); cmd.nvme_cmd.opc = SPDK_NVME_OPC_GET_LOG_PAGE; cmd.nvme_cmd.cdw10 = SPDK_NVME_LOG_ERROR | (req.length / 4 - 1) << 16; CU_ASSERT(spdk_nvmf_ctrlr_get_log_page(&req) == SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE); CU_ASSERT(req.rsp->nvme_cpl.status.sct == SPDK_NVME_SCT_GENERIC); CU_ASSERT(req.rsp->nvme_cpl.status.sc == SPDK_NVME_SC_SUCCESS); /* Get Log Page with invalid log ID */ memset(&cmd, 0, sizeof(cmd)); memset(&rsp, 0, sizeof(rsp)); cmd.nvme_cmd.opc = SPDK_NVME_OPC_GET_LOG_PAGE; cmd.nvme_cmd.cdw10 = 0; CU_ASSERT(spdk_nvmf_ctrlr_get_log_page(&req) == SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE); CU_ASSERT(req.rsp->nvme_cpl.status.sct == SPDK_NVME_SCT_GENERIC); CU_ASSERT(req.rsp->nvme_cpl.status.sc == SPDK_NVME_SC_INVALID_FIELD); /* Get Log Page with invalid offset (not dword aligned) */ memset(&cmd, 0, sizeof(cmd)); memset(&rsp, 0, sizeof(rsp)); cmd.nvme_cmd.opc = SPDK_NVME_OPC_GET_LOG_PAGE; cmd.nvme_cmd.cdw10 = SPDK_NVME_LOG_ERROR | (req.length / 4 - 1) << 16; cmd.nvme_cmd.cdw12 = 2; CU_ASSERT(spdk_nvmf_ctrlr_get_log_page(&req) == SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE); CU_ASSERT(req.rsp->nvme_cpl.status.sct == SPDK_NVME_SCT_GENERIC); CU_ASSERT(req.rsp->nvme_cpl.status.sc == SPDK_NVME_SC_INVALID_FIELD); /* Get Log Page without data buffer */ memset(&cmd, 0, sizeof(cmd)); memset(&rsp, 0, sizeof(rsp)); req.data = NULL; cmd.nvme_cmd.opc = SPDK_NVME_OPC_GET_LOG_PAGE; cmd.nvme_cmd.cdw10 = SPDK_NVME_LOG_ERROR | (req.length / 4 - 1) << 16; CU_ASSERT(spdk_nvmf_ctrlr_get_log_page(&req) == SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE); CU_ASSERT(req.rsp->nvme_cpl.status.sct == SPDK_NVME_SCT_GENERIC); CU_ASSERT(req.rsp->nvme_cpl.status.sc == SPDK_NVME_SC_INVALID_FIELD); req.data = data; } static void test_process_fabrics_cmd(void) { struct spdk_nvmf_request req = {}; int ret; struct spdk_nvmf_qpair req_qpair = {}; union nvmf_h2c_msg req_cmd = {}; union nvmf_c2h_msg req_rsp = {}; req.qpair = &req_qpair; req.cmd = &req_cmd; req.rsp = &req_rsp; req.qpair->ctrlr = NULL; /* No ctrlr and invalid command check */ req.cmd->nvmf_cmd.fctype = SPDK_NVMF_FABRIC_COMMAND_PROPERTY_GET; ret = spdk_nvmf_ctrlr_process_fabrics_cmd(&req); CU_ASSERT_EQUAL(req.rsp->nvme_cpl.status.sc, SPDK_NVME_SC_COMMAND_SEQUENCE_ERROR); CU_ASSERT_EQUAL(ret, SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE); } 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("nvmf", NULL, NULL); if (suite == NULL) { CU_cleanup_registry(); return CU_get_error(); } if ( CU_add_test(suite, "get_log_page", test_get_log_page) == NULL || CU_add_test(suite, "process_fabrics_cmd", test_process_fabrics_cmd) == 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; }