source: rtems/testsuites/psxtmtests/psxtmsem01/init.c @ 8fbe2e6

4.11
Last change on this file since 8fbe2e6 was 8fbe2e6, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 4, 2014 at 1:59:49 PM

Use correct prototype of benchmark_timer_read()

This change starts with removing the effectively empty file
timerdrv.h. The prototypes for benchmark_timer_XXX() were in
btimer.h which was not universally used. Thus every use of
timerdrv.h had to be changed to btimer.h. Then the prototypes
for benchmark_timer_read() had to be adjusted to return
benchmark_timer_t rather than int or uint32_t.

I took this opportunity to also correct the file headers to
separate the copyright from the file description comments which
is needed to ensure the copyright isn't propagated into Doxygen
output.

  • Property mode set to 100644
File size: 4.3 KB
Line 
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 <errno.h>
15#include <fcntl.h>
16#include <semaphore.h>
17#include <tmacros.h>
18#include <timesys.h>
19#include <rtems/btimer.h>
20#include "test_support.h"
21
22const char rtems_test_name[] = "PSXTMSEM 01";
23
24/* forward declarations to avoid warnings */
25void *POSIX_Init(void *argument);
26
27#define MAX_SEMS  2
28
29sem_t           sem1;
30sem_t           *n_sem1;
31sem_t           *n_sem2;
32
33static void benchmark_sem_init(void)
34{
35  benchmark_timer_t end_time;
36  int  status;
37
38  benchmark_timer_initialize();
39    status = sem_init( &sem1, 0, 1 );
40  end_time = benchmark_timer_read();
41  rtems_test_assert( status == 0 );
42
43  put_time(
44    "sem_init: only case",
45    end_time,
46    1,        /* Only executed once */
47    0,
48    0
49  );
50}
51
52static void benchmark_sem_destroy(void)
53{
54  benchmark_timer_t end_time;
55  int  status;
56
57  benchmark_timer_initialize();
58    status = sem_destroy( &sem1 );
59  end_time = benchmark_timer_read();
60  rtems_test_assert( status == 0 );
61
62  put_time(
63    "sem_destroy: only case",
64    end_time,
65    1,        /* Only executed once */
66    0,
67    0
68  );
69}
70
71static void benchmark_sem_open(bool report_time)
72{
73  benchmark_timer_t end_time;
74
75  benchmark_timer_initialize();
76    n_sem1 = sem_open( "sem1", O_CREAT, 0777, 1 );
77  end_time = benchmark_timer_read();
78
79  if ( report_time ) {
80    put_time(
81      "sem_open: first open O_CREAT",
82      end_time,
83      1,        /* Only executed once */
84      0,
85      0
86    );
87  }
88}
89
90static void benchmark_sem_close(bool report_time)
91{
92  benchmark_timer_t end_time;
93  int  status;
94
95  benchmark_timer_initialize();
96    status = sem_close( n_sem1 );
97  end_time = benchmark_timer_read();
98  rtems_test_assert( status == 0 );
99
100  if ( report_time ) {
101    put_time(
102      "sem_close: named first/nested close",
103      end_time,
104      1,        /* Only executed once */
105      0,
106      0
107    );
108  }
109}
110
111static void benchmark_sem_unlink(const char *message)
112{
113  benchmark_timer_t end_time;
114  int  status;
115
116  benchmark_timer_initialize();
117    status = sem_unlink( "sem1" );
118  end_time = benchmark_timer_read();
119  rtems_test_assert( status == 0 );
120
121  put_time(
122    message,
123    end_time,
124    1,        /* Only executed once */
125    0,
126    0
127  );
128}
129
130static void benchmark_sem_open_second(void)
131{
132  benchmark_timer_t end_time;
133
134  benchmark_timer_initialize();
135    n_sem2 = sem_open( "sem1", O_EXCL, 0777, 1 );
136  end_time = benchmark_timer_read();
137
138  put_time(
139    "sem_open: second open O_EXCL",
140    end_time,
141    1,        /* Only executed once */
142    0,
143    0
144  );
145}
146
147static void benchmark_sem_close_second(void)
148{
149  benchmark_timer_t end_time;
150  int  status;
151
152  benchmark_timer_initialize();
153    status = sem_close( n_sem2 );
154  end_time = benchmark_timer_read();
155  rtems_test_assert( status == 0 );
156
157  put_time(
158    "sem_close: named second close",
159    end_time,
160    1,        /* Only executed once */
161    0,
162    0
163  );
164}
165
166void *POSIX_Init(void *argument)
167{
168
169  TEST_BEGIN();
170
171  /* creating unnamed semaphore */
172  benchmark_sem_init();
173  /* destroying unnamed semaphore */
174  benchmark_sem_destroy();
175
176  /* opening named semaphore first time o_flag = O_CREAT */
177  benchmark_sem_open(true);
178  /* opening named semaphore second time o_flag = O_EXCL */
179  benchmark_sem_open_second();
180  /* close named semaphore first time  -- does not delete */
181  benchmark_sem_close(true);
182  /* unlink named semaphore -- does not delete */
183  benchmark_sem_unlink("sem_unlink: does not delete");
184  /*  close semaphore the second time, this actually deletes it */
185  benchmark_sem_close_second();
186
187  /* recrate named semaphore first time o_flag = O_CREAT */
188  benchmark_sem_open(false);
189  benchmark_sem_close(false);
190  benchmark_sem_unlink("sem_unlink: deletes semaphore");
191
192  TEST_END();
193
194  rtems_test_exit(0);
195}
196
197/* configuration information */
198
199#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
200#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
201
202#define CONFIGURE_MAXIMUM_POSIX_THREADS     1
203#define CONFIGURE_MAXIMUM_POSIX_SEMAPHORES  MAX_SEMS
204#define CONFIGURE_POSIX_INIT_THREAD_TABLE
205
206#define CONFIGURE_INIT
207
208#include <rtems/confdefs.h>
209/* end of file */
Note: See TracBrowser for help on using the repository browser.