source: rtems/testsuites/psxtests/psx12/init.c @ 83fe4468

4.115
Last change on this file since 83fe4468 was 83fe4468, checked in by Gedare Bloom <gedare@…>, on 02/23/15 at 14:59:49

psxtests: add string param to printf. closes #2241

  • Property mode set to 100644
File size: 4.4 KB
RevLine 
[1b4f2b30]1/*
[2e7e636f]2 *  COPYRIGHT (c) 1989-2009.
[54e34e7]3 *  On-Line Applications Research Corporation (OAR).
4 *
[98e4ebf5]5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
[c499856]7 *  http://www.rtems.org/license/LICENSE.
[54e34e7]8 */
9
[cafefbf]10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
[75c9dfbd]14#include <sched.h>
15
[54e34e7]16#define CONFIGURE_INIT
17#include "system.h"
18#include <errno.h>
[4562dd8]19#include "pritime.h"
[54e34e7]20
[698c2e50]21const char rtems_test_name[] = "PSX 12";
22
[2e7e636f]23void print_schedparam(
24  char               *prefix,
25  struct sched_param *schedparam
26);
27
[54e34e7]28void print_schedparam(
29  char               *prefix,
30  struct sched_param *schedparam
31)
32{
33  printf( "%ssched priority      = %d\n", prefix, schedparam->sched_priority );
34#if defined(_POSIX_SPORADIC_SERVER)
[66c9ad8]35  printf( "%ssched_ss_low_priority     = %d\n",
36     prefix, schedparam->sched_ss_low_priority );
[4562dd8]37  printf( "%ssched_ss_repl_period = (%" PRIdtime_t ", %ld)\n", prefix,
[66c9ad8]38     schedparam->sched_ss_repl_period.tv_sec,
39     schedparam->sched_ss_repl_period.tv_nsec );
[4562dd8]40  printf( "%ssched_ss_init_budget = (%" PRIdtime_t ", %ld)\n", prefix,
[66c9ad8]41     schedparam->sched_ss_init_budget.tv_sec,
42     schedparam->sched_ss_init_budget.tv_nsec );
[54e34e7]43#else
[83fe4468]44  printf( "%s_POSIX_SPORADIC_SERVER is not defined\n", prefix );
[54e34e7]45#endif
46}
47
48void *POSIX_Init(
49  void *argument
50)
51{
52  int                 status;
53  pthread_attr_t      attr;
54  struct sched_param  schedparam;
55
[698c2e50]56  TEST_BEGIN();
[54e34e7]57
58  /* set the time of day, and print our buffer in multiple ways */
59
60  set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 );
61
62  /* get id of this thread */
63
64  Init_id = pthread_self();
[39615f4]65  printf( "Init's ID is 0x%08" PRIxpthread_t "\n", Init_id );
[1b4f2b30]66
[54e34e7]67  /* invalid scheduling policy error */
68
69  puts( "Init: pthread_attr_init - SUCCESSFUL" );
70  status = pthread_attr_init( &attr );
[33c46f1]71  rtems_test_assert( !status );
[54e34e7]72
[2ffcc2ed]73  status = pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED );
[33c46f1]74  rtems_test_assert( !status );
[54e34e7]75  attr.schedpolicy = -1;
76
77  puts( "Init: pthread_create - EINVAL (invalid scheduling policy)" );
78  status = pthread_create( &Task_id, &attr, Task_1, NULL );
[33c46f1]79  rtems_test_assert( status == EINVAL );
[54e34e7]80
81  /* replenish period < budget error */
82
83  puts( "Init: pthread_attr_init - SUCCESSFUL" );
84  status = pthread_attr_init( &attr );
[33c46f1]85  rtems_test_assert( !status );
[54e34e7]86
87  puts( "Init: set scheduling parameter attributes for sporadic server" );
88  status = pthread_attr_setschedpolicy( &attr, SCHED_SPORADIC );
[33c46f1]89  rtems_test_assert( !status );
[54e34e7]90
[66c9ad8]91  schedparam.sched_ss_repl_period.tv_sec = 1;
92  schedparam.sched_ss_repl_period.tv_nsec = 0;
93  schedparam.sched_ss_init_budget.tv_sec = 2;
94  schedparam.sched_ss_init_budget.tv_nsec = 0;
[1b4f2b30]95
[54e34e7]96  schedparam.sched_priority = 200;
[66c9ad8]97  schedparam.sched_ss_low_priority = 100;
[54e34e7]98
99  status = pthread_attr_setschedparam( &attr, &schedparam );
[33c46f1]100  rtems_test_assert( !status );
[54e34e7]101
[2ffcc2ed]102  status = pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED );
[33c46f1]103  rtems_test_assert( !status );
[1b4f2b30]104
[54e34e7]105  puts( "Init: pthread_create - EINVAL (replenish < budget)" );
106  status = pthread_create( &Task_id, &attr, Task_1, NULL );
[33c46f1]107  rtems_test_assert( status == EINVAL );
[54e34e7]108
[66c9ad8]109  /* invalid sched_ss_low_priority error */
[54e34e7]110
[66c9ad8]111  schedparam.sched_ss_repl_period.tv_sec = 2;
112  schedparam.sched_ss_repl_period.tv_nsec = 0;
113  schedparam.sched_ss_init_budget.tv_sec = 1;
114  schedparam.sched_ss_init_budget.tv_nsec = 0;
[1b4f2b30]115
[54e34e7]116  schedparam.sched_priority = 200;
[66c9ad8]117  schedparam.sched_ss_low_priority = -1;
[54e34e7]118
119  status = pthread_attr_setschedparam( &attr, &schedparam );
[33c46f1]120  rtems_test_assert( !status );
[54e34e7]121
[66c9ad8]122  puts( "Init: pthread_create - EINVAL (invalid sched_ss_low_priority)" );
[54e34e7]123  status = pthread_create( &Task_id, &attr, Task_1, NULL );
[33c46f1]124  rtems_test_assert( status == EINVAL );
[54e34e7]125
126  /* create a thread as a sporadic server */
127
[66c9ad8]128  schedparam.sched_ss_repl_period.tv_sec = 2;
129  schedparam.sched_ss_repl_period.tv_nsec = 0;
130  schedparam.sched_ss_init_budget.tv_sec = 1;
131  schedparam.sched_ss_init_budget.tv_nsec = 0;
[1b4f2b30]132
[5abf63d]133  schedparam.sched_priority = sched_get_priority_max( SCHED_FIFO );
[66c9ad8]134  schedparam.sched_ss_low_priority = sched_get_priority_max( SCHED_FIFO ) - 6;
[1b4f2b30]135
[54e34e7]136  status = pthread_attr_setschedparam( &attr, &schedparam );
[33c46f1]137  rtems_test_assert( !status );
[1b4f2b30]138
[54e34e7]139  puts( "Init: pthread_create - SUCCESSFUL" );
140  status = pthread_create( &Task_id, &attr, Task_1, NULL );
[33c46f1]141  rtems_test_assert( !status );
[54e34e7]142
143  status = pthread_join( Task_id, NULL );
[33c46f1]144  rtems_test_assert( status );
[54e34e7]145
146    /* switch to Task_1 */
147
[698c2e50]148  TEST_END();
[d802489]149  rtems_test_exit( 0 );
[54e34e7]150
151  return NULL; /* just so the compiler thinks we returned something */
152}
Note: See TracBrowser for help on using the repository browser.