source: rtems/testsuites/psxtmtests/psxtmmutex03/init.c @ 91b38c6

4.115
Last change on this file since 91b38c6 was 91b38c6, checked in by Joel Sherrill <joel.sherrill@…>, on 07/12/11 at 13:22:24

2011-07-12 Ricardo Aguirre <el.mastin@…>

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