source: rtems/testsuites/psxtests/psxclassic01/init.c @ 7147dc4

5
Last change on this file since 7147dc4 was 7147dc4, checked in by Sebastian Huber <sebastian.huber@…>, on 11/08/17 at 13:37:35

posix: Remove POSIX_API_Control::schedpolicy

Use the thread CPU budget algorithm to determine the scheduler policy.
This fixes also pthread_getschedparam() for Classic tasks.

Update #2514.

  • Property mode set to 100644
File size: 4.5 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#include <string.h>
28#include <sched.h>
29
30const char rtems_test_name[] = "PSXCLASSIC 1";
31
32static int       Caught_signo = -1;
33static siginfo_t Caught_siginfo = { -1, -1, };
34
35static void handler(int signo)
36{
37  Caught_signo = signo;
38}
39
40static void handler_info(int signo, siginfo_t *info, void *context)
41{
42  Caught_signo = signo;
43  Caught_siginfo = *info;
44}
45
46static rtems_task test_task(rtems_task_argument arg)
47{
48  int sc;
49  struct sigaction new_action;
50  sigset_t mask;
51  int policy;
52  struct sched_param param;
53
54  printf("test_task starting...\n");
55
56  policy = -1;
57  memset( &param, -1, sizeof( param ) );
58  sc = pthread_getschedparam( pthread_self(), &policy, &param );
59  rtems_test_assert( sc == 0 );
60  rtems_test_assert( policy == SCHED_FIFO );
61  rtems_test_assert(
62    param.sched_priority == sched_get_priority_max( SCHED_FIFO )
63  );
64
65  sc = pthread_setschedparam( pthread_self(), policy, &param );
66  rtems_test_assert( sc == 0 );
67
68  sc = sigemptyset (&new_action.sa_mask);
69  rtems_test_assert( sc == 0 );
70
71  sc = sigfillset  (&new_action.sa_mask);
72  rtems_test_assert( sc == 0 );
73
74  sc = sigdelset   (&new_action.sa_mask, SIGUSR1);
75  rtems_test_assert( sc == 0 );
76
77  new_action.sa_handler = handler;
78  new_action.sa_flags = SA_SIGINFO;
79  new_action.sa_sigaction = handler_info;
80
81  sc = sigaction(SIGUSR1,&new_action,NULL);
82  rtems_test_assert( sc == 0 );
83
84  sc = sigemptyset(&mask);
85  rtems_test_assert( sc == 0 );
86
87  sc = sigaddset(&mask, SIGUSR1);
88  rtems_test_assert( sc == 0 );
89
90  sc = pthread_sigmask( SIG_UNBLOCK, &mask, NULL);
91  rtems_test_assert( sc == 0 );
92
93  printf("test_task waiting for signal...\n");
94
95  while(1) {
96    sleep(1);
97    if ( Caught_siginfo.si_signo != -1 ) {
98      printf( "Signal_info: %d si_signo= %d si_code= %d value= %d\n",
99        Caught_signo,
100        Caught_siginfo.si_signo,
101        Caught_siginfo.si_code,
102        Caught_siginfo.si_value.sival_int
103      );
104      break;
105    }
106    if ( Caught_signo != -1 ) {
107      printf( "Signal: %d caught\n", Caught_signo );
108      break;
109    }
110  }
111  puts( "test_task exiting thread" );
112  pthread_exit( (void *) 123 );
113}
114
115
116static rtems_id create_task( void )
117{
118  rtems_status_code sc;
119  rtems_id          task_id;
120
121  sc = rtems_task_create(
122    rtems_build_name('T','E','S','T'),
123    1,
124    RTEMS_MINIMUM_STACK_SIZE,
125    RTEMS_DEFAULT_MODES,
126    RTEMS_DEFAULT_ATTRIBUTES,
127    &task_id
128  );
129  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
130
131  sc = rtems_task_start( task_id,  test_task, 0 );
132  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
133
134  return task_id;
135}
136
137static rtems_task Init( rtems_task_argument arg )
138{
139  rtems_id  task_id;
140  int       status;
141  void     *retval;
142
143  TEST_BEGIN();
144
145  task_id = create_task();
146
147  puts( "Init - pthread_equal on Classic Ids" );
148  status = pthread_equal( task_id, task_id );
149  rtems_test_assert( status != 0 );
150 
151  puts( "Init - pthread_cancel on Classic Task" );
152  status = pthread_cancel( task_id );
153  rtems_test_assert( status == 0 );
154 
155  status = pthread_detach( task_id );
156  rtems_test_assert( status == 0 );
157
158  retval = (void *) 456;
159  status = pthread_join( task_id, &retval );
160  rtems_test_assert( status == ESRCH );
161  rtems_test_assert( retval == (void *) 456 );
162
163  status = pthread_kill( task_id, SIGUSR1 );
164  rtems_test_assert( status == ESRCH );
165
166  task_id = create_task();
167
168  status = pthread_kill( task_id, SIGUSR1 );
169  rtems_test_assert( status == 0 );
170
171  status = pthread_join( task_id, &retval );
172  rtems_test_assert( status == 0 );
173  rtems_test_assert( retval == (void *) 123 );
174
175  TEST_END();
176  exit(0);
177}
178
179/* configuration information */
180#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
181#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
182
183#define CONFIGURE_MAXIMUM_TASKS 2
184
185#define CONFIGURE_INIT_TASK_INITIAL_MODES \
186  (RTEMS_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_ASR | RTEMS_INTERRUPT_LEVEL(0))
187
188#define CONFIGURE_INIT_TASK_PRIORITY 4
189#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
190
191#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
192
193#define CONFIGURE_UNIFIED_WORK_AREAS
194
195#define CONFIGURE_INIT
196#include <rtems/confdefs.h>
197/* end of file */
Note: See TracBrowser for help on using the repository browser.