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

4.115
Last change on this file since 8fbe2e6 was 8fbe2e6, checked in by Joel Sherrill <joel.sherrill@…>, on 09/04/14 at 13:59:49

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