source: rtems/testsuites/psxtmtests/psxtmmutexattr01/init.c @ c05d7a9d

5
Last change on this file since c05d7a9d was edae517, checked in by Himanshu40 <himanshuwindows8.1@…>, on 11/20/18 at 01:11:58

psxtmutexattr01: Added new POSIX timing suite (GCI 2018)

  • Property mode set to 100644
File size: 6.0 KB
Line 
1/*
2 *  COPYRIGHT (c) 2018.
3 *  Himanshu Sekhar Nayak( GCI 2018 )
4 *
5 *  Permission to use, copy, modify, and/or distribute this software
6 *  for any purpose with or without fee is hereby granted.
7 *
8 *  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
9 *  WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
10 *  WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
11 *  BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
12 *  OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
13 *  WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
14 *  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#ifdef HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <pthread.h>
22#include <timesys.h>
23#include <rtems/btimer.h>
24#include <tmacros.h>
25#include <sched.h>
26#include "test_support.h"
27
28const char rtems_test_name[] = "PSXTMMUTEXATTR01";
29
30/* forward declarations to avoid warnings */
31static void *POSIX_Init(void *argument);
32
33static pthread_mutexattr_t attr;
34
35static void benchmark_create_pthread_mutexattr(void)
36{
37  long end_time;
38  int  status;
39
40  benchmark_timer_initialize();
41  status = pthread_mutexattr_init( &attr );
42  end_time = benchmark_timer_read();
43  rtems_test_assert( status == 0 );
44
45  put_time(
46    "pthread_mutexattr_init: only case",
47    end_time,
48    1,        /* Only executed once */
49    0,
50    0
51  );
52
53}
54
55static void benchmark_pthread_mutexattr_setprioceiling(void)
56{
57  long end_time;
58  int  status;
59
60  benchmark_timer_initialize();
61  status = pthread_mutexattr_setprioceiling( &attr, SCHED_FIFO);
62  end_time = benchmark_timer_read();
63  rtems_test_assert( status == 0 );
64
65  put_time(
66    "pthread_mutexattr_setprioceiling: only case",
67    end_time,
68    1,        /* Only executed once */
69    0,
70    0
71  );
72
73}
74
75static void benchmark_pthread_mutexattr_getprioceiling(void)
76{
77  long end_time;
78  int  status;
79  int prioceiling;
80
81  benchmark_timer_initialize();
82  status = pthread_mutexattr_getprioceiling( &attr, &prioceiling);
83  end_time = benchmark_timer_read();
84  rtems_test_assert( status == 0 );
85  rtems_test_assert( prioceiling == SCHED_FIFO);
86
87  put_time(
88    "pthread_mutexattr_getprioceiling: only case",
89    end_time,
90    1,        /* Only executed once */
91    0,
92    0
93  );
94
95}
96
97static void benchmark_pthread_mutexattr_setprotocol(void)
98{
99  long end_time;
100  int  status;
101
102  benchmark_timer_initialize();
103  status = pthread_mutexattr_setprotocol( &attr, PTHREAD_PRIO_INHERIT );
104  end_time = benchmark_timer_read();
105  rtems_test_assert( status == 0 );
106
107  put_time(
108    "pthread_mutexattr_setprotocol: only case",
109    end_time,
110    1,        /* Only executed once */
111    0,
112    0
113  );
114
115}
116
117static void benchmark_pthread_mutexattr_getprotocol(void)
118{
119  long end_time;
120  int  status;
121  int protocol;
122
123  benchmark_timer_initialize();
124  status = pthread_mutexattr_getprotocol( &attr, &protocol );
125  end_time = benchmark_timer_read();
126  rtems_test_assert( status == 0 );
127  rtems_test_assert( protocol == PTHREAD_PRIO_INHERIT );
128
129  put_time(
130    "pthread_mutexattr_getprotocol: only case",
131    end_time,
132    1,        /* Only executed once */
133    0,
134    0
135  );
136
137}
138
139static void benchmark_pthread_mutexattr_setpshared(void)
140{
141  long end_time;
142  int  status;
143
144  benchmark_timer_initialize();
145  status = pthread_mutexattr_setpshared( &attr, PTHREAD_PROCESS_PRIVATE );
146  end_time = benchmark_timer_read();
147  rtems_test_assert( status == 0 );
148
149  put_time(
150    "pthread_mutexattr_setpshared: only case",
151    end_time,
152    1,        /* Only executed once */
153    0,
154    0
155  );
156
157}
158
159static void benchmark_pthread_mutexattr_getpshared(void)
160{
161  long end_time;
162  int  status;
163  int pshared;
164
165  benchmark_timer_initialize();
166  status = pthread_mutexattr_getpshared( &attr, &pshared );
167  end_time = benchmark_timer_read();
168  rtems_test_assert( status == 0 );
169  rtems_test_assert( pshared == PTHREAD_PROCESS_PRIVATE );
170
171  put_time(
172    "pthread_mutexattr_getpshared: only case",
173    end_time,
174    1,        /* Only executed once */
175    0,
176    0
177  );
178
179}
180
181static void benchmark_pthread_mutexattr_settype(void)
182{
183  long end_time;
184  int  status;
185
186  benchmark_timer_initialize();
187  status = pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_DEFAULT );
188  end_time = benchmark_timer_read();
189  rtems_test_assert( status == 0 );
190
191  put_time(
192    "pthread_mutexattr_settype: only case",
193    end_time,
194    1,        /* Only executed once */
195    0,
196    0
197  );
198
199}
200
201static void benchmark_pthread_mutexattr_gettype(void)
202{
203  long end_time;
204  int  status;
205  int type;
206
207  benchmark_timer_initialize();
208  status = pthread_mutexattr_gettype( &attr, &type );
209  end_time = benchmark_timer_read();
210  rtems_test_assert( status == 0 );
211  rtems_test_assert( type == PTHREAD_MUTEX_DEFAULT );
212
213  put_time(
214    "pthread_mutexattr_gettype: only case",
215    end_time,
216    1,        /* Only executed once */
217    0,
218    0
219  );
220
221}
222
223static void benchmark_destroy_pthread_mutexattr(void)
224{
225  long end_time;
226  int  status;
227
228  benchmark_timer_initialize();
229  status = pthread_mutexattr_destroy( &attr );
230  end_time = benchmark_timer_read();
231  rtems_test_assert( status == 0 );
232
233  put_time(
234    "pthread_mutexattr_destroy: only case",
235    end_time,
236    1,        /* Only executed once */
237    0,
238    0
239  );
240
241}
242
243void *POSIX_Init(
244  void *argument
245)
246{
247
248  TEST_BEGIN();
249
250  benchmark_create_pthread_mutexattr();
251  benchmark_pthread_mutexattr_setprioceiling();
252  benchmark_pthread_mutexattr_getprioceiling();
253  benchmark_pthread_mutexattr_setprotocol();
254  benchmark_pthread_mutexattr_getprotocol();
255  benchmark_pthread_mutexattr_setpshared();
256  benchmark_pthread_mutexattr_getpshared();
257  benchmark_pthread_mutexattr_settype();
258  benchmark_pthread_mutexattr_gettype();
259  benchmark_destroy_pthread_mutexattr();
260
261  TEST_END();
262  rtems_test_exit(0);
263}
264
265/* configuration information */
266
267#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
268#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
269
270
271#define CONFIGURE_MAXIMUM_POSIX_THREADS     1
272#define CONFIGURE_POSIX_INIT_THREAD_TABLE
273
274#define CONFIGURE_INIT
275
276#include <rtems/confdefs.h>
277/* end of file */
Note: See TracBrowser for help on using the repository browser.