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 <tmacros.h> |
---|
15 | #include "test_support.h" |
---|
16 | #include <pthread.h> |
---|
17 | #include <errno.h> |
---|
18 | |
---|
19 | const char rtems_test_name[] = "PSXSIGNAL 6"; |
---|
20 | |
---|
21 | /* forward declarations to avoid warnings */ |
---|
22 | void *POSIX_Init(void *argument); |
---|
23 | void Handler(int signo); |
---|
24 | void *TestThread(void *argument); |
---|
25 | |
---|
26 | pthread_t ThreadId; |
---|
27 | pthread_cond_t CondVarId; |
---|
28 | pthread_mutex_t MutexId; |
---|
29 | |
---|
30 | void Handler( |
---|
31 | int signo |
---|
32 | ) |
---|
33 | { |
---|
34 | } |
---|
35 | |
---|
36 | void *TestThread( |
---|
37 | void *argument |
---|
38 | ) |
---|
39 | { |
---|
40 | int status; |
---|
41 | sigset_t mask; |
---|
42 | struct sigaction act; |
---|
43 | unsigned int left; |
---|
44 | |
---|
45 | /* unblock SIGUSR1 */ |
---|
46 | status = sigemptyset( &mask ); |
---|
47 | rtems_test_assert( !status ); |
---|
48 | |
---|
49 | status = sigaddset( &mask, SIGUSR1 ); |
---|
50 | rtems_test_assert( !status ); |
---|
51 | |
---|
52 | puts( "Test: Unblock SIGUSR1" ); |
---|
53 | status = sigprocmask( SIG_UNBLOCK, &mask, NULL ); |
---|
54 | rtems_test_assert( !status ); |
---|
55 | |
---|
56 | /* install a signal handler for SIGUSR1 */ |
---|
57 | act.sa_handler = Handler; |
---|
58 | act.sa_flags = 0; |
---|
59 | sigaction( SIGUSR1, &act, NULL ); |
---|
60 | |
---|
61 | status = pthread_mutex_lock( &MutexId ); |
---|
62 | rtems_test_assert( !status ); |
---|
63 | |
---|
64 | /* interrupting condition wait returns 0 */ |
---|
65 | puts( "Test: pthread_cond_wait - OK" ); |
---|
66 | status = pthread_cond_wait( &CondVarId, &MutexId ); |
---|
67 | rtems_test_assert( !status ); |
---|
68 | puts( "Test: pthread_cond_wait - interrupted by signal" ); |
---|
69 | |
---|
70 | left = sleep( 10 ); |
---|
71 | printf( "Test: seconds left=%d\n", left ); |
---|
72 | |
---|
73 | return NULL; |
---|
74 | } |
---|
75 | |
---|
76 | void *POSIX_Init(void *argument) |
---|
77 | { |
---|
78 | int status; |
---|
79 | |
---|
80 | TEST_BEGIN(); |
---|
81 | |
---|
82 | puts( "Init: pthread_cond_init - OK" ); |
---|
83 | status = pthread_cond_init( &CondVarId, NULL ); |
---|
84 | rtems_test_assert( !status ); |
---|
85 | |
---|
86 | puts( "Init: pthread_mutex_init - OK" ); |
---|
87 | status = pthread_mutex_init( &MutexId, NULL ); |
---|
88 | rtems_test_assert( !status ); |
---|
89 | |
---|
90 | puts( "Init: pthread_create - OK" ); |
---|
91 | status = pthread_create( &ThreadId, NULL, TestThread, NULL ); |
---|
92 | rtems_test_assert( !status ); |
---|
93 | |
---|
94 | sleep( 1 ); |
---|
95 | |
---|
96 | /* let TestThread run */ |
---|
97 | |
---|
98 | puts( "Init: pthread_kill - SIGUSR to Test Thread - OK" ); |
---|
99 | status = pthread_kill( ThreadId, SIGUSR1 ); |
---|
100 | rtems_test_assert( !status ); |
---|
101 | |
---|
102 | sleep( 2 ); |
---|
103 | |
---|
104 | /* let TestThread run */ |
---|
105 | |
---|
106 | puts( "Init: pthread_kill - SIGUSR to Test Thread - OK" ); |
---|
107 | status = pthread_kill( ThreadId, SIGUSR1 ); |
---|
108 | rtems_test_assert( !status ); |
---|
109 | |
---|
110 | sleep( 1 ); |
---|
111 | |
---|
112 | /* let TestThread run */ |
---|
113 | |
---|
114 | |
---|
115 | |
---|
116 | TEST_END(); |
---|
117 | |
---|
118 | rtems_test_exit(0); |
---|
119 | } |
---|
120 | |
---|
121 | /* configuration information */ |
---|
122 | |
---|
123 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
124 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
125 | |
---|
126 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
127 | |
---|
128 | #define CONFIGURE_MAXIMUM_POSIX_THREADS 2 |
---|
129 | #define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES 2 |
---|
130 | #define CONFIGURE_MAXIMUM_POSIX_MUTEXES 1 |
---|
131 | |
---|
132 | #define CONFIGURE_POSIX_INIT_THREAD_TABLE |
---|
133 | |
---|
134 | #define CONFIGURE_INIT |
---|
135 | #include <rtems/confdefs.h> |
---|
136 | /* end of file */ |
---|