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 #if !defined(OPERATION_COUNT)
0030 #define OPERATION_COUNT 100
0031 #endif
0032
0033 #if defined(USE_WAIT)
0034 #define TEST_NUMBER "08"
0035 #define TEST_CASE "pthread_cond_wait: blocking"
0036 #elif defined(USE_TIMEDWAIT_WITH_VALUE)
0037 #define TEST_NUMBER "09"
0038 #define TEST_CASE "pthread_cond_timedwait: blocking"
0039 #elif defined(USE_TIMEDWAIT_WAIT_VALUE_IN_PAST)
0040 #define TEST_NUMBER "10"
0041 #define TEST_CASE "pthread_cond_timedwait: time in past error"
0042 #else
0043 #error "How am I being compiled?"
0044 #endif
0045
0046 #ifdef HAVE_CONFIG_H
0047 #include "config.h"
0048 #endif
0049
0050 #include <sys/time.h>
0051 #include <stdio.h>
0052 #include <time.h>
0053 #include <errno.h>
0054 #include <sched.h>
0055 #include <timesys.h>
0056 #include <tmacros.h>
0057 #include <rtems/btimer.h>
0058 #include "test_support.h"
0059
0060 #include <pthread.h>
0061
0062 const char rtems_test_name[] = "PSXTMCOND " TEST_NUMBER;
0063
0064
0065 void *POSIX_Init(void *argument);
0066 void *Middle(void *argument);
0067 void *Low(void *argument);
0068
0069 pthread_cond_t CondID;
0070 pthread_mutex_t MutexID;
0071 struct timespec sleepTime;
0072
0073 void *Low(
0074 void *argument
0075 )
0076 {
0077 uint32_t end_time;
0078
0079 end_time = benchmark_timer_read();
0080
0081 put_time(
0082 TEST_CASE,
0083 end_time,
0084 OPERATION_COUNT,
0085 0,
0086 0
0087 );
0088
0089 TEST_END();
0090
0091 rtems_test_exit( 0 );
0092 return NULL;
0093 }
0094
0095 void *Middle(
0096 void *argument
0097 )
0098 {
0099 int rc;
0100
0101
0102 rc = pthread_mutex_lock(&MutexID);
0103 rtems_test_assert( rc == 0 );
0104
0105
0106
0107 #if defined(USE_WAIT)
0108 rc = pthread_cond_wait( &CondID, &MutexID );
0109 rtems_test_assert( rc == 0 );
0110
0111 #elif defined(USE_TIMEDWAIT_WITH_VALUE)
0112
0113 ++sleepTime.tv_sec;
0114
0115 rc = pthread_cond_timedwait( &CondID, &MutexID, &sleepTime );
0116 rtems_test_assert( rc == 0 );
0117
0118 #elif defined(USE_TIMEDWAIT_WAIT_VALUE_IN_PAST)
0119 {
0120
0121 sleepTime.tv_sec = 0;
0122 sleepTime.tv_nsec = 5;
0123
0124
0125 rc = pthread_cond_timedwait( &CondID, &MutexID, &sleepTime );
0126 rtems_test_assert(rc == ETIMEDOUT);
0127 benchmark_timer_read();
0128 }
0129 #endif
0130
0131 pthread_mutex_unlock(&MutexID);
0132 #if defined(USE_TIMEDWAIT_WAIT_VALUE_IN_PAST)
0133
0134
0135
0136
0137
0138
0139 sched_yield();
0140 #endif
0141 return NULL;
0142 }
0143
0144 void *POSIX_Init(
0145 void *argument
0146 )
0147 {
0148 int i;
0149 int status;
0150 pthread_t threadId;
0151 int rc;
0152 struct timeval tp;
0153
0154 TEST_BEGIN();
0155
0156 rc = gettimeofday(&tp, NULL);
0157 rtems_test_assert( rc == 0 );
0158
0159
0160 sleepTime.tv_sec = tp.tv_sec;
0161 sleepTime.tv_nsec = tp.tv_usec * 1000;
0162
0163 rc = pthread_cond_init(&CondID, NULL);
0164 rtems_test_assert( rc == 0 );
0165
0166 rc = pthread_mutex_init(&MutexID, NULL);
0167 rtems_test_assert( rc == 0 );
0168
0169 rc = pthread_mutex_lock(&MutexID);
0170 rtems_test_assert( rc == 0 );
0171
0172 for ( i=0 ; i < OPERATION_COUNT - 1 ; i++ ) {
0173 status = pthread_create( &threadId, NULL, Middle, NULL );
0174 rtems_test_assert( !status );
0175 }
0176
0177 status = pthread_create( &threadId, NULL, Low, NULL );
0178 rtems_test_assert( !status );
0179
0180
0181 benchmark_timer_initialize();
0182
0183 rc = pthread_mutex_unlock(&MutexID);
0184 rtems_test_assert( rc == 0 );
0185
0186
0187 return NULL;
0188 }
0189
0190
0191
0192 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0193 #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
0194
0195 #define CONFIGURE_MAXIMUM_POSIX_THREADS OPERATION_COUNT + 2
0196 #define CONFIGURE_POSIX_INIT_THREAD_TABLE
0197
0198 #define CONFIGURE_INIT
0199
0200 #include <rtems/confdefs.h>
0201