source: rtems/testsuites/psxtests/psxclassic01/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.9 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( 0 );
103}
104
105rtems_task Init(rtems_task_argument arg)
106{
107  rtems_status_code sc;
108  rtems_id          task_id;
109  int               status;
110  void             *retval;
111
112  TEST_BEGIN();
113
114  sc = rtems_task_create(
115    rtems_build_name('T','E','S','T'),
116    1,
117    RTEMS_MINIMUM_STACK_SIZE,
118    RTEMS_DEFAULT_MODES,
119    RTEMS_DEFAULT_ATTRIBUTES,
120    &task_id
121  );
122  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
123
124  sc = rtems_task_start( task_id,  test_task, 0 );
125  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
126
127
128  puts( "Init - pthread_equal on Classic Ids" );
129  status = pthread_equal( task_id, task_id );
130  rtems_test_assert( status != 0 );
131 
132  puts( "Init - pthread_cancel on Classic Task" );
133  status = pthread_cancel( task_id );
134  rtems_test_assert( status == 0 );
135 
136  status = pthread_detach( task_id );
137  rtems_test_assert( status == 0 );
138
139  status = pthread_join( task_id, &retval );
140  if ( status != EINVAL ) printf( "JOIN %s\n", strerror( status ) );
141  rtems_test_assert( status == EINVAL );
142
143  status = pthread_kill( task_id, SIGUSR1 );
144  rtems_test_assert( status == 0 );
145
146  TEST_END();
147  exit(0);
148}
149
150/* configuration information */
151#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
152#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
153
154#define CONFIGURE_MAXIMUM_TASKS 2
155
156#define CONFIGURE_INIT_TASK_INITIAL_MODES \
157  (RTEMS_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_ASR | RTEMS_INTERRUPT_LEVEL(0))
158
159#define CONFIGURE_INIT_TASK_PRIORITY 4
160#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
161
162#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
163
164#define CONFIGURE_UNIFIED_WORK_AREAS
165
166#define CONFIGURE_INIT
167#include <rtems/confdefs.h>
168/* end of file */
Note: See TracBrowser for help on using the repository browser.