source: rtems/testsuites/sptests/spcbssched02/task_periodic.c @ 74416035

4.115
Last change on this file since 74416035 was 74416035, checked in by Joel Sherrill <joel.sherrill@…>, on 09/20/11 at 13:06:58

2011-09-20 Petr Benes <benesp16@…>

PR 1916/testing

  • spcbssched02/init.c, spcbssched02/spcbssched02.scn, spcbssched02/system.h, spcbssched02/task_periodic.c, spedfsched03/init.c, spedfsched03/system.h, spedfsched03/tasks_aperiodic.c: Improve coverage.
  • Property mode set to 100644
File size: 5.1 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.com/license/LICENSE.
14 *
15 *  $Id$
16 */
17
18#include "system.h"
19
20rtems_task Task_Periodic(
21  rtems_task_argument argument
22)
23{
24  rtems_id          rmid;
25  rtems_status_code status;
26
27  time_t approved_budget, exec_time, abs_time, remaining_budget;
28
29  int start, stop, now;
30
31  rtems_cbs_server_id server_id, tsid;
32  rtems_cbs_parameters params, tparams;
33
34  params.deadline = Period;
35  params.budget = Execution+1;
36
37  /* Taks 1 will be attached to a server, task 2 not. */
38  if ( argument == 1 ) {
39    printf( "Periodic task: Create server and Attach thread\n" );
40    if ( rtems_cbs_create_server( &params, NULL, &server_id ) )
41      printf( "ERROR: CREATE SERVER FAILED\n" );
42    if ( rtems_cbs_attach_thread( server_id, Task_id ) )
43      printf( "ERROR: ATTACH THREAD FAILED\n" );
44
45    printf( "Periodic task: ID and Get parameters\n" );
46    if ( rtems_cbs_get_server_id( Task_id, &tsid ) )
47      printf( "ERROR: GET SERVER ID FAILED\n" );
48    if ( tsid != server_id )
49      printf( "ERROR: SERVER ID MISMATCH\n" );
50    if ( rtems_cbs_get_parameters( server_id, &tparams ) )
51      printf( "ERROR: GET PARAMETERS FAILED\n" );
52    if ( params.deadline != tparams.deadline ||
53         params.budget != tparams.budget )
54      printf( "ERROR: PARAMETERS MISMATCH\n" );
55
56    printf( "Periodic task: Detach thread and Destroy server\n" );
57    if ( rtems_cbs_detach_thread( server_id, Task_id ) )
58      printf( "ERROR: DETACH THREAD FAILED\n" );
59    if ( rtems_cbs_destroy_server( server_id ) )
60      printf( "ERROR: DESTROY SERVER FAILED\n" );
61    if ( rtems_cbs_create_server( &params, NULL, &server_id ) )
62      printf( "ERROR: CREATE SERVER FAILED\n" );
63
64    printf( "Periodic task: Remaining budget and Execution time\n" );
65    if ( rtems_cbs_get_remaining_budget( server_id, &remaining_budget ) )
66      printf( "ERROR: GET REMAINING BUDGET FAILED\n" );
67    if ( remaining_budget != params.budget )
68      printf( "ERROR: REMAINING BUDGET MISMATCH\n" );
69    if ( rtems_cbs_get_execution_time( server_id, &exec_time, &abs_time ) )
70      printf( "ERROR: GET EXECUTION TIME FAILED\n" );
71
72    printf( "Periodic task: Set parameters\n" );
73    if ( rtems_cbs_attach_thread( server_id, Task_id ) )
74      printf( "ERROR: ATTACH THREAD FAILED\n" );
75    params.deadline = Period * 2;
76    params.budget = Execution * 2 +1;
77    if ( rtems_cbs_set_parameters( server_id, &params ) )
78      printf( "ERROR: SET PARAMS FAILED\n" );
79    if ( rtems_cbs_get_parameters( server_id, &tparams ) )
80      printf( "ERROR: GET PARAMS FAILED\n" );
81    if ( params.deadline != tparams.deadline ||
82         params.budget != tparams.budget )
83      printf( "ERROR: PARAMS MISMATCH\n" );
84    params.deadline = Period;
85    params.budget = Execution+1;
86    if ( rtems_cbs_set_parameters( server_id, &params ) )
87      printf( "ERROR: SET PARAMS FAILED\n" );
88    if ( rtems_cbs_get_approved_budget( server_id, &approved_budget ) )
89      printf( "ERROR: GET APPROVED BUDGET FAILED\n" );
90
91    printf( "Periodic task: Approved budget\n" );
92    if ( approved_budget != params.budget )
93      printf( "ERROR: APPROVED BUDGET MISMATCH\n" );
94  }
95
96  status = rtems_rate_monotonic_create( argument, &rmid );
97  directive_failed( status, "rtems_rate_monotonic_create" );
98
99  /* Starting periodic behavior of the task */
100  printf( "Periodic task: Starting periodic behavior\n" );
101  status = rtems_task_wake_after( 1 + Phase );
102  directive_failed( status, "rtems_task_wake_after" );
103
104  while ( FOREVER ) {
105    if ( rtems_rate_monotonic_period(rmid, Period) == RTEMS_TIMEOUT )
106      printf( "P%" PRIdPTR " - Deadline miss\n", argument );
107
108    rtems_clock_get( RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &start );
109    printf( "P%" PRIdPTR "-S ticks:%d\n", argument, start );
110    if ( start > 4*Period+Phase ) break; /* stop */
111    /* active computing */
112    while(FOREVER) {
113      rtems_clock_get( RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &now );
114      if ( now >= start + Execution ) break;
115
116      if ( rtems_cbs_get_execution_time( server_id, &exec_time, &abs_time ) )
117        printf( "ERROR: GET EXECUTION TIME FAILED\n" );
118      if ( rtems_cbs_get_remaining_budget( server_id, &remaining_budget) )
119        printf( "ERROR: GET REMAINING BUDGET FAILED\n" );
120      if ( (remaining_budget + exec_time) > (Execution + 1) ) {
121        printf( "ERROR: REMAINING BUDGET AND EXECUTION TIME MISMATCH\n" );
122        rtems_test_exit( 0 );
123      }
124    }
125    rtems_clock_get( RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &stop );
126    printf( "P%" PRIdPTR "-F ticks:%d\n", argument, stop );
127  }
128
129  /* delete period and SELF */
130  status = rtems_rate_monotonic_delete( rmid );
131  if ( status != RTEMS_SUCCESSFUL ) {
132    printf("rtems_rate_monotonic_delete failed with status of %d.\n", status);
133    rtems_test_exit( 0 );
134  }
135  printf( "Periodic task: Deleting self\n" );
136  status = rtems_task_delete( RTEMS_SELF );
137  directive_failed( status, "rtems_task_delete of RTEMS_SELF" );
138}
Note: See TracBrowser for help on using the repository browser.