From 031e8246d485ce994376fdf1b94ef37a11f02361 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Mon, 20 Jul 2020 19:18:16 +0200 Subject: spintrcritical16: Use T_interrupt_test() --- testsuites/sptests/Makefile.am | 4 +- testsuites/sptests/spintrcritical16/init.c | 140 +++++++++++++-------- .../sptests/spintrcritical16/spintrcritical16.scn | 31 +++-- 3 files changed, 115 insertions(+), 60 deletions(-) (limited to 'testsuites') diff --git a/testsuites/sptests/Makefile.am b/testsuites/sptests/Makefile.am index 0cf00f7fa6..136a8378b5 100644 --- a/testsuites/sptests/Makefile.am +++ b/testsuites/sptests/Makefile.am @@ -1320,9 +1320,7 @@ if TEST_spintrcritical16 sp_tests += spintrcritical16 sp_screens += spintrcritical16/spintrcritical16.scn sp_docs += spintrcritical16/spintrcritical16.doc -spintrcritical16_SOURCES = spintrcritical16/init.c \ - spintrcritical_support/intrcritical.c \ - spintrcritical_support/intrcritical.h +spintrcritical16_SOURCES = spintrcritical16/init.c spintrcritical16_CPPFLAGS = $(AM_CPPFLAGS) \ $(TEST_FLAGS_spintrcritical16) $(support_includes) \ -I$(top_srcdir)/spintrcritical_support diff --git a/testsuites/sptests/spintrcritical16/init.c b/testsuites/sptests/spintrcritical16/init.c index 1879cbd189..ed9ecfd7de 100644 --- a/testsuites/sptests/spintrcritical16/init.c +++ b/testsuites/sptests/spintrcritical16/init.c @@ -1,4 +1,6 @@ /* + * Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de) + * * COPYRIGHT (c) 1989-2009. * On-Line Applications Research Corporation (OAR). * @@ -11,88 +13,128 @@ #include "config.h" #endif -#include -#include +#include +#include #include const char rtems_test_name[] = "SPINTRCRITICAL 16"; -static Thread_Control *Main_TCB; - -static rtems_id Semaphore; +typedef struct { + Thread_Control *thread; + rtems_id semaphore; +} test_context; -static bool case_hit; - -static bool interrupts_blocking_op(void) +static T_interrupt_test_state interrupt( void *arg ) { - Thread_Wait_flags flags = _Thread_Wait_flags_get( Main_TCB ); + test_context *ctx; + T_interrupt_test_state state; + Thread_Wait_flags flags; + rtems_status_code sc; - return - flags == ( THREAD_WAIT_CLASS_OBJECT | THREAD_WAIT_STATE_INTEND_TO_BLOCK ); -} + state = T_interrupt_test_get_state(); -static rtems_timer_service_routine test_release_from_isr( - rtems_id timer, - void *arg -) -{ - if ( interrupts_blocking_op() ) { - case_hit = true; - (void) rtems_semaphore_release( Semaphore ); + if (state != T_INTERRUPT_TEST_ACTION) { + return T_INTERRUPT_TEST_CONTINUE; } - if ( Main_TCB->Wait.queue != NULL ) { - _Thread_Timeout( &Main_TCB->Timer.Watchdog ); + ctx = arg; + flags = _Thread_Wait_flags_get( ctx->thread ); + + if ( + flags == ( THREAD_WAIT_CLASS_OBJECT | THREAD_WAIT_STATE_INTEND_TO_BLOCK ) + ) { + state = T_INTERRUPT_TEST_DONE; + } else if ( + flags == ( THREAD_WAIT_CLASS_EVENT | THREAD_WAIT_STATE_BLOCKED ) + ) { + state = T_INTERRUPT_TEST_LATE; + } else { + state = T_INTERRUPT_TEST_EARLY; } + + sc = rtems_semaphore_release( ctx->semaphore ); + T_quiet_rsc_success( sc ); + + return state; } -static bool test_body( void *arg ) +static void prepare( void *arg ) { + test_context *ctx; rtems_status_code sc; - (void) arg; + ctx = arg; + + do { + sc = rtems_semaphore_obtain( ctx->semaphore, RTEMS_NO_WAIT, 0 ); + } while ( sc == RTEMS_SUCCESSFUL ); +} - sc = rtems_semaphore_obtain( Semaphore, RTEMS_DEFAULT_OPTIONS, 2 ); - rtems_test_assert( sc == RTEMS_SUCCESSFUL || sc == RTEMS_TIMEOUT ); +static void action( void *arg ) +{ + test_context *ctx; + rtems_status_code sc; - return case_hit; + ctx = arg; + sc = rtems_semaphore_obtain( ctx->semaphore, RTEMS_DEFAULT_OPTIONS, 2 ); + T_quiet_rsc_success( sc ); } -static rtems_task Init( - rtems_task_argument ignored -) +static void blocked( void *arg ) { - rtems_status_code sc; + test_context *ctx; + rtems_status_code sc; - TEST_BEGIN(); - puts( - "Init - Trying to generate timeout of a thread that had its blocking\n" - "Init - request satisfied while blocking but before time timeout" + T_interrupt_test_change_state( + T_INTERRUPT_TEST_ACTION, + T_INTERRUPT_TEST_LATE ); - puts( "Init - rtems_semaphore_create - OK" ); + ctx = arg; + sc = rtems_semaphore_release( ctx->semaphore ); + T_quiet_rsc_success( sc ); +} + +static const T_interrupt_test_config config = { + .prepare = prepare, + .action = action, + .interrupt = interrupt, + .blocked = blocked, + .max_iteration_count = 10000 +}; + +/* + * Trying to generate timeout of a thread that had its blocking request + * satisfied while blocking but before time timeout. + */ +T_TEST_CASE( SemaphoreSatisfyBeforeTimeout ) +{ + test_context ctx; + rtems_status_code sc; + T_interrupt_test_state state; + + ctx.thread = _Thread_Get_executing(); + sc = rtems_semaphore_create( rtems_build_name( 'S', 'M', '1', ' ' ), 0, RTEMS_DEFAULT_ATTRIBUTES, RTEMS_NO_PRIORITY, - &Semaphore + &ctx.semaphore ); - directive_failed( sc, "rtems_semaphore_create of SM1" ); - - Main_TCB = _Thread_Get_executing(); + T_assert_rsc_success( sc ); - interrupt_critical_section_test( test_body, NULL, test_release_from_isr ); - - if ( case_hit ) { - puts( "Init - Case hit" ); - TEST_END(); - } else - puts( "Init - Case not hit - ran too long" ); + state = T_interrupt_test( &config, &ctx ); + T_eq_int( state, T_INTERRUPT_TEST_DONE ); + sc = rtems_semaphore_delete( ctx.semaphore ); + T_rsc_success( sc ); +} - rtems_test_exit(0); +static rtems_task Init( rtems_task_argument argument ) +{ + rtems_test_run( argument, TEST_STATE ); } /* configuration information */ @@ -101,9 +143,7 @@ static rtems_task Init( #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER #define CONFIGURE_MAXIMUM_TASKS 1 -#define CONFIGURE_MAXIMUM_TIMERS 1 #define CONFIGURE_MAXIMUM_SEMAPHORES 1 -#define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1 #define CONFIGURE_MICROSECONDS_PER_TICK 1000 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION diff --git a/testsuites/sptests/spintrcritical16/spintrcritical16.scn b/testsuites/sptests/spintrcritical16/spintrcritical16.scn index 49e6597047..aeb8946788 100644 --- a/testsuites/sptests/spintrcritical16/spintrcritical16.scn +++ b/testsuites/sptests/spintrcritical16/spintrcritical16.scn @@ -1,7 +1,24 @@ -*** TEST INTERRUPT CRITICAL SECTION 16 *** -Init - Trying to generate timeout of a thread that had its blocking -Init - request satisfied while blocking but before time timeout -Init - rtems_semaphore_create - OK -Support - rtems_timer_create - creating timer 1 -Init - Case hit -*** END OF TEST INTERRUPT CRITICAL SECTION 16 *** +*** BEGIN OF TEST SPINTRCRITICAL 16 *** +*** TEST VERSION: 6.0.0.929e49a54ab4d2d18c9fb8d03610614f63e25b8d +*** TEST STATE: EXPECTED_PASS +*** TEST BUILD: RTEMS_DEBUG RTEMS_POSIX_API RTEMS_SMP +*** TEST TOOLS: 10.0.1 20200406 (RTEMS 6, RSB bec88a6dd856892c3e66e4598252ea07d7a0d762, Newlib ece49e4) +A:SPINTRCRITICAL 16 +S:Platform:RTEMS +S:Compiler:10.0.1 20200406 (RTEMS 6, RSB bec88a6dd856892c3e66e4598252ea07d7a0d762, Newlib ece49e4) +S:Version:6.0.0.929e49a54ab4d2d18c9fb8d03610614f63e25b8d +S:BSP:realview_pbx_a9_qemu +S:RTEMS_DEBUG:1 +S:RTEMS_MULTIPROCESSING:0 +S:RTEMS_POSIX_API:1 +S:RTEMS_PROFILING:0 +S:RTEMS_SMP:1 +B:SemaphoreSatisfyBeforeTimeout +P:0:0:UI1:init.c:119 +P:1:0:UI1:init.c:122 +P:2:0:UI1:init.c:125 +E:SemaphoreSatisfyBeforeTimeout:N:3:F:0:D:0.058378 +Z:SPINTRCRITICAL 16:C:1:N:3:F:0:D:0.059654 +Y:ReportHash:SHA256:c1e358e47313edf10cbf9e1aef2cdd06ce96bc85c69d109e3494b4d1e0880f8f + +*** END OF TEST SPINTRCRITICAL 16 *** -- cgit v1.2.3