Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:47

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  Copyright (C) 2020 embedded brains GmbH & Co. KG
0005  *
0006  *  COPYRIGHT (c) 1989-2009.
0007  *  On-Line Applications Research Corporation (OAR).
0008  *
0009  * Redistribution and use in source and binary forms, with or without
0010  * modification, are permitted provided that the following conditions
0011  * are met:
0012  * 1. Redistributions of source code must retain the above copyright
0013  *    notice, this list of conditions and the following disclaimer.
0014  * 2. Redistributions in binary form must reproduce the above copyright
0015  *    notice, this list of conditions and the following disclaimer in the
0016  *    documentation and/or other materials provided with the distribution.
0017  *
0018  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0019  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0020  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0021  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0022  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0023  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0024  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0025  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0026  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0027  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0028  * POSSIBILITY OF SUCH DAMAGE.
0029  */
0030 
0031 #ifdef HAVE_CONFIG_H
0032 #include "config.h"
0033 #endif
0034 
0035 #include <rtems/test.h>
0036 #include <rtems/test-info.h>
0037 
0038 #include <rtems/score/threadimpl.h>
0039 
0040 const char rtems_test_name[] = "SPINTRCRITICAL 16";
0041 
0042 typedef struct {
0043   Thread_Control *thread;
0044   rtems_id        semaphore;
0045 } test_context;
0046 
0047 static T_interrupt_test_state interrupt( void *arg )
0048 {
0049   test_context *ctx;
0050   T_interrupt_test_state state;
0051   Thread_Wait_flags flags;
0052   rtems_status_code sc;
0053 
0054   state = T_interrupt_test_get_state();
0055 
0056   if (state != T_INTERRUPT_TEST_ACTION) {
0057     return T_INTERRUPT_TEST_CONTINUE;
0058   }
0059 
0060   ctx = arg;
0061   flags = _Thread_Wait_flags_get( ctx->thread );
0062 
0063   if (
0064     flags == ( THREAD_WAIT_CLASS_OBJECT | THREAD_WAIT_STATE_INTEND_TO_BLOCK )
0065   ) {
0066     state = T_INTERRUPT_TEST_DONE;
0067   } else if (
0068     flags == ( THREAD_WAIT_CLASS_OBJECT | THREAD_WAIT_STATE_BLOCKED )
0069   ) {
0070     state = T_INTERRUPT_TEST_LATE;
0071   } else {
0072     state = T_INTERRUPT_TEST_EARLY;
0073   }
0074 
0075   sc = rtems_semaphore_release( ctx->semaphore );
0076   T_quiet_rsc_success( sc );
0077 
0078   return state;
0079 }
0080 
0081 static void prepare( void *arg )
0082 {
0083   test_context *ctx;
0084   rtems_status_code sc;
0085 
0086   ctx = arg;
0087 
0088   do {
0089     sc = rtems_semaphore_obtain( ctx->semaphore, RTEMS_NO_WAIT, 0 );
0090   } while ( sc == RTEMS_SUCCESSFUL );
0091 }
0092 
0093 static void action( void *arg )
0094 {
0095   test_context *ctx;
0096   rtems_status_code sc;
0097 
0098   ctx = arg;
0099   sc = rtems_semaphore_obtain( ctx->semaphore, RTEMS_DEFAULT_OPTIONS, 2 );
0100   T_quiet_rsc_success( sc );
0101 }
0102 
0103 static void blocked( void *arg )
0104 {
0105   test_context *ctx;
0106   rtems_status_code sc;
0107 
0108   T_interrupt_test_change_state(
0109     T_INTERRUPT_TEST_ACTION,
0110     T_INTERRUPT_TEST_LATE
0111   );
0112 
0113   ctx = arg;
0114   sc = rtems_semaphore_release( ctx->semaphore );
0115   T_quiet_rsc_success( sc );
0116 }
0117 
0118 static const T_interrupt_test_config config = {
0119   .prepare = prepare,
0120   .action = action,
0121   .interrupt = interrupt,
0122   .blocked = blocked,
0123   .max_iteration_count = 10000
0124 };
0125 
0126 /*
0127  * Trying to generate timeout of a thread that had its blocking request
0128  * satisfied while blocking but before time timeout.
0129  */
0130 T_TEST_CASE( SemaphoreSatisfyBeforeTimeout )
0131 {
0132   test_context ctx;
0133   rtems_status_code sc;
0134   T_interrupt_test_state state;
0135 
0136   ctx.thread = _Thread_Get_executing();
0137 
0138   sc = rtems_semaphore_create(
0139     rtems_build_name( 'S', 'M', '1', ' ' ),
0140     0,
0141     RTEMS_DEFAULT_ATTRIBUTES,
0142     RTEMS_NO_PRIORITY,
0143     &ctx.semaphore
0144   );
0145   T_assert_rsc_success( sc );
0146 
0147   state = T_interrupt_test( &config, &ctx );
0148   T_eq_int( state, T_INTERRUPT_TEST_DONE );
0149 
0150   sc = rtems_semaphore_delete( ctx.semaphore );
0151   T_rsc_success( sc );
0152 }
0153 
0154 static rtems_task Init( rtems_task_argument argument )
0155 {
0156   rtems_test_run( argument, TEST_STATE );
0157 }
0158 
0159 /* configuration information */
0160 
0161 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0162 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0163 
0164 #define CONFIGURE_MAXIMUM_TASKS          1
0165 #define CONFIGURE_MAXIMUM_SEMAPHORES     1
0166 #define CONFIGURE_MICROSECONDS_PER_TICK  1000
0167 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0168 
0169 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0170 
0171 #define CONFIGURE_INIT
0172 #include <rtems/confdefs.h>
0173 
0174 /* global variables */