source: rtems/testsuites/sptests/sp69/init.c @ e5f7481

4.10
Last change on this file since e5f7481 was e5f7481, checked in by Ralf Corsepius <ralf.corsepius@…>, on 02/08/11 at 07:24:00

2011-02-08 Ralf Corsépius <ralf.corsepius@…>

  • sp69/init.c: Use "ld" instead of PRId32 to print struct timespec->tv_nsec.
  • Property mode set to 100644
File size: 6.1 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2009.
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.com/license/LICENSE.
8 *
9 *  $Id$
10 */
11
12#include <rtems/cpuuse.h>
13#include <tmacros.h>
14#include "test_support.h"
15
16rtems_task Init(
17  rtems_task_argument argument
18)
19{
20  rtems_id                                period_id;
21  rtems_name                              period_name;
22  rtems_rate_monotonic_period_status      period_status;
23  rtems_status_code                       status;
24  rtems_rate_monotonic_period_statistics  statistics;
25  int                                     i;
26
27  period_name = rtems_build_name('P','E','R','1');
28
29  puts( "\n\n*** TEST 69 ***" );
30
31  /* create period */
32  status = rtems_rate_monotonic_create(
33      period_name,
34      &period_id
35  );
36  directive_failed( status, "rate_monotonic_create" );
37
38  /*
39   * Check get_status on an inactive period.
40   */
41  puts(
42    "rtems_rate_monotonic_get_status - verify values of an inactive period"
43  );
44
45  status = rtems_rate_monotonic_get_status( period_id, &period_status );
46  directive_failed( status, "rate_monotonic_get_status" );
47
48  /* Check status values. */
49  rtems_test_assert( period_status.owner == rtems_task_self() );
50  rtems_test_assert( period_status.state == RATE_MONOTONIC_INACTIVE );
51  #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
52    rtems_test_assert( period_status.since_last_period.tv_sec == 0 );
53    rtems_test_assert( period_status.since_last_period.tv_nsec == 0 );
54    rtems_test_assert( period_status.executed_since_last_period.tv_sec == 0 );
55    rtems_test_assert( period_status.executed_since_last_period.tv_nsec == 0 );
56  #else
57    rtems_test_assert( period_status.since_last_period == 0 );
58    rtems_test_assert( period_status.executed_since_last_period == 0 );
59  #endif
60
61  /*
62   * Check get_status error cases.
63   */
64  puts( "rtems_rate_monotonic_get_status - check RTEMS_NOT_DEFINED" );
65
66  /* Do some work to get a non-zero cpu usage */
67  rtems_test_spin_for_ticks( 10 );
68
69  status = rtems_rate_monotonic_period( period_id, 100 );
70  directive_failed( status, "rate_monotonic_period" );
71
72  /* Do some more work */
73  rtems_test_spin_for_ticks( 10 );
74
75  /* Reset the cpu usage statistics. */
76  rtems_cpu_usage_reset();
77
78  /* Status should be undefined. */
79  status = rtems_rate_monotonic_get_status( period_id, &period_status );
80  fatal_directive_status(
81    status,
82    RTEMS_NOT_DEFINED,
83    "rtems_rate_monotonic_get_status after cpu usage reset"
84  );
85
86  /* Clean up. */
87  status = rtems_rate_monotonic_cancel( period_id );
88  directive_failed( status, "rate_monotonic_cancel" );
89
90  /*
91   * Check normal get_status results.
92   */
93  puts( "rtems_rate_monotonic_get_status - verify values of an active period" );
94  rtems_test_spin_until_next_tick();
95  status = rtems_rate_monotonic_period( period_id, 100 );
96  directive_failed( status, "rate_monotonic_period" );
97
98  /* Do some work */
99  rtems_test_spin_for_ticks( 10 );
100
101  /* Block a little */
102  status = rtems_task_wake_after( 50 );
103
104  /* Check the status */
105  status = rtems_rate_monotonic_get_status( period_id, &period_status );
106  directive_failed( status, "rate_monotonic_get_status" );
107
108  /* Check status values. */
109  #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
110  /* Note: POSIX mandates struct timespec->tv_nsec to be a "long" */
111    printf(
112      "wall time should be ~600000000 is %ld\n",
113      period_status.since_last_period.tv_nsec
114    );
115    printf(
116      "cpu time should be ~100000000 is %ld\n",
117      period_status.executed_since_last_period.tv_nsec
118    );
119    rtems_test_assert( period_status.since_last_period.tv_sec == 0 );
120    rtems_test_assert( period_status.since_last_period.tv_nsec >= 600000000 );
121    rtems_test_assert( period_status.since_last_period.tv_nsec <= 610000000 );
122    rtems_test_assert( period_status.executed_since_last_period.tv_sec == 0 );
123    rtems_test_assert(
124      period_status.executed_since_last_period.tv_nsec >= 100000000
125    );
126    rtems_test_assert(
127      period_status.executed_since_last_period.tv_nsec <= 110000000
128    );
129  #else
130    printf(
131      "wall time should be ~60 is %" PRId32 "\n",
132      (int) period_status.since_last_period
133    );
134    printf(
135      "cpu time should be ~10 is %" PRId32 "\n",
136      (int) period_status.executed_since_last_period
137    );
138    rtems_test_assert( period_status.since_last_period >= 60 );
139    rtems_test_assert( period_status.since_last_period <= 61 );
140    rtems_test_assert( period_status.executed_since_last_period >= 10 );
141    rtems_test_assert( period_status.executed_since_last_period <= 12 );
142  #endif
143
144  /* ensure the missed periods are properly accounted for */
145  puts( "rtems_rate_monotonic_cancel -  OK" );
146  status = rtems_rate_monotonic_cancel( period_id );
147  directive_failed( status, "rate_monotonic_cancel" );
148
149  puts( "Testing statistics on missed periods" );
150  rtems_test_spin_until_next_tick();
151  status = rtems_rate_monotonic_period( period_id, 50 );
152  directive_failed( status, "rate_monotonic_period above loop" );
153
154  for ( i=1 ; i <= 3 ; i++ ) {
155    status = rtems_task_wake_after( 100 );
156    directive_failed( status, "rtems_task_wake_after(100)" );
157
158    rtems_test_spin_until_next_tick();
159    status = rtems_rate_monotonic_period( period_id, 50 );
160    fatal_directive_status(
161      status,
162      RTEMS_TIMEOUT,
163      "rtems_rate_monotonic_period 2-n"
164    );
165
166    status = rtems_rate_monotonic_get_statistics( period_id, &statistics );
167    directive_failed( status, "rate_monotonic_get_statistics" );
168    if ( statistics.missed_count != i ) {
169      printf(
170        "Expected %d got %" PRIu32 " for missed_count\n",
171        i,
172        statistics.missed_count
173      );
174    }
175   
176    rtems_test_assert( statistics.missed_count == i );
177  }
178 
179  puts( "*** END OF TEST 69 ***" );
180
181  rtems_test_exit(0);
182}
183
184/* configuration information */
185
186#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
187#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
188
189#define CONFIGURE_MILLISECONDS_PER_TICK 1
190
191#define CONFIGURE_MAXIMUM_TASKS             1
192#define CONFIGURE_MAXIMUM_PERIODS           1
193
194#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
195
196
197#define CONFIGURE_INIT
198
199#include <rtems/confdefs.h>
200/* end of file */
Note: See TracBrowser for help on using the repository browser.