Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 2014.
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 <rtems.h>
0034 
0035 #include "tmacros.h"
0036 
0037 const char rtems_test_name[] = "SMPSCHEDSEM 01";
0038 
0039 #define NUM_CPUS   1
0040 #define TASK_COUNT 2
0041 #define TASK_PRIORITY 8
0042 #define SEM_PRIORITY 5
0043 
0044 /*
0045  * Test verifies priority,
0046  * Changes priority by obtaining a higher priority semaphore
0047  * Releases semaphore to return priority
0048  */
0049 static void test(void)
0050 {
0051   rtems_status_code   sc;
0052   rtems_task_priority priority;
0053   rtems_id            task_sem;
0054 
0055   sc = rtems_semaphore_create(  
0056     rtems_build_name('S', 'E', 'M', '0'),
0057     1,
0058     RTEMS_BINARY_SEMAPHORE |
0059     RTEMS_PRIORITY     |
0060     RTEMS_PRIORITY_CEILING, 
0061     5,
0062     &task_sem
0063   );  
0064   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0065 
0066   rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &priority);
0067   printf("Init: priority %d expected %d\n",(int)priority, TASK_PRIORITY );
0068   rtems_test_assert( priority == TASK_PRIORITY );
0069 
0070   printf("Init: Obtain Semaphore\n");
0071   sc = rtems_semaphore_obtain (task_sem, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
0072   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0073   rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &priority);
0074   printf("Init: priority %d expected %d\n",(int)priority, SEM_PRIORITY );
0075   rtems_test_assert( priority == SEM_PRIORITY );
0076 
0077   printf("Init: Release Semaphore\n");
0078   rtems_semaphore_release(task_sem);
0079   rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &priority);
0080   printf("Init: priority %d expected %d\n",(int)priority, TASK_PRIORITY );
0081   rtems_test_assert( priority == TASK_PRIORITY );
0082 }
0083 
0084 static void Init(rtems_task_argument arg)
0085 {
0086   TEST_BEGIN();
0087 
0088   test();
0089 
0090   TEST_END();
0091   rtems_test_exit(0);
0092 }
0093 
0094 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0095 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0096 
0097 #define CONFIGURE_SCHEDULER_PRIORITY_AFFINITY_SMP
0098 
0099 #define CONFIGURE_MAXIMUM_PROCESSORS NUM_CPUS
0100 
0101 #define CONFIGURE_MAXIMUM_TASKS          TASK_COUNT
0102 #define CONFIGURE_MAXIMUM_SEMAPHORES     1
0103 
0104 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0105 
0106 #define CONFIGURE_INIT_TASK_PRIORITY     TASK_PRIORITY
0107 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0108 
0109 #define CONFIGURE_INIT
0110 
0111 #include <rtems/confdefs.h>