source: rtems/testsuites/psxtmtests/psxtmsem03/init.c @ d2e6a127

4.115
Last change on this file since d2e6a127 was d2e6a127, checked in by Ralf Corsepius <ralf.corsepius@…>, on 09/29/11 at 15:59:10

2011-09-29 Ralf Corsépius <ralf.corsepius@…>

  • psxtmsem03/init.c: Add HAVE_CONFIG_H.
  • Property mode set to 100644
File size: 2.6 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#include <pthread.h>
24#include <sched.h>
25
26#define MAX_SEMS  2
27
28sem_t  sem1;
29
30void *Low(
31  void *argument
32)
33{
34  long 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    "sem_wait - not available, block",
48    end_time,
49    OPERATION_COUNT,
50    0,
51    0
52  );
53
54  puts( "*** END OF POSIX TIME TEST PSXTMSEM03 ***" );
55
56  rtems_test_exit( 0 );
57  return NULL;
58}
59
60void *Middle(
61  void *argument
62)
63{
64  /*
65   * Now we have finished the thread startup overhead,
66   * so let other threads run.  When we return, we can
67   * finish the benchmark.
68   */
69  sched_yield();
70    /* let other threads run */
71
72    (void) sem_wait( &sem1 );
73    rtems_test_assert( FALSE );
74  return NULL;
75}
76
77void *POSIX_Init(
78  void *argument
79)
80{
81  int        i;
82  int        status;
83  pthread_t  threadId;
84
85  puts( "\n\n*** POSIX TIME TEST PSXTMSEM03 ***" );
86
87  for ( i=0 ; i < OPERATION_COUNT - 1 ; i++ ) {
88    status = pthread_create( &threadId, NULL, Middle, NULL );
89    rtems_test_assert( status == 0 );
90  }
91 
92  status = pthread_create( &threadId, NULL, Low, NULL );
93  rtems_test_assert( status == 0 );
94
95  /*
96   * Deliberately create the semaphore after the threads.  This way if the
97   * threads do run before we intend, they will get an error.
98   */
99    status = sem_init( &sem1, 0, 1 );
100  rtems_test_assert( status == 0 );
101
102  /*
103   * Let the other threads start so the thread startup overhead,
104   * is accounted for.  When we return, we can start the benchmark.
105   */
106  sched_yield();
107    /* let other threads run */
108
109  /* start the timer and switch through all the other tasks */
110  benchmark_timer_initialize();
111    status = sem_wait(&sem1);
112  rtems_test_assert( status == 0 );
113  return NULL;
114}
115
116/* configuration information */
117
118#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
119#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
120
121#define CONFIGURE_MAXIMUM_POSIX_THREADS     OPERATION_COUNT + 2
122#define CONFIGURE_MAXIMUM_POSIX_SEMAPHORES  MAX_SEMS
123#define CONFIGURE_POSIX_INIT_THREAD_TABLE
124
125#define CONFIGURE_INIT
126
127#include <rtems/confdefs.h>
128  /* end of file */
Note: See TracBrowser for help on using the repository browser.