test/nvme_opal: build nvme_opal unittest file
Change-Id: I74bd112800f0d8369bc4d4b7a02080fe3e6cbd1c Signed-off-by: Mao Jiang <maox.jiang@intel.com> Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6695 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Community-CI: Mellanox Build Bot
This commit is contained in:
parent
6d93f9ef67
commit
e9d964bd3c
@ -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_transport.c nvme_io_msg.c nvme_pcie_common.c nvme_fabric.c \
|
||||
nvme_quirks.c nvme_tcp.c nvme_transport.c nvme_io_msg.c nvme_pcie_common.c nvme_fabric.c nvme_opal.c \
|
||||
|
||||
DIRS-$(CONFIG_RDMA) += nvme_rdma.c
|
||||
DIRS-$(CONFIG_NVME_CUSE) += nvme_cuse.c
|
||||
|
1
test/unit/lib/nvme/nvme_opal.c/.gitignore
vendored
Normal file
1
test/unit/lib/nvme/nvme_opal.c/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
nvme_opal_ut
|
38
test/unit/lib/nvme/nvme_opal.c/Makefile
Normal file
38
test/unit/lib/nvme/nvme_opal.c/Makefile
Normal file
@ -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_opal_ut.c
|
||||
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.unittest.mk
|
142
test/unit/lib/nvme/nvme_opal.c/nvme_opal_ut.c
Normal file
142
test/unit/lib/nvme/nvme_opal.c/nvme_opal_ut.c
Normal file
@ -0,0 +1,142 @@
|
||||
/*-
|
||||
* 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_opal.c"
|
||||
#include "common/lib/test_env.c"
|
||||
|
||||
SPDK_LOG_REGISTER_COMPONENT(nvme)
|
||||
|
||||
DEFINE_STUB(spdk_nvme_ctrlr_cmd_security_receive, int,
|
||||
(struct spdk_nvme_ctrlr *ctrlr, uint8_t secp, uint16_t spsp,
|
||||
uint8_t nssf, void *payload, uint32_t payload_size,
|
||||
spdk_nvme_cmd_cb cb_fn, void *cb_arg), 1);
|
||||
|
||||
DEFINE_STUB(spdk_nvme_ctrlr_security_receive, int,
|
||||
(struct spdk_nvme_ctrlr *ctrlr, uint8_t secp,
|
||||
uint16_t spsp, uint8_t nssf, void *payload, size_t size), 0);
|
||||
|
||||
DEFINE_STUB(spdk_nvme_ctrlr_process_admin_completions, int,
|
||||
(struct spdk_nvme_ctrlr *ctrlr), 0);
|
||||
|
||||
DEFINE_STUB(spdk_nvme_ctrlr_cmd_security_send, int,
|
||||
(struct spdk_nvme_ctrlr *ctrlr, uint8_t secp,
|
||||
uint16_t spsp, uint8_t nssf, void *payload,
|
||||
uint32_t payload_size, spdk_nvme_cmd_cb cb_fn, void *cb_arg), 0);
|
||||
|
||||
static int g_ut_recv_status = 0;
|
||||
static void *g_ut_sess_ctx;
|
||||
|
||||
static void
|
||||
ut_opal_sess_cb(struct opal_session *sess, int status, void *ctx)
|
||||
{
|
||||
g_ut_recv_status = status;
|
||||
g_ut_sess_ctx = ctx;
|
||||
}
|
||||
|
||||
static void
|
||||
reset_ut_global_variables(void)
|
||||
{
|
||||
g_ut_recv_status = 0;
|
||||
g_ut_sess_ctx = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
test_opal_nvme_security_recv_send_done(void)
|
||||
{
|
||||
struct spdk_nvme_cpl cpl = {};
|
||||
struct spdk_opal_compacket header = {};
|
||||
struct spdk_opal_dev dev = {};
|
||||
struct opal_session sess = {};
|
||||
|
||||
sess.sess_cb = ut_opal_sess_cb;
|
||||
sess.cb_arg = (void *)0xDEADBEEF;
|
||||
sess.dev = &dev;
|
||||
memcpy(sess.resp, &header, sizeof(header));
|
||||
|
||||
/* Case 1: receive/send IO error */
|
||||
reset_ut_global_variables();
|
||||
cpl.status.sct = SPDK_NVME_SCT_MEDIA_ERROR;
|
||||
|
||||
opal_nvme_security_recv_done(&sess, &cpl);
|
||||
CU_ASSERT(g_ut_recv_status == -EIO);
|
||||
CU_ASSERT(g_ut_sess_ctx == (void *)0xDEADBEEF);
|
||||
|
||||
reset_ut_global_variables();
|
||||
opal_nvme_security_send_done(&sess, &cpl);
|
||||
CU_ASSERT(g_ut_recv_status == -EIO);
|
||||
CU_ASSERT(g_ut_sess_ctx == (void *)0xDEADBEEF);
|
||||
|
||||
/* Case 2: receive with opal header no outstanding data */
|
||||
reset_ut_global_variables();
|
||||
memset(&header, 0, sizeof(header));
|
||||
cpl.status.sct = SPDK_NVME_SCT_GENERIC;
|
||||
|
||||
opal_nvme_security_recv_done(&sess, &cpl);
|
||||
CU_ASSERT(g_ut_recv_status == 0);
|
||||
CU_ASSERT(g_ut_sess_ctx == (void *)0xDEADBEEF);
|
||||
|
||||
/* Case 3: receive with opal header outstanding data and send done success */
|
||||
reset_ut_global_variables();
|
||||
header.outstanding_data = 0xff;
|
||||
memcpy(sess.resp, &header, sizeof(header));
|
||||
cpl.status.sct = SPDK_NVME_SCT_GENERIC;
|
||||
|
||||
opal_nvme_security_recv_done(&sess, &cpl);
|
||||
CU_ASSERT(g_ut_recv_status == 1);
|
||||
CU_ASSERT(g_ut_sess_ctx == (void *)0xDEADBEEF);
|
||||
|
||||
reset_ut_global_variables();
|
||||
opal_nvme_security_send_done(&sess, &cpl);
|
||||
CU_ASSERT(g_ut_recv_status == 1);
|
||||
CU_ASSERT(g_ut_sess_ctx == (void *)0xDEADBEEF);
|
||||
}
|
||||
|
||||
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_opal", NULL, NULL);
|
||||
CU_ADD_TEST(suite, test_opal_nvme_security_recv_send_done);
|
||||
|
||||
CU_basic_set_mode(CU_BRM_VERBOSE);
|
||||
CU_basic_run_tests();
|
||||
num_failures = CU_get_number_of_failures();
|
||||
CU_cleanup_registry();
|
||||
return num_failures;
|
||||
}
|
@ -86,6 +86,7 @@ function unittest_nvme() {
|
||||
$valgrind $testdir/lib/nvme/nvme_io_msg.c/nvme_io_msg_ut
|
||||
$valgrind $testdir/lib/nvme/nvme_pcie_common.c/nvme_pcie_common_ut
|
||||
$valgrind $testdir/lib/nvme/nvme_fabric.c/nvme_fabric_ut
|
||||
$valgrind $testdir/lib/nvme/nvme_opal.c/nvme_opal_ut
|
||||
}
|
||||
|
||||
function unittest_nvmf() {
|
||||
|
Loading…
Reference in New Issue
Block a user