test/nvme_ns_cmd: cases for namespace command reading and setup

Change-Id: I774c386480bc5fb20ce40a58ce9b72798f280e6d
Signed-off-by: Mao Jiang <maox.jiang@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7029
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Mao Jiang 2021-03-24 16:53:27 +08:00 committed by Jim Harris
parent 7cccf5c5f4
commit 661825cfc9

View File

@ -2025,6 +2025,70 @@ test_nvme_ns_cmd_compare_with_md(void)
free(metadata);
}
static void
test_nvme_ns_cmd_setup_request(void)
{
struct spdk_nvme_ns ns = {};
struct nvme_request req = {};
ns.id = 1;
ns.pi_type = SPDK_NVME_FMT_NVM_PROTECTION_TYPE1;
ns.flags = SPDK_NVME_NS_DPS_PI_SUPPORTED;
_nvme_ns_cmd_setup_request(&ns, &req, SPDK_NVME_OPC_READ,
1024, 256, SPDK_NVME_IO_FLAGS_PRACT, 1, 1);
CU_ASSERT(req.cmd.cdw10 == 1024);
CU_ASSERT(req.cmd.opc == SPDK_NVME_OPC_READ);
CU_ASSERT(req.cmd.nsid == 1);
CU_ASSERT(req.cmd.cdw14 == 1024);
CU_ASSERT(req.cmd.fuse == 0);
CU_ASSERT(req.cmd.cdw12 == (255 | SPDK_NVME_IO_FLAGS_PRACT));
CU_ASSERT(req.cmd.cdw15 == (1 << 16 | 1));
}
static void
test_spdk_nvme_ns_cmd_readv_with_md(void)
{
struct spdk_nvme_ns ns;
struct spdk_nvme_ctrlr ctrlr;
struct spdk_nvme_qpair qpair;
int rc = 0;
char *metadata = NULL;
uint32_t lba_count = 256;
uint32_t sector_size = 512;
uint32_t md_size = 128;
uint64_t sge_length = lba_count * sector_size;
metadata = (void *)0xDEADBEEF;
prepare_for_test(&ns, &ctrlr, &qpair, sector_size,
md_size, 128 * 1024, 0, false);
rc = spdk_nvme_ns_cmd_readv_with_md(&ns, &qpair, 0x1000, lba_count, NULL,
&sge_length, 0, nvme_request_reset_sgl,
nvme_request_next_sge, metadata, 0, 0);
CU_ASSERT(rc == 0);
SPDK_CU_ASSERT_FATAL(g_request != NULL);
CU_ASSERT(g_request->cmd.opc == SPDK_NVME_OPC_READ);
CU_ASSERT(nvme_payload_type(&g_request->payload) == NVME_PAYLOAD_TYPE_SGL);
CU_ASSERT(g_request->payload.reset_sgl_fn == nvme_request_reset_sgl);
CU_ASSERT(g_request->payload.next_sge_fn == nvme_request_next_sge);
CU_ASSERT(g_request->payload.contig_or_cb_arg == &sge_length);
CU_ASSERT(g_request->payload.md == (void *)0xDEADBEEF);
CU_ASSERT(g_request->cmd.nsid == ns.id);
CU_ASSERT(g_request->payload_size == 256 * 512);
CU_ASSERT(g_request->qpair == &qpair);
CU_ASSERT(g_request->md_offset == 0);
CU_ASSERT(g_request->payload_offset == 0);
rc = spdk_nvme_ns_cmd_readv_with_md(&ns, &qpair, 0x1000, lba_count, NULL,
NULL, 0, nvme_request_reset_sgl, NULL,
metadata, 0, 0);
CU_ASSERT(rc == -EINVAL);
nvme_free_request(g_request);
cleanup_after_test(&qpair);
}
int main(int argc, char **argv)
{
CU_pSuite suite = NULL;
@ -2060,6 +2124,8 @@ int main(int argc, char **argv)
CU_ADD_TEST(suite, test_nvme_ns_cmd_compare_and_write);
CU_ADD_TEST(suite, test_nvme_ns_cmd_compare_with_md);
CU_ADD_TEST(suite, test_nvme_ns_cmd_comparev_with_md);
CU_ADD_TEST(suite, test_nvme_ns_cmd_setup_request);
CU_ADD_TEST(suite, test_spdk_nvme_ns_cmd_readv_with_md);
g_spdk_nvme_driver = &_g_nvme_driver;