1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2011. |
---|
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.rtems.org/license/LICENSE. |
---|
8 | */ |
---|
9 | |
---|
10 | #ifdef HAVE_CONFIG_H |
---|
11 | #include "config.h" |
---|
12 | #endif |
---|
13 | |
---|
14 | #include "system.h" |
---|
15 | |
---|
16 | #include <rtems/score/watchdogimpl.h> |
---|
17 | |
---|
18 | /* |
---|
19 | runtime of TA6 should be shorter than TA5 |
---|
20 | */ |
---|
21 | #define TA6_ITERATIONS 10 |
---|
22 | #define TA6_PERIOD_FACTOR 10 |
---|
23 | |
---|
24 | uint32_t Periods[7] = { 0, 2, 2, 2, 2, 100, 0 }; |
---|
25 | uint32_t Iterations[7] = { 0, 50, 50, 50, 50, 1, TA6_ITERATIONS }; |
---|
26 | rtems_task_priority Priorities[7] = { 0, 1, 1, 3, 4, 5, 1 }; |
---|
27 | |
---|
28 | static char *name( size_t i, char buf[ 4 ] ) |
---|
29 | { |
---|
30 | rtems_name_to_characters( |
---|
31 | Task_name[ i ], |
---|
32 | &buf[ 0 ], |
---|
33 | &buf[ 1 ], |
---|
34 | &buf[ 2 ], |
---|
35 | &buf[ 3 ] |
---|
36 | ); |
---|
37 | buf[ 3 ] = '\0'; |
---|
38 | return &buf[ 0 ]; |
---|
39 | } |
---|
40 | |
---|
41 | rtems_task Task_1_through_6( |
---|
42 | rtems_task_argument argument |
---|
43 | ) |
---|
44 | { |
---|
45 | rtems_id rmid; |
---|
46 | rtems_id test_rmid; |
---|
47 | int index; |
---|
48 | int pass; |
---|
49 | uint32_t failed; |
---|
50 | rtems_status_code status; |
---|
51 | char buf[ 4 ]; |
---|
52 | |
---|
53 | status = rtems_rate_monotonic_create( argument, &rmid ); |
---|
54 | directive_failed( status, "rtems_rate_monotonic_create" ); |
---|
55 | rtems_test_printf( |
---|
56 | "%s - rtems_rate_monotonic_create id = 0x%08" PRIxrtems_id "\n", |
---|
57 | name( argument, buf ), |
---|
58 | rmid |
---|
59 | ); |
---|
60 | |
---|
61 | status = rtems_rate_monotonic_ident( argument, &test_rmid ); |
---|
62 | directive_failed( status, "rtems_rate_monotonic_ident" ); |
---|
63 | rtems_test_printf( |
---|
64 | "%s - rtems_rate_monotonic_ident id = 0x%08" PRIxrtems_id "\n", |
---|
65 | name( argument, buf ), |
---|
66 | test_rmid |
---|
67 | ); |
---|
68 | |
---|
69 | if ( rmid != test_rmid ) { |
---|
70 | rtems_test_printf( |
---|
71 | "RMID's DO NOT MATCH (0x%" PRIxrtems_id " and 0x%" PRIxrtems_id ")\n", |
---|
72 | rmid, |
---|
73 | test_rmid |
---|
74 | ); |
---|
75 | rtems_test_exit( 0 ); |
---|
76 | } |
---|
77 | |
---|
78 | rtems_test_printf( |
---|
79 | "%s - (0x%08" PRIxrtems_id ") period %" PRIu32 "\n", |
---|
80 | name( argument, buf ), |
---|
81 | rmid, |
---|
82 | Periods[ argument ] |
---|
83 | ); |
---|
84 | |
---|
85 | status = rtems_task_wake_after( 2 ); |
---|
86 | directive_failed( status, "rtems_task_wake_after" ); |
---|
87 | |
---|
88 | switch ( argument ) { |
---|
89 | case 1: |
---|
90 | case 2: |
---|
91 | case 3: |
---|
92 | case 4: |
---|
93 | while ( FOREVER ) { |
---|
94 | status = rtems_rate_monotonic_period( rmid, Periods[ argument ] ); |
---|
95 | directive_failed( status, "rtems_rate_monotonic_period" ); |
---|
96 | |
---|
97 | Count.count[ argument ]++; |
---|
98 | } |
---|
99 | break; |
---|
100 | case 5: |
---|
101 | pass = 0; |
---|
102 | failed = 0; |
---|
103 | |
---|
104 | status = rtems_rate_monotonic_period( rmid, Periods[ argument ] ); |
---|
105 | directive_failed( status, "rtems_rate_monotonic_period 1 of TA5" ); |
---|
106 | |
---|
107 | Get_all_counters(); |
---|
108 | |
---|
109 | while ( FOREVER ) { |
---|
110 | |
---|
111 | status = rtems_rate_monotonic_period( rmid, Periods[ argument ] ); |
---|
112 | directive_failed( status, "rtems_rate_monotonic_period 2 of TA5" ); |
---|
113 | |
---|
114 | Get_all_counters(); |
---|
115 | |
---|
116 | for( index = 1 ; index <= 4 ; index++ ) { |
---|
117 | if ( Temporary_count.count[ index ] != Iterations[ index ] ) { |
---|
118 | rtems_test_printf( |
---|
119 | "%s - FAIL - Actual=%" PRIu32 ", Expected=%" PRIu32 "\n", |
---|
120 | name( index, buf ), |
---|
121 | Temporary_count.count[ index ], |
---|
122 | Iterations[ index ] |
---|
123 | ); |
---|
124 | failed += 1; |
---|
125 | } |
---|
126 | } |
---|
127 | |
---|
128 | if ( failed == 5 ) |
---|
129 | rtems_test_exit( 0 ); |
---|
130 | |
---|
131 | pass += 1; |
---|
132 | |
---|
133 | rtems_test_printf( "TA5 - PERIODS CHECK OK (%d)\n", pass ); |
---|
134 | |
---|
135 | if ( pass == 10 ) { |
---|
136 | end_of_test(); |
---|
137 | } |
---|
138 | |
---|
139 | } |
---|
140 | break; |
---|
141 | case 6: |
---|
142 | /* test changing periods */ |
---|
143 | { |
---|
144 | uint32_t time[TA6_ITERATIONS+1]; |
---|
145 | rtems_interval period; |
---|
146 | |
---|
147 | period = 1*TA6_PERIOD_FACTOR; |
---|
148 | status = rtems_rate_monotonic_period( rmid, period); |
---|
149 | directive_failed( status, "rtems_rate_monotonic_period of TA6" ); |
---|
150 | time[0] = _Watchdog_Ticks_since_boot; /* timestamp */ |
---|
151 | /*rtems_test_printf("%d - %d\n", period, time[0]);*/ |
---|
152 | |
---|
153 | for (index = 1; index <= TA6_ITERATIONS; index++) { |
---|
154 | period = (index+1)*TA6_PERIOD_FACTOR; |
---|
155 | status = rtems_rate_monotonic_period( rmid, period); |
---|
156 | directive_failed( status, "rtems_rate_monotonic_period of TA6" ); |
---|
157 | time[index] = _Watchdog_Ticks_since_boot; /* timestamp */ |
---|
158 | /*rtems_test_printf("%d - %d\n", period, time[index]);*/ |
---|
159 | } |
---|
160 | |
---|
161 | for (index = 1; index <= TA6_ITERATIONS; index++) { |
---|
162 | rtems_interval meas = time[index] - time[index-1]; |
---|
163 | period = index*TA6_PERIOD_FACTOR; |
---|
164 | rtems_test_printf( |
---|
165 | "TA6 - Actual: %" PRIdrtems_interval |
---|
166 | " Expected: %" PRIdrtems_interval, |
---|
167 | meas, |
---|
168 | period |
---|
169 | ); |
---|
170 | if (period == meas) rtems_test_printf(" - OK\n"); |
---|
171 | else rtems_test_printf(" - FAILED\n"); |
---|
172 | } |
---|
173 | } |
---|
174 | rtems_task_suspend(RTEMS_SELF); |
---|
175 | break; |
---|
176 | } |
---|
177 | } |
---|