source: rtems/testsuites/psxtmtests/psxtmmutex03/init.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

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