source: rtems/testsuites/psxtmtests/psxtmcond03/init.c

Last change on this file was 94fa540, checked in by Joel Sherrill <joel@…>, on 04/07/22 at 16:16:26

testsuites/psxtmtests: Change license to BSD-2

Updates #3053.

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/*
4 *  COPYRIGHT (c) 1989-2013.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifdef HAVE_CONFIG_H
30#include "config.h"
31#endif
32
33#include <tmacros.h>
34#include <timesys.h>
35#include "test_support.h"
36#include <pthread.h>
37#include <sched.h>
38#include <rtems/btimer.h>
39
40const char rtems_test_name[] = "PSXTMCOND 03";
41
42/* forward declarations to avoid warnings */
43void *POSIX_Init(void *argument);
44void *Blocker(void *argument);
45
46pthread_mutex_t MutexID;
47pthread_cond_t CondID;
48
49void *Blocker(
50  void *argument
51)
52{
53  int status;
54
55  status = pthread_mutex_lock(&MutexID);
56  rtems_test_assert( status == 0 );
57 
58  /* Unlock mutex, block, wait for CondID to be signaled */
59  pthread_cond_wait(&CondID,&MutexID);
60 
61 /* should never return */
62  rtems_test_assert( FALSE );
63
64  return NULL;
65}
66
67void *POSIX_Init(
68  void *argument
69)
70{
71  int        status;
72  pthread_t  threadId;
73  uint32_t   end_time;
74  struct sched_param param;
75  int policy;
76
77  TEST_BEGIN();
78
79  status = pthread_create( &threadId, NULL, Blocker, NULL );
80  rtems_test_assert( status == 0 );
81 
82  status = pthread_mutex_init(&MutexID, NULL);
83  rtems_test_assert( status == 0 );
84
85  status = pthread_cond_init(&CondID, NULL); /* Create condition variable */
86  rtems_test_assert( status == 0 );
87
88  /*
89   * Let the other thread start so the thread startup overhead,
90   * is accounted for.  When we return, we can start the benchmark.
91   */
92  sched_yield();
93    /* let other thread run */
94
95  /* To be extra sure we don't get preempted on the signal */
96  status = pthread_getschedparam(pthread_self(), &policy, &param);
97  rtems_test_assert( status == 0);
98  param.sched_priority = sched_get_priority_max(policy) - 1;
99  status = pthread_setschedparam(pthread_self(), policy, &param);
100  rtems_test_assert( status == 0);
101
102  benchmark_timer_initialize();
103  status = pthread_cond_signal(&CondID);
104  end_time = benchmark_timer_read();
105  rtems_test_assert( status == 0 );
106
107  put_time(
108    "pthread_cond_signal: thread waiting no preempt",
109    end_time,
110    1,
111    0,
112    0
113  );
114
115  TEST_END();
116  rtems_test_exit( 0 );
117
118  return NULL;
119}
120
121/* configuration information */
122
123#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
124#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
125
126#define CONFIGURE_MAXIMUM_POSIX_THREADS     2
127#define CONFIGURE_POSIX_INIT_THREAD_TABLE
128
129#define CONFIGURE_INIT
130
131#include <rtems/confdefs.h>
132  /* end of file */
Note: See TracBrowser for help on using the repository browser.