Commit 05e32e93 authored by Anisa Su's avatar Anisa Su Committed by Konrad Sztyber
Browse files

test/unit: add poller_get_stats unit test



Change-Id: Ibf94c19643ba2ae33998dd3b6e5fad174872c9c6
Signed-off-by: default avatarAnisa Su <anisa.su@samsung.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/24526


Reviewed-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Community-CI: Mellanox Build Bot
parent 9c56fc47
Loading
Loading
Loading
Loading
+41 −0
Original line number Diff line number Diff line
@@ -1125,6 +1125,12 @@ ut_assert_poller_state_running(void *ctx)
	return SPDK_POLLER_IDLE;
}

static int
ut_busy_poll(void *ctx)
{
	return SPDK_POLLER_BUSY;
}

static int
ut_nested_ch_create_cb(void *io_device, void *ctx_buf)
{
@@ -2129,6 +2135,40 @@ poller_get_period_ticks(void)
	free_threads();
}

static void
poller_get_stats(void)
{
	struct spdk_poller *idle_poller = NULL;
	struct spdk_poller *busy_poller = NULL;
	struct spdk_poller_stats stats;
	int period = 5;

	allocate_threads(1);
	set_thread(0);

	/* Register a "busy" and "idle" poller */
	idle_poller = spdk_poller_register(ut_null_poll, NULL, period);
	busy_poller = spdk_poller_register(ut_busy_poll, NULL, period);

	spdk_delay_us(period);
	poll_thread(0);

	/* Check busy poller stats */
	spdk_poller_get_stats(busy_poller, &stats);
	CU_ASSERT_EQUAL(stats.run_count, 1);
	CU_ASSERT_EQUAL(stats.busy_count, 1);

	memset(&stats, 0, sizeof(stats));
	/* Check idle poller stats */
	spdk_poller_get_stats(idle_poller, &stats);
	CU_ASSERT_EQUAL(stats.run_count, 1);
	CU_ASSERT_EQUAL(stats.busy_count, 0);

	spdk_poller_unregister(&idle_poller);
	spdk_poller_unregister(&busy_poller);
	free_threads();
}


int
main(int argc, char **argv)
@@ -2164,6 +2204,7 @@ main(int argc, char **argv)
	CU_ADD_TEST(suite, poller_get_id);
	CU_ADD_TEST(suite, poller_get_state_str);
	CU_ADD_TEST(suite, poller_get_period_ticks);
	CU_ADD_TEST(suite, poller_get_stats);

	num_failures = spdk_ut_run_tests(argc, argv, NULL);
	CU_cleanup_registry();