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.com/license/LICENSE. |
---|
8 | */ |
---|
9 | |
---|
10 | #ifdef HAVE_CONFIG_H |
---|
11 | #include "config.h" |
---|
12 | #endif |
---|
13 | |
---|
14 | #include <errno.h> |
---|
15 | #include <fcntl.h> |
---|
16 | #include <semaphore.h> |
---|
17 | #include <tmacros.h> |
---|
18 | #include <timesys.h> |
---|
19 | #include <rtems/timerdrv.h> |
---|
20 | #include "test_support.h" |
---|
21 | |
---|
22 | /* forward declarations to avoid warnings */ |
---|
23 | void *POSIX_Init(void *argument); |
---|
24 | |
---|
25 | sem_t sem1; |
---|
26 | sem_t *n_sem1; |
---|
27 | |
---|
28 | static void benchmark_sem_getvalue(void) |
---|
29 | { |
---|
30 | benchmark_timer_t end_time; |
---|
31 | int status; |
---|
32 | int value; |
---|
33 | |
---|
34 | benchmark_timer_initialize(); |
---|
35 | status = sem_getvalue(&sem1, &value); |
---|
36 | end_time = benchmark_timer_read(); |
---|
37 | rtems_test_assert( status == 0 ); |
---|
38 | |
---|
39 | put_time( |
---|
40 | "sem_getvalue: only case", |
---|
41 | end_time, |
---|
42 | 1, /* Only executed once */ |
---|
43 | 0, |
---|
44 | 0 |
---|
45 | ); |
---|
46 | } |
---|
47 | |
---|
48 | static void benchmark_sem_wait(void) |
---|
49 | { |
---|
50 | benchmark_timer_t end_time; |
---|
51 | int status; |
---|
52 | |
---|
53 | benchmark_timer_initialize(); |
---|
54 | status = sem_wait(&sem1); |
---|
55 | end_time = benchmark_timer_read(); |
---|
56 | rtems_test_assert( status == 0 ); |
---|
57 | |
---|
58 | put_time( |
---|
59 | "sem_wait: available", |
---|
60 | end_time, |
---|
61 | 1, /* Only executed once */ |
---|
62 | 0, |
---|
63 | 0 |
---|
64 | ); |
---|
65 | } |
---|
66 | |
---|
67 | static void benchmark_sem_post(void) |
---|
68 | { |
---|
69 | benchmark_timer_t end_time; |
---|
70 | int status; |
---|
71 | |
---|
72 | benchmark_timer_initialize(); |
---|
73 | status = sem_post(&sem1); |
---|
74 | end_time = benchmark_timer_read(); |
---|
75 | rtems_test_assert( status == 0 ); |
---|
76 | |
---|
77 | put_time( |
---|
78 | "sem_post: no threads waiting", |
---|
79 | end_time, |
---|
80 | 1, /* Only executed once */ |
---|
81 | 0, |
---|
82 | 0 |
---|
83 | ); |
---|
84 | } |
---|
85 | |
---|
86 | static void benchmark_sem_trywait_available(void) |
---|
87 | { |
---|
88 | benchmark_timer_t end_time; |
---|
89 | int status; |
---|
90 | |
---|
91 | benchmark_timer_initialize(); |
---|
92 | status = sem_trywait(&sem1); |
---|
93 | end_time = benchmark_timer_read(); |
---|
94 | rtems_test_assert( status == 0 ); |
---|
95 | |
---|
96 | put_time( |
---|
97 | "sem_trywait: available", |
---|
98 | end_time, |
---|
99 | 1, /* Only executed once */ |
---|
100 | 0, |
---|
101 | 0 |
---|
102 | ); |
---|
103 | } |
---|
104 | |
---|
105 | static void benchmark_sem_trywait_not_available(void) |
---|
106 | { |
---|
107 | benchmark_timer_t end_time; |
---|
108 | int status; |
---|
109 | |
---|
110 | benchmark_timer_initialize(); |
---|
111 | status = sem_trywait(&sem1); |
---|
112 | end_time = benchmark_timer_read(); |
---|
113 | /*it must be non avalible, so status should be non zero*/ |
---|
114 | rtems_test_assert( status != 0 ); |
---|
115 | |
---|
116 | put_time( |
---|
117 | "sem_trywait: not available", |
---|
118 | end_time, |
---|
119 | 1, /* Only executed once */ |
---|
120 | 0, |
---|
121 | 0 |
---|
122 | ); |
---|
123 | } |
---|
124 | |
---|
125 | void *POSIX_Init(void *argument) |
---|
126 | { |
---|
127 | int status; |
---|
128 | puts( "\n\n*** POSIX TIME TEST PSXTMSEM02 ***" ); |
---|
129 | |
---|
130 | /* create the semaphore */ |
---|
131 | status = sem_init( &sem1, 0, 1 ); |
---|
132 | rtems_test_assert( status == 0 ); |
---|
133 | |
---|
134 | /* obtain the actual semaphore value */ |
---|
135 | benchmark_sem_getvalue(); |
---|
136 | /* lock the semaphore */ |
---|
137 | benchmark_sem_wait(); |
---|
138 | /* unlock the semaphore */ |
---|
139 | benchmark_sem_post(); |
---|
140 | /* try to lock the semaphore - available */ |
---|
141 | benchmark_sem_trywait_available(); |
---|
142 | /* try to lock the semaphore, not available */ |
---|
143 | benchmark_sem_trywait_not_available(); |
---|
144 | |
---|
145 | puts( "*** END OF POSIX TIME TEST PSXTMSEM02 ***" ); |
---|
146 | |
---|
147 | /*Destroying the semaphore*/ |
---|
148 | status = sem_destroy(&sem1); |
---|
149 | rtems_test_assert( status == 0 ); |
---|
150 | |
---|
151 | rtems_test_exit(0); |
---|
152 | } |
---|
153 | |
---|
154 | /* configuration information */ |
---|
155 | |
---|
156 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
157 | #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER |
---|
158 | |
---|
159 | #define CONFIGURE_MAXIMUM_POSIX_THREADS 1 |
---|
160 | #define CONFIGURE_MAXIMUM_POSIX_SEMAPHORES 2 |
---|
161 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
162 | |
---|
163 | #define CONFIGURE_INIT |
---|
164 | #include <rtems/confdefs.h> |
---|
165 | /* end of file */ |
---|