Skip to content

Commit

Permalink
UT/nvme_pcie_common:test for nvme_pcie_poll_group_get_stats
Browse files Browse the repository at this point in the history
Signed-off-by: xiaoxiangxzhang <[email protected]>
Change-Id: I92d4e2a18a281f1e9abc89f0ccb76063a3709784
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15415
Tested-by: SPDK CI Jenkins <[email protected]>
Reviewed-by: Changpeng Liu <[email protected]>
Reviewed-by: Tomasz Zawadzki <[email protected]>
  • Loading branch information
xiaoxiangxzhang authored and tomzawadzki committed Nov 21, 2022
1 parent d6256d4 commit 1a0ccf3
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/unit/lib/nvme/nvme_pcie_common.c/nvme_pcie_common_ut.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,40 @@ test_nvme_pcie_ctrlr_construct_admin_qpair(void)
CU_ASSERT(rc == 0);
}

static void
test_nvme_pcie_poll_group_get_stats(void)
{
int rc = 0;
struct nvme_pcie_poll_group *pgroup = NULL;
struct spdk_nvme_transport_poll_group *tgroup = NULL;
struct spdk_nvme_transport_poll_group_stat *tgroup_stat = NULL;

tgroup = nvme_pcie_poll_group_create();
CU_ASSERT(tgroup != NULL);
pgroup = SPDK_CONTAINEROF(tgroup, struct nvme_pcie_poll_group, group);
CU_ASSERT(pgroup != NULL);

/* Invalid group pointer, expect fail and return -EINVAL */
rc = nvme_pcie_poll_group_get_stats(NULL, &tgroup_stat);
CU_ASSERT(rc == -EINVAL);
CU_ASSERT(tgroup_stat == NULL);

/* Invalid stats, expect fail and return -EINVAL */
rc = nvme_pcie_poll_group_get_stats(tgroup, NULL);
CU_ASSERT(rc == -EINVAL);

/* Get state success */
rc = nvme_pcie_poll_group_get_stats(tgroup, &tgroup_stat);
CU_ASSERT(rc == 0);
CU_ASSERT(tgroup_stat != NULL);
CU_ASSERT(tgroup_stat->trtype == SPDK_NVME_TRANSPORT_PCIE);
CU_ASSERT(memcmp(&tgroup_stat->pcie, &pgroup->stats, sizeof(struct spdk_nvme_pcie_stat)) == 0);

nvme_pcie_poll_group_free_stats(tgroup, tgroup_stat);
rc = nvme_pcie_poll_group_destroy(tgroup);
CU_ASSERT(rc == 0);
}

int
main(int argc, char **argv)
{
Expand All @@ -560,6 +594,7 @@ main(int argc, char **argv)
CU_ADD_TEST(suite, test_nvme_pcie_ctrlr_cmd_create_delete_io_queue);
CU_ADD_TEST(suite, test_nvme_pcie_ctrlr_connect_qpair);
CU_ADD_TEST(suite, test_nvme_pcie_ctrlr_construct_admin_qpair);
CU_ADD_TEST(suite, test_nvme_pcie_poll_group_get_stats);

CU_basic_set_mode(CU_BRM_VERBOSE);
CU_basic_run_tests();
Expand Down

0 comments on commit 1a0ccf3

Please sign in to comment.