source: rtems/testsuites/psxtmtests/psxtmrwlock05/init.c @ 50162e0

4.115
Last change on this file since 50162e0 was 50162e0, checked in by Joel Sherrill <joel.sherrill@…>, on 12/07/13 at 18:18:02

psxtmtests: Make output more uniform

  • 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.com/license/LICENSE.
8 */
9
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13#include <coverhd.h>
14#include <errno.h>
15#include <timesys.h>
16#include <tmacros.h>
17#include <sched.h>
18#include <pthread.h>
19#include <rtems/timerdrv.h>
20#include "test_support.h"
21
22/* forward declarations to avoid warnings */
23void *POSIX_Init(void *argument);
24void *Middle(void *argument);
25void *Low(void *argument);
26
27pthread_rwlock_t     rwlock;
28struct timespec      abstime;
29
30void *Low(
31  void *argument
32)
33{
34  benchmark_timer_t end_time;
35
36  /*
37   * Now we have finished the thread startup overhead,
38   * so let other threads run.  When we return, we can
39   * finish the benchmark.
40   */
41  sched_yield();
42    /* let other threads run */
43
44  end_time = benchmark_timer_read();
45
46  put_time(
47    "pthread_rwlock_timedwrlock: not available blocks",
48    end_time,
49    OPERATION_COUNT,
50    0,
51    0
52  );
53
54  puts( "*** END OF POSIX TIME PSXTMRWLOCK 05 TEST ***" );
55
56  rtems_test_exit( 0 );
57  return NULL;
58}
59
60void *Middle(
61  void *argument
62)
63{
64  int status;
65
66  /*
67   * Now we have finished the thread startup overhead,
68   * so let other threads run.  When we return, we can
69   * finish the benchmark.
70   */
71  sched_yield();
72    /* let other threads run */
73
74  /* This timed write lock operation will be blocked
75   * because the other write operation has the lock
76   */
77    status = pthread_rwlock_timedwrlock(&rwlock, &abstime);
78  rtems_test_assert( status == 0 );
79  return NULL;
80}
81
82void *POSIX_Init(
83  void *argument
84)
85{
86  int        i;
87  int        status;
88  pthread_t  threadId;
89  pthread_rwlockattr_t attr;
90
91  puts( "\n\n*** POSIX TIME PSXTMRWLOCK 05 TEST ***" );
92
93  for ( i=0 ; i < OPERATION_COUNT - 1 ; i++ ) {
94    status = pthread_create( &threadId, NULL, Middle, NULL );
95    rtems_test_assert( !status );
96  }
97 
98  status = pthread_create( &threadId, NULL, Low, NULL );
99  rtems_test_assert( !status );
100
101  /*
102   *  Timeout for 5 seconds from now.
103   */
104  status = clock_gettime( CLOCK_REALTIME, &abstime );
105  rtems_test_assert( !status );
106  abstime.tv_sec += 5;
107
108  /*
109   * Deliberately create the rwlock after the threads.  This way if the
110   * threads do run before we intend, they will get an error.
111   */
112  status = pthread_rwlockattr_init( &attr );
113  rtems_test_assert( status == 0 );
114    status = pthread_rwlock_init( &rwlock, &attr );
115  rtems_test_assert( status == 0 );
116  /*
117   * Let the other threads start so the thread startup overhead,
118   * is accounted for.  When we return, we can start the benchmark.
119   */
120  sched_yield();
121    /* let other threads run */
122
123 
124  /* start the timer and switch through all the other tasks */
125  benchmark_timer_initialize();
126
127  /* write lock operation, this could be any write lock
128   * I decided to use timedwrlock just to continue in the timed line  */
129    status = pthread_rwlock_timedwrlock(&rwlock,0);
130  rtems_test_assert( status == 0 );
131  return NULL;
132}
133
134/* configuration information */
135
136#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
137#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
138
139#define CONFIGURE_MAXIMUM_POSIX_THREADS     OPERATION_COUNT + 2
140#define CONFIGURE_MAXIMUM_POSIX_RWLOCKS     1
141#define CONFIGURE_POSIX_INIT_THREAD_TABLE
142
143#define CONFIGURE_INIT
144
145#include <rtems/confdefs.h>
146  /* end of file */
Note: See TracBrowser for help on using the repository browser.