From 1c2b94a61c3054fbcebb24b3bb49c7649be020b0 Mon Sep 17 00:00:00 2001 From: Petr Benes Date: Sun, 15 Apr 2012 23:12:08 -0400 Subject: PR1908: QoS library for CBS scheduler Add the lipqos and sptest. --- testsuites/sptests/spqreslib/Makefile.am | 28 ++++ testsuites/sptests/spqreslib/init.c | 227 +++++++++++++++++++++++++++ testsuites/sptests/spqreslib/spqreslib.doc | 22 +++ testsuites/sptests/spqreslib/spqreslib.scn | 30 ++++ testsuites/sptests/spqreslib/system.h | 62 ++++++++ testsuites/sptests/spqreslib/task_periodic.c | 138 ++++++++++++++++ 6 files changed, 507 insertions(+) create mode 100644 testsuites/sptests/spqreslib/Makefile.am create mode 100644 testsuites/sptests/spqreslib/init.c create mode 100644 testsuites/sptests/spqreslib/spqreslib.doc create mode 100644 testsuites/sptests/spqreslib/spqreslib.scn create mode 100644 testsuites/sptests/spqreslib/system.h create mode 100644 testsuites/sptests/spqreslib/task_periodic.c (limited to 'testsuites') diff --git a/testsuites/sptests/spqreslib/Makefile.am b/testsuites/sptests/spqreslib/Makefile.am new file mode 100644 index 0000000000..bd8323ff9d --- /dev/null +++ b/testsuites/sptests/spqreslib/Makefile.am @@ -0,0 +1,28 @@ +## +## $Id$ +## + +MANAGERS = io rate_monotonic semaphore clock + +rtems_tests_PROGRAMS = spqreslib +spqreslib_SOURCES = init.c task_periodic.c system.h + +dist_rtems_tests_DATA = spqreslib.scn +dist_rtems_tests_DATA += spqreslib.doc + +include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg +include $(top_srcdir)/../automake/compile.am +include $(top_srcdir)/../automake/leaf.am + +spqreslib_LDADD = $(MANAGERS_NOT_WANTED:%=$(PROJECT_LIB)/no-%.rel) + +AM_CPPFLAGS += -I$(top_srcdir)/../support/include + +LINK_OBJS = $(spqreslib_OBJECTS) $(spqreslib_LDADD) +LINK_LIBS = $(spqreslib_LDLIBS) + +spqreslib$(EXEEXT): $(spqreslib_OBJECTS) $(spqreslib_DEPENDENCIES) + @rm -f spqreslib$(EXEEXT) + $(make-exe) + +include $(top_srcdir)/../automake/local.am diff --git a/testsuites/sptests/spqreslib/init.c b/testsuites/sptests/spqreslib/init.c new file mode 100644 index 0000000000..20745d7ea2 --- /dev/null +++ b/testsuites/sptests/spqreslib/init.c @@ -0,0 +1,227 @@ +/* Init + * + * This routine is the initialization task for this test program. + * It is a user initialization task and has the responsibility for creating + * and starting the tasks that make up the test. If the time of day + * clock is required for the test, it should also be set to a known + * value by this function. + * + * Input params: + * argument - task argument + * + * Output params: NONE + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#define CONFIGURE_INIT +#include "system.h" + +rtems_task Init( + rtems_task_argument argument +) +{ + rtems_status_code status; + qres_sid_t server_id, server_id2; + time_t approved_budget, exec_time, abs_time, current_budget; + qres_params_t params, params1, params2, params3, params4; + + Priority = 30; + Period = 30; + Execution = 10; + Phase = 0; + + params.P = 1; + params.Q = 1; + + params1 = params2 = params3 = params4 = params; + params1.Q = -1; + params2.Q = SCHEDULER_EDF_PRIO_MSB + 1; + params3.P = -1; + params4.P = SCHEDULER_EDF_PRIO_MSB + 1; + + puts( "\n\n*** TEST QRES LIBRARY ***" ); + + Task_name = rtems_build_name( 'P', 'T', '1', ' ' ); + + status = rtems_task_create( + Task_name, + Priority, + RTEMS_MINIMUM_STACK_SIZE * 4, + RTEMS_DEFAULT_MODES, + RTEMS_DEFAULT_ATTRIBUTES, + &Task_id + ); + directive_failed( status, "rtems_task_create loop" ); + + printf( "Init: Initializing the qres library\n" ); + if ( qres_init() ) + printf( "ERROR: QRES INITIALIZATION FAILED\n" ); + + /* Error checks for Create server and Destroy server */ + printf( "Init: Create server and Destroy server\n" ); + if ( qres_destroy_server( -5 ) != + QOS_E_INVALID_PARAM ) + printf( "ERROR: DESTROY SERVER PASSED UNEXPECTEDLY\n" ); + if ( qres_destroy_server( 5 ) != + QOS_E_INVALID_PARAM ) + printf( "ERROR: DESTROY SERVER PASSED UNEXPECTEDLY\n" ); + if ( qres_destroy_server( 0 ) != QOS_E_NOSERVER ) + printf( "ERROR: DESTROY SERVER PASSED UNEXPECTEDLY\n" ); + if ( qres_create_server( ¶ms1, &server_id ) != + QOS_E_INVALID_PARAM ) + printf( "ERROR: CREATE SERVER PASSED UNEXPECTEDLY\n" ); + if ( qres_create_server( ¶ms2, &server_id ) != + QOS_E_INVALID_PARAM ) + printf( "ERROR: CREATE SERVER PASSED UNEXPECTEDLY\n" ); + if ( qres_create_server( ¶ms3, &server_id ) != + QOS_E_INVALID_PARAM ) + printf( "ERROR: CREATE SERVER PASSED UNEXPECTEDLY\n" ); + if ( qres_create_server( ¶ms4, &server_id ) != + QOS_E_INVALID_PARAM ) + printf( "ERROR: CREATE SERVER PASSED UNEXPECTEDLY\n" ); + if ( qres_create_server( ¶ms, &server_id2 ) ) + printf( "ERROR: CREATE SERVER FAILED\n" ); + if ( qres_create_server( ¶ms, &server_id ) ) + printf( "ERROR: CREATE SERVER FAILED\n" ); + if ( qres_create_server( ¶ms, &server_id ) != + QOS_E_FULL ) + printf( "ERROR: CREATE SERVER PASSED UNEXPECTEDLY\n" ); + + /* Error checks for Attach thread and Detach thread */ + printf( "Init: Attach thread\n" ); + if ( qres_attach_thread( -5, 0, RTEMS_SELF ) != + QOS_E_INVALID_PARAM ) + printf( "ERROR: ATTACH THREAD PASSED UNEXPECTEDLY\n" ); + if ( qres_attach_thread( 5, 0, RTEMS_SELF ) != + QOS_E_INVALID_PARAM ) + printf( "ERROR: ATTACH THREAD PASSED UNEXPECTEDLY\n" ); + if ( qres_attach_thread( server_id, 0, 1234 ) != + QOS_E_INVALID_PARAM ) + printf( "ERROR: ATTACH THREAD PASSED UNEXPECTEDLY\n" ); + if ( qres_attach_thread( server_id, 0, RTEMS_SELF ) ) + printf( "ERROR: ATTACH THREAD FAILED\n" ); + if ( qres_attach_thread( server_id, 0, RTEMS_SELF ) != + QOS_E_FULL ) + printf( "ERROR: ATTACH THREAD AGAIN PASSED UNEXPECTEDLY\n" ); + if ( qres_attach_thread( server_id, 0, Task_id ) != + QOS_E_FULL ) + printf( "ERROR: ATTACH THREAD TO FULL SERVER PASSED UNEXPECTEDLY \n" ); + if ( qres_destroy_server( server_id ) ) + printf( "ERROR: DESTROY SERVER WITH THREAD ATTACHED FAILED\n" ); + if ( qres_attach_thread( server_id, 0, RTEMS_SELF ) != + QOS_E_NOSERVER ) + printf( "ERROR: ATTACH THREAD PASSED UNEXPECTEDLY\n" ); + + printf( "Init: Detach thread\n" ); + if ( qres_detach_thread( -5, 0, RTEMS_SELF ) != + QOS_E_INVALID_PARAM ) + printf( "ERROR: DETACH THREAD PASSED UNEXPECTEDLY\n" ); + if ( qres_detach_thread( 5, 0, RTEMS_SELF ) != + QOS_E_INVALID_PARAM ) + printf( "ERROR: DETACH THREAD PASSED UNEXPECTEDLY\n" ); + if ( qres_detach_thread( server_id2, 0, 1234 ) != + QOS_E_INVALID_PARAM ) + printf( "ERROR: DETACH THREAD PASSED UNEXPECTEDLY \n" ); + if ( qres_detach_thread( server_id, 0, RTEMS_SELF ) != + QOS_E_NOSERVER ) + printf( "ERROR: DETACH THREAD PASSED UNEXPECTEDLY4\n" ); + qres_destroy_server( server_id2 ); + + /* Error checks for Set params and Get params */ + printf( "Init: Set params and Get params\n" ); + if ( qres_set_params( -5, ¶ms ) != + QOS_E_INVALID_PARAM ) + printf( "ERROR: SET PARAMS PASSED UNEXPECTEDLY\n" ); + if ( qres_set_params( 5, ¶ms ) != + QOS_E_INVALID_PARAM ) + printf( "ERROR: SET PARAMS PASSED UNEXPECTEDLY\n" ); + if ( qres_set_params( server_id, ¶ms ) != + QOS_E_NOSERVER ) + printf( "ERROR: SET PARAMS PASSED UNEXPECTEDLY\n" ); + + if ( qres_get_params( -5, ¶ms ) != + QOS_E_INVALID_PARAM ) + printf( "ERROR: GET PARAMS PASSED UNEXPECTEDLY\n" ); + if ( qres_get_params( 5, ¶ms ) != + QOS_E_INVALID_PARAM ) + printf( "ERROR: GET PARAMS PASSED UNEXPECTEDLY\n" ); + if ( qres_get_params( server_id, ¶ms ) != + QOS_E_NOSERVER ) + printf( "ERROR: GET PARAMS PASSED UNEXPECTEDLY\n" ); + + if ( qres_set_params( server_id, ¶ms1 ) != + QOS_E_INVALID_PARAM ) + printf( "ERROR: SET PARAMS PASSED UNEXPECTEDLY\n" ); + if ( qres_set_params( server_id, ¶ms2 ) != + QOS_E_INVALID_PARAM ) + printf( "ERROR: SET PARAMS PASSED UNEXPECTEDLY\n" ); + if ( qres_set_params( server_id, ¶ms3 ) != + QOS_E_INVALID_PARAM ) + printf( "ERROR: SET PARAMS PASSED UNEXPECTEDLY\n" ); + if ( qres_set_params( server_id, ¶ms4 ) != + QOS_E_INVALID_PARAM ) + printf( "ERROR: SET PARAMS PASSED UNEXPECTEDLY\n" ); + + /* Error checks for Get server id */ + printf( "Init: Get server id\n" ); + if ( qres_get_sid( 0, RTEMS_SELF, &server_id ) != + QOS_E_NOSERVER ) + printf( "ERROR: GET SERVER ID PASSED UNEXPECTEDLY\n" ); + + /* Error checks for Get approved budget */ + printf( "Init: Get approved budget\n" ); + if ( qres_get_appr_budget( -5, &approved_budget ) != + QOS_E_INVALID_PARAM ) + printf( "ERROR: GET APPROVED BUDGET PASSED UNEXPECTEDLY\n" ); + if ( qres_get_appr_budget( 5, &approved_budget ) != + QOS_E_INVALID_PARAM ) + printf( "ERROR: GET APPROVED BUDGET PASSED UNEXPECTEDLY\n" ); + if ( qres_get_appr_budget( server_id, &approved_budget ) != + QOS_E_NOSERVER ) + printf( "ERROR: GET APPROVED BUDGET PASSED UNEXPECTEDLY\n" ); + + /* Error checks for Get current budget */ + printf( "Init: Get current budget\n" ); + if ( qres_get_curr_budget( -5, ¤t_budget ) != + QOS_E_INVALID_PARAM ) + printf( "ERROR: GET REMAINING BUDGET PASSED UNEXPECTEDLY\n" ); + if ( qres_get_curr_budget( 5, ¤t_budget ) != + QOS_E_INVALID_PARAM ) + printf( "ERROR: GET REMAINING BUDGET PASSED UNEXPECTEDLY\n" ); + if ( qres_get_curr_budget( server_id, ¤t_budget ) != + QOS_E_NOSERVER ) + printf( "ERROR: GET REMAINING BUDGET PASSED UNEXPECTEDLY\n" ); + + /* Error checks for Get execution time */ + printf( "Init: Get execution time\n" ); + if ( qres_get_exec_time( -5, &exec_time, &abs_time ) != + QOS_E_INVALID_PARAM ) + printf( "ERROR: GET EXECUTION TIME PASSED UNEXPECTEDLY\n" ); + if ( qres_get_exec_time( 5, &exec_time, &abs_time ) != + QOS_E_INVALID_PARAM ) + printf( "ERROR: GET EXECUTION TIME PASSED UNEXPECTEDLY\n" ); + if ( qres_get_exec_time( server_id, &exec_time, &abs_time ) != + QOS_E_NOSERVER ) + printf( "ERROR: GET EXECUTION TIME PASSED UNEXPECTEDLY\n" ); + + /* Restart QRES library */ + printf( "Init: Cleaning up QRES\n" ); + if ( qres_cleanup() ) + printf( "ERROR: QRES CLEANUP FAILED\n" ); + printf( "Init: Initializing the QRES\n" ); + if ( qres_init() ) + printf( "ERROR: QRES INITIALIZATION FAILED\n" ); + + /* Start periodic task */ + printf( "Init: Starting periodic task\n" ); + status = rtems_task_start( Task_id, Task_Periodic, 1 ); + directive_failed( status, "rtems_task_start periodic" ); + + status = rtems_task_delete( RTEMS_SELF ); + directive_failed( status, "rtems_task_delete of RTEMS_SELF" ); +} diff --git a/testsuites/sptests/spqreslib/spqreslib.doc b/testsuites/sptests/spqreslib/spqreslib.doc new file mode 100644 index 0000000000..f590216547 --- /dev/null +++ b/testsuites/sptests/spqreslib/spqreslib.doc @@ -0,0 +1,22 @@ +# +# $Id$ +# +# COPYRIGHT (c) 1989-1999. +# On-Line Applications Research Corporation (OAR). +# +# The license and distribution terms for this file may be +# found in the file LICENSE in this distribution or at +# http://www.rtems.com/license/LICENSE. +# + + +This file describes the directives and concepts tested by this test set. + +test set name: spqreslib + +directives: + + +concepts: + + a. Verifies QRES library functionality. diff --git a/testsuites/sptests/spqreslib/spqreslib.scn b/testsuites/sptests/spqreslib/spqreslib.scn new file mode 100644 index 0000000000..de79c34fec --- /dev/null +++ b/testsuites/sptests/spqreslib/spqreslib.scn @@ -0,0 +1,30 @@ +*** TEST QRES LIBRARY *** +Init: Initializing the qres library +Init: Create server and Destroy server +Init: Attach thread +Init: Detach thread +Init: Set params and Get params +Init: Get server id +Init: Get approved budget +Init: Get current budget +Init: Get execution time +Init: Cleaning up QRES +Init: Initializing the QRES +Init: Starting periodic task +Periodic task: Create server and Attach thread +Periodic task: ID and Get parameters +Periodic task: Detach thread and Destroy server +Periodic task: Current budget and Execution time +Periodic task: Set parameters +Periodic task: Approved budget +Periodic task: Starting periodic behavior +P1-S ticks:1 +P1-F ticks:11 +P1-S ticks:31 +P1-F ticks:41 +P1-S ticks:61 +P1-F ticks:71 +P1-S ticks:91 +P1-F ticks:101 +P1-S ticks:121 +*** END OF TEST QRES LIBRARY *** diff --git a/testsuites/sptests/spqreslib/system.h b/testsuites/sptests/spqreslib/system.h new file mode 100644 index 0000000000..f99b5f459d --- /dev/null +++ b/testsuites/sptests/spqreslib/system.h @@ -0,0 +1,62 @@ +/* system.h + * + * This include file contains information that is included in every + * function in the test set. + * + * COPYRIGHT (c) 1989-1999. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#include + +/* functions */ + +rtems_task Init( + rtems_task_argument argument +); + +rtems_task Task_Periodic( + rtems_task_argument argument +); + +/* configuration information */ + +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER + +#define CONFIGURE_MICROSECONDS_PER_TICK 100000 + +#define CONFIGURE_MAXIMUM_TASKS 2 +#define CONFIGURE_MAXIMUM_PERIODS 10 + +#define CONFIGURE_INIT_TASK_PRIORITY 100 +#define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES +#define CONFIGURE_RTEMS_INIT_TASKS_TABLE + +#define CONFIGURE_EXTRA_TASK_STACKS (6 * 4 * RTEMS_MINIMUM_STACK_SIZE) + +#define CONFIGURE_SCHEDULER_CBS + +#include + +#include +#include +#include +#include + +/* global variables */ + +rtems_id Task_id; +rtems_name Task_name; +rtems_task_priority Priority; +time_t Period; +time_t Execution; +time_t Phase; + +/* end of include file */ diff --git a/testsuites/sptests/spqreslib/task_periodic.c b/testsuites/sptests/spqreslib/task_periodic.c new file mode 100644 index 0000000000..eb353c5c0c --- /dev/null +++ b/testsuites/sptests/spqreslib/task_periodic.c @@ -0,0 +1,138 @@ +/* Tasks_Periodic + * + * This routine serves as a test task for the CBS scheduler + * implementation. + * + * Input parameters: + * argument - task argument + * + * Output parameters: NONE + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#include "system.h" + +rtems_task Task_Periodic( + rtems_task_argument argument +) +{ + rtems_id rmid; + rtems_status_code status; + + time_t approved_budget, exec_time, abs_time, current_budget; + + int start, stop, now; + + qres_sid_t server_id, tsid; + qres_params_t params, tparams; + + params.P = Period; + params.Q = Execution+1; + + printf( "Periodic task: Create server and Attach thread\n" ); + if ( qres_create_server( ¶ms, &server_id ) ) + printf( "ERROR: CREATE SERVER FAILED\n" ); + if ( qres_attach_thread( server_id, 0, Task_id ) ) + printf( "ERROR: ATTACH THREAD FAILED\n" ); + + printf( "Periodic task: ID and Get parameters\n" ); + if ( qres_get_sid( 0, Task_id, &tsid ) ) + printf( "ERROR: GET SERVER ID FAILED\n" ); + if ( tsid != server_id ) + printf( "ERROR: SERVER ID MISMATCH\n" ); + if ( qres_get_params( server_id, &tparams ) ) + printf( "ERROR: GET PARAMETERS FAILED\n" ); + if ( params.P != tparams.P || + params.Q != tparams.Q ) + printf( "ERROR: PARAMETERS MISMATCH\n" ); + + printf( "Periodic task: Detach thread and Destroy server\n" ); + if ( qres_detach_thread( server_id, 0, Task_id ) ) + printf( "ERROR: DETACH THREAD FAILED\n" ); + if ( qres_destroy_server( server_id ) ) + printf( "ERROR: DESTROY SERVER FAILED\n" ); + if ( qres_create_server( ¶ms, &server_id ) ) + printf( "ERROR: CREATE SERVER FAILED\n" ); + + printf( "Periodic task: Current budget and Execution time\n" ); + if ( qres_get_curr_budget( server_id, ¤t_budget ) ) + printf( "ERROR: GET REMAINING BUDGET FAILED\n" ); + if ( current_budget != params.Q ) + printf( "ERROR: REMAINING BUDGET MISMATCH\n" ); + if ( qres_get_exec_time( server_id, &exec_time, &abs_time ) ) + printf( "ERROR: GET EXECUTION TIME FAILED\n" ); + + printf( "Periodic task: Set parameters\n" ); + if ( qres_attach_thread( server_id, 0, Task_id ) ) + printf( "ERROR: ATTACH THREAD FAILED\n" ); + params.P = Period * 2; + params.Q = Execution * 2 +1; + if ( qres_set_params( server_id, ¶ms ) ) + printf( "ERROR: SET PARAMS FAILED\n" ); + if ( qres_get_params( server_id, &tparams ) ) + printf( "ERROR: GET PARAMS FAILED\n" ); + if ( params.P != tparams.P || + params.Q != tparams.Q ) + printf( "ERROR: PARAMS MISMATCH\n" ); + params.P = Period; + params.Q = Execution+1; + if ( qres_set_params( server_id, ¶ms ) ) + printf( "ERROR: SET PARAMS FAILED\n" ); + if ( qres_get_appr_budget( server_id, &approved_budget ) ) + printf( "ERROR: GET APPROVED BUDGET FAILED\n" ); + + printf( "Periodic task: Approved budget\n" ); + if ( approved_budget != params.Q ) + printf( "ERROR: APPROVED BUDGET MISMATCH\n" ); + + status = rtems_rate_monotonic_create( argument, &rmid ); + directive_failed( status, "rtems_rate_monotonic_create" ); + + /* Starting periodic behavior of the task */ + printf( "Periodic task: Starting periodic behavior\n" ); + status = rtems_task_wake_after( 1 + Phase ); + directive_failed( status, "rtems_task_wake_after" ); + + while ( FOREVER ) { + if ( rtems_rate_monotonic_period(rmid, Period) == RTEMS_TIMEOUT ) + printf( "P%" PRIdPTR " - Deadline miss\n", argument ); + + rtems_clock_get( RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &start ); + printf( "P%" PRIdPTR "-S ticks:%d\n", argument, start ); + if ( start > 4*Period+Phase ) break; /* stop */ + /* active computing */ + while(FOREVER) { + rtems_clock_get( RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &now ); + if ( now >= start + Execution ) break; + + if ( qres_get_exec_time( server_id, &exec_time, &abs_time ) ) + printf( "ERROR: GET EXECUTION TIME FAILED\n" ); + if ( qres_get_curr_budget( server_id, ¤t_budget) ) + printf( "ERROR: GET CURRENT BUDGET FAILED\n" ); + if ( (current_budget + exec_time) > (Execution + 1) ) { + printf( "ERROR: CURRENT BUDGET AND EXECUTION TIME MISMATCH\n" ); + rtems_test_exit( 0 ); + } + } + rtems_clock_get( RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &stop ); + printf( "P%" PRIdPTR "-F ticks:%d\n", argument, stop ); + } + + /* delete period and SELF */ + status = rtems_rate_monotonic_delete( rmid ); + if ( status != RTEMS_SUCCESSFUL ) { + printf("rtems_rate_monotonic_delete failed with status of %d.\n", status); + rtems_test_exit( 0 ); + } + if ( qres_cleanup() ) + printf( "ERROR: QRES CLEANUP\n" ); + + fflush(stdout); + puts( "*** END OF TEST QRES LIBRARY ***" ); + rtems_test_exit( 0 ); +} -- cgit v1.2.3