File indexing completed on 2025-05-11 08:24:46
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #ifdef HAVE_CONFIG_H
0030 #include "config.h"
0031 #endif
0032
0033 #include <rtems/cpuuse.h>
0034 #include <tmacros.h>
0035 #include "test_support.h"
0036
0037 const char rtems_test_name[] = "SP 69";
0038
0039
0040 rtems_task Init(rtems_task_argument argument);
0041
0042 rtems_task Init(
0043 rtems_task_argument argument
0044 )
0045 {
0046 rtems_id period_id;
0047 rtems_name period_name;
0048 rtems_rate_monotonic_period_status period_status;
0049 rtems_status_code status;
0050 rtems_rate_monotonic_period_statistics statistics;
0051 int i;
0052
0053 period_name = rtems_build_name('P','E','R','1');
0054
0055 TEST_BEGIN();
0056
0057
0058 status = rtems_rate_monotonic_create(
0059 period_name,
0060 &period_id
0061 );
0062 directive_failed( status, "rate_monotonic_create" );
0063
0064
0065
0066
0067 puts(
0068 "rtems_rate_monotonic_get_status - verify values of an inactive period"
0069 );
0070
0071 status = rtems_rate_monotonic_get_status( period_id, &period_status );
0072 directive_failed( status, "rate_monotonic_get_status" );
0073
0074
0075 rtems_test_assert( period_status.owner == rtems_task_self() );
0076 rtems_test_assert( period_status.state == RATE_MONOTONIC_INACTIVE );
0077 rtems_test_assert( period_status.since_last_period.tv_sec == 0 );
0078 rtems_test_assert( period_status.since_last_period.tv_nsec == 0 );
0079 rtems_test_assert( period_status.executed_since_last_period.tv_sec == 0 );
0080 rtems_test_assert( period_status.executed_since_last_period.tv_nsec == 0 );
0081
0082
0083 status = rtems_rate_monotonic_cancel( period_id );
0084 directive_failed( status, "rate_monotonic_cancel" );
0085
0086
0087
0088
0089 puts( "rtems_rate_monotonic_get_status - verify values of an active period" );
0090 rtems_test_spin_until_next_tick();
0091 status = rtems_rate_monotonic_period( period_id, 100 );
0092 directive_failed( status, "rate_monotonic_period" );
0093
0094
0095 rtems_test_spin_for_ticks( 10 );
0096
0097
0098 status = rtems_task_wake_after( 50 );
0099
0100
0101 status = rtems_rate_monotonic_get_status( period_id, &period_status );
0102 directive_failed( status, "rate_monotonic_get_status" );
0103
0104
0105
0106 printf(
0107 "wall time should be ~600000000 is %ld\n",
0108 period_status.since_last_period.tv_nsec
0109 );
0110 printf(
0111 "cpu time should be ~100000000 is %ld\n",
0112 period_status.executed_since_last_period.tv_nsec
0113 );
0114 rtems_test_assert( period_status.since_last_period.tv_sec == 0 );
0115 rtems_test_assert( period_status.since_last_period.tv_nsec >= 600000000 );
0116 rtems_test_assert( period_status.since_last_period.tv_nsec <= 610000000 );
0117 rtems_test_assert( period_status.executed_since_last_period.tv_sec == 0 );
0118 rtems_test_assert(
0119 period_status.executed_since_last_period.tv_nsec >= 100000000
0120 );
0121 rtems_test_assert(
0122 period_status.executed_since_last_period.tv_nsec <= 110000000
0123 );
0124
0125
0126 puts( "rtems_rate_monotonic_cancel - OK" );
0127 status = rtems_rate_monotonic_cancel( period_id );
0128 directive_failed( status, "rate_monotonic_cancel" );
0129
0130 puts( "Testing statistics on missed periods" );
0131 rtems_test_spin_until_next_tick();
0132 status = rtems_rate_monotonic_period( period_id, 50 );
0133 directive_failed( status, "rate_monotonic_period above loop" );
0134
0135 for ( i=1 ; i <= 3 ; i++ ) {
0136 status = rtems_task_wake_after( 100 );
0137 directive_failed( status, "rtems_task_wake_after(100)" );
0138
0139 rtems_test_spin_until_next_tick();
0140 status = rtems_rate_monotonic_period( period_id, 50 );
0141 fatal_directive_status(
0142 status,
0143 RTEMS_TIMEOUT,
0144 "rtems_rate_monotonic_period 2-n"
0145 );
0146
0147 status = rtems_rate_monotonic_get_statistics( period_id, &statistics );
0148 directive_failed( status, "rate_monotonic_get_statistics" );
0149 if ( statistics.missed_count != i ) {
0150 printf(
0151 "Expected %d got %" PRIu32 " for missed_count\n",
0152 i,
0153 statistics.missed_count
0154 );
0155 }
0156
0157 rtems_test_assert( statistics.missed_count == i );
0158 }
0159
0160
0161 status = rtems_rate_monotonic_get_status( period_id, &period_status );
0162 directive_failed( status, "rate_monotonic_get_status" );
0163 puts(
0164 "rtems_rate_monotonic_get_status - verify value of a postponed jobs count"
0165 );
0166 rtems_test_assert( period_status.postponed_jobs_count == 3 );
0167
0168 TEST_END();
0169
0170 rtems_test_exit(0);
0171 }
0172
0173
0174
0175 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0176 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0177
0178 #define CONFIGURE_MAXIMUM_TASKS 1
0179 #define CONFIGURE_MAXIMUM_PERIODS 1
0180
0181 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0182
0183 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0184
0185
0186 #define CONFIGURE_INIT
0187
0188 #include <rtems/confdefs.h>
0189