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