source: rtems/testsuites/psxtmtests/psxtmcond06/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.3 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
14#include <coverhd.h>
15#include <tmacros.h>
16#include <timesys.h>
17#include "test_support.h"
18#include <pthread.h>
19#include <sched.h>
20#include <rtems/timerdrv.h>
21
22#define N 5
23
24/* forward declarations to avoid warnings */
25void *POSIX_Init(void *argument);
26void *Blocker(void *argument);
27
28pthread_mutex_t MutexID;
29pthread_cond_t CondID;
30
31void *Blocker(
32  void *argument
33)
34{
35  int status;
36
37  status = pthread_mutex_lock(&MutexID);
38  rtems_test_assert( status == 0 );
39
40  /* Unlock mutex, block, wait for CondID to be signaled */
41  pthread_cond_wait(&CondID,&MutexID);
42
43 /* should never return */
44  rtems_test_assert( FALSE );
45
46  return NULL;
47}
48
49void *POSIX_Init(
50  void *argument
51)
52{
53  long                end_time;
54  int                 status;
55  int                 i;
56  pthread_t           threadId;
57  pthread_attr_t      attr;
58  struct sched_param  param;
59  int                 policy;
60
61  puts( "\n\n*** POSIX TIME TEST PSXTMCOND06 ***" );
62
63  /* Setup variables */
64  status = pthread_create( &threadId, NULL, Blocker, NULL );
65  rtems_test_assert( status == 0 );
66  status = pthread_mutex_init(&MutexID, NULL);
67  rtems_test_assert( status == 0 );
68  status = pthread_cond_init(&CondID, NULL);
69  rtems_test_assert( status == 0 );
70
71  /* Setup so threads are created with a high enough priority to preempt
72   * as they get created.
73   */
74  status = pthread_attr_init( &attr );
75  rtems_test_assert( status == 0 );
76  status = pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED );
77  rtems_test_assert( status == 0 );
78  status = pthread_attr_setschedpolicy( &attr, SCHED_FIFO );
79  rtems_test_assert( status == 0 );
80  param.sched_priority = sched_get_priority_max(SCHED_FIFO) / 2;
81  status = pthread_attr_setschedparam( &attr, &param );
82  rtems_test_assert( status == 0 );
83
84  for ( i=0 ; i < N ; i++) {
85    /* Threads will preempt as they are created, start up, and block */
86    status = pthread_create(&threadId, &attr, Blocker, NULL);
87    rtems_test_assert( status == 0 );
88  }
89
90  /* Now that all the threads have been created, adjust our priority
91   * so we don't get preempted on broadcast.
92   */
93  status = pthread_getschedparam(pthread_self(), &policy, &param);
94  rtems_test_assert( status == 0 );
95  param.sched_priority = sched_get_priority_max(policy) - 1;
96  status = pthread_setschedparam(pthread_self(), policy, &param);
97  rtems_test_assert( status == 0 );
98
99  benchmark_timer_initialize();
100  status = pthread_cond_broadcast(&CondID);
101  end_time = benchmark_timer_read();
102  rtems_test_assert( status == 0 );
103
104  put_time(
105    "pthread_cond_broadcast: threads waiting no preempt",
106    end_time,
107    1,
108    0,
109    0
110  );
111
112  puts( "*** END OF POSIX TIME TEST PSXTMCOND06 ***" );
113  rtems_test_exit( 0 );
114
115  return NULL;
116}
117
118/* configuration information */
119
120#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
121#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
122
123#define CONFIGURE_MAXIMUM_POSIX_THREADS  2 + N
124#define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES 2
125#define CONFIGURE_MAXIMUM_POSIX_MUTEXES 2
126#define CONFIGURE_POSIX_INIT_THREAD_TABLE
127
128#define CONFIGURE_INIT
129
130#include <rtems/confdefs.h>
131  /* end of file */
Note: See TracBrowser for help on using the repository browser.