summaryrefslogtreecommitdiffstats
path: root/testsuites/sptests/spqreslib/init.c
blob: 2db540c9bc6e6110c8ff8beb6e8a44947c111521 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*  Init
 *
 *  This routine is the initialization task for this test program.
 *  It is a user initialization task and has the responsibility for creating
 *  and starting the tasks that make up the test.  If the time of day
 *  clock is required for the test, it should also be set to a known
 *  value by this function.
 *
 *  Input params:
 *    argument - task argument
 *
 *  Output params:  NONE
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.org/license/LICENSE.
 */

#define TEST_INIT

#define CONFIGURE_INIT
#include "system.h"

#include <rtems/score/scheduleredfimpl.h>

const char rtems_test_name[] = "SPQRESLIB";

rtems_id   Task_id;
rtems_task_priority Priority;
time_t  Period;
time_t  Execution;
time_t  Phase;

rtems_task Init(
  rtems_task_argument argument
)
{
  rtems_status_code status;
  qres_sid_t server_id, server_id2;
  time_t approved_budget, exec_time, abs_time, current_budget;
  qres_params_t params, params1, params3;

  Priority = 30;
  Period    = 30;
  Execution = 10;
  Phase = 0;

  params.P = 1;
  params.Q = 1;

  params1 = params3 = params;
  params1.Q = -1;
  params3.P = -1;

  TEST_BEGIN();


  status = rtems_task_create(
    rtems_build_name( 'P', 'T', '1', ' ' ),
    Priority,
    RTEMS_MINIMUM_STACK_SIZE * 4,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &Task_id
  );
  directive_failed( status, "rtems_task_create loop" );

  printf( "Init: Initializing the qres library\n" );
  if ( qres_init() )
    printf( "ERROR: QRES INITIALIZATION FAILED\n" );

  /* Error checks for Create server and Destroy server  */
  printf( "Init: Create server and Destroy server\n" );
  if ( qres_destroy_server( -5 ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: DESTROY SERVER PASSED UNEXPECTEDLY\n" );
  if ( qres_destroy_server( 5 ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: DESTROY SERVER PASSED UNEXPECTEDLY\n" );
  if ( qres_destroy_server( 0 ) != QOS_E_NOSERVER )
    printf( "ERROR: DESTROY SERVER PASSED UNEXPECTEDLY\n" );
  if ( qres_create_server( &params1, &server_id ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: CREATE SERVER PASSED UNEXPECTEDLY\n" );
  if ( qres_create_server( &params3, &server_id ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: CREATE SERVER PASSED UNEXPECTEDLY\n" );
  if ( qres_create_server( &params, &server_id2 ) )
    printf( "ERROR: CREATE SERVER FAILED\n" );
  if ( qres_create_server( &params, &server_id ) )
    printf( "ERROR: CREATE SERVER FAILED\n" );
  if ( qres_create_server( &params, &server_id ) !=
       QOS_E_FULL )
    printf( "ERROR: CREATE SERVER PASSED UNEXPECTEDLY\n" );

  /* Error checks for Attach thread and Detach thread */
  printf( "Init: Attach thread\n" );
  if ( qres_attach_thread( -5, 0, RTEMS_SELF ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: ATTACH THREAD PASSED UNEXPECTEDLY\n" );
  if ( qres_attach_thread( 5, 0, RTEMS_SELF ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: ATTACH THREAD PASSED UNEXPECTEDLY\n" );
  if ( qres_attach_thread( server_id, 0, 1234 ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: ATTACH THREAD PASSED UNEXPECTEDLY\n" );
  if ( qres_attach_thread( server_id, 0, RTEMS_SELF ) )
    printf( "ERROR: ATTACH THREAD FAILED\n" );
  if ( qres_attach_thread( server_id, 0, RTEMS_SELF ) !=
       QOS_E_FULL )
    printf( "ERROR: ATTACH THREAD AGAIN PASSED UNEXPECTEDLY\n" );
  if ( qres_attach_thread( server_id, 0, Task_id ) !=
       QOS_E_FULL )
    printf( "ERROR: ATTACH THREAD TO FULL SERVER PASSED UNEXPECTEDLY \n" );
  if ( qres_destroy_server( server_id ) )
    printf( "ERROR: DESTROY SERVER WITH THREAD ATTACHED FAILED\n" );
  if ( qres_attach_thread( server_id, 0, RTEMS_SELF ) !=
       QOS_E_NOSERVER )
    printf( "ERROR: ATTACH THREAD PASSED UNEXPECTEDLY\n" );

  printf( "Init: Detach thread\n" );
  if ( qres_detach_thread( -5, 0, RTEMS_SELF ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: DETACH THREAD PASSED UNEXPECTEDLY\n" );
  if ( qres_detach_thread( 5, 0, RTEMS_SELF ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: DETACH THREAD PASSED UNEXPECTEDLY\n" );
  if ( qres_detach_thread( server_id2, 0, 1234 ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: DETACH THREAD PASSED UNEXPECTEDLY \n" );
  if ( qres_detach_thread( server_id, 0, RTEMS_SELF ) !=
       QOS_E_NOSERVER )
    printf( "ERROR: DETACH THREAD PASSED UNEXPECTEDLY4\n" );
  qres_destroy_server( server_id2 );

  /* Error checks for Set params and Get params */
  printf( "Init: Set params and Get params\n" );
  if ( qres_set_params( -5, &params ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: SET PARAMS PASSED UNEXPECTEDLY\n" );
  if ( qres_set_params( 5, &params ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: SET PARAMS PASSED UNEXPECTEDLY\n" );
  if ( qres_set_params( server_id, &params ) !=
       QOS_E_NOSERVER )
    printf( "ERROR: SET PARAMS PASSED UNEXPECTEDLY\n" );

  if ( qres_get_params( -5, &params ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: GET PARAMS PASSED UNEXPECTEDLY\n" );
  if ( qres_get_params( 5, &params ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: GET PARAMS PASSED UNEXPECTEDLY\n" );
  if ( qres_get_params( server_id, &params ) !=
       QOS_E_NOSERVER )
    printf( "ERROR: GET PARAMS PASSED UNEXPECTEDLY\n" );

  if ( qres_set_params( server_id, &params1 ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: SET PARAMS PASSED UNEXPECTEDLY\n" );
  if ( qres_set_params( server_id, &params3 ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: SET PARAMS PASSED UNEXPECTEDLY\n" );

  /* Error checks for Get server id */
  printf( "Init: Get server id\n" );
  if ( qres_get_sid( 0, RTEMS_SELF, &server_id ) !=
       QOS_E_NOSERVER )
    printf( "ERROR: GET SERVER ID PASSED UNEXPECTEDLY\n" );

  /* Error checks for Get approved budget */
  printf( "Init: Get approved budget\n" );
  if ( qres_get_appr_budget( -5, &approved_budget ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: GET APPROVED BUDGET PASSED UNEXPECTEDLY\n" );
  if ( qres_get_appr_budget( 5, &approved_budget ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: GET APPROVED BUDGET PASSED UNEXPECTEDLY\n" );
  if ( qres_get_appr_budget( server_id, &approved_budget ) !=
       QOS_E_NOSERVER )
    printf( "ERROR: GET APPROVED BUDGET PASSED UNEXPECTEDLY\n" );

  /* Error checks for Get current budget */
  printf( "Init: Get current budget\n" );
  if ( qres_get_curr_budget( -5, &current_budget ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: GET REMAINING BUDGET PASSED UNEXPECTEDLY\n" );
  if ( qres_get_curr_budget( 5, &current_budget ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: GET REMAINING BUDGET PASSED UNEXPECTEDLY\n" );
  if ( qres_get_curr_budget( server_id, &current_budget ) !=
       QOS_E_NOSERVER )
    printf( "ERROR: GET REMAINING BUDGET PASSED UNEXPECTEDLY\n" );

  /* Error checks for Get execution time */
  printf( "Init: Get execution time\n" );
  if ( qres_get_exec_time( -5, &exec_time, &abs_time ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: GET EXECUTION TIME PASSED UNEXPECTEDLY\n" );
  if ( qres_get_exec_time( 5, &exec_time, &abs_time ) !=
       QOS_E_INVALID_PARAM )
    printf( "ERROR: GET EXECUTION TIME PASSED UNEXPECTEDLY\n" );
  if ( qres_get_exec_time( server_id, &exec_time, &abs_time ) !=
       QOS_E_NOSERVER )
    printf( "ERROR: GET EXECUTION TIME PASSED UNEXPECTEDLY\n" );

  /* Restart QRES library */
  printf( "Init: Cleaning up QRES\n" );
  if ( qres_cleanup() )
    printf( "ERROR: QRES CLEANUP FAILED\n" );
  printf( "Init: Initializing the QRES\n" );
  if ( qres_init() )
    printf( "ERROR: QRES INITIALIZATION FAILED\n" );

  /* Start periodic task */
  printf( "Init: Starting periodic task\n" );
  status = rtems_task_start( Task_id, Task_Periodic, 1 );
  directive_failed( status, "rtems_task_start periodic" );

  status = rtems_task_delete( RTEMS_SELF );
  directive_failed( status, "rtems_task_delete of RTEMS_SELF" );
}