source: rtems/testsuites/psxtmtests/psxtmcond06/init.c @ de549c3

4.115
Last change on this file since de549c3 was de549c3, checked in by Joel Sherrill <joel.sherrill@…>, on 09/03/14 at 15:16:43

Misc psxtmtests: Use uint32_t not long for end_time to match printf() format expectations

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