source: rtems/testsuites/psxtmtests/psxtmsem04/init.c @ c4b8b147

5
Last change on this file since c4b8b147 was c4b8b147, checked in by Sebastian Huber <sebastian.huber@…>, on 11/03/17 at 07:35:38

tests: Use simple console driver

Update #3170.
Update #3199.

  • Property mode set to 100644
File size: 2.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 <errno.h>
15#include <fcntl.h>
16#include <semaphore.h>
17#include <coverhd.h>
18#include <tmacros.h>
19#include <timesys.h>
20#include "test_support.h"
21#include <pthread.h>
22#include <sched.h>
23#include <rtems/btimer.h>
24
25const char rtems_test_name[] = "PSXTMSEM 04";
26
27/* forward declarations to avoid warnings */
28void *POSIX_Init(void *argument);
29void *Blocker(void *argument);
30
31#define MAX_SEMS  2
32
33sem_t           sem1;
34sem_t           *n_sem1;
35
36void *Blocker( void *argument)
37{
38  (void) sem_wait(&sem1);
39  /* should never return */
40  rtems_test_assert( FALSE );
41
42  return NULL;
43}
44
45void *POSIX_Init(void *argument)
46{
47  int        status;
48  pthread_t  threadId;
49  benchmark_timer_t end_time;
50
51  TEST_BEGIN();
52
53  status = pthread_create( &threadId, NULL, Blocker, NULL );
54  rtems_test_assert( status == 0 );
55 
56  /*
57   * Deliberately create the semaphore after the threads.  This way if the
58   * threads do run before we intend, they will get an error.
59   */
60  status = sem_init( &sem1, 0, 1 );
61  rtems_test_assert( status == 0 );
62
63  /*
64   * Ensure the semaphore is unavailable so the other threads block.
65   * Lock semaphore resource to ensure thread blocks.
66   */
67  status = sem_wait(&sem1);
68  rtems_test_assert( status == 0 );
69
70  /*
71   * Let the other thread start so the thread startup overhead,
72   * is accounted for.  When we return, we can start the benchmark.
73   */
74  sched_yield();
75    /* let other thread run */
76
77  benchmark_timer_initialize();
78    status = sem_post( &sem1 ); /* semaphore unblocking operation */
79  end_time = benchmark_timer_read();
80  rtems_test_assert( status == 0 );
81
82  put_time(
83    "sem_post: thread waiting no preempt",
84    end_time,
85    1,
86    0,
87    0
88  );
89
90  TEST_END();
91  rtems_test_exit( 0 );
92
93  return NULL;
94}
95
96/* configuration information */
97
98#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
99#define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER
100
101#define CONFIGURE_MAXIMUM_POSIX_THREADS     2
102#define CONFIGURE_POSIX_INIT_THREAD_TABLE
103
104#define CONFIGURE_INIT
105
106#include <rtems/confdefs.h>
107  /* end of file */
Note: See TracBrowser for help on using the repository browser.