[rtems commit] PR1908: QoS library for CBS scheduler

gedare at rtems.org gedare at rtems.org
Mon Apr 16 03:09:45 UTC 2012


Module:    rtems
Branch:    master
Commit:    1c2b94a61c3054fbcebb24b3bb49c7649be020b0
Changeset: http://git.rtems.org/rtems/commit/?id=1c2b94a61c3054fbcebb24b3bb49c7649be020b0

Author:    Petr Benes <petben at petben.net>
Date:      Sun Apr 15 23:12:08 2012 -0400

PR1908: QoS library for CBS scheduler

Add the lipqos and sptest.

---

 cpukit/libqos/Makefile.am                    |   12 ++
 cpukit/libqos/qreslib.h                      |   81 +++++++++
 cpukit/libqos/qreslib.inl                    |  214 ++++++++++++++++++++++++
 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 ++++++++++++++++
 9 files changed, 814 insertions(+), 0 deletions(-)

diff --git a/cpukit/libqos/Makefile.am b/cpukit/libqos/Makefile.am
new file mode 100644
index 0000000..3223dcd
--- /dev/null
+++ b/cpukit/libqos/Makefile.am
@@ -0,0 +1,12 @@
+##
+## $Id$
+##
+
+include $(top_srcdir)/automake/multilib.am
+include $(top_srcdir)/automake/compile.am
+
+include_HEADERS = qreslib.h
+include_HEADERS += qreslib.inl
+
+include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/libqos/qreslib.h b/cpukit/libqos/qreslib.h
new file mode 100644
index 0000000..22bbd3e
--- /dev/null
+++ b/cpukit/libqos/qreslib.h
@@ -0,0 +1,81 @@
+/**
+ * @file qreslib.h
+ *
+ *  This include file contains all the constants and structures associated
+ *  with the QoS RES library in RTEMS.
+ *
+ * @note The library is available only together with CBS scheduler.
+ */
+
+/*
+ *  Copyright (C) 2011 Petr Benes.
+ *  Copyright (C) 2011 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$
+ */
+
+#ifndef CONFIGURE_SCHEDULER_CBS
+  #error "qreslib.h available only with CONFIGURE_SCHEDULER_CBS"
+#endif
+
+#ifndef _QRESLIB_H
+#define _QRESLIB_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdint.h>
+#include <rtems/score/schedulercbs.h>
+
+/** Return values. */
+typedef int qos_rv;
+
+/* Return codes. */
+#define QOS_OK                   SCHEDULER_CBS_OK
+#define QOS_E_GENERIC            SCHEDULER_CBS_ERROR_GENERIC
+#define QOS_E_NO_MEMORY          SCHEDULER_CBS_ERROR_NO_MEMORY
+#define QOS_E_INVALID_PARAM      SCHEDULER_CBS_ERROR_INVALID_PARAMETER
+#define QOS_E_UNAUTHORIZED       SCHEDULER_CBS_ERROR_UNAUTHORIZED
+#define QOS_E_UNIMPLEMENTED      SCHEDULER_CBS_ERROR_UNIMPLEMENTED
+#define QOS_E_MISSING_COMPONENT  SCHEDULER_CBS_ERROR_MISSING_COMPONENT
+#define QOS_E_INCONSISTENT_STATE SCHEDULER_CBS_ERROR_INCONSISTENT_STATE
+#define QOS_E_SYSTEM_OVERLOAD    SCHEDULER_CBS_ERROR_SYSTEM_OVERLOAD
+#define QOS_E_INTERNAL_ERROR     SCHEDULER_CBS_ERROR_INTERNAL_ERROR
+#define QOS_E_NOT_FOUND          SCHEDULER_CBS_ERROR_NOT_FOUND
+#define QOS_E_FULL               SCHEDULER_CBS_ERROR_FULL
+#define QOS_E_EMPTY              SCHEDULER_CBS_ERROR_EMPTY
+#define QOS_E_NOSERVER           SCHEDULER_CBS_ERROR_NOSERVER
+
+/** Server id. */
+typedef Scheduler_CBS_Server_id qres_sid_t;
+
+/** Task id. */
+typedef rtems_id tid_t;
+
+/** Time value. */
+typedef time_t qres_time_t;
+
+/** Absolute time value */
+typedef time_t qres_atime_t;
+
+/** Server parameters. */
+typedef struct {
+  /** Relative deadline of the server. */
+  uint32_t P;
+  /** Budget (computation time) of the server. */
+  uint32_t Q;
+} qres_params_t;
+
+#include <qreslib.inl>
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/libqos/qreslib.inl b/cpukit/libqos/qreslib.inl
new file mode 100644
index 0000000..094d1e6
--- /dev/null
+++ b/cpukit/libqos/qreslib.inl
@@ -0,0 +1,214 @@
+/**
+ * @file qreslib.inl
+ *
+ *  This include file contains all the constants and structures associated
+ *  with the QoS RES library.
+ *
+ * @note The library is available only together with CBS scheduler.
+ */
+
+/*
+ *  Copyright (C) 2011 Petr Benes.
+ *  Copyright (C) 2011 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$
+ */
+
+#ifndef _QRESLIB_H
+# error "Never use <qreslib.inl> directly; include <qreslib.h> instead."
+#endif
+
+#include <rtems/score/schedulercbs.h>
+
+/**
+ *  @brief qres init
+ *
+ *  Initializes the QoS RES library.
+ *
+ *  @return status code.
+ */
+RTEMS_INLINE_ROUTINE qos_rv qres_init ( void )
+{
+  return _Scheduler_CBS_Initialize();
+}
+
+/**
+ *  @brief qres cleanup
+ *
+ *  Cleanup resources associated to the QoS RES Library.
+ *
+ *  @return status code.
+ */
+RTEMS_INLINE_ROUTINE qos_rv qres_cleanup ( void )
+{
+  return _Scheduler_CBS_Cleanup();
+}
+
+/**
+ *  @brief qres create server
+ *
+ *  Create a new server with specified parameters.
+ *
+ *  @return status code.
+ */
+RTEMS_INLINE_ROUTINE qos_rv qres_create_server (
+  qres_params_t *params,
+  qres_sid_t    *server_id
+)
+{
+  return _Scheduler_CBS_Create_server(
+             (Scheduler_CBS_Parameters *) params,
+             NULL,
+             server_id
+         );
+}
+
+/**
+ *  @brief qres attach thread
+ *
+ *  Attach a task to an already existing server.
+ *
+ *  @return status code.
+ */
+RTEMS_INLINE_ROUTINE qos_rv qres_attach_thread (
+  qres_sid_t server_id,
+  pid_t      pid,
+  tid_t      task_id
+)
+{
+  return _Scheduler_CBS_Attach_thread( server_id, task_id );
+}
+
+/**
+ *  @brief qres detach thread
+ *
+ *  Detach from the QoS Server.
+ *
+ *  @return status code.
+ */
+RTEMS_INLINE_ROUTINE qos_rv qres_detach_thread (
+  qres_sid_t server_id,
+  pid_t      pid,
+  tid_t      task_id
+)
+{
+  return _Scheduler_CBS_Detach_thread( server_id, task_id );
+}
+
+/**
+ *  @brief qres destroy server
+ *
+ *  Detach all tasks from a server and destroy it.
+ *
+ *  @return status code.
+ */
+RTEMS_INLINE_ROUTINE qos_rv qres_destroy_server (
+  qres_sid_t server_id
+)
+{
+  return _Scheduler_CBS_Destroy_server( server_id );
+}
+
+/**
+ *  @brief qres get server id
+ *
+ *  Get a thread server id, or QOS_E_NOT_FOUND if it is not
+ *  attached to any server.
+ *
+ *  @return status code.
+ */
+RTEMS_INLINE_ROUTINE qos_rv qres_get_sid (
+  pid_t       pid,
+  tid_t       task_id,
+  qres_sid_t *server_id
+)
+{
+  return _Scheduler_CBS_Get_server_id( task_id, server_id );
+}
+
+/**
+ *  @brief qres get params
+ *
+ *  Retrieve QoS scheduling parameters.
+ *
+ *  @return status code.
+ */
+RTEMS_INLINE_ROUTINE qos_rv qres_get_params (
+  qres_sid_t     server_id,
+  qres_params_t *params
+)
+{
+  return _Scheduler_CBS_Get_parameters(
+             server_id,
+             (Scheduler_CBS_Parameters *) params
+         );
+}
+
+/**
+ *  @brief qres set params
+ *
+ *  Change QoS scheduling parameters.
+ *
+ *  @return status code.
+ */
+RTEMS_INLINE_ROUTINE qos_rv qres_set_params (
+  qres_sid_t     server_id,
+  qres_params_t *params
+)
+{
+  return _Scheduler_CBS_Set_parameters(
+             server_id,
+             (Scheduler_CBS_Parameters *) params
+         );
+}
+
+/**
+ *  @brief qres get execution time
+ *
+ *  Retrieve time info relative to the current server.
+ *
+ *  @return status code.
+ */
+RTEMS_INLINE_ROUTINE qos_rv qres_get_exec_time (
+  qres_sid_t    server_id,
+  qres_time_t  *exec_time,
+  qres_atime_t *abs_time
+)
+{
+  return _Scheduler_CBS_Get_execution_time( server_id, exec_time, abs_time );
+}
+
+/**
+ *  @brief qres get current budget
+ *
+ *  Retrieve remaining budget for the current server instance.
+ *
+ *  @return status code.
+ */
+RTEMS_INLINE_ROUTINE qos_rv qres_get_curr_budget (
+  qres_sid_t   server_id,
+  qres_time_t *current_budget
+)
+{
+  return _Scheduler_CBS_Get_remaining_budget( server_id, current_budget );
+}
+
+/**
+ *  @brief qres get approved budget
+ *
+ *  Retrieve the budget that has been approved for the subsequent
+ *  server instances.
+ *
+ *  @return status code.
+ */
+RTEMS_INLINE_ROUTINE qos_rv qres_get_appr_budget (
+  qres_sid_t   server_id,
+  qres_time_t *appr_budget
+)
+{
+  return _Scheduler_CBS_Get_approved_budget( server_id, appr_budget );
+}
diff --git a/testsuites/sptests/spqreslib/Makefile.am b/testsuites/sptests/spqreslib/Makefile.am
new file mode 100644
index 0000000..bd8323f
--- /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 at .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 0000000..20745d7
--- /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( &params1, &server_id ) !=
+       QOS_E_INVALID_PARAM )
+    printf( "ERROR: CREATE SERVER PASSED UNEXPECTEDLY\n" );
+  if ( qres_create_server( &params2, &server_id ) !=
+       QOS_E_INVALID_PARAM )
+    printf( "ERROR: CREATE SERVER PASSED UNEXPECTEDLY\n" );
+  if ( qres_create_server( &params3, &server_id ) !=
+       QOS_E_INVALID_PARAM )
+    printf( "ERROR: CREATE SERVER PASSED UNEXPECTEDLY\n" );
+  if ( qres_create_server( &params4, &server_id ) !=
+       QOS_E_INVALID_PARAM )
+    printf( "ERROR: CREATE SERVER PASSED UNEXPECTEDLY\n" );
+  if ( qres_create_server( &params, &server_id2 ) )
+    printf( "ERROR: CREATE SERVER FAILED\n" );
+  if ( qres_create_server( &params, &server_id ) )
+    printf( "ERROR: CREATE SERVER FAILED\n" );
+  if ( qres_create_server( &params, &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, &params ) !=
+       QOS_E_INVALID_PARAM )
+    printf( "ERROR: SET PARAMS PASSED UNEXPECTEDLY\n" );
+  if ( qres_set_params( 5, &params ) !=
+       QOS_E_INVALID_PARAM )
+    printf( "ERROR: SET PARAMS PASSED UNEXPECTEDLY\n" );
+  if ( qres_set_params( server_id, &params ) !=
+       QOS_E_NOSERVER )
+    printf( "ERROR: SET PARAMS PASSED UNEXPECTEDLY\n" );
+
+  if ( qres_get_params( -5, &params ) !=
+       QOS_E_INVALID_PARAM )
+    printf( "ERROR: GET PARAMS PASSED UNEXPECTEDLY\n" );
+  if ( qres_get_params( 5, &params ) !=
+       QOS_E_INVALID_PARAM )
+    printf( "ERROR: GET PARAMS PASSED UNEXPECTEDLY\n" );
+  if ( qres_get_params( server_id, &params ) !=
+       QOS_E_NOSERVER )
+    printf( "ERROR: GET PARAMS PASSED UNEXPECTEDLY\n" );
+
+  if ( qres_set_params( server_id, &params1 ) !=
+       QOS_E_INVALID_PARAM )
+    printf( "ERROR: SET PARAMS PASSED UNEXPECTEDLY\n" );
+  if ( qres_set_params( server_id, &params2 ) !=
+       QOS_E_INVALID_PARAM )
+    printf( "ERROR: SET PARAMS PASSED UNEXPECTEDLY\n" );
+  if ( qres_set_params( server_id, &params3 ) !=
+       QOS_E_INVALID_PARAM )
+    printf( "ERROR: SET PARAMS PASSED UNEXPECTEDLY\n" );
+  if ( qres_set_params( server_id, &params4 ) !=
+       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, &current_budget ) !=
+       QOS_E_INVALID_PARAM )
+    printf( "ERROR: GET REMAINING BUDGET PASSED UNEXPECTEDLY\n" );
+  if ( qres_get_curr_budget( 5, &current_budget ) !=
+       QOS_E_INVALID_PARAM )
+    printf( "ERROR: GET REMAINING BUDGET PASSED UNEXPECTEDLY\n" );
+  if ( qres_get_curr_budget( server_id, &current_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 0000000..f590216
--- /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 0000000..de79c34
--- /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 0000000..f99b5f4
--- /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 <tmacros.h>
+
+/* 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 <rtems/confdefs.h>
+
+#include <rtems/rtems/clock.h>
+#include <rtems/score/isr.h>
+#include <rtems/rtems/intr.h>
+#include <qreslib.h>
+
+/* 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 0000000..eb353c5
--- /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( &params, &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( &params, &server_id ) )
+    printf( "ERROR: CREATE SERVER FAILED\n" );
+
+  printf( "Periodic task: Current budget and Execution time\n" );
+  if ( qres_get_curr_budget( server_id, &current_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, &params ) )
+    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, &params ) )
+    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, &current_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 );
+}




More information about the vc mailing list