source: rtems/testsuites/psxtmtests/psxtmbarrier03/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.5 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#if !defined(OPERATION_COUNT)
30#define OPERATION_COUNT 100
31#endif
32
33#ifdef HAVE_CONFIG_H
34#include "config.h"
35#endif
36
37#include <tmacros.h>
38#include <timesys.h>
39#include "test_support.h"
40#include <pthread.h>
41#include <sched.h>
42#include <rtems/btimer.h>
43
44const char rtems_test_name[] = "PSXTMBARRIER 03";
45
46/* forward declarations to avoid warnings */
47void *POSIX_Init(void *argument);
48void *Blocker(void *argument);
49
50#define N  2
51pthread_barrier_t     barrier;
52
53void *Blocker(
54  void *argument
55)
56{
57  (void) pthread_barrier_wait( &barrier );
58  rtems_test_assert( FALSE );
59  return NULL;
60}
61
62void *POSIX_Init(
63  void *argument
64)
65{
66  int        status;
67  pthread_t  threadId;
68  benchmark_timer_t end_time;
69
70  TEST_BEGIN();
71
72  status = pthread_create( &threadId, NULL, Blocker, NULL );
73  rtems_test_assert( status == 0 );
74
75  /*
76   * Deliberately create the barrier after the threads.  This way if the
77   * threads do run before we intend, they will get an error.
78   * The barrier will be released on the Nth thread blocking.
79   */
80  status = pthread_barrier_init( &barrier, NULL, N );
81  rtems_test_assert( status == 0 );
82
83  /*
84   * Let the other thread start so the thread startup overhead,
85   * is accounted for.  When we return, we can start the benchmark.
86   */
87  sched_yield();
88    /* let other thread run */
89
90  /*
91   * Because this is the Nth thread at the barrier, this is an
92   * unblocking operation.
93   */
94  benchmark_timer_initialize();
95  status = pthread_barrier_wait( &barrier );
96  end_time = benchmark_timer_read();
97  /*
98   * Upon successful completion return value, the status should be
99   * PTHREAD_BARRIER_SERIAL_THREAD.
100   */
101  rtems_test_assert( status == PTHREAD_BARRIER_SERIAL_THREAD );
102
103  put_time(
104    "pthread_barrier_wait: releasing no preempt",
105    end_time,
106    1,
107    0,
108    0
109  );
110
111  TEST_END();
112  rtems_test_exit( 0 );
113
114  return NULL;
115}
116
117/* configuration information */
118
119#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
120#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
121
122#define CONFIGURE_MAXIMUM_POSIX_THREADS     2
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.