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: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Change-Id: I0793e6dcc41c447dc11ed8ab28eb9041c5d82628 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8409 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com> Community-CI: Mellanox Build Bot Reviewed-by: Konrad Sztyber <konrad.sztyber@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Ziye Yang <ziye.yang@intel.com>
This commit is contained in:
parent
a3aa222a39
commit
012b233426
@ -40,7 +40,21 @@
|
|||||||
#include "event/scheduler_static.c"
|
#include "event/scheduler_static.c"
|
||||||
#include "event/scheduler_dynamic.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
|
static void
|
||||||
test_create_reactor(void)
|
test_create_reactor(void)
|
||||||
@ -521,6 +535,7 @@ static uint32_t
|
|||||||
_run_events_till_completion(uint32_t reactor_count)
|
_run_events_till_completion(uint32_t reactor_count)
|
||||||
{
|
{
|
||||||
struct spdk_reactor *reactor;
|
struct spdk_reactor *reactor;
|
||||||
|
struct spdk_thread *app_thread = _spdk_get_app_thread();
|
||||||
uint32_t i, events;
|
uint32_t i, events;
|
||||||
uint32_t total_events = 0;
|
uint32_t total_events = 0;
|
||||||
|
|
||||||
@ -531,6 +546,11 @@ _run_events_till_completion(uint32_t reactor_count)
|
|||||||
CU_ASSERT(reactor != NULL);
|
CU_ASSERT(reactor != NULL);
|
||||||
MOCK_SET(spdk_env_get_current_core, i);
|
MOCK_SET(spdk_env_get_current_core, i);
|
||||||
events += event_queue_run_batch(reactor);
|
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);
|
MOCK_CLEAR(spdk_env_get_current_core);
|
||||||
}
|
}
|
||||||
total_events += events;
|
total_events += events;
|
||||||
@ -868,7 +888,7 @@ test_governor(void)
|
|||||||
MOCK_SET(spdk_env_get_current_core, 0);
|
MOCK_SET(spdk_env_get_current_core, 0);
|
||||||
_reactors_scheduler_gather_metrics(NULL, NULL);
|
_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);
|
MOCK_SET(spdk_env_get_current_core, 0);
|
||||||
|
|
||||||
/* Main core should be busy more than 50% time now - frequency should be raised */
|
/* 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);
|
MOCK_SET(spdk_env_get_current_core, 0);
|
||||||
_reactors_scheduler_gather_metrics(NULL, NULL);
|
_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);
|
MOCK_SET(spdk_env_get_current_core, 0);
|
||||||
|
|
||||||
for (i = 0; i < 2; i++) {
|
for (i = 0; i < 2; i++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user