From c75e03367ac136f20938c7ea7d9979e69d3c50e5 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Tue, 5 Jul 2022 10:12:34 +0200 Subject: validation: Test thread free of FPU owner Update #3716. --- testsuites/validation/tc-score-thread.c | 74 +++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'testsuites/validation') diff --git a/testsuites/validation/tc-score-thread.c b/testsuites/validation/tc-score-thread.c index 53b939e3c5..694fcaefab 100644 --- a/testsuites/validation/tc-score-thread.c +++ b/testsuites/validation/tc-score-thread.c @@ -56,6 +56,7 @@ #include #include +#include "ts-config.h" #include "tx-support.h" #include @@ -86,6 +87,14 @@ * * - Clean up all used resources. * + * - Delete a thread which least recently used the floating point coprocessor. + * + * - Start the worker thread. Let it use the floating point coprocessor. + * + * - Delete the worker thread and free the thread resources. + * + * - Clean up all used resources. + * * @{ */ @@ -102,6 +111,11 @@ typedef struct { * @brief This member contains the killer task identifier. */ rtems_id killer_id; + + /** + * @brief This member contains a floating-point object. + */ + volatile double fp_obj; } ScoreThreadValThread_Context; static ScoreThreadValThread_Context @@ -126,6 +140,29 @@ static void WorkerTask( rtems_task_argument arg ) SuspendSelf(); } +static void GoBackToRunner( void *arg ) +{ + Context *ctx; + + ctx = arg; + SetPriority( ctx->worker_id, PRIO_LOW ); +} + +static void FloatingPointTask( rtems_task_argument arg ) +{ + Context *ctx; + + ctx = (Context *) arg; + ctx->fp_obj *= 1.23; + + /* + * We use an interrupt to go back to the runner since on some + * architectures, the floating-point context is only saved during interrupt + * processing and not for synchronous thread switches. + */ + CallWithinISR( GoBackToRunner, ctx ); +} + static void KillerTask( rtems_task_argument arg ) { Context *ctx; @@ -216,6 +253,42 @@ static void ScoreThreadValThread_Action_0( ScoreThreadValThread_Context *ctx ) T_rsc_success( sc ); } +/** + * @brief Delete a thread which least recently used the floating point + * coprocessor. + */ +static void ScoreThreadValThread_Action_1( ScoreThreadValThread_Context *ctx ) +{ + rtems_status_code sc; + + SetSelfPriority( PRIO_NORMAL ); + sc = rtems_task_create( + rtems_build_name( 'W', 'O', 'R', 'K'), + PRIO_HIGH, + TEST_MINIMUM_STACK_SIZE, + RTEMS_DEFAULT_MODES, + RTEMS_FLOATING_POINT, + &ctx->worker_id + ); + T_rsc_success( sc ); + + /* + * Start the worker thread. Let it use the floating point coprocessor. + */ + StartTask( ctx->worker_id, FloatingPointTask, ctx ); + + /* + * Delete the worker thread and free the thread resources. + */ + DeleteTask( ctx->worker_id ); + KillZombies(); + + /* + * Clean up all used resources. + */ + RestoreRunnerPriority(); +} + /** * @fn void T_case_body_ScoreThreadValThread( void ) */ @@ -226,6 +299,7 @@ T_TEST_CASE_FIXTURE( ScoreThreadValThread, &ScoreThreadValThread_Fixture ) ctx = T_fixture_context(); ScoreThreadValThread_Action_0( ctx ); + ScoreThreadValThread_Action_1( ctx ); } /** @} */ -- cgit v1.2.3