source: rtems/testsuites/psxtests/psxclassic01/init.c @ 12a1228c

5
Last change on this file since 12a1228c was 12a1228c, checked in by Sebastian Huber <sebastian.huber@…>, on 05/17/16 at 15:23:44

psxclassic01: Assume correct pthread_detach()

Update #2714.

  • Property mode set to 100644
File size: 4.2 KB
Line 
1/**
2 *  @file
3 *
4 *  Based upon user code supplied in conjunction with PR1759
5 */
6
7/*
8 *  COPYRIGHT (c) 1989-2012.
9 *  On-Line Applications Research Corporation (OAR).
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.rtems.org/license/LICENSE.
14 */
15
16#ifdef HAVE_CONFIG_H
17#include "config.h"
18#endif
19
20#include "tmacros.h"
21
22#include <stdio.h>
23#include <rtems.h>
24#include <pthread.h>
25#include <unistd.h>
26#include <errno.h>
27
28const char rtems_test_name[] = "PSXCLASSIC 1";
29
30int       Caught_signo = -1;
31siginfo_t Caught_siginfo = { -1, -1, };
32
33/* forward declarations to avoid warnings */
34rtems_task Init(rtems_task_argument arg);
35void handler(int signo);
36void handler_info(int signo, siginfo_t *info, void *context);
37rtems_task test_task(rtems_task_argument arg);
38
39void handler(int signo)
40{
41  Caught_signo = signo;
42}
43
44void handler_info(int signo, siginfo_t *info, void *context)
45{
46  Caught_signo = signo;
47  Caught_siginfo = *info;
48}
49
50rtems_task test_task(rtems_task_argument arg)
51{
52  int sc;
53  struct sigaction new_action;
54  sigset_t mask;
55
56  printf("test_task starting...\n");
57
58  sc = sigemptyset (&new_action.sa_mask);
59  rtems_test_assert( sc == 0 );
60
61  sc = sigfillset  (&new_action.sa_mask);
62  rtems_test_assert( sc == 0 );
63
64  sc = sigdelset   (&new_action.sa_mask, SIGUSR1);
65  rtems_test_assert( sc == 0 );
66
67  new_action.sa_handler = handler;
68  new_action.sa_flags = SA_SIGINFO;
69  new_action.sa_sigaction = handler_info;
70
71  sc = sigaction(SIGUSR1,&new_action,NULL);
72  rtems_test_assert( sc == 0 );
73
74  sc = sigemptyset(&mask);
75  rtems_test_assert( sc == 0 );
76
77  sc = sigaddset(&mask, SIGUSR1);
78  rtems_test_assert( sc == 0 );
79
80  sc = pthread_sigmask( SIG_UNBLOCK, &mask, NULL);
81  rtems_test_assert( sc == 0 );
82
83  printf("test_task waiting for signal...\n");
84
85  while(1) {
86    sleep(1);
87    if ( Caught_siginfo.si_signo != -1 ) {
88      printf( "Signal_info: %d si_signo= %d si_code= %d value= %d\n",
89        Caught_signo,
90        Caught_siginfo.si_signo,
91        Caught_siginfo.si_code,
92        Caught_siginfo.si_value.sival_int
93      );
94      break;
95    }
96    if ( Caught_signo != -1 ) {
97      printf( "Signal: %d caught\n", Caught_signo );
98      break;
99    }
100  }
101  puts( "test_task exiting thread" );
102  pthread_exit( (void *) 123 );
103}
104
105
106static rtems_id create_task( void )
107{
108  rtems_status_code sc;
109  rtems_id          task_id;
110
111  sc = rtems_task_create(
112    rtems_build_name('T','E','S','T'),
113    1,
114    RTEMS_MINIMUM_STACK_SIZE,
115    RTEMS_DEFAULT_MODES,
116    RTEMS_DEFAULT_ATTRIBUTES,
117    &task_id
118  );
119  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
120
121  sc = rtems_task_start( task_id,  test_task, 0 );
122  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
123
124  return task_id;
125}
126
127rtems_task Init( rtems_task_argument arg )
128{
129  rtems_id  task_id;
130  int       status;
131  void     *retval;
132
133  TEST_BEGIN();
134
135  task_id = create_task();
136
137  puts( "Init - pthread_equal on Classic Ids" );
138  status = pthread_equal( task_id, task_id );
139  rtems_test_assert( status != 0 );
140 
141  puts( "Init - pthread_cancel on Classic Task" );
142  status = pthread_cancel( task_id );
143  rtems_test_assert( status == 0 );
144 
145  status = pthread_detach( task_id );
146  rtems_test_assert( status == 0 );
147
148  retval = (void *) 456;
149  status = pthread_join( task_id, &retval );
150  rtems_test_assert( status == ESRCH );
151  rtems_test_assert( retval == (void *) 456 );
152
153  status = pthread_kill( task_id, SIGUSR1 );
154  rtems_test_assert( status == ESRCH );
155
156  task_id = create_task();
157
158  status = pthread_kill( task_id, SIGUSR1 );
159  rtems_test_assert( status == 0 );
160
161  status = pthread_join( task_id, &retval );
162  rtems_test_assert( status == 0 );
163  rtems_test_assert( retval == (void *) 123 );
164
165  TEST_END();
166  exit(0);
167}
168
169/* configuration information */
170#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
171#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
172
173#define CONFIGURE_MAXIMUM_TASKS 2
174
175#define CONFIGURE_INIT_TASK_INITIAL_MODES \
176  (RTEMS_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_ASR | RTEMS_INTERRUPT_LEVEL(0))
177
178#define CONFIGURE_INIT_TASK_PRIORITY 4
179#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
180
181#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
182
183#define CONFIGURE_UNIFIED_WORK_AREAS
184
185#define CONFIGURE_INIT
186#include <rtems/confdefs.h>
187/* end of file */
Note: See TracBrowser for help on using the repository browser.