source: rtems/testsuites/psxtmtests/psxtmsem02/init.c @ e6a675e

4.115
Last change on this file since e6a675e was e6a675e, checked in by Ralf Corsépius <ralf.corsepius@…>, on 03/02/12 at 13:51:10

2011-03-02 Ralf Corsépius <ralf.corsepius@…>

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