summaryrefslogtreecommitdiffstats
path: root/testsuites/psxtests/psxclassic01/init.c
blob: 575f38b31b2f2eebe869580cd5349a227673697f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
 *  Based upon user code supplied in conjunction with PR1759
 *
 *  COPYRIGHT (c) 1989-2011.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.com/license/LICENSE.
 *
 *  $Id$
 */


#include "tmacros.h"

#include <stdio.h>
#include <rtems.h>
#include <pthread.h>
#include <unistd.h>
#include <errno.h>

int       Caught_signo = -1;
siginfo_t Caught_siginfo = { -1, -1, };

void handler(int signo)
{
  Caught_signo = signo;
}

void handler_info(int signo, siginfo_t *info, void *context)
{
  Caught_signo = signo;
  Caught_siginfo = *info;
}

rtems_task test_task(rtems_task_argument arg)
{
  int sc;
  struct sigaction new_action;
  sigset_t mask;

  printf("test_task starting...\n");

  sc = sigemptyset (&new_action.sa_mask);
  rtems_test_assert( sc == 0 );

  sc = sigfillset  (&new_action.sa_mask);
  rtems_test_assert( sc == 0 );

  sc = sigdelset   (&new_action.sa_mask, SIGUSR1);
  rtems_test_assert( sc == 0 );

  new_action.sa_handler = handler;
  new_action.sa_flags = SA_SIGINFO;
  new_action.sa_sigaction = handler_info;

  sc = sigaction(SIGUSR1,&new_action,NULL);
  rtems_test_assert( sc == 0 );

  sc = sigemptyset(&mask);
  rtems_test_assert( sc == 0 );

  sc = sigaddset(&mask, SIGUSR1);
  rtems_test_assert( sc == 0 );

  sc = pthread_sigmask( SIG_UNBLOCK, &mask, NULL);
  rtems_test_assert( sc == 0 );

  printf("test_task waiting for signal...\n");

  while(1) {
    sleep(1);
    if ( Caught_siginfo.si_signo != -1 ) {
      printf( "Signal_info: %d si_signo= %d si_code= %d value= %d\n",
        Caught_signo,
        Caught_siginfo.si_signo,
        Caught_siginfo.si_code,
        Caught_siginfo.si_value.sival_int
      );
      break;
    }
    if ( Caught_signo != -1 ) {
      printf( "Signal: %d caught\n", Caught_signo );
      break;
    }
  }
  puts( "test_task exiting thread" );
  pthread_exit( 0 );
}

rtems_task Init(rtems_task_argument arg)
{
  rtems_status_code sc;
  rtems_id          task_id;
  int               status;
  void             *retval;

  puts( "*** START OF CLASSIC API TEST OF POSIX 01 ***" );

  sc = rtems_task_create(
    rtems_build_name('T','E','S','T'),
    1,
    RTEMS_MINIMUM_STACK_SIZE,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_id
  );
  rtems_test_assert( sc == RTEMS_SUCCESSFUL );

  sc = rtems_task_start( task_id,  test_task, 0 );
  rtems_test_assert( sc == RTEMS_SUCCESSFUL );


  puts( "Init - pthread_equal on Classic Ids" );
  status = pthread_equal( task_id, task_id );
  rtems_test_assert( status != 0 );
  
  puts( "Init - pthread_cancel on Classic Task" );
  status = pthread_cancel( task_id );
  rtems_test_assert( status == 0 );
  
  status = pthread_detach( task_id );
  rtems_test_assert( status == 0 );

  status = pthread_join( task_id, &retval );
  if ( status != EINVAL ) printf( "JOIN %s\n", strerror( status ) );
  rtems_test_assert( status == EINVAL );

  status = pthread_kill( task_id, SIGUSR1 );
  rtems_test_assert( status == 0 );

  puts( "*** END OF CLASSIC API TEST OF POSIX 01 ***" );
  exit(0);
}

/* configuration information */
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER

#define CONFIGURE_MAXIMUM_TASKS 2

#define CONFIGURE_INIT_TASK_INITIAL_MODES \
  (RTEMS_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_ASR | RTEMS_INTERRUPT_LEVEL(0))

#define CONFIGURE_INIT_TASK_PRIORITY 4
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE

#define CONFIGURE_UNIFIED_WORK_AREAS

#define CONFIGURE_INIT
#include <rtems/confdefs.h>
/* end of file */