source: rtems/testsuites/sptests/spqreslib/task_periodic.c @ 6c0301d

4.115
Last change on this file since 6c0301d was 6c0301d, checked in by Sebastian Huber <sebastian.huber@…>, on 03/25/14 at 07:06:21

tests/sptests: Use <rtems/test.h>

  • Property mode set to 100644
File size: 4.6 KB
Line 
1/*  Tasks_Periodic
2 *
3 *  This routine serves as a test task for the CBS scheduler
4 *  implementation.
5 *
6 *  Input parameters:
7 *    argument - task argument
8 *
9 *  Output parameters:  NONE
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#include "system.h"
17
18rtems_task Task_Periodic(
19  rtems_task_argument argument
20)
21{
22  rtems_id          rmid;
23  rtems_status_code status;
24
25  time_t approved_budget, exec_time, abs_time, current_budget;
26
27  int start, stop, now;
28
29  qres_sid_t server_id, tsid;
30  qres_params_t params, tparams;
31
32  params.P = Period;
33  params.Q = Execution+1;
34
35  printf( "Periodic task: Create server and Attach thread\n" );
36  if ( qres_create_server( &params, &server_id ) )
37    printf( "ERROR: CREATE SERVER FAILED\n" );
38  if ( qres_attach_thread( server_id, 0, Task_id ) )
39    printf( "ERROR: ATTACH THREAD FAILED\n" );
40
41  printf( "Periodic task: ID and Get parameters\n" );
42  if ( qres_get_sid( 0, Task_id, &tsid ) )
43    printf( "ERROR: GET SERVER ID FAILED\n" );
44  if ( tsid != server_id )
45    printf( "ERROR: SERVER ID MISMATCH\n" );
46  if ( qres_get_params( server_id, &tparams ) )
47    printf( "ERROR: GET PARAMETERS FAILED\n" );
48  if ( params.P != tparams.P ||
49       params.Q != tparams.Q )
50    printf( "ERROR: PARAMETERS MISMATCH\n" );
51
52  printf( "Periodic task: Detach thread and Destroy server\n" );
53  if ( qres_detach_thread( server_id, 0, Task_id ) )
54    printf( "ERROR: DETACH THREAD FAILED\n" );
55  if ( qres_destroy_server( server_id ) )
56    printf( "ERROR: DESTROY SERVER FAILED\n" );
57  if ( qres_create_server( &params, &server_id ) )
58    printf( "ERROR: CREATE SERVER FAILED\n" );
59
60  printf( "Periodic task: Current budget and Execution time\n" );
61  if ( qres_get_curr_budget( server_id, &current_budget ) )
62    printf( "ERROR: GET REMAINING BUDGET FAILED\n" );
63  if ( current_budget != params.Q )
64    printf( "ERROR: REMAINING BUDGET MISMATCH\n" );
65  if ( qres_get_exec_time( server_id, &exec_time, &abs_time ) )
66    printf( "ERROR: GET EXECUTION TIME FAILED\n" );
67
68  printf( "Periodic task: Set parameters\n" );
69  if ( qres_attach_thread( server_id, 0, Task_id ) )
70    printf( "ERROR: ATTACH THREAD FAILED\n" );
71  params.P = Period * 2;
72  params.Q = Execution * 2 +1;
73  if ( qres_set_params( server_id, &params ) )
74    printf( "ERROR: SET PARAMS FAILED\n" );
75  if ( qres_get_params( server_id, &tparams ) )
76    printf( "ERROR: GET PARAMS FAILED\n" );
77  if ( params.P != tparams.P ||
78       params.Q != tparams.Q )
79    printf( "ERROR: PARAMS MISMATCH\n" );
80  params.P = Period;
81  params.Q = Execution+1;
82  if ( qres_set_params( server_id, &params ) )
83    printf( "ERROR: SET PARAMS FAILED\n" );
84  if ( qres_get_appr_budget( server_id, &approved_budget ) )
85    printf( "ERROR: GET APPROVED BUDGET FAILED\n" );
86
87  printf( "Periodic task: Approved budget\n" );
88  if ( approved_budget != params.Q )
89    printf( "ERROR: APPROVED BUDGET MISMATCH\n" );
90
91  status = rtems_rate_monotonic_create( argument, &rmid );
92  directive_failed( status, "rtems_rate_monotonic_create" );
93
94  /* Starting periodic behavior of the task */
95  printf( "Periodic task: Starting periodic behavior\n" );
96  status = rtems_task_wake_after( 1 + Phase );
97  directive_failed( status, "rtems_task_wake_after" );
98
99  while ( FOREVER ) {
100    if ( rtems_rate_monotonic_period(rmid, Period) == RTEMS_TIMEOUT )
101      printf( "P%" PRIdPTR " - Deadline miss\n", argument );
102
103    rtems_clock_get( RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &start );
104    printf( "P%" PRIdPTR "-S ticks:%d\n", argument, start );
105    if ( start > 4*Period+Phase ) break; /* stop */
106    /* active computing */
107    while(FOREVER) {
108      rtems_clock_get( RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &now );
109      if ( now >= start + Execution ) break;
110
111      if ( qres_get_exec_time( server_id, &exec_time, &abs_time ) )
112        printf( "ERROR: GET EXECUTION TIME FAILED\n" );
113      if ( qres_get_curr_budget( server_id, &current_budget) )
114        printf( "ERROR: GET CURRENT BUDGET FAILED\n" );
115      if ( (current_budget + exec_time) > (Execution + 1) ) {
116        printf( "ERROR: CURRENT BUDGET AND EXECUTION TIME MISMATCH\n" );
117        rtems_test_exit( 0 );
118      }
119    }
120    rtems_clock_get( RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &stop );
121    printf( "P%" PRIdPTR "-F ticks:%d\n", argument, stop );
122  }
123
124  /* delete period and SELF */
125  status = rtems_rate_monotonic_delete( rmid );
126  if ( status != RTEMS_SUCCESSFUL ) {
127    printf("rtems_rate_monotonic_delete failed with status of %d.\n", status);
128    rtems_test_exit( 0 );
129  }
130  if ( qres_cleanup() )
131    printf( "ERROR: QRES CLEANUP\n" );
132
133  fflush(stdout);
134  TEST_END();
135  rtems_test_exit( 0 );
136}
Note: See TracBrowser for help on using the repository browser.