Commit 012b2334 authored by Tomasz Zawadzki's avatar Tomasz Zawadzki
Browse files

ut/reactor: implement stub for _spdk_get_app_thread()



Functions that set reactor interrupt mode were not tested
since _spdk_get_app_thread() always returned NULL and
implementation did not verify the RC.

This patch will return a thread from scheduling reactor
as the app thread. Which is not exact, but otherwise
a new app thread would have to be added to each UT.

spdk_reactor_set_interrupt_mode() requires the completion to
be executed on app_thread. Added the poll of that thread
to make sure it gets drained.

Since now the UT actually executes the code path,
additional 4 events will be processed.

Signed-off-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Change-Id: I0793e6dcc41c447dc11ed8ab28eb9041c5d82628
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8409


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarZiye Yang <ziye.yang@intel.com>
parent a3aa222a
Loading
Loading
Loading
Loading
+23 −3
Original line number Diff line number Diff line
@@ -40,7 +40,21 @@
#include "event/scheduler_static.c"
#include "event/scheduler_dynamic.c"

DEFINE_STUB(_spdk_get_app_thread, struct spdk_thread *, (void), NULL);
struct spdk_thread *
_spdk_get_app_thread(void)
{
	struct spdk_lw_thread *lw_thread;
	struct spdk_thread *thread;

	/* Assume there has to be at least one thread on main
	 * reactor, that has at least one thread. */
	lw_thread = TAILQ_FIRST(&g_scheduling_reactor->threads);
	SPDK_CU_ASSERT_FATAL(lw_thread != NULL);
	thread = spdk_thread_get_from_ctx(lw_thread);
	SPDK_CU_ASSERT_FATAL(thread != NULL);

	return thread;
}

static void
test_create_reactor(void)
@@ -521,6 +535,7 @@ static uint32_t
_run_events_till_completion(uint32_t reactor_count)
{
	struct spdk_reactor *reactor;
	struct spdk_thread *app_thread = _spdk_get_app_thread();
	uint32_t i, events;
	uint32_t total_events = 0;

@@ -531,6 +546,11 @@ _run_events_till_completion(uint32_t reactor_count)
			CU_ASSERT(reactor != NULL);
			MOCK_SET(spdk_env_get_current_core, i);
			events += event_queue_run_batch(reactor);

			/* Some events still require app_thread to run */
			MOCK_SET(spdk_env_get_current_core, g_scheduling_reactor->lcore);
			spdk_thread_poll(app_thread, 0, 0);

			MOCK_CLEAR(spdk_env_get_current_core);
		}
		total_events += events;
@@ -868,7 +888,7 @@ test_governor(void)
	MOCK_SET(spdk_env_get_current_core, 0);
	_reactors_scheduler_gather_metrics(NULL, NULL);

	CU_ASSERT(_run_events_till_completion(2) == 2);
	CU_ASSERT(_run_events_till_completion(2) == 6);
	MOCK_SET(spdk_env_get_current_core, 0);

	/* Main core should be busy more than 50% time now - frequency should be raised */
@@ -891,7 +911,7 @@ test_governor(void)
	MOCK_SET(spdk_env_get_current_core, 0);
	_reactors_scheduler_gather_metrics(NULL, NULL);

	CU_ASSERT(_run_events_till_completion(2) == 2);
	CU_ASSERT(_run_events_till_completion(2) == 6);
	MOCK_SET(spdk_env_get_current_core, 0);

	for (i = 0; i < 2; i++) {