Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2012.
0005  *  On-Line Applications Research Corporation (OAR).
0006  *
0007  * Redistribution and use in source and binary forms, with or without
0008  * modification, are permitted provided that the following conditions
0009  * are met:
0010  * 1. Redistributions of source code must retain the above copyright
0011  *    notice, this list of conditions and the following disclaimer.
0012  * 2. Redistributions in binary form must reproduce the above copyright
0013  *    notice, this list of conditions and the following disclaimer in the
0014  *    documentation and/or other materials provided with the distribution.
0015  *
0016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0026  * POSSIBILITY OF SUCH DAMAGE.
0027  */
0028 
0029 #ifdef HAVE_CONFIG_H
0030 #include "config.h"
0031 #endif
0032 
0033 #include <tmacros.h>
0034 #include <unistd.h>
0035 
0036 /* forward declarations to avoid warnings */
0037 rtems_task Init(rtems_task_argument argument);
0038 rtems_task Task_1(rtems_task_argument arg);
0039 
0040 #if defined(INHERIT_CEILING)
0041   #define TEST_NAME                "66"
0042   #define TASK_PRIORITY            2
0043 #else
0044   #define TEST_NAME                "65"
0045   #define TASK_PRIORITY            1
0046 #endif
0047 
0048 const char rtems_test_name[] = "SP " TEST_NAME;
0049 
0050 static void assert_priority(rtems_task_priority expected)
0051 {
0052   rtems_status_code sc;
0053   rtems_task_priority prio;
0054 
0055   sc = rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &prio);
0056   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0057 
0058   rtems_test_assert(prio == expected);
0059 }
0060 
0061 rtems_task Init(
0062   rtems_task_argument ignored
0063 )
0064 {
0065   int                  status;
0066   rtems_id             Mutex_id, Task_id;
0067 
0068   TEST_BEGIN();
0069 
0070   /*
0071    * Verify that an initially locked priority ceiling mutex elevates the
0072    * priority of the creating task.
0073    */
0074 
0075   status = rtems_semaphore_create(
0076     rtems_build_name( 's','e','m','1' ),
0077     0,
0078     RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY | RTEMS_PRIORITY_CEILING,
0079     1,
0080     &Mutex_id
0081   );
0082   rtems_test_assert(status == RTEMS_SUCCESSFUL);
0083 
0084   assert_priority(1);
0085 
0086   status = rtems_semaphore_release(Mutex_id);
0087   rtems_test_assert(status == RTEMS_SUCCESSFUL);
0088 
0089   assert_priority(TASK_PRIORITY);
0090 
0091   status = rtems_semaphore_delete(Mutex_id);
0092   rtems_test_assert(status == RTEMS_SUCCESSFUL);
0093 
0094   /*
0095    *  Create binary semaphore (a.k.a. Mutex) with Priority Ceiling
0096    *  attribute.
0097    */
0098 
0099   puts( "Creating semaphore" );
0100   status = rtems_semaphore_create(
0101     rtems_build_name( 's','e','m','1' ),
0102     1,
0103     RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY | RTEMS_PRIORITY_CEILING,
0104     1,
0105     &Mutex_id
0106   );
0107   directive_failed( status, "rtems_semaphore_create" );
0108 
0109   puts( "Calling rtems_semaphore_obtain" );
0110   status = rtems_semaphore_obtain( Mutex_id, RTEMS_DEFAULT_OPTIONS, 0 );
0111   directive_failed( status, "rtems_semaphore_obtain" );
0112 
0113   puts( "Calling rtems_task_create" );
0114   status = rtems_task_create( rtems_build_name( 'T', 'A', 'S', '1' ),
0115     TASK_PRIORITY,
0116     RTEMS_MINIMUM_STACK_SIZE,
0117     RTEMS_DEFAULT_MODES,
0118     RTEMS_DEFAULT_ATTRIBUTES,
0119     &Task_id
0120   );
0121   directive_failed( status, "rtems_task_create" );
0122 
0123   puts( "Calling rtems_task_start" );
0124   status = rtems_task_start( Task_id, Task_1, (rtems_task_argument)&Mutex_id );
0125   directive_failed( status, "rtems_task_start" );
0126 
0127   sleep(1);
0128 
0129   puts( "Calling semaphore release" );
0130   status = rtems_semaphore_release( Mutex_id );
0131   directive_failed( status, "rtems_semaphore_release" );
0132 
0133   TEST_END();
0134 
0135   rtems_test_exit(0);
0136 }
0137 
0138 rtems_task Task_1(
0139   rtems_task_argument arg
0140 )
0141 {
0142   int status_in_task;
0143   rtems_id *Mutex_id = (rtems_id *)arg;
0144 
0145   puts( "Init Task_1: Obtaining semaphore" );
0146   status_in_task = rtems_semaphore_obtain(
0147     *Mutex_id,
0148     RTEMS_DEFAULT_OPTIONS,
0149     0
0150   );
0151   directive_failed( status_in_task, "Task_1 rtems_semaphore_obtain" );
0152   return;
0153 }
0154 
0155 /* configuration information */
0156 
0157 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0158 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0159 
0160 #define CONFIGURE_MAXIMUM_TASKS         2
0161 #define CONFIGURE_MAXIMUM_SEMAPHORES    1
0162 #define CONFIGURE_INIT_TASK_PRIORITY    TASK_PRIORITY
0163 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0164 
0165 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0166 
0167 #define CONFIGURE_INIT
0168 #include <rtems/confdefs.h>
0169 
0170 /* global variables */