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

5
Last change on this file since c4b8b147 was c4b8b147, checked in by Sebastian Huber <sebastian.huber@…>, on 11/03/17 at 07:35:38

tests: Use simple console driver

Update #3170.
Update #3199.

  • Property mode set to 100644
File size: 5.8 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  rtems_test_assert( period_status.since_last_period.tv_sec == 0 );
59  rtems_test_assert( period_status.since_last_period.tv_nsec == 0 );
60  rtems_test_assert( period_status.executed_since_last_period.tv_sec == 0 );
61  rtems_test_assert( period_status.executed_since_last_period.tv_nsec == 0 );
62
63  /*
64   * Check get_status error cases.
65   */
66  puts( "rtems_rate_monotonic_get_status - check RTEMS_NOT_DEFINED" );
67
68  /* Do some work to get a non-zero cpu usage */
69  rtems_test_spin_for_ticks( 10 );
70
71  status = rtems_rate_monotonic_period( period_id, 100 );
72  directive_failed( status, "rate_monotonic_period" );
73
74  /* Do some more work */
75  rtems_test_spin_for_ticks( 10 );
76
77  /* Reset the cpu usage statistics. */
78  rtems_cpu_usage_reset();
79
80  /* Status should be undefined. */
81  status = rtems_rate_monotonic_get_status( period_id, &period_status );
82  fatal_directive_status(
83    status,
84    RTEMS_NOT_DEFINED,
85    "rtems_rate_monotonic_get_status after cpu usage reset"
86  );
87
88  /* Clean up. */
89  status = rtems_rate_monotonic_cancel( period_id );
90  directive_failed( status, "rate_monotonic_cancel" );
91
92  /*
93   * Check normal get_status results.
94   */
95  puts( "rtems_rate_monotonic_get_status - verify values of an active period" );
96  rtems_test_spin_until_next_tick();
97  status = rtems_rate_monotonic_period( period_id, 100 );
98  directive_failed( status, "rate_monotonic_period" );
99
100  /* Do some work */
101  rtems_test_spin_for_ticks( 10 );
102
103  /* Block a little */
104  status = rtems_task_wake_after( 50 );
105
106  /* Check the status */
107  status = rtems_rate_monotonic_get_status( period_id, &period_status );
108  directive_failed( status, "rate_monotonic_get_status" );
109
110  /* Check status values. */
111  /* Note: POSIX mandates struct timespec->tv_nsec to be a "long" */
112  printf(
113    "wall time should be ~600000000 is %ld\n",
114    period_status.since_last_period.tv_nsec
115  );
116  printf(
117    "cpu time should be ~100000000 is %ld\n",
118    period_status.executed_since_last_period.tv_nsec
119  );
120  rtems_test_assert( period_status.since_last_period.tv_sec == 0 );
121  rtems_test_assert( period_status.since_last_period.tv_nsec >= 600000000 );
122  rtems_test_assert( period_status.since_last_period.tv_nsec <= 610000000 );
123  rtems_test_assert( period_status.executed_since_last_period.tv_sec == 0 );
124  rtems_test_assert(
125    period_status.executed_since_last_period.tv_nsec >= 100000000
126  );
127  rtems_test_assert(
128    period_status.executed_since_last_period.tv_nsec <= 110000000
129  );
130
131  /* ensure the missed periods are properly accounted for */
132  puts( "rtems_rate_monotonic_cancel -  OK" );
133  status = rtems_rate_monotonic_cancel( period_id );
134  directive_failed( status, "rate_monotonic_cancel" );
135
136  puts( "Testing statistics on missed periods" );
137  rtems_test_spin_until_next_tick();
138  status = rtems_rate_monotonic_period( period_id, 50 );
139  directive_failed( status, "rate_monotonic_period above loop" );
140
141  for ( i=1 ; i <= 3 ; i++ ) {
142    status = rtems_task_wake_after( 100 );
143    directive_failed( status, "rtems_task_wake_after(100)" );
144
145    rtems_test_spin_until_next_tick();
146    status = rtems_rate_monotonic_period( period_id, 50 );
147    fatal_directive_status(
148      status,
149      RTEMS_TIMEOUT,
150      "rtems_rate_monotonic_period 2-n"
151    );
152
153    status = rtems_rate_monotonic_get_statistics( period_id, &statistics );
154    directive_failed( status, "rate_monotonic_get_statistics" );
155    if ( statistics.missed_count != i ) {
156      printf(
157        "Expected %d got %" PRIu32 " for missed_count\n",
158        i,
159        statistics.missed_count
160      );
161    }
162
163    rtems_test_assert( statistics.missed_count == i );
164  }
165
166  /* Check the status */
167  status = rtems_rate_monotonic_get_status( period_id, &period_status );
168  directive_failed( status, "rate_monotonic_get_status" );
169  puts(
170    "rtems_rate_monotonic_get_status - verify value of a postponed jobs count"
171  );
172  rtems_test_assert( period_status.postponed_jobs_count == 3 );
173
174  TEST_END();
175
176  rtems_test_exit(0);
177}
178
179/* configuration information */
180
181#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
182#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
183
184#define CONFIGURE_MILLISECONDS_PER_TICK 1
185
186#define CONFIGURE_MAXIMUM_TASKS             1
187#define CONFIGURE_MAXIMUM_PERIODS           1
188
189#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
190
191#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
192
193
194#define CONFIGURE_INIT
195
196#include <rtems/confdefs.h>
197/* end of file */
Note: See TracBrowser for help on using the repository browser.