From: Pavel Pisa Date: Wed, 26 Sep 2012 07:11:25 +0000 (+0200) Subject: Added test application to check priority inheritance behavior. X-Git-Url: http://rtime.felk.cvut.cz/gitweb/rtems-devel.git/commitdiff_plain/32b279bb027ab22e599d6a9cedf11d0609adccae Added test application to check priority inheritance behavior. Signed-off-by: Pavel Pisa --- diff --git a/rtems-tests/.gitignore b/rtems-tests/.gitignore new file mode 100644 index 0000000..189b17f --- /dev/null +++ b/rtems-tests/.gitignore @@ -0,0 +1,2 @@ +_build +_compiled diff --git a/rtems-tests/Makefile b/rtems-tests/Makefile new file mode 120000 index 0000000..30da041 --- /dev/null +++ b/rtems-tests/Makefile @@ -0,0 +1 @@ +../rtems-omk-template/Makefile \ No newline at end of file diff --git a/rtems-tests/Makefile.omk b/rtems-tests/Makefile.omk new file mode 100644 index 0000000..db47999 --- /dev/null +++ b/rtems-tests/Makefile.omk @@ -0,0 +1,2 @@ +SUBDIRS = prioinh_check libbar + diff --git a/rtems-tests/Makefile.rules b/rtems-tests/Makefile.rules new file mode 120000 index 0000000..0521cdd --- /dev/null +++ b/rtems-tests/Makefile.rules @@ -0,0 +1 @@ +../rtems-omk-template/Makefile.rules \ No newline at end of file diff --git a/rtems-tests/config b/rtems-tests/config new file mode 120000 index 0000000..438f837 --- /dev/null +++ b/rtems-tests/config @@ -0,0 +1 @@ +../rtems-omk-template/config \ No newline at end of file diff --git a/rtems-tests/libbar b/rtems-tests/libbar new file mode 120000 index 0000000..e2e4eb9 --- /dev/null +++ b/rtems-tests/libbar @@ -0,0 +1 @@ +../rtems-omk-template/libbar \ No newline at end of file diff --git a/rtems-tests/prioinh_check/Makefile b/rtems-tests/prioinh_check/Makefile new file mode 100644 index 0000000..76b56fd --- /dev/null +++ b/rtems-tests/prioinh_check/Makefile @@ -0,0 +1,14 @@ +# Generic directory or leaf node makefile for OCERA make framework + +ifndef MAKERULES_DIR +MAKERULES_DIR := $(shell ( old_pwd="" ; while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" = `pwd` ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) ) +endif + +ifeq ($(MAKERULES_DIR),) +all : default +.DEFAULT:: + @echo -e "\nThe Makefile.rules has not been found in this or parent directory\n" +else +include $(MAKERULES_DIR)/Makefile.rules +endif + diff --git a/rtems-tests/prioinh_check/Makefile.omk b/rtems-tests/prioinh_check/Makefile.omk new file mode 100644 index 0000000..3f217da --- /dev/null +++ b/rtems-tests/prioinh_check/Makefile.omk @@ -0,0 +1,15 @@ +default_CONFIG += CONFIG_OC_BUILD4RTEMS=y +default_CONFIG += CONFIG_OC_GDBSTUB=n + +bin_PROGRAMS = prioinh_check + +#lib_LIBRARIES = + +#include_HEADERS = + +prioinh_check_SOURCES += init.c prio_inherit_test.c + +#appfoo_EMBEDTARFILES = rootfs + +#lib_LOADLIBES += + diff --git a/rtems-tests/prioinh_check/app_def.h b/rtems-tests/prioinh_check/app_def.h new file mode 100644 index 0000000..2d5b015 --- /dev/null +++ b/rtems-tests/prioinh_check/app_def.h @@ -0,0 +1,42 @@ +#ifndef _APP_DEF_H +#define _APP_DEF_H + +#ifndef COND_EXTERN + #ifdef CONFIGURE_INIT + #define COND_EXTERN + #else + #define COND_EXTERN extern + #endif +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +COND_EXTERN rtems_id Task_1_id; /* Task 1 id */ +COND_EXTERN rtems_name Task_1_name; /* Task 1 name */ + +rtems_task Task_1( + rtems_task_argument argument +); + +void bad_rtems_status(rtems_status_code status, int fail_level, const char *text); + +static inline +void check_rtems_status(rtems_status_code status, int fail_level, const char *text) +{ + if(!rtems_is_status_successful(status)) + bad_rtems_status(status, fail_level, text); +} + +#define SHELL_TASK_PRIORITY 30 +#define TASK_HI_PRIORITY 40 +#define TASK_MID_PRIORITY 45 +#define TASK_1_PRIORITY 50 +#define TASK_LO_PRIORITY 60 + +#ifdef __cplusplus +} +#endif + +#endif /*_APP_DEF_H*/ diff --git a/rtems-tests/prioinh_check/init.c b/rtems-tests/prioinh_check/init.c new file mode 100644 index 0000000..7968847 --- /dev/null +++ b/rtems-tests/prioinh_check/init.c @@ -0,0 +1,113 @@ +/* Init + * + * This routine is the initialization task for this test program. + * It is called from init_exec 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 parameters: NONE + * + * Output parameters: NONE + * + * 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: init.c,v 1.12.4.1 2003/09/04 18:46:30 joel Exp $ + */ + +#define CONFIGURE_INIT +#include "system.h" +#include "app_def.h" +#include +#include +#include +#include +#include + +#define VER_CODE(major,minor,patch) (major*0x10000+minor*0x100+patch) + +#define BUILD_VERSION_STRING(major,minor,patch) \ + __XSTRING(major) "." __XSTRING(minor) "." __XSTRING(patch) + +#define RTEMS_VER_CODE VER_CODE(__RTEMS_MAJOR__ ,__RTEMS_MINOR__ ,__RTEMS_REVISION__) + +#if RTEMS_VER_CODE < VER_CODE(4,7,99) + #define rtems_shell_add_cmd shell_add_cmd + #define rtems_shell_init(m_task_name,m_task_stacksize,m_task_priority,m_devname,m_forever,m_wait,m_login_check) \ + shell_init(m_task_name,m_task_stacksize,m_task_priority,m_devname,B19200 | CS8,m_forever) +#elif RTEMS_VER_CODE < VER_CODE(4,9,99) + #define rtems_shell_init(m_task_name,m_task_stacksize,m_task_priority,m_devname,m_forever,m_wait,m_login_check) \ + rtems_shell_init(m_task_name,m_task_stacksize,m_task_priority,m_devname,m_forever,m_wait) +#endif + +void +bad_rtems_status(rtems_status_code status, int fail_level, const char *text) +{ + printf("ERROR: %s status %s\n", text, rtems_status_text(status)); + status = rtems_task_delete( RTEMS_SELF ); +} + +int testcmd_forshell(int argc, char **argv) +{ + int i; + printf("Command %s called\n",argv[0]); + for(i=1;i +#include +#include +#include + +#include "app_def.h" + +rtems_id shared_with_hi_sem; +rtems_id shared_with_lo_sem; + +rtems_id release_hi_sem; +rtems_id release_mid_sem; +rtems_id release_lo_sem; + +rtems_id hi_task_id; +rtems_id mid_task_id; +rtems_id lo_task_id; + + +void block_delay(int delay) +{ + volatile int l; + + while(delay--) { + l = 100000; + while(l--); + } +} + + +rtems_task hi_task( + rtems_task_argument argument +) +{ + rtems_status_code status; + + printf("THI created\n"); + while(1){ + status=rtems_semaphore_obtain(release_hi_sem,RTEMS_WAIT,RTEMS_NO_TIMEOUT); + check_rtems_status(status, 0, "rtems_semaphore_obtain RHI from THI"); + printf("THI released (RHI)\n"); + + status=rtems_semaphore_obtain(shared_with_hi_sem,RTEMS_WAIT,RTEMS_NO_TIMEOUT); + check_rtems_status(status, 0, "rtems_semaphore_obtain SHI from THI"); + printf("THI obtained SHI\n"); + + block_delay(100); + + printf("THI going to release SHI\n"); + status=rtems_semaphore_release(shared_with_hi_sem); + check_rtems_status(status, 0, "rtems_semaphore_release SHI from THI"); + printf("THI released SHI\n"); + } +} + +rtems_task mid_task( + rtems_task_argument argument +) +{ + rtems_status_code status; + + printf("TMID created\n"); + while(1){ + status=rtems_semaphore_obtain(release_mid_sem,RTEMS_WAIT,RTEMS_NO_TIMEOUT); + check_rtems_status(status, 0, "rtems_semaphore_obtain RMID from TMID"); + printf("MID released (RMID)\n"); + + block_delay(100); + + printf("MID going to sleep\n"); + } +} + +rtems_task lo_task( + rtems_task_argument argument +) +{ + rtems_status_code status; + + printf("LO created\n"); + while(1){ + status=rtems_semaphore_obtain(release_lo_sem,RTEMS_WAIT,RTEMS_NO_TIMEOUT); + check_rtems_status(status, 0, "rtems_semaphore_obtain RLO from TLO"); + printf("TLO released (RLO)\n"); + + status=rtems_semaphore_obtain(shared_with_lo_sem,RTEMS_WAIT,RTEMS_NO_TIMEOUT); + check_rtems_status(status, 0, "rtems_semaphore_obtain SLO from TLO"); + printf("TLO obtained SLO\n"); + + block_delay(100); + + printf("TLO going to release SLO\n"); + status=rtems_semaphore_release(shared_with_lo_sem); + check_rtems_status(status, 0, "rtems_semaphore_release SLO from TLO"); + printf("TLO released SLO\n"); + } +} + + +rtems_task Task_1( + rtems_task_argument argument +) +{ + rtems_status_code status; + rtems_task_priority prio; + + status = rtems_task_wake_after( TICKS_PER_SECOND ); + check_rtems_status( status, 0, "rtems_task_wake_after" ); + + printf("*** Starting up Task_1 ***\n"); + + + status=rtems_semaphore_create(rtems_build_name('S','H','I',' '), + 1, + RTEMS_PRIORITY|RTEMS_BINARY_SEMAPHORE|RTEMS_INHERIT_PRIORITY|RTEMS_LOCAL, + 0, + &shared_with_hi_sem); + check_rtems_status( status, 0, "rtems_semaphore_create SHI" ); + + status=rtems_semaphore_create(rtems_build_name('S','L','O',' '), + 1, + RTEMS_PRIORITY|RTEMS_BINARY_SEMAPHORE|RTEMS_INHERIT_PRIORITY|RTEMS_LOCAL, + 0, + &shared_with_lo_sem); + check_rtems_status( status, 0, "rtems_semaphore_create SLO" ); + + status=rtems_semaphore_create(rtems_build_name('R','H','I',' '), + 0, + RTEMS_PRIORITY|RTEMS_SIMPLE_BINARY_SEMAPHORE|RTEMS_LOCAL, + 0, + &release_hi_sem); + check_rtems_status( status, 0, "rtems_semaphore_create RHI" ); + + status=rtems_semaphore_create(rtems_build_name('R','M','I','D'), + 0, + RTEMS_PRIORITY|RTEMS_SIMPLE_BINARY_SEMAPHORE|RTEMS_LOCAL, + 0, + &release_mid_sem); + check_rtems_status( status, 0, "rtems_semaphore_create RMID" ); + + status=rtems_semaphore_create(rtems_build_name('R','L','O',' '), + 0, + RTEMS_PRIORITY|RTEMS_SIMPLE_BINARY_SEMAPHORE|RTEMS_LOCAL, + 0, + &release_lo_sem); + check_rtems_status( status, 0, "rtems_semaphore_create RLO" ); + + status = rtems_task_create(rtems_build_name('T','H','I',' '), + TASK_HI_PRIORITY, + RTEMS_MINIMUM_STACK_SIZE+0x1000, + RTEMS_DEFAULT_MODES /*& ~(RTEMS_TIMESLICE_MASK) | RTEMS_TIMESLICE*/, + RTEMS_DEFAULT_ATTRIBUTES, + &hi_task_id + ); + check_rtems_status(status, 0, "rtems_task_create THI"); + + status = rtems_task_create(rtems_build_name('T','M','I','D'), + TASK_MID_PRIORITY, + RTEMS_MINIMUM_STACK_SIZE+0x1000, + RTEMS_DEFAULT_MODES /*& ~(RTEMS_TIMESLICE_MASK) | RTEMS_TIMESLICE*/, + RTEMS_DEFAULT_ATTRIBUTES, + &mid_task_id + ); + check_rtems_status(status, 0, "rtems_task_create MID"); + + status = rtems_task_create(rtems_build_name('T','L','O',' '), + TASK_LO_PRIORITY, + RTEMS_MINIMUM_STACK_SIZE+0x1000, + RTEMS_DEFAULT_MODES /*& ~(RTEMS_TIMESLICE_MASK) | RTEMS_TIMESLICE*/, + RTEMS_DEFAULT_ATTRIBUTES, + &lo_task_id + ); + check_rtems_status(status, 0, "rtems_task_create LO"); + + status = rtems_task_start( hi_task_id, hi_task, 0 ); + check_rtems_status(status, 0, "rtems_task_start THI\n"); + + status = rtems_task_start( mid_task_id, mid_task, 0 ); + check_rtems_status(status, 0, "rtems_task_start MID\n"); + + status = rtems_task_start( lo_task_id, lo_task, 0 ); + check_rtems_status(status, 0, "rtems_task_start LO\n"); + + + while(1){ + + + status=rtems_semaphore_obtain(shared_with_lo_sem,RTEMS_WAIT,RTEMS_NO_TIMEOUT); + check_rtems_status(status, 0, "rtems_semaphore_obtain SLO"); + printf("1 obtained SLO\n"); + + printf("1 going to release RLO\n"); + status=rtems_semaphore_release(release_lo_sem); + check_rtems_status(status, 0, "rtems_semaphore_release RLO"); + + status=rtems_semaphore_obtain(shared_with_hi_sem,RTEMS_WAIT,RTEMS_NO_TIMEOUT); + check_rtems_status(status, 0, "rtems_semaphore_obtain SHI"); + printf("1 obtained SHI\n"); + + printf("1 going to release RHI\n"); + status=rtems_semaphore_release(release_hi_sem); + check_rtems_status(status, 0, "rtems_semaphore_release RHI"); + + status = rtems_task_wake_after( TICKS_PER_SECOND ); + check_rtems_status( status, 0, "rtems_task_wake_after" ); + + status = rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &prio); + check_rtems_status( status, 0, "rtems_task_set_priority"); + printf("1 priority is %d\n", (int)prio); + + printf("1 going to release RMID\n"); + status=rtems_semaphore_release(release_mid_sem); + check_rtems_status(status, 0, "rtems_semaphore_release RMID"); + + block_delay(100); + + printf("1 going to release SHI\n"); + status=rtems_semaphore_release(shared_with_hi_sem); + check_rtems_status(status, 0, "rtems_semaphore_release SHI"); + + status = rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &prio); + check_rtems_status( status, 0, "rtems_task_set_priority"); + printf("1 priority is %d\n", (int)prio); + + block_delay(100); + + printf("1 going to release SLO\n"); + status=rtems_semaphore_release(shared_with_lo_sem); + check_rtems_status(status, 0, "rtems_semaphore_release SLO"); + printf("1 released both SHI and SLO\n"); + + status = rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &prio); + check_rtems_status( status, 0, "rtems_task_set_priority"); + printf("1 priority is %d\n", (int)prio); + + block_delay(100); + + printf("1 going to sleep\n"); + status = rtems_task_wake_after( TICKS_PER_SECOND ); + check_rtems_status( status, 0, "rtems_task_wake_after" ); + } +} diff --git a/rtems-tests/prioinh_check/system.h b/rtems-tests/prioinh_check/system.h new file mode 100644 index 0000000..7279551 --- /dev/null +++ b/rtems-tests/prioinh_check/system.h @@ -0,0 +1,66 @@ +/* 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: system.h,v 1.13.6.1 2003/09/04 18:46:30 joel Exp $ + */ + +#include + +/* functions */ + +rtems_task Init( + rtems_task_argument argument +); + +/* configuration information */ + +#include /* for device driver prototypes */ + +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK + +#define TICKS_PER_SECOND 1000 + +#define CONFIGURE_MAXIMUM_TIMERS 32 +#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 32 +#define CONFIGURE_MAXIMUM_SEMAPHORES 32 +#define CONFIGURE_MAXIMUM_TASKS 32 +#define CONFIGURE_MAXIMUM_PERIODS 4 +#define CONFIGURE_MAXIMUM_USER_EXTENSIONS 2 +#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32 +#define CONFIGURE_MAXIMUM_DRIVERS (CONFIGURE_NUMBER_OF_DRIVERS+10) + +#ifdef RTEMS_POSIX_API +#define CONFIGURE_MAXIMUM_POSIX_THREADS 32 +#define CONFIGURE_MAXIMUM_POSIX_MUTEXES 20 +#define CONFIGURE_MAXIMUM_POSIX_SEMAPHORES 10 +#endif /*RTEMS_POSIX_API*/ + +#define CONFIGURE_RTEMS_INIT_TASKS_TABLE + + +#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM +/*#define CONFIGURE_USE_MINIIMFS_AS_BASE_FILESYSTEM*/ + +#define CONFIGURE_MICROSECONDS_PER_TICK 1000 + +#define CONFIGURE_INIT_TASK_STACK_SIZE (10*1024) +#define CONFIGURE_INIT_TASK_PRIORITY 120 +#define CONFIGURE_INIT_TASK_INITIAL_MODES (RTEMS_PREEMPT | \ + RTEMS_NO_TIMESLICE | \ + RTEMS_NO_ASR | \ + RTEMS_INTERRUPT_LEVEL(0)) + +#include + +/* end of include file */