OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [c/] [src/] [tests/] [psxtests/] [psx12/] [init.c] - Blame information for rev 1771

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*
2
 *  COPYRIGHT (c) 1989-1999.
3
 *  On-Line Applications Research Corporation (OAR).
4
 *
5
 *  The license and distribution terms for this file may be
6
 *  found in the file LICENSE in this distribution or at
7
 *  http://www.OARcorp.com/rtems/license.html.
8
 *
9
 *  init.c,v 1.7 2002/08/02 00:53:21 joel Exp
10
 */
11
 
12
#define CONFIGURE_INIT
13
#include "system.h"
14
#include <errno.h>
15
 
16
void print_schedparam(
17
  char               *prefix,
18
  struct sched_param *schedparam
19
)
20
{
21
  printf( "%ssched priority      = %d\n", prefix, schedparam->sched_priority );
22
#if defined(_POSIX_SPORADIC_SERVER)
23
  printf( "%sss_low_priority     = %d\n", prefix, schedparam->ss_low_priority );
24
  printf( "%sss_replenish_period = (%ld, %ld)\n", prefix,
25
     schedparam->ss_replenish_period.tv_sec,
26
     schedparam->ss_replenish_period.tv_nsec );
27
  printf( "%sss_initial_budget = (%ld, %ld)\n", prefix,
28
     schedparam->ss_initial_budget.tv_sec,
29
     schedparam->ss_initial_budget.tv_nsec );
30
#else
31
  printf( "%s_POSIX_SPORADIC_SERVER is not defined\n" );
32
#endif
33
}
34
 
35
void *POSIX_Init(
36
  void *argument
37
)
38
{
39
  int                 status;
40
  pthread_attr_t      attr;
41
  struct sched_param  schedparam;
42
 
43
  puts( "\n\n*** POSIX TEST 12 ***" );
44
 
45
  /* set the time of day, and print our buffer in multiple ways */
46
 
47
  set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 );
48
 
49
  /* get id of this thread */
50
 
51
  Init_id = pthread_self();
52
  printf( "Init's ID is 0x%08x\n", Init_id );
53
 
54
  /* invalid scheduling policy error */
55
 
56
  puts( "Init: pthread_attr_init - SUCCESSFUL" );
57
  status = pthread_attr_init( &attr );
58
  assert( !status );
59
 
60
  status = pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED );
61
  assert( !status );
62
  attr.schedpolicy = -1;
63
 
64
  puts( "Init: pthread_create - EINVAL (invalid scheduling policy)" );
65
  status = pthread_create( &Task_id, &attr, Task_1, NULL );
66
  assert( status == EINVAL );
67
 
68
  /* replenish period < budget error */
69
 
70
  puts( "Init: pthread_attr_init - SUCCESSFUL" );
71
  status = pthread_attr_init( &attr );
72
  assert( !status );
73
 
74
  puts( "Init: set scheduling parameter attributes for sporadic server" );
75
  status = pthread_attr_setschedpolicy( &attr, SCHED_SPORADIC );
76
  assert( !status );
77
 
78
  schedparam.ss_replenish_period.tv_sec = 1;
79
  schedparam.ss_replenish_period.tv_nsec = 0;
80
  schedparam.ss_initial_budget.tv_sec = 2;
81
  schedparam.ss_initial_budget.tv_nsec = 0;
82
 
83
  schedparam.sched_priority = 200;
84
  schedparam.ss_low_priority = 100;
85
 
86
  status = pthread_attr_setschedparam( &attr, &schedparam );
87
  assert( !status );
88
 
89
  status = pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED );
90
  assert( !status );
91
 
92
  puts( "Init: pthread_create - EINVAL (replenish < budget)" );
93
  status = pthread_create( &Task_id, &attr, Task_1, NULL );
94
  assert( status == EINVAL );
95
 
96
  /* invalid ss_low_priority error */
97
 
98
  schedparam.ss_replenish_period.tv_sec = 2;
99
  schedparam.ss_replenish_period.tv_nsec = 0;
100
  schedparam.ss_initial_budget.tv_sec = 1;
101
  schedparam.ss_initial_budget.tv_nsec = 0;
102
 
103
  schedparam.sched_priority = 200;
104
  schedparam.ss_low_priority = -1;
105
 
106
  status = pthread_attr_setschedparam( &attr, &schedparam );
107
  assert( !status );
108
 
109
  puts( "Init: pthread_create - EINVAL (invalid ss_low_priority)" );
110
  status = pthread_create( &Task_id, &attr, Task_1, NULL );
111
  assert( status == EINVAL );
112
 
113
  /* create a thread as a sporadic server */
114
 
115
  schedparam.ss_replenish_period.tv_sec = 2;
116
  schedparam.ss_replenish_period.tv_nsec = 0;
117
  schedparam.ss_initial_budget.tv_sec = 1;
118
  schedparam.ss_initial_budget.tv_nsec = 0;
119
 
120
  schedparam.sched_priority = 200;
121
  schedparam.ss_low_priority = 100;
122
 
123
  status = pthread_attr_setschedparam( &attr, &schedparam );
124
  assert( !status );
125
 
126
  puts( "Init: pthread_create - SUCCESSFUL" );
127
  status = pthread_create( &Task_id, &attr, Task_1, NULL );
128
  assert( !status );
129
 
130
  status = pthread_join( Task_id, NULL );
131
  assert( status );
132
 
133
    /* switch to Task_1 */
134
 
135
  puts( "*** END OF POSIX TEST 12 ***" );
136
  rtems_test_exit( 0 );
137
 
138
  return NULL; /* just so the compiler thinks we returned something */
139
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.