Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:46

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2012.
0005  *  On-Line Applications Research Corporation (OAR).
0006  *
0007  * Redistribution and use in source and binary forms, with or without
0008  * modification, are permitted provided that the following conditions
0009  * are met:
0010  * 1. Redistributions of source code must retain the above copyright
0011  *    notice, this list of conditions and the following disclaimer.
0012  * 2. Redistributions in binary form must reproduce the above copyright
0013  *    notice, this list of conditions and the following disclaimer in the
0014  *    documentation and/or other materials provided with the distribution.
0015  *
0016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0026  * POSSIBILITY OF SUCH DAMAGE.
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 /* forward declarations to avoid warnings */
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   /* create period */
0058   status = rtems_rate_monotonic_create(
0059       period_name,
0060       &period_id
0061   );
0062   directive_failed( status, "rate_monotonic_create" );
0063 
0064   /*
0065    * Check get_status on an inactive period.
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   /* Check status values. */
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   /* Clean up. */
0083   status = rtems_rate_monotonic_cancel( period_id );
0084   directive_failed( status, "rate_monotonic_cancel" );
0085 
0086   /*
0087    * Check normal get_status results.
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   /* Do some work */
0095   rtems_test_spin_for_ticks( 10 );
0096 
0097   /* Block a little */
0098   status = rtems_task_wake_after( 50 );
0099 
0100   /* Check the status */
0101   status = rtems_rate_monotonic_get_status( period_id, &period_status );
0102   directive_failed( status, "rate_monotonic_get_status" );
0103 
0104   /* Check status values. */
0105   /* Note: POSIX mandates struct timespec->tv_nsec to be a "long" */
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   /* ensure the missed periods are properly accounted for */
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   /* Check the status */
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 /* configuration information */
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 /* end of file */