source: rtems/testsuites/psxtests/psxeintr_join/init.c @ 698c2e50

4.115
Last change on this file since 698c2e50 was 698c2e50, checked in by Sebastian Huber <sebastian.huber@…>, on 03/25/14 at 07:06:16

tests/psxtests: Use <rtems/test.h>

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2012.
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 <stdio.h>
15#include <signal.h>
16#include <semaphore.h>
17#include <pthread.h>
18
19#include <rtems.h>
20#include <tmacros.h>
21#include "test_support.h"
22
23const char rtems_test_name[] = "PSXEINTR_JOIN";
24
25#define SIG_SUSPEND SIGUSR1
26#define SIG_THR_RESTART SIGUSR2
27
28/* forward declarations to avoid warnings */
29void *POSIX_Init(void *argument);
30static void print_sig_mask(const char * str);
31void GC_suspend_handler(int sig);
32void GC_restart_handler(int sig);
33void *run(void *arg);
34
35sem_t GC_suspend_ack_sem;
36
37static void print_sig_mask( const char * str )
38{
39  sigset_t blocked;
40  int      i;
41  int      status;
42
43  status = pthread_sigmask( SIG_BLOCK, NULL, &blocked );
44  rtems_test_assert( status == 0 );
45
46  printf( "%s blocked:\n", str );
47  for ( i = 1; i < NSIG; i++) {
48    if ( sigismember( &blocked, i ) )
49      printf( "%d ", i );
50  }
51  printf( "\n" );
52}
53
54void GC_suspend_handler( int sig )
55{
56  puts( "run in GC_suspend_handler" );
57  sem_post( &GC_suspend_ack_sem );
58}
59
60void GC_restart_handler( int sig )
61{
62  puts( "run in GC_restart_handler" );
63}
64
65void *run( void *arg )
66{
67  int       status;
68  pthread_t id = *(pthread_t *)arg;
69
70  print_sig_mask( "New Thread" );
71
72  status = pthread_kill( id, SIG_SUSPEND );
73  rtems_test_assert( status == 0 );
74
75  puts( "New Thread: after pthread_kill" );
76  status = sem_wait( &GC_suspend_ack_sem );
77  rtems_test_assert( status == 0 );
78
79  puts( "New Thread over!" );
80  return NULL;
81}
82
83void *POSIX_Init( void *arg )
84{
85  struct sigaction act;
86  pthread_t        newThread;
87  pthread_t        mainThread;
88  int              status;
89
90  TEST_BEGIN();
91  status = sem_init( &GC_suspend_ack_sem, 0, 0);
92  rtems_test_assert( status == 0 );
93
94  status = sigemptyset( &act.sa_mask );
95  rtems_test_assert( status == 0 );
96
97  status = sigaddset( &act.sa_mask, SIG_SUSPEND );
98  rtems_test_assert( status == 0 );
99
100  status = pthread_sigmask( SIG_UNBLOCK, &act.sa_mask, NULL );
101  rtems_test_assert( status == 0 );
102
103  act.sa_handler = GC_suspend_handler;
104
105  status = sigaction( SIG_SUSPEND, &act, NULL );
106  rtems_test_assert( status == 0 );
107
108  act.sa_handler = GC_restart_handler;
109
110  print_sig_mask( "Main Thread" );
111
112  mainThread = pthread_self();
113  status = pthread_create( &newThread, NULL, run, &mainThread );
114  rtems_test_assert( status == 0 );
115
116  pthread_join( newThread, NULL );
117  puts( "Back from pthread_join" );
118
119  TEST_END();
120  rtems_test_exit( 0 );
121
122  return NULL;
123}
124
125/* configuration information */
126#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
127#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
128
129#define CONFIGURE_POSIX_INIT_THREAD_TABLE
130#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
131
132#define CONFIGURE_MAXIMUM_POSIX_THREADS 2
133#define CONFIGURE_MAXIMUM_POSIX_SEMAPHORES 1
134
135#define CONFIGURE_INIT
136#include <rtems/confdefs.h>
137/* end of file */
138
Note: See TracBrowser for help on using the repository browser.