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 02";
0042
0043
0044 void *POSIX_Init(void *argument);
0045
0046 sem_t sem1;
0047 sem_t *n_sem1;
0048
0049 static void benchmark_sem_getvalue(void)
0050 {
0051 benchmark_timer_t end_time;
0052 int status;
0053 int value;
0054
0055 benchmark_timer_initialize();
0056 status = sem_getvalue(&sem1, &value);
0057 end_time = benchmark_timer_read();
0058 rtems_test_assert( status == 0 );
0059
0060 put_time(
0061 "sem_getvalue: only case",
0062 end_time,
0063 1,
0064 0,
0065 0
0066 );
0067 }
0068
0069 static void benchmark_sem_wait(void)
0070 {
0071 benchmark_timer_t end_time;
0072 int status;
0073
0074 benchmark_timer_initialize();
0075 status = sem_wait(&sem1);
0076 end_time = benchmark_timer_read();
0077 rtems_test_assert( status == 0 );
0078
0079 put_time(
0080 "sem_wait: available",
0081 end_time,
0082 1,
0083 0,
0084 0
0085 );
0086 }
0087
0088 static void benchmark_sem_post(void)
0089 {
0090 benchmark_timer_t end_time;
0091 int status;
0092
0093 benchmark_timer_initialize();
0094 status = sem_post(&sem1);
0095 end_time = benchmark_timer_read();
0096 rtems_test_assert( status == 0 );
0097
0098 put_time(
0099 "sem_post: no threads waiting",
0100 end_time,
0101 1,
0102 0,
0103 0
0104 );
0105 }
0106
0107 static void benchmark_sem_trywait_available(void)
0108 {
0109 benchmark_timer_t end_time;
0110 int status;
0111
0112 benchmark_timer_initialize();
0113 status = sem_trywait(&sem1);
0114 end_time = benchmark_timer_read();
0115 rtems_test_assert( status == 0 );
0116
0117 put_time(
0118 "sem_trywait: available",
0119 end_time,
0120 1,
0121 0,
0122 0
0123 );
0124 }
0125
0126 static void benchmark_sem_trywait_not_available(void)
0127 {
0128 benchmark_timer_t end_time;
0129 int status;
0130
0131 benchmark_timer_initialize();
0132 status = sem_trywait(&sem1);
0133 end_time = benchmark_timer_read();
0134
0135 rtems_test_assert( status != 0 );
0136
0137 put_time(
0138 "sem_trywait: not available",
0139 end_time,
0140 1,
0141 0,
0142 0
0143 );
0144 }
0145
0146 void *POSIX_Init(void *argument)
0147 {
0148 int status;
0149 TEST_BEGIN();
0150
0151
0152 status = sem_init( &sem1, 0, 1 );
0153 rtems_test_assert( status == 0 );
0154
0155
0156 benchmark_sem_getvalue();
0157
0158 benchmark_sem_wait();
0159
0160 benchmark_sem_post();
0161
0162 benchmark_sem_trywait_available();
0163
0164 benchmark_sem_trywait_not_available();
0165
0166 TEST_END();
0167
0168
0169 status = sem_destroy(&sem1);
0170 rtems_test_assert( status == 0 );
0171
0172 rtems_test_exit(0);
0173 }
0174
0175
0176
0177 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0178 #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
0179
0180 #define CONFIGURE_MAXIMUM_POSIX_THREADS 1
0181 #define CONFIGURE_POSIX_INIT_THREAD_TABLE
0182
0183 #define CONFIGURE_INIT
0184 #include <rtems/confdefs.h>
0185