test/nvme: Add test sanitize to unittest.

Add test_sanitize in nvme_ctrlr_cmd_ut.c, this will
increase code coverage rate.

Change-Id: I80dec6eed5e2114c91db1406d1aa6c6a5e287293
Signed-off-by: yidong0635 <dongx.yi@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/469576
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
yidong0635 2019-09-26 14:46:49 -04:00 committed by Changpeng Liu
parent 6bcd3588d1
commit 46d6711825

View File

@ -55,6 +55,7 @@ uint16_t abort_cid = 1;
uint16_t abort_sqid = 1;
uint32_t namespace_management_nsid = 1;
uint32_t format_nvme_nsid = 1;
uint32_t sanitize_nvme_nsid = 1;
uint32_t expected_feature_ns = 2;
uint32_t expected_feature_cdw10 = SPDK_NVME_FEAT_LBA_RANGE_TYPE;
@ -269,6 +270,14 @@ static void verify_fw_image_download(struct nvme_request *req)
CU_ASSERT(req->cmd.cdw11 == fw_img_offset >> 2);
}
static void verify_nvme_sanitize(struct nvme_request *req)
{
CU_ASSERT(req->cmd.opc == SPDK_NVME_OPC_SANITIZE);
CU_ASSERT(req->cmd.cdw10 == 0x309);
CU_ASSERT(req->cmd.cdw11 == 0);
CU_ASSERT(req->cmd.nsid == sanitize_nvme_nsid);
}
struct nvme_request *
nvme_allocate_request_user_copy(struct spdk_nvme_qpair *qpair, void *buffer, uint32_t payload_size,
spdk_nvme_cmd_cb cb_fn, void *cb_arg, bool host_to_controller)
@ -601,6 +610,23 @@ test_fw_image_download(void)
NULL, NULL);
}
static void
test_sanitize(void)
{
DECLARE_AND_CONSTRUCT_CTRLR();
struct spdk_nvme_sanitize sanitize = {};
sanitize.sanact = 1;
sanitize.ause = 1;
sanitize.oipbp = 1;
sanitize.ndas = 1;
verify_fn = verify_nvme_sanitize;
nvme_ctrlr_cmd_sanitize(&ctrlr, sanitize_nvme_nsid, &sanitize, 0, NULL, NULL);
}
int main(int argc, char **argv)
{
CU_pSuite suite = NULL;
@ -632,6 +658,7 @@ int main(int argc, char **argv)
|| CU_add_test(suite, "test ctrlr cmd format_nvme", test_format_nvme) == NULL
|| CU_add_test(suite, "test ctrlr cmd fw_commit", test_fw_commit) == NULL
|| CU_add_test(suite, "test ctrlr cmd fw_image_download", test_fw_image_download) == NULL
|| CU_add_test(suite, "test ctrlr cmd sanitize", test_sanitize) == NULL
) {
CU_cleanup_registry();
return CU_get_error();