From 320fdaa325f1671cee1712995dd4467dfbde9c71 Mon Sep 17 00:00:00 2001 From: Tomasz Zawadzki Date: Mon, 17 May 2021 10:17:04 -0400 Subject: [PATCH] ut/event: add current reactor tsc accounting This patch does not change the UT in functional way. Added accounting of last_tsc and spdk_get_ticks() similar to the real application. First the reactor_run() [not _reactor_run()] starts reactor->tsc_last to current time. UT now set it at the start and never touch it again directly. Second the spdk_get_ticks() is updated to the elapsed time to simulate flow of time, and make sure that its further usage is up to date to the current time. Fixed typo in test case description for test_reactor_stats. Signed-off-by: Tomasz Zawadzki Change-Id: Iaa2eb00fa3bffc2f21f1692da0259f1d023086b8 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7904 Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Aleksey Marchuk Reviewed-by: Konrad Sztyber Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto Community-CI: Mellanox Build Bot --- test/unit/lib/event/reactor.c/reactor_ut.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/test/unit/lib/event/reactor.c/reactor_ut.c b/test/unit/lib/event/reactor.c/reactor_ut.c index 347b0af29..7c7830d5b 100644 --- a/test/unit/lib/event/reactor.c/reactor_ut.c +++ b/test/unit/lib/event/reactor.c/reactor_ut.c @@ -371,7 +371,7 @@ test_reactor_stats(void) * - thread1 for 300 with idle * - thread2 for 400 with busy. * Then, - * - both elapsed TSC of thread1 and thread2 should be 1000 (= 100 + 900). + * - both elapsed TSC of thread1 and thread2 should be 1100 (= 100 + 1000). * - busy TSC of reactor should be 500 (= 100 + 400). * - idle TSC of reactor should be 500 (= 200 + 300). */ @@ -384,7 +384,12 @@ test_reactor_stats(void) spdk_cpuset_set_cpu(&cpuset, 0, true); + reactor = spdk_reactor_get(0); + SPDK_CU_ASSERT_FATAL(reactor != NULL); + + /* First reactor_run() sets the tsc_last. */ MOCK_SET(spdk_get_ticks, 100); + reactor->tsc_last = spdk_get_ticks(); thread1 = spdk_thread_create(NULL, &cpuset); SPDK_CU_ASSERT_FATAL(thread1 != NULL); @@ -392,11 +397,6 @@ test_reactor_stats(void) thread2 = spdk_thread_create(NULL, &cpuset); SPDK_CU_ASSERT_FATAL(thread2 != NULL); - reactor = spdk_reactor_get(0); - SPDK_CU_ASSERT_FATAL(reactor != NULL); - - reactor->tsc_last = 100; - spdk_set_thread(thread1); busy1 = spdk_poller_register(poller_run_busy, (void *)100, 0); CU_ASSERT(busy1 != NULL); @@ -421,6 +421,9 @@ test_reactor_stats(void) CU_ASSERT(reactor->busy_tsc == 100); CU_ASSERT(reactor->idle_tsc == 300); + /* 100 + 100 + 300 = 500 ticks elapsed */ + CU_ASSERT(reactor->tsc_last == 500); + spdk_set_thread(thread1); spdk_poller_unregister(&busy1); idle1 = spdk_poller_register(poller_run_idle, (void *)200, 0); @@ -447,6 +450,9 @@ test_reactor_stats(void) CU_ASSERT(reactor->busy_tsc == 500); CU_ASSERT(reactor->idle_tsc == 500); + /* 500 + 200 + 400 = 1100 ticks elapsed */ + CU_ASSERT(reactor->tsc_last == 1100); + spdk_set_thread(thread1); spdk_poller_unregister(&idle1); spdk_thread_exit(thread1); @@ -459,6 +465,9 @@ test_reactor_stats(void) CU_ASSERT(TAILQ_EMPTY(&reactor->threads)); + /* No further than 1100 ticks elapsed */ + CU_ASSERT(reactor->tsc_last == 1100); + spdk_reactors_fini(); free_cores();