source: rtems/testsuites/psxtmtests/psxtmmutex03/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: 3.7 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 <timesys.h>
15#include <rtems/btimer.h>
16#include <errno.h>
17#include <pthread.h>
18#include "test_support.h"
19
20const char rtems_test_name[] = "PSXTMMUTEX 03";
21
22/* forward declarations to avoid warnings */
23void *POSIX_Init(void *argument);
24void benchmark_mutex_lock_available(void);
25void benchmark_mutex_unlock_no_threads_waiting(void);
26void benchmark_mutex_trylock_available(void);
27void benchmark_mutex_trylock_not_available(void);
28void benchmark_mutex_timedlock_available(void);
29
30pthread_mutex_t MutexId;
31
32void benchmark_mutex_lock_available(void)
33{
34  benchmark_timer_t end_time;
35  int  status;
36
37  benchmark_timer_initialize();
38    status = pthread_mutex_lock( &MutexId );
39  end_time = benchmark_timer_read();
40  rtems_test_assert( !status );
41
42  put_time(
43    "pthread_mutex_lock: available",
44    end_time,
45    1,
46    0,
47    0
48  );
49}
50
51void benchmark_mutex_unlock_no_threads_waiting(void)
52{
53  benchmark_timer_t end_time;
54  int  status;
55
56  benchmark_timer_initialize();
57    status = pthread_mutex_unlock( &MutexId );
58  end_time = benchmark_timer_read();
59  rtems_test_assert( !status );
60
61  put_time(
62    "pthread_mutex_unlock: no threads waiting",
63    end_time,
64    1,
65    0,
66    0
67  );
68}
69
70void benchmark_mutex_trylock_available(void)
71{
72  benchmark_timer_t end_time;
73  int  status;
74
75  benchmark_timer_initialize();
76    status = pthread_mutex_trylock( &MutexId );
77  end_time = benchmark_timer_read();
78  rtems_test_assert( !status );
79
80  put_time(
81    "pthread_mutex_trylock: available",
82    end_time,
83    1,
84    0,
85    0
86  );
87}
88
89void benchmark_mutex_trylock_not_available(void)
90{
91  benchmark_timer_t end_time;
92  int  status;
93
94  benchmark_timer_initialize();
95    status = pthread_mutex_trylock( &MutexId );
96    /*
97     * it has to return a negative value
98     * because it try to lock a not available mutex   
99     * so the assert call is make with status instead !status
100     */
101  end_time = benchmark_timer_read();
102  rtems_test_assert( status );
103
104  put_time(
105    "pthread_mutex_trylock: not available",
106    end_time,
107    1,
108    0,
109    0
110  );
111}
112
113void benchmark_mutex_timedlock_available(void)
114{
115  benchmark_timer_t end_time;
116  int  status;
117
118  benchmark_timer_initialize();
119    status = pthread_mutex_timedlock( &MutexId, 0 );
120  end_time = benchmark_timer_read();
121  rtems_test_assert( !status );
122
123  put_time(
124    "pthread_mutex_timedlock: available",
125    end_time,
126    1,
127    0,
128    0
129  );
130}
131
132void *POSIX_Init(
133  void *argument
134)
135{
136  int  status;
137
138  TEST_BEGIN();
139 
140  /*
141   * Create the single Mutex used in all the test case
142   */
143  status = pthread_mutex_init( &MutexId, NULL );
144  rtems_test_assert( !status );
145
146  /*
147   * Now invoke subroutines to time each test case
148   * get the goal depends of its order
149   */
150  benchmark_mutex_lock_available();
151  benchmark_mutex_unlock_no_threads_waiting();
152  benchmark_mutex_trylock_available();
153  benchmark_mutex_trylock_not_available();
154  benchmark_mutex_unlock_no_threads_waiting();
155  benchmark_mutex_timedlock_available();
156  benchmark_mutex_unlock_no_threads_waiting();
157 
158
159  /*
160   *  Destroy the mutex used in the tests
161   */
162  status = pthread_mutex_destroy( &MutexId );
163  rtems_test_assert( !status );
164
165  TEST_END();
166
167  rtems_test_exit(0);
168}
169
170/* configuration information */
171
172#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
173#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
174
175#define CONFIGURE_MAXIMUM_POSIX_THREADS     1
176#define CONFIGURE_MAXIMUM_POSIX_MUTEXES     1
177#define CONFIGURE_POSIX_INIT_THREAD_TABLE
178
179#define CONFIGURE_INIT
180
181#include <rtems/confdefs.h>
182/* end of file */
Note: See TracBrowser for help on using the repository browser.