source: rtems/testsuites/psxtests/psxclassic01/init.c @ 408eea8

4.115
Last change on this file since 408eea8 was 408eea8, checked in by Joel Sherrill <joel.sherrill@…>, on 03/08/11 at 22:10:39

2011-03-08 Joel Sherrill <joel.sherrilL@…>

PR 1759/cpukit

  • Makefile.am, configure.ac: Add test to use some pthread calls with Classic Tasks.
  • psxclassic01/.cvsignore, psxclassic01/Makefile.am, psxclassic01/init.c, psxclassic01/psxclassic01.doc, psxclassic01/psxclassic01.scn: New files.
  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 *  Based upon user code supplied in conjunction with PR1759
3 *
4 *  COPYRIGHT (c) 1989-2011.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14
15#include "tmacros.h"
16
17#include <stdio.h>
18#include <rtems.h>
19#include <pthread.h>
20#include <unistd.h>
21#include <errno.h>
22
23int       Caught_signo = -1;
24siginfo_t Caught_siginfo = { -1, -1, };
25
26void handler(int signo)
27{
28  Caught_signo = signo;
29}
30
31void handler_info(int signo, siginfo_t *info, void *context)
32{
33  Caught_signo = signo;
34  Caught_siginfo = *info;
35}
36
37rtems_task test_task(rtems_task_argument arg)
38{
39  int sc;
40  struct sigaction new_action;
41  sigset_t mask;
42
43  printf("test_task starting...\n");
44
45  sc = sigemptyset (&new_action.sa_mask);
46  rtems_test_assert( sc == 0 );
47
48  sc = sigfillset  (&new_action.sa_mask);
49  rtems_test_assert( sc == 0 );
50
51  sc = sigdelset   (&new_action.sa_mask, SIGUSR1);
52  rtems_test_assert( sc == 0 );
53
54  new_action.sa_handler = handler;
55  new_action.sa_flags = SA_SIGINFO;
56  new_action.sa_sigaction = handler_info;
57
58  sc = sigaction(SIGUSR1,&new_action,NULL);
59  rtems_test_assert( sc == 0 );
60
61  sc = sigemptyset(&mask);
62  rtems_test_assert( sc == 0 );
63
64  sc = sigaddset(&mask, SIGUSR1);
65  rtems_test_assert( sc == 0 );
66
67  sc = pthread_sigmask( SIG_UNBLOCK, &mask, NULL);
68  rtems_test_assert( sc == 0 );
69
70  printf("test_task waiting for signal...\n");
71
72  while(1) {
73    sleep(1);
74    if ( Caught_siginfo.si_signo != -1 ) {
75      printf( "Signal_info: %d si_signo= %d si_code= %d value= %d\n",
76        Caught_signo,
77        Caught_siginfo.si_signo,
78        Caught_siginfo.si_code,
79        Caught_siginfo.si_value.sival_int
80      );
81      break;
82    }
83    if ( Caught_signo != -1 ) {
84      printf( "Signal: %d caught\n", Caught_signo );
85      break;
86    }
87  }
88  puts( "test_task exiting thread" );
89  pthread_exit( 0 );
90}
91
92rtems_task Init(rtems_task_argument arg)
93{
94  rtems_status_code sc;
95  rtems_id          task_id;
96  int               status;
97  void             *retval;
98
99  puts( "*** START OF CLASSIC API TEST OF POSIX 01 ***" );
100
101  sc = rtems_task_create(
102    rtems_build_name('T','E','S','T'),
103    1,
104    RTEMS_MINIMUM_STACK_SIZE,
105    RTEMS_DEFAULT_MODES,
106    RTEMS_DEFAULT_ATTRIBUTES,
107    &task_id
108  );
109  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
110
111  sc = rtems_task_start( task_id,  test_task, 0 );
112  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
113
114
115  puts( "Init - pthread_equal on Classic Ids" );
116  status = pthread_equal( task_id, task_id );
117  rtems_test_assert( status != 0 );
118 
119  puts( "Init - pthread_cancel on Classic Task" );
120  status = pthread_cancel( task_id );
121  rtems_test_assert( status == 0 );
122 
123  status = pthread_detach( task_id );
124  rtems_test_assert( status == 0 );
125
126  status = pthread_join( task_id, &retval );
127  if ( status != EINVAL ) printf( "JOIN %s\n", strerror( status ) );
128  rtems_test_assert( status == EINVAL );
129
130  status = pthread_kill( task_id, SIGUSR1 );
131  rtems_test_assert( status == 0 );
132
133  puts( "*** END OF CLASSIC API TEST OF POSIX 01 ***" );
134  exit(0);
135}
136
137/* configuration information */
138#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
139#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
140
141#define CONFIGURE_MAXIMUM_TASKS 2
142
143#define CONFIGURE_INIT_TASK_INITIAL_MODES \
144  (RTEMS_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_ASR | RTEMS_INTERRUPT_LEVEL(0))
145
146#define CONFIGURE_INIT_TASK_PRIORITY 4
147#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
148
149#define CONFIGURE_UNIFIED_WORK_AREAS
150
151#define CONFIGURE_INIT
152#include <rtems/confdefs.h>
153/* end of file */
Note: See TracBrowser for help on using the repository browser.