File indexing completed on 2025-05-11 08:24:41
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 #ifdef HAVE_CONFIG_H
0030 #include "config.h"
0031 #endif
0032
0033 #include <errno.h>
0034 #include <fcntl.h>
0035 #include <semaphore.h>
0036 #include <tmacros.h>
0037 #include <timesys.h>
0038 #include <rtems/btimer.h>
0039 #include "test_support.h"
0040
0041 const char rtems_test_name[] = "PSXTMSEM 01";
0042
0043
0044 void *POSIX_Init(void *argument);
0045
0046 #define MAX_SEMS 2
0047
0048 sem_t sem1;
0049 sem_t *n_sem1;
0050 sem_t *n_sem2;
0051
0052 static void benchmark_sem_init(void)
0053 {
0054 benchmark_timer_t end_time;
0055 int status;
0056
0057 benchmark_timer_initialize();
0058 status = sem_init( &sem1, 0, 1 );
0059 end_time = benchmark_timer_read();
0060 rtems_test_assert( status == 0 );
0061
0062 put_time(
0063 "sem_init: only case",
0064 end_time,
0065 1,
0066 0,
0067 0
0068 );
0069 }
0070
0071 static void benchmark_sem_destroy(void)
0072 {
0073 benchmark_timer_t end_time;
0074 int status;
0075
0076 benchmark_timer_initialize();
0077 status = sem_destroy( &sem1 );
0078 end_time = benchmark_timer_read();
0079 rtems_test_assert( status == 0 );
0080
0081 put_time(
0082 "sem_destroy: only case",
0083 end_time,
0084 1,
0085 0,
0086 0
0087 );
0088 }
0089
0090 static void benchmark_sem_open(bool report_time)
0091 {
0092 benchmark_timer_t end_time;
0093
0094 benchmark_timer_initialize();
0095 n_sem1 = sem_open( "sem1", O_CREAT, 0777, 1 );
0096 end_time = benchmark_timer_read();
0097
0098 if ( report_time ) {
0099 put_time(
0100 "sem_open: first open O_CREAT",
0101 end_time,
0102 1,
0103 0,
0104 0
0105 );
0106 }
0107 }
0108
0109 static void benchmark_sem_close(bool report_time)
0110 {
0111 benchmark_timer_t end_time;
0112 int status;
0113
0114 benchmark_timer_initialize();
0115 status = sem_close( n_sem1 );
0116 end_time = benchmark_timer_read();
0117 rtems_test_assert( status == 0 );
0118
0119 if ( report_time ) {
0120 put_time(
0121 "sem_close: named first/nested close",
0122 end_time,
0123 1,
0124 0,
0125 0
0126 );
0127 }
0128 }
0129
0130 static void benchmark_sem_unlink(const char *message)
0131 {
0132 benchmark_timer_t end_time;
0133 int status;
0134
0135 benchmark_timer_initialize();
0136 status = sem_unlink( "sem1" );
0137 end_time = benchmark_timer_read();
0138 rtems_test_assert( status == 0 );
0139
0140 put_time(
0141 message,
0142 end_time,
0143 1,
0144 0,
0145 0
0146 );
0147 }
0148
0149 static void benchmark_sem_open_second(void)
0150 {
0151 benchmark_timer_t end_time;
0152
0153 benchmark_timer_initialize();
0154 n_sem2 = sem_open( "sem1", O_EXCL, 0777, 1 );
0155 end_time = benchmark_timer_read();
0156
0157 put_time(
0158 "sem_open: second open O_EXCL",
0159 end_time,
0160 1,
0161 0,
0162 0
0163 );
0164 }
0165
0166 static void benchmark_sem_close_second(void)
0167 {
0168 benchmark_timer_t end_time;
0169 int status;
0170
0171 benchmark_timer_initialize();
0172 status = sem_close( n_sem2 );
0173 end_time = benchmark_timer_read();
0174 rtems_test_assert( status == 0 );
0175
0176 put_time(
0177 "sem_close: named second close",
0178 end_time,
0179 1,
0180 0,
0181 0
0182 );
0183 }
0184
0185 void *POSIX_Init(void *argument)
0186 {
0187
0188 TEST_BEGIN();
0189
0190
0191 benchmark_sem_init();
0192
0193 benchmark_sem_destroy();
0194
0195
0196 benchmark_sem_open(true);
0197
0198 benchmark_sem_open_second();
0199
0200 benchmark_sem_close(true);
0201
0202 benchmark_sem_unlink("sem_unlink: does not delete");
0203
0204 benchmark_sem_close_second();
0205
0206
0207 benchmark_sem_open(false);
0208 benchmark_sem_close(false);
0209 benchmark_sem_unlink("sem_unlink: deletes semaphore");
0210
0211 TEST_END();
0212
0213 rtems_test_exit(0);
0214 }
0215
0216
0217
0218 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0219 #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
0220
0221 #define CONFIGURE_MAXIMUM_POSIX_THREADS 1
0222 #define CONFIGURE_MAXIMUM_POSIX_SEMAPHORES MAX_SEMS
0223 #define CONFIGURE_POSIX_INIT_THREAD_TABLE
0224
0225 #define CONFIGURE_INIT
0226
0227 #include <rtems/confdefs.h>
0228