nvme/tcp: Add UT to nvme_tcp_build_iovs

There was no UT to process SGL for PDU, and add UT in this patch.

Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: Icd07683ba94b584cd3c6e5a88fee78d512d5832d
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/458541
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Ziye Yang <ziye.yang@intel.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: Paul Luse <paul.e.luse@intel.com>
This commit is contained in:
Shuhei Matsumoto 2019-06-19 13:20:26 +09:00 committed by Darek Stojaczyk
parent 5cfc19af37
commit b2982b7d44

View File

@ -118,6 +118,69 @@ test_nvme_tcp_pdu_set_data_buf(void)
}
}
static void
test_nvme_tcp_build_iovs(void)
{
struct nvme_tcp_pdu pdu = {};
struct iovec iovs[4] = {};
uint32_t mapped_length = 0;
int rc;
pdu.hdr.common.pdu_type = SPDK_NVME_TCP_PDU_TYPE_CAPSULE_CMD;
pdu.hdr.common.hlen = sizeof(struct spdk_nvme_tcp_cmd);
pdu.hdr.common.plen = pdu.hdr.common.hlen + SPDK_NVME_TCP_DIGEST_LEN + 4096 * 2 +
SPDK_NVME_TCP_DIGEST_LEN;
pdu.data_len = 4096 * 2;
pdu.padding_len = 0;
pdu.data_iov[0].iov_base = (void *)0xDEADBEEF;
pdu.data_iov[0].iov_len = 4096 * 2;
pdu.data_iovcnt = 1;
rc = nvme_tcp_build_iovs(iovs, 4, &pdu, true, true, &mapped_length);
CU_ASSERT(rc == 3);
CU_ASSERT(iovs[0].iov_base == (void *)&pdu.hdr.raw);
CU_ASSERT(iovs[0].iov_len == sizeof(struct spdk_nvme_tcp_cmd) + SPDK_NVME_TCP_DIGEST_LEN);
CU_ASSERT(iovs[1].iov_base == (void *)0xDEADBEEF);
CU_ASSERT(iovs[1].iov_len == 4096 * 2);
CU_ASSERT(iovs[2].iov_base == (void *)pdu.data_digest);
CU_ASSERT(iovs[2].iov_len == SPDK_NVME_TCP_DIGEST_LEN);
CU_ASSERT(mapped_length == sizeof(struct spdk_nvme_tcp_cmd) + SPDK_NVME_TCP_DIGEST_LEN +
4096 * 2 + SPDK_NVME_TCP_DIGEST_LEN);
pdu.writev_offset += sizeof(struct spdk_nvme_tcp_cmd) + SPDK_NVME_TCP_DIGEST_LEN;
rc = nvme_tcp_build_iovs(iovs, 6, &pdu, true, true, &mapped_length);
CU_ASSERT(rc == 2);
CU_ASSERT(iovs[0].iov_base == (void *)0xDEADBEEF);
CU_ASSERT(iovs[0].iov_len == 4096 * 2);
CU_ASSERT(iovs[1].iov_base == (void *)pdu.data_digest);
CU_ASSERT(iovs[1].iov_len == SPDK_NVME_TCP_DIGEST_LEN);
CU_ASSERT(mapped_length == 4096 * 2 + SPDK_NVME_TCP_DIGEST_LEN);
pdu.writev_offset += 4096 * 2;
rc = nvme_tcp_build_iovs(iovs, 6, &pdu, true, true, &mapped_length);
CU_ASSERT(rc == 1);
CU_ASSERT(iovs[0].iov_base == (void *)pdu.data_digest);
CU_ASSERT(iovs[0].iov_len == SPDK_NVME_TCP_DIGEST_LEN);
CU_ASSERT(mapped_length == SPDK_NVME_TCP_DIGEST_LEN);
pdu.writev_offset += SPDK_NVME_TCP_DIGEST_LEN;
rc = nvme_tcp_build_iovs(iovs, 6, &pdu, true, true, &mapped_length);
CU_ASSERT(rc == 0);
pdu.writev_offset = 0;
rc = nvme_tcp_build_iovs(iovs, 2, &pdu, true, true, &mapped_length);
CU_ASSERT(rc == 2);
CU_ASSERT(iovs[0].iov_base == (void *)&pdu.hdr.raw);
CU_ASSERT(iovs[0].iov_len == sizeof(struct spdk_nvme_tcp_cmd) + SPDK_NVME_TCP_DIGEST_LEN);
CU_ASSERT(iovs[1].iov_base == (void *)0xDEADBEEF);
CU_ASSERT(iovs[1].iov_len == 4096 * 2);
}
int main(int argc, char **argv)
{
CU_pSuite suite = NULL;
@ -134,7 +197,10 @@ int main(int argc, char **argv)
}
if (CU_add_test(suite, "nvme_tcp_pdu_set_data_buf",
test_nvme_tcp_pdu_set_data_buf) == NULL) {
test_nvme_tcp_pdu_set_data_buf) == NULL ||
CU_add_test(suite, "nvme_tcp_build_iovs",
test_nvme_tcp_build_iovs) == NULL
) {
CU_cleanup_registry();
return CU_get_error();
}