1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2013. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * |
---|
5 | * The license and distribution terms for this file may be |
---|
6 | * found in the file LICENSE in this distribution or at |
---|
7 | * http://www.rtems.org/license/LICENSE. |
---|
8 | */ |
---|
9 | |
---|
10 | #ifdef HAVE_CONFIG_H |
---|
11 | #include "config.h" |
---|
12 | #endif |
---|
13 | |
---|
14 | #include <timesys.h> |
---|
15 | #include <rtems/btimer.h> |
---|
16 | #include <errno.h> |
---|
17 | #include <pthread.h> |
---|
18 | #include "test_support.h" |
---|
19 | |
---|
20 | const char rtems_test_name[] = "PSXTMMUTEX 03"; |
---|
21 | |
---|
22 | /* forward declarations to avoid warnings */ |
---|
23 | void *POSIX_Init(void *argument); |
---|
24 | void benchmark_mutex_lock_available(void); |
---|
25 | void benchmark_mutex_unlock_no_threads_waiting(void); |
---|
26 | void benchmark_mutex_trylock_available(void); |
---|
27 | void benchmark_mutex_trylock_not_available(void); |
---|
28 | void benchmark_mutex_timedlock_available(void); |
---|
29 | |
---|
30 | pthread_mutex_t MutexId; |
---|
31 | |
---|
32 | void benchmark_mutex_lock_available(void) |
---|
33 | { |
---|
34 | benchmark_timer_t end_time; |
---|
35 | int status; |
---|
36 | |
---|
37 | benchmark_timer_initialize(); |
---|
38 | status = pthread_mutex_lock( &MutexId ); |
---|
39 | end_time = benchmark_timer_read(); |
---|
40 | rtems_test_assert( !status ); |
---|
41 | |
---|
42 | put_time( |
---|
43 | "pthread_mutex_lock: available", |
---|
44 | end_time, |
---|
45 | 1, |
---|
46 | 0, |
---|
47 | 0 |
---|
48 | ); |
---|
49 | } |
---|
50 | |
---|
51 | void benchmark_mutex_unlock_no_threads_waiting(void) |
---|
52 | { |
---|
53 | benchmark_timer_t end_time; |
---|
54 | int status; |
---|
55 | |
---|
56 | benchmark_timer_initialize(); |
---|
57 | status = pthread_mutex_unlock( &MutexId ); |
---|
58 | end_time = benchmark_timer_read(); |
---|
59 | rtems_test_assert( !status ); |
---|
60 | |
---|
61 | put_time( |
---|
62 | "pthread_mutex_unlock: no threads waiting", |
---|
63 | end_time, |
---|
64 | 1, |
---|
65 | 0, |
---|
66 | 0 |
---|
67 | ); |
---|
68 | } |
---|
69 | |
---|
70 | void benchmark_mutex_trylock_available(void) |
---|
71 | { |
---|
72 | benchmark_timer_t end_time; |
---|
73 | int status; |
---|
74 | |
---|
75 | benchmark_timer_initialize(); |
---|
76 | status = pthread_mutex_trylock( &MutexId ); |
---|
77 | end_time = benchmark_timer_read(); |
---|
78 | rtems_test_assert( !status ); |
---|
79 | |
---|
80 | put_time( |
---|
81 | "pthread_mutex_trylock: available", |
---|
82 | end_time, |
---|
83 | 1, |
---|
84 | 0, |
---|
85 | 0 |
---|
86 | ); |
---|
87 | } |
---|
88 | |
---|
89 | void benchmark_mutex_trylock_not_available(void) |
---|
90 | { |
---|
91 | benchmark_timer_t end_time; |
---|
92 | int status; |
---|
93 | |
---|
94 | benchmark_timer_initialize(); |
---|
95 | status = pthread_mutex_trylock( &MutexId ); |
---|
96 | /* |
---|
97 | * it has to return a negative value |
---|
98 | * because it try to lock a not available mutex |
---|
99 | * so the assert call is make with status instead !status |
---|
100 | */ |
---|
101 | end_time = benchmark_timer_read(); |
---|
102 | rtems_test_assert( status ); |
---|
103 | |
---|
104 | put_time( |
---|
105 | "pthread_mutex_trylock: not available", |
---|
106 | end_time, |
---|
107 | 1, |
---|
108 | 0, |
---|
109 | 0 |
---|
110 | ); |
---|
111 | } |
---|
112 | |
---|
113 | void benchmark_mutex_timedlock_available(void) |
---|
114 | { |
---|
115 | benchmark_timer_t end_time; |
---|
116 | int status; |
---|
117 | |
---|
118 | benchmark_timer_initialize(); |
---|
119 | status = pthread_mutex_timedlock( &MutexId, 0 ); |
---|
120 | end_time = benchmark_timer_read(); |
---|
121 | rtems_test_assert( !status ); |
---|
122 | |
---|
123 | put_time( |
---|
124 | "pthread_mutex_timedlock: available", |
---|
125 | end_time, |
---|
126 | 1, |
---|
127 | 0, |
---|
128 | 0 |
---|
129 | ); |
---|
130 | } |
---|
131 | |
---|
132 | void *POSIX_Init( |
---|
133 | void *argument |
---|
134 | ) |
---|
135 | { |
---|
136 | int status; |
---|
137 | |
---|
138 | TEST_BEGIN(); |
---|
139 | |
---|
140 | /* |
---|
141 | * Create the single Mutex used in all the test case |
---|
142 | */ |
---|
143 | status = pthread_mutex_init( &MutexId, NULL ); |
---|
144 | rtems_test_assert( !status ); |
---|
145 | |
---|
146 | /* |
---|
147 | * Now invoke subroutines to time each test case |
---|
148 | * get the goal depends of its order |
---|
149 | */ |
---|
150 | benchmark_mutex_lock_available(); |
---|
151 | benchmark_mutex_unlock_no_threads_waiting(); |
---|
152 | benchmark_mutex_trylock_available(); |
---|
153 | benchmark_mutex_trylock_not_available(); |
---|
154 | benchmark_mutex_unlock_no_threads_waiting(); |
---|
155 | benchmark_mutex_timedlock_available(); |
---|
156 | benchmark_mutex_unlock_no_threads_waiting(); |
---|
157 | |
---|
158 | |
---|
159 | /* |
---|
160 | * Destroy the mutex used in the tests |
---|
161 | */ |
---|
162 | status = pthread_mutex_destroy( &MutexId ); |
---|
163 | rtems_test_assert( !status ); |
---|
164 | |
---|
165 | TEST_END(); |
---|
166 | |
---|
167 | rtems_test_exit(0); |
---|
168 | } |
---|
169 | |
---|
170 | /* configuration information */ |
---|
171 | |
---|
172 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
173 | #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER |
---|
174 | |
---|
175 | #define CONFIGURE_MAXIMUM_POSIX_THREADS 1 |
---|
176 | #define CONFIGURE_MAXIMUM_POSIX_MUTEXES 1 |
---|
177 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
178 | |
---|
179 | #define CONFIGURE_INIT |
---|
180 | |
---|
181 | #include <rtems/confdefs.h> |
---|
182 | /* end of file */ |
---|