diff options
Diffstat (limited to 'testsuites/sptests/spedfsched04/init.c')
-rw-r--r-- | testsuites/sptests/spedfsched04/init.c | 86 |
1 files changed, 44 insertions, 42 deletions
diff --git a/testsuites/sptests/spedfsched04/init.c b/testsuites/sptests/spedfsched04/init.c index f80883d31d..bcaced994c 100644 --- a/testsuites/sptests/spedfsched04/init.c +++ b/testsuites/sptests/spedfsched04/init.c @@ -1,24 +1,25 @@ /** - * @brief A heuristic example to demonstrate how the postponed jobs are handled. + * @brief A heuristic example to demonstrate how the postponed jobs are handled in EDF. * * Given two tasks with implicit deadline under EDF policy. - * Task 1 has (4, 5) and task 2 has (4, 6), where (execution time, period/deadline). - * For the simplicity, we only execute the first task twice. + * Task 1 has (400, 500) and task 2 has (450, 550), where (required ticks, period/deadline). + * For the simplicity, we only execute the first task three times. * In the original implementation in v4.11, no matter how many periods are * expired, only one job will be released with a shifted deadline assignment. * - * In this example, the first job of task 2 will be blocked by the second job - * of task 1, so that there at least one following job is postponed. - * Due to overhead/delay, the second following job will be postponed as well. + * In this example, task 2 will be blocked by the second and third jobs + * of task 1, so that there are two jobs are postponed. + * Due to the domino effects, the following jobs of task 2 will be postponed until Job 9. * * If the overrun handling is correct, the period of task 2 changes back to - * normal status at time 22. - * Otherwise, the release time of job 3 is no longer periodic. + * normal status at Job 9. + * Otherwise, the release time of job 3 is no longer periodic + * and there is no more postponed jobs. * */ /* - * COPYRIGHT (c) 2016 Kuan-Hsun Chen. + * COPYRIGHT (c) 2016-2017 Kuan-Hsun Chen. * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at @@ -30,23 +31,19 @@ #endif #include <rtems/cpuuse.h> -#include <rtems/counter.h> - -#include <stdio.h> -#include <inttypes.h> - -#include "tmacros.h" +#include <tmacros.h> +#include "test_support.h" const char rtems_test_name[] = "SPEDFSCHED 4"; -static const uint32_t Periods[] = { 5000, 6000 }; -static const uint32_t Iterations[] = { 4000, 4000 }; +static const uint32_t Periods[] = { 500, 550 }; +static const uint32_t Iterations[] = { 400, 450 }; static const rtems_name Task_name[] = { rtems_build_name( 'T', 'A', '1', ' ' ), rtems_build_name( 'T', 'A', '2', ' ' ) }; static const rtems_task_priority Prio[3] = { 2, 5 }; -static const uint32_t testnumber = 11; /* stop condition */ +static const uint32_t testnumber = 9; /* stop condition */ static uint32_t tsk_counter[] = { 0, 0 }; static rtems_id Task_id[ 2 ]; @@ -58,35 +55,41 @@ static rtems_task Task( rtems_task_argument argument ) { - rtems_status_code status; - rtems_id RM_period; - rtems_id selfid=rtems_task_self(); - uint32_t start, end, flag=0, index; - rtems_counter_ticks t0; + rtems_status_code status; + rtems_id RM_period; + rtems_id selfid=rtems_task_self(); + rtems_rate_monotonic_period_status period_status; + uint32_t flag=0; - t0 = rtems_counter_nanoseconds_to_ticks( 1000000 ); //1ms ticks counter - /*create period*/ + /* create period */ status = rtems_rate_monotonic_create( Task_name[ argument ], &RM_period ); directive_failed( status, "rtems_rate_monotonic_create" ); while ( FOREVER ) { status = rtems_rate_monotonic_period( RM_period, Periods[ argument ] ); - if( flag == 0 && status == RTEMS_TIMEOUT ){ - flag = 1; - printf( "RTEMS_TIMEOUT\n" ); - } else if ( flag == 1 && status == RTEMS_SUCCESSFUL ) { - flag = 0; - printf( "RTEMS_SUCCESSFUL\n" ); - } - start = rtems_clock_get_ticks_since_boot(); - printf( "Job %" PRIu32 " Task %" PRIuPTR " starts at tick %" PRIu32 ".\n", tsk_counter[ argument ]+1, argument, start ); - for( index = 0; index < Iterations[ argument ]; index++ ){ - rtems_counter_delay_ticks( t0 ); - } - end = rtems_clock_get_ticks_since_boot(); - printf( " Job %" PRIu32" Task %" PRIuPTR " ends at tick %" PRIu32".\n", tsk_counter[ argument ]+1, argument, end ); + /* Do some work */ + rtems_test_spin_for_ticks( Iterations[ argument ] ); + if( argument == 1 ){ + if( status == RTEMS_TIMEOUT ){ + if( flag == 0 ){ + puts( "First time RTEMS_TIMEOUT" ); + puts( "Task 2 should have 2 postponed job due to preemption." ); + rtems_test_assert( period_status.postponed_jobs_count == 2 ); + flag = 1; + } + } else if ( flag == 1 && status == RTEMS_SUCCESSFUL ) { + puts( "RTEMS_SUCCESSFUL" ); + puts( "Overrun handling is finished, now Task 2 becomes normal." ); + rtems_test_assert( period_status.postponed_jobs_count == 0 ); + flag = 0; + } + + /* Check the status */ + status = rtems_rate_monotonic_get_status( RM_period, &period_status ); + directive_failed( status, "rate_monotonic_get_status" ); + if( tsk_counter[ argument ] == testnumber ){ TEST_END(); status = rtems_rate_monotonic_delete( RM_period ); @@ -97,7 +100,8 @@ static rtems_task Task( tsk_counter[ argument ]+=1; if ( argument == 0 ){ - if( tsk_counter[ argument ] == 2 ){ + if( tsk_counter[ argument ] == 3 ){ + puts("Task 1 has released 3 jobs and finished."); status = rtems_rate_monotonic_delete( RM_period ); directive_failed( status, "rtems_rate_monotonic_delete" ); status = rtems_task_delete( selfid ); @@ -116,7 +120,6 @@ static rtems_task Init( TEST_BEGIN(); - printf( "\nTicks per second in your system: %" PRIu32 "\n", rtems_clock_get_ticks_per_second() ); /* Create two tasks */ for ( index = 0; index < RTEMS_ARRAY_SIZE(Task_name); ++index ){ @@ -127,7 +130,6 @@ static rtems_task Init( directive_failed( status, "rtems_task_create loop" ); } - /* After creating the periods for tasks, start to run them sequencially. */ for ( index = 0; index < RTEMS_ARRAY_SIZE(Task_name); ++index ){ status = rtems_task_start( Task_id[ index ], Task, index); |