File indexing completed on 2025-05-11 08:24:45
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 #ifdef HAVE_CONFIG_H
0032 #include "config.h"
0033 #endif
0034
0035 #include <bsp.h>
0036 #include <tmacros.h>
0037
0038 #include <stdio.h>
0039 #include <stdlib.h>
0040
0041
0042 rtems_task Init(rtems_task_argument argument);
0043 void starttask(int arg);
0044 rtems_task subtask(rtems_task_argument arg);
0045 void doTest(void);
0046
0047 #define NTASK 4
0048
0049 #if defined(USE_COUNTING_SEMAPHORE)
0050 #define TEST_NAME "27a"
0051 #define TEST_SEMAPHORE_TYPE "counting"
0052 #define TEST_SEMAPHORE_ATTRIBUTES RTEMS_DEFAULT_ATTRIBUTES
0053 #else
0054 #define TEST_NAME "27"
0055 #define TEST_SEMAPHORE_TYPE "binary"
0056 #define TEST_SEMAPHORE_ATTRIBUTES (RTEMS_LOCAL| \
0057 RTEMS_BINARY_SEMAPHORE|RTEMS_NO_INHERIT_PRIORITY| \
0058 RTEMS_NO_PRIORITY_CEILING|RTEMS_FIFO)
0059 #endif
0060
0061 const char rtems_test_name[] = "SP " TEST_NAME;
0062
0063 rtems_id semaphore;
0064 volatile int flags[NTASK];
0065
0066 rtems_task subtask(
0067 rtems_task_argument arg
0068 )
0069 {
0070 rtems_status_code sc;
0071
0072 for (;;) {
0073 flags[arg]++;
0074 sc = rtems_semaphore_obtain(semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
0075 if (sc == RTEMS_SUCCESSFUL)
0076 puts("Obtained semaphore -- and should not have done so!");
0077 else if (sc != RTEMS_UNSATISFIED)
0078 printf("Can't get semaphore: %s\n", rtems_status_text(sc));
0079 }
0080 }
0081
0082 void starttask(
0083 int arg
0084 )
0085 {
0086 rtems_id tid;
0087 rtems_status_code sc;
0088 rtems_task_priority priority;
0089
0090 rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &priority);
0091 sc = rtems_task_create(rtems_build_name('S', 'R', 'V', arg + 'A'),
0092 priority,
0093 RTEMS_MINIMUM_STACK_SIZE,
0094 RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0),
0095 RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL,
0096 &tid);
0097 directive_failed( sc, "task create" );
0098
0099 sc = rtems_task_start(tid, subtask, (rtems_task_argument) arg);
0100 directive_failed( sc, "task start" );
0101 }
0102
0103 void doTest(void)
0104 {
0105 rtems_status_code sc;
0106 int pass, i;
0107
0108 sc = rtems_semaphore_create(
0109 rtems_build_name('S', 'E', 'M', 'F'),
0110 0,
0111 TEST_SEMAPHORE_ATTRIBUTES,
0112 0,
0113 &semaphore);
0114 directive_failed( sc, "semaphore create" );
0115
0116 for (i = 0 ; i < NTASK ; i++)
0117 flags[i] = 0;
0118
0119 for (i = 0 ; i < NTASK ; i++)
0120 starttask(i);
0121
0122 for (pass = 1 ; pass < 10 ; pass++) {
0123 rtems_task_wake_after(1);
0124 for (i = 0 ; i < NTASK ; i++) {
0125 if (flags[i] != pass)
0126 printf("flags[%d] = %d -- expected %d\n", i, flags[i], pass);
0127 }
0128 sc = rtems_semaphore_flush(semaphore);
0129 directive_failed( sc, "semaphore flush" );
0130 }
0131
0132 printf("Flushed all waiting tasks\n" );
0133 }
0134
0135 rtems_task Init(
0136 rtems_task_argument ignored
0137 )
0138 {
0139 TEST_BEGIN();
0140 puts( "Testing " TEST_SEMAPHORE_TYPE " semaphore flush" );
0141 doTest();
0142 TEST_END();
0143
0144 rtems_test_exit(0);
0145 }
0146
0147
0148
0149 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0150
0151 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0152
0153 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0154 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0155
0156 #define CONFIGURE_MAXIMUM_TASKS 6
0157 #define CONFIGURE_MAXIMUM_SEMAPHORES 1
0158
0159 #define CONFIGURE_INIT
0160
0161 #include <rtems/confdefs.h>
0162
0163
0164