]> rtime.felk.cvut.cz Git - rtems-pluggable-edf.git/blob - src/test_cbs/task.c
Test_CBS: test updated for testing a basic part of reps_lib API
[rtems-pluggable-edf.git] / src / test_cbs / task.c
1 #include <system_def.h>
2 #include "system.h"
3 #include "app_def.h"
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <rtems/untar.h>
7 #include <rtems/error.h>
8 #include <rtems/mw_uid.h>
9 #include <errno.h>
10 #include <stdint.h>
11 #include <rtems/score/wkspace.h>
12 #include <reps_lib.h>
13
14
15
16 #define TEST_DURATION 130
17
18 //utilization setup: T1 3/7, T2 5/10
19
20 #define T1_DUR 300
21 #define T2_DUR 500
22 #define T1_PER 7
23 #define T2_PER 10
24 #define T1_SERVER 0
25 #define T2_SERVER 2
26
27 // budget overrun signal handler
28 rtems_asr signal_handler (rtems_signal_set signals) {
29         printf("SIGNAL kill you \n");
30 }
31
32 void test_loop ( unsigned int id, rtems_name name, unsigned int period_length, unsigned int max_j)
33 {
34   rtems_id period;
35   rtems_status_code status;
36   char output1[50];
37   char output2[50];
38   unsigned int start, stop, max_i;
39   unsigned int i,j,k;
40   void *mem;
41   
42   status = rtems_rate_monotonic_create( name, &period );
43   rtems_signal_catch(&signal_handler, RTEMS_DEFAULT_MODES);
44   
45   if ( status != RTEMS_SUCCESSFUL ) {
46         printf( "rtems_monotonic_create failed with status of %d.\n", status);
47             exit( 1 );
48   }
49   
50   max_i = 1000; 
51   edf_deadline_init(name, &period);
52   while ( 1 ) {
53           if (edf_next_period(period,period_length, 0))
54                      printf("P%u - Deadline miss", id);
55           
56           rtems_clock_get(RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &start);
57           sprintf(output1,"P%u-S  ticks:%u  prio:%u", id,start, (unsigned int) _Per_CPU_Information.executing->current_priority);
58           puts(output1);
59           
60           if ( start >= TEST_DURATION ) break;
61           
62           /* active computing */ 
63           for ( i = 1 ; i < max_i; i++) 
64           { 
65                   j =  i/12 ; j++;
66                   for ( j = 1; j < max_j; j++) 
67                   {
68                           k = j/ 3; 
69                           k++;                    
70                           mem = _Workspace_Allocate (4);
71                           _Workspace_Free(mem);
72                  }
73           }
74          
75           rtems_clock_get(RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &stop);
76           sprintf(output2,"P%u-F  ticks:%u",id, stop);
77           puts(output2);
78   }
79   
80   /* missed period so delete period and SELF */
81   status = edf_deadline_cancel(period);
82   if ( status != RTEMS_SUCCESSFUL ) {
83           printf( "rtems_rate_monotonic_delete failed with status of %d.\n", status );
84           exit( 0 );
85   }
86   
87   puts( "*** END OF TEST - edf***" );
88   exit( 0 );    
89 }
90
91
92
93 rtems_task Task_1(
94   rtems_task_argument argument
95 )
96 {
97         rtems_name name;
98         name = rtems_build_name( 'P', 'E', 'R', 'A' );
99         test_loop(1, name, T1_PER,T1_DUR);
100 }
101
102
103 rtems_task Task_2(
104   rtems_task_argument argument
105 )
106 {
107         rtems_id sid;
108         reps_params_t p_params;
109         rtems_name name;
110         name = rtems_build_name( 'P', 'E', 'R', 'B' );
111         // create a server observation
112
113         reps_init();    
114         p_params.P = T2_PER;
115         p_params.Q = T2_SERVER;
116         reps_create_server(&p_params, &sid);    
117         if (reps_attach_thread(sid, Task_2_id) != REPS_OK)
118                 printf("err: attach \n");
119
120 /*      Objects_Locations location;
121         Thread_Control *the_thread = _Thread_Get(Task_2_id, &location); 
122         RBT_Node *node = (RBT_Node*)the_thread->scheduler_info;         
123         printf("task2 server params Q %d, P %d\n", node->cmp_time, node->rel_deadline);*/
124         
125         test_loop(2, name, T2_PER,T2_DUR);
126
127 }
128