mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2026-09-21 00:25:13 +08:00
spintrcritical16: Use T_interrupt_test()
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 <tmacros.h>
|
||||
#include <intrcritical.h>
|
||||
#include <rtems/test.h>
|
||||
#include <rtems/test-info.h>
|
||||
|
||||
#include <rtems/score/threadimpl.h>
|
||||
|
||||
const char rtems_test_name[] = "SPINTRCRITICAL 16";
|
||||
|
||||
static Thread_Control *Main_TCB;
|
||||
typedef struct {
|
||||
Thread_Control *thread;
|
||||
rtems_id semaphore;
|
||||
} test_context;
|
||||
|
||||
static rtems_id Semaphore;
|
||||
|
||||
static bool case_hit;
|
||||
|
||||
static bool interrupts_blocking_op(void)
|
||||
{
|
||||
Thread_Wait_flags flags = _Thread_Wait_flags_get( Main_TCB );
|
||||
|
||||
return
|
||||
flags == ( THREAD_WAIT_CLASS_OBJECT | THREAD_WAIT_STATE_INTEND_TO_BLOCK );
|
||||
}
|
||||
|
||||
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 ( Main_TCB->Wait.queue != NULL ) {
|
||||
_Thread_Timeout( &Main_TCB->Timer.Watchdog );
|
||||
}
|
||||
}
|
||||
|
||||
static bool test_body( void *arg )
|
||||
static T_interrupt_test_state interrupt( void *arg )
|
||||
{
|
||||
test_context *ctx;
|
||||
T_interrupt_test_state state;
|
||||
Thread_Wait_flags flags;
|
||||
rtems_status_code sc;
|
||||
|
||||
(void) arg;
|
||||
state = T_interrupt_test_get_state();
|
||||
|
||||
sc = rtems_semaphore_obtain( Semaphore, RTEMS_DEFAULT_OPTIONS, 2 );
|
||||
rtems_test_assert( sc == RTEMS_SUCCESSFUL || sc == RTEMS_TIMEOUT );
|
||||
if (state != T_INTERRUPT_TEST_ACTION) {
|
||||
return T_INTERRUPT_TEST_CONTINUE;
|
||||
}
|
||||
|
||||
return case_hit;
|
||||
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 rtems_task Init(
|
||||
rtems_task_argument ignored
|
||||
)
|
||||
static void prepare( 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"
|
||||
ctx = arg;
|
||||
|
||||
do {
|
||||
sc = rtems_semaphore_obtain( ctx->semaphore, RTEMS_NO_WAIT, 0 );
|
||||
} while ( sc == RTEMS_SUCCESSFUL );
|
||||
}
|
||||
|
||||
static void action( void *arg )
|
||||
{
|
||||
test_context *ctx;
|
||||
rtems_status_code sc;
|
||||
|
||||
ctx = arg;
|
||||
sc = rtems_semaphore_obtain( ctx->semaphore, RTEMS_DEFAULT_OPTIONS, 2 );
|
||||
T_quiet_rsc_success( sc );
|
||||
}
|
||||
|
||||
static void blocked( void *arg )
|
||||
{
|
||||
test_context *ctx;
|
||||
rtems_status_code sc;
|
||||
|
||||
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" );
|
||||
T_assert_rsc_success( sc );
|
||||
|
||||
Main_TCB = _Thread_Get_executing();
|
||||
state = T_interrupt_test( &config, &ctx );
|
||||
T_eq_int( state, T_INTERRUPT_TEST_DONE );
|
||||
|
||||
interrupt_critical_section_test( test_body, NULL, test_release_from_isr );
|
||||
sc = rtems_semaphore_delete( ctx.semaphore );
|
||||
T_rsc_success( sc );
|
||||
}
|
||||
|
||||
if ( case_hit ) {
|
||||
puts( "Init - Case hit" );
|
||||
TEST_END();
|
||||
} else
|
||||
puts( "Init - Case not hit - ran too long" );
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
@@ -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 ***
|
||||
|
||||
Reference in New Issue
Block a user