test/nvme_ns: cases for identifying id descriptor and find descriptor
Change-Id: I20d0a798423ee08f4a9e019aa62b93981586d134 Signed-off-by: Mao Jiang <maox.jiang@intel.com> Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7161 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
This commit is contained in:
parent
5f106e26c9
commit
a417658803
@ -63,11 +63,15 @@ static struct spdk_nvme_zns_ns_data nsdata_zns = {
|
||||
.mor = 1024,
|
||||
};
|
||||
|
||||
struct spdk_nvme_cmd g_ut_cmd = {};
|
||||
|
||||
int
|
||||
nvme_ctrlr_cmd_identify(struct spdk_nvme_ctrlr *ctrlr, uint8_t cns, uint16_t cntid, uint32_t nsid,
|
||||
uint8_t csi, void *payload, size_t payload_size,
|
||||
spdk_nvme_cmd_cb cb_fn, void *cb_arg)
|
||||
{
|
||||
memset(&g_ut_cmd, 0, sizeof(g_ut_cmd));
|
||||
|
||||
if (cns == SPDK_NVME_IDENTIFY_NS) {
|
||||
assert(payload_size == sizeof(struct spdk_nvme_ns_data));
|
||||
if (fake_nsdata) {
|
||||
@ -81,6 +85,12 @@ nvme_ctrlr_cmd_identify(struct spdk_nvme_ctrlr *ctrlr, uint8_t cns, uint16_t cnt
|
||||
assert(payload_size == sizeof(struct spdk_nvme_zns_ns_data));
|
||||
memcpy(payload, &nsdata_zns, sizeof(struct spdk_nvme_zns_ns_data));
|
||||
return 0;
|
||||
} else if (cns == SPDK_NVME_IDENTIFY_NS_ID_DESCRIPTOR_LIST) {
|
||||
g_ut_cmd.cdw10_bits.identify.cns = cns;
|
||||
g_ut_cmd.cdw10_bits.identify.cntid = cntid;
|
||||
g_ut_cmd.cdw11_bits.identify.csi = csi;
|
||||
g_ut_cmd.nsid = nsid;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@ -453,6 +463,64 @@ test_nvme_ctrlr_identify_ns_iocs_specific(void)
|
||||
CU_ASSERT(ns.nsdata_zns == NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
test_nvme_ctrlr_identify_id_desc(void)
|
||||
{
|
||||
struct spdk_nvme_ns ns = {};
|
||||
struct spdk_nvme_ctrlr ctrlr = {};
|
||||
int rc;
|
||||
|
||||
ns.ctrlr = &ctrlr;
|
||||
ns.ctrlr->vs.raw = SPDK_NVME_VERSION(1, 3, 0);
|
||||
ns.ctrlr->cap.bits.css |= SPDK_NVME_CAP_CSS_IOCS;
|
||||
ns.id = 1;
|
||||
|
||||
rc = nvme_ctrlr_identify_id_desc(&ns);
|
||||
CU_ASSERT(rc == 0);
|
||||
CU_ASSERT(g_ut_cmd.cdw10_bits.identify.cns == SPDK_NVME_IDENTIFY_NS_ID_DESCRIPTOR_LIST);
|
||||
CU_ASSERT(g_ut_cmd.cdw10_bits.identify.cntid == 0);
|
||||
CU_ASSERT(g_ut_cmd.cdw11_bits.identify.csi == spdk_nvme_ns_get_csi(&ns));
|
||||
CU_ASSERT(g_ut_cmd.nsid == 1);
|
||||
|
||||
/* NVME version and css unsupported */
|
||||
ns.ctrlr->vs.raw = SPDK_NVME_VERSION(1, 2, 0);
|
||||
ns.ctrlr->cap.bits.css &= ~SPDK_NVME_CAP_CSS_IOCS;
|
||||
|
||||
rc = nvme_ctrlr_identify_id_desc(&ns);
|
||||
CU_ASSERT(rc == 0);
|
||||
}
|
||||
|
||||
static void
|
||||
test_nvme_ns_find_id_desc(void)
|
||||
{
|
||||
struct spdk_nvme_ns ns = {};
|
||||
struct spdk_nvme_ns_id_desc *desc = NULL;
|
||||
const uint8_t *csi = NULL;
|
||||
size_t length = 0;
|
||||
|
||||
desc = (void *)ns.id_desc_list;
|
||||
desc->nidl = 4;
|
||||
desc->nidt = SPDK_NVME_NIDT_CSI;
|
||||
|
||||
/* Case 1: get id descriptor successfully */
|
||||
csi = nvme_ns_find_id_desc(&ns, SPDK_NVME_NIDT_CSI, &length);
|
||||
CU_ASSERT(csi == desc->nid);
|
||||
CU_ASSERT(length == 4);
|
||||
|
||||
/* Case 2: ns_id length invalid, expect fail */
|
||||
desc->nidl = 0;
|
||||
|
||||
csi = nvme_ns_find_id_desc(&ns, SPDK_NVME_NIDT_CSI, &length);
|
||||
CU_ASSERT(csi == NULL);
|
||||
|
||||
/* Case 3: No correct id descriptor type entry, expect fail */
|
||||
desc->nidl = 4;
|
||||
desc->nidt = SPDK_NVME_NIDT_CSI;
|
||||
|
||||
csi = nvme_ns_find_id_desc(&ns, SPDK_NVME_NIDT_UUID, &length);
|
||||
CU_ASSERT(csi == NULL);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
CU_pSuite suite = NULL;
|
||||
@ -473,6 +541,8 @@ int main(int argc, char **argv)
|
||||
CU_ADD_TEST(suite, spdk_nvme_ns_supports);
|
||||
CU_ADD_TEST(suite, test_nvme_ns_has_supported_iocs_specific_data);
|
||||
CU_ADD_TEST(suite, test_nvme_ctrlr_identify_ns_iocs_specific);
|
||||
CU_ADD_TEST(suite, test_nvme_ctrlr_identify_id_desc);
|
||||
CU_ADD_TEST(suite, test_nvme_ns_find_id_desc);
|
||||
|
||||
CU_basic_set_mode(CU_BRM_VERBOSE);
|
||||
CU_basic_run_tests();
|
||||
|
Loading…
Reference in New Issue
Block a user