[PATCH 01/11] sptests: back-port spsem01, spsem02, and spsem03 from 4.11

Gedare Bloom gedare at rtems.org
Fri Mar 23 16:15:37 UTC 2018


---
 testsuites/sptests/Makefile.am         |   2 +
 testsuites/sptests/configure.ac        |   3 +
 testsuites/sptests/spsem01/Makefile.am |  21 ++++
 testsuites/sptests/spsem01/init.c      | 156 +++++++++++++++++++++++++++
 testsuites/sptests/spsem01/spsem01.doc |  19 ++++
 testsuites/sptests/spsem01/spsem01.scn |  15 +++
 testsuites/sptests/spsem02/Makefile.am |  21 ++++
 testsuites/sptests/spsem02/init.c      | 192 +++++++++++++++++++++++++++++++++
 testsuites/sptests/spsem02/spsem02.doc |  23 ++++
 testsuites/sptests/spsem02/spsem02.scn |  21 ++++
 testsuites/sptests/spsem03/Makefile.am |  19 ++++
 testsuites/sptests/spsem03/init.c      | 155 ++++++++++++++++++++++++++
 testsuites/sptests/spsem03/spsem03.doc |  12 +++
 testsuites/sptests/spsem03/spsem03.scn |   2 +
 14 files changed, 661 insertions(+)
 create mode 100644 testsuites/sptests/spsem01/Makefile.am
 create mode 100644 testsuites/sptests/spsem01/init.c
 create mode 100644 testsuites/sptests/spsem01/spsem01.doc
 create mode 100644 testsuites/sptests/spsem01/spsem01.scn
 create mode 100644 testsuites/sptests/spsem02/Makefile.am
 create mode 100644 testsuites/sptests/spsem02/init.c
 create mode 100644 testsuites/sptests/spsem02/spsem02.doc
 create mode 100644 testsuites/sptests/spsem02/spsem02.scn
 create mode 100644 testsuites/sptests/spsem03/Makefile.am
 create mode 100644 testsuites/sptests/spsem03/init.c
 create mode 100644 testsuites/sptests/spsem03/spsem03.doc
 create mode 100644 testsuites/sptests/spsem03/spsem03.scn

diff --git a/testsuites/sptests/Makefile.am b/testsuites/sptests/Makefile.am
index d17ffed..2424716 100644
--- a/testsuites/sptests/Makefile.am
+++ b/testsuites/sptests/Makefile.am
@@ -23,6 +23,8 @@ _SUBDIRS = \
     spintrcritical09 spintrcritical10 spintrcritical11 spintrcritical12 \
     spintrcritical13 spintrcritical14 spintrcritical15 spintrcritical16 \
     spintrcritical17
+
+_SUBDIRS += spsem01 spsem02 spsem03
  
 DIST_SUBDIRS = $(_SUBDIRS) spfatal_support spintrcritical_support
 EXTRA_DIST = spfatal_support/init.c spfatal_support/system.h
diff --git a/testsuites/sptests/configure.ac b/testsuites/sptests/configure.ac
index db964ad..8ef651d 100644
--- a/testsuites/sptests/configure.ac
+++ b/testsuites/sptests/configure.ac
@@ -131,6 +131,9 @@ spintrcritical17/Makefile
 spnotepad01/Makefile
 spobjgetnext/Makefile
 spprintk/Makefile
+spsem01/Makefile
+spsem02/Makefile
+spsem03/Makefile
 spsize/Makefile
 spstkalloc/Makefile
 spthreadq01/Makefile
diff --git a/testsuites/sptests/spsem01/Makefile.am b/testsuites/sptests/spsem01/Makefile.am
new file mode 100644
index 0000000..a957b05
--- /dev/null
+++ b/testsuites/sptests/spsem01/Makefile.am
@@ -0,0 +1,21 @@
+
+rtems_tests_PROGRAMS = spsem01
+spsem01_SOURCES = init.c
+
+dist_rtems_tests_DATA = spsem01.scn
+dist_rtems_tests_DATA += spsem01.doc
+
+include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP at .cfg
+include $(top_srcdir)/../automake/compile.am
+include $(top_srcdir)/../automake/leaf.am
+
+AM_CPPFLAGS += -I$(top_srcdir)/../support/include
+
+LINK_OBJS = $(spsem01_OBJECTS)
+LINK_LIBS = $(spsem01_LDLIBS)
+
+spsem01$(EXEEXT): $(spsem01_OBJECTS) $(spsem01_DEPENDENCIES)
+	@rm -f spsem01$(EXEEXT)
+	$(make-exe)
+
+include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/sptests/spsem01/init.c b/testsuites/sptests/spsem01/init.c
new file mode 100644
index 0000000..abc7ca7
--- /dev/null
+++ b/testsuites/sptests/spsem01/init.c
@@ -0,0 +1,156 @@
+/*
+ * Copyright (c) 2013 Gedare Bloom.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#include <rtems.h>
+
+#include <stdio.h>
+#include "tmacros.h"
+
+/* configuration information */
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+#define CONFIGURE_MAXIMUM_TASKS 3
+#define CONFIGURE_MAXIMUM_SEMAPHORES 2
+#define CONFIGURE_INIT
+#include <rtems/confdefs.h>
+
+const char rtems_test_name[] = "SPSEM 1";
+
+rtems_task Task01(rtems_task_argument ignored);
+rtems_task Task02(rtems_task_argument ignored);
+rtems_task Init(rtems_task_argument ignored);
+
+static int getprio(void)
+{
+  rtems_status_code status;
+  rtems_task_priority pri;
+
+  status = rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &pri);
+  directive_failed( status, "rtems_task_set_priority");
+  return (int)pri;
+}
+
+rtems_id   Task_id[2];
+rtems_name Task_name[2];
+
+rtems_id   sem_id[2];
+rtems_name sem_name[2];
+
+rtems_task Init(rtems_task_argument ignored)
+{
+  rtems_status_code status;
+  rtems_attribute sem_attr;
+
+  printf("*** BEGIN OF TEST SPSEM01 ***\n");
+
+  sem_attr = RTEMS_INHERIT_PRIORITY | RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY;
+
+  sem_name[0] = rtems_build_name( 'S','0',' ',' ');
+  status = rtems_semaphore_create(
+    sem_name[0],
+    1,
+    sem_attr,
+    0,
+    &sem_id[0]
+  );
+  directive_failed( status, "rtems_semaphore_create of S0");
+  printf("init: S0 created\n");
+
+  sem_name[1] = rtems_build_name( 'S','1',' ',' ');
+  status = rtems_semaphore_create(
+    sem_name[1],
+    1,
+    sem_attr,
+    0,
+    &sem_id[1]
+  );
+  directive_failed( status, "rtems_semaphore_create of S1");
+  printf("init: S1 created\n");
+
+  Task_name[0] = rtems_build_name( 'T','A','0','1');
+  status = rtems_task_create(
+    Task_name[0],
+    36,
+    RTEMS_MINIMUM_STACK_SIZE,
+    RTEMS_DEFAULT_MODES,
+    RTEMS_DEFAULT_ATTRIBUTES,
+    &Task_id[0]
+  );
+  directive_failed( status, "rtems_task_create of TA01");
+  printf("init: TA01 created with priority 36\n");
+
+  Task_name[1] = rtems_build_name( 'T','A','0','2');
+  status = rtems_task_create(
+    Task_name[1],
+    34,
+    RTEMS_MINIMUM_STACK_SIZE,
+    RTEMS_DEFAULT_MODES,
+    RTEMS_DEFAULT_ATTRIBUTES,
+    &Task_id[1]
+  );
+  directive_failed( status , "rtems_task_create of TA02\n");
+  printf("init: TA02 created with priority 34\n");
+
+  status = rtems_task_start( Task_id[0], Task01, 0);
+  directive_failed( status, "rtems_task_start of TA01");
+
+  status = rtems_task_delete( RTEMS_SELF);
+  directive_failed( status, "rtems_task_delete of INIT");
+}
+
+/* Task01 starts with priority 36 */
+rtems_task Task01(rtems_task_argument ignored)
+{
+  rtems_status_code status;
+  printf("TA01: started with priority %d\n", getprio());
+
+  status = rtems_semaphore_obtain( sem_id[0], RTEMS_WAIT, 0 );
+  directive_failed( status, "rtems_semaphore_obtain of S0\n");
+  printf("TA01: priority %d, holding S0\n", getprio());
+
+  status = rtems_semaphore_obtain( sem_id[1], RTEMS_WAIT, 0 );
+  directive_failed( status, "rtems_semaphore_obtain of S1");
+  printf("TA01: priority %d, holding S0, S1\n", getprio());
+
+  /* Start Task 2 (TA02) with priority 34. It will run immediately. */
+  status = rtems_task_start( Task_id[1], Task02, 0);
+  directive_failed( status, "rtems_task_start of TA02\n");
+
+  status = rtems_semaphore_release(sem_id[1]);
+  directive_failed( status, "rtems_semaphore_release of S1\n");
+  printf("TA01: priority %d, holding S0\n", getprio());
+
+  status = rtems_semaphore_release(sem_id[0]);
+  directive_failed( status, "rtems_semaphore_release of S0\n");
+  printf("TA01: priority %d\n", getprio());
+
+  printf("TA01: exiting\n");
+  printf("*** END OF TEST SPSEM01 ***\n");
+
+  rtems_test_exit(0);
+}
+
+/* TA02 starts at Task02 with priority 34 */
+rtems_task Task02(rtems_task_argument ignored)
+{
+  rtems_status_code status;
+
+  printf("TA02: started with priority %d\n", getprio());
+
+  /* Obtain S1, which should be held by TA01 by now */
+  status = rtems_semaphore_obtain( sem_id[1], RTEMS_WAIT, 0 );
+  directive_failed( status, " rtems_semaphore_obtain S1");
+  printf("TA02: priority %d, holding S1\n", getprio());
+
+  printf("TA02: suspending\n");
+  status = rtems_task_suspend( RTEMS_SELF);
+  directive_failed( status, "rtems_task_suspend TA02");
+}
+
diff --git a/testsuites/sptests/spsem01/spsem01.doc b/testsuites/sptests/spsem01/spsem01.doc
new file mode 100644
index 0000000..8a09526
--- /dev/null
+++ b/testsuites/sptests/spsem01/spsem01.doc
@@ -0,0 +1,19 @@
+This test exposes a potential priority inversion when priority inheritance is
+used and multiple locks are acquired by a low priority task. The scenario
+consists of 2 tasks of different priority and 2 semaphore/mutexes using
+priority inheritance. The scenario is:
+
+Task 1 has priority 36.  Task 2 has priority 34.
+
+1. Task 1 obtains semaphore S1.
+2. Task 1 obtains semaphore S2
+3. Task 2 preempts Task 1.
+4. Task 2 blocks on S2.  Task 1 inherits priority 34.
+5. Task 1 resumes. Task 1 releases S2. Task 1 continues to run at priority 34.
+6. Task 1 releases S1. Task 1 changes priority back to 36.
+7. Task 2 now preempts Task 1 and begins operating again.
+
+During steps 5-6 Task 1 executes when Task 2 should be able to execute.
+
+Stepping down the priority of Task 1 when it releases S2 back to its original
+priority when it obtained S2 fixes the priority inversion.
diff --git a/testsuites/sptests/spsem01/spsem01.scn b/testsuites/sptests/spsem01/spsem01.scn
new file mode 100644
index 0000000..35e6b94
--- /dev/null
+++ b/testsuites/sptests/spsem01/spsem01.scn
@@ -0,0 +1,15 @@
+*** BEGIN OF TEST SPSEM 1 ***
+init: S0 created
+init: S1 created
+init: TA01 created with priority 36
+init: TA02 created with priority 34
+TA01: started with priority 36
+TA01: priority 36, holding S0
+TA01: priority 36, holding S0, S1
+TA02: started with priority 34
+TA01: priority 34, holding S0
+TA02: priority 34, holding S1
+TA02: suspending
+TA01: priority 36
+TA01: exiting
+*** END OF TEST SPSEM 1 ***
diff --git a/testsuites/sptests/spsem02/Makefile.am b/testsuites/sptests/spsem02/Makefile.am
new file mode 100644
index 0000000..a4df8dd
--- /dev/null
+++ b/testsuites/sptests/spsem02/Makefile.am
@@ -0,0 +1,21 @@
+
+rtems_tests_PROGRAMS = spsem02
+spsem02_SOURCES = init.c
+
+dist_rtems_tests_DATA = spsem02.scn
+dist_rtems_tests_DATA += spsem02.doc
+
+include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP at .cfg
+include $(top_srcdir)/../automake/compile.am
+include $(top_srcdir)/../automake/leaf.am
+
+AM_CPPFLAGS += -I$(top_srcdir)/../support/include
+
+LINK_OBJS = $(spsem02_OBJECTS)
+LINK_LIBS = $(spsem02_LDLIBS)
+
+spsem02$(EXEEXT): $(spsem02_OBJECTS) $(spsem02_DEPENDENCIES)
+	@rm -f spsem02$(EXEEXT)
+	$(make-exe)
+
+include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/sptests/spsem02/init.c b/testsuites/sptests/spsem02/init.c
new file mode 100644
index 0000000..e15412d
--- /dev/null
+++ b/testsuites/sptests/spsem02/init.c
@@ -0,0 +1,192 @@
+/*
+ * Copyright (c) 2013 Gedare Bloom.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#include <rtems.h>
+
+#include <stdio.h>
+#include "tmacros.h"
+
+/* configuration information */
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+#define CONFIGURE_MAXIMUM_TASKS 4
+#define CONFIGURE_MAXIMUM_SEMAPHORES 2
+#define CONFIGURE_INIT
+#include <rtems/confdefs.h>
+
+const char rtems_test_name[] = "SPSEM 2";
+
+rtems_task Task01(rtems_task_argument ignored);
+rtems_task Task02(rtems_task_argument ignored);
+rtems_task Task03(rtems_task_argument ignored);
+rtems_task Init(rtems_task_argument ignored);
+
+static int getprio(void)
+{
+  rtems_status_code status;
+  rtems_task_priority pri;
+
+  status = rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &pri);
+  directive_failed( status, "rtems_task_set_priority");
+  return (int)pri;
+}
+
+rtems_id   Task_id[3];
+rtems_name Task_name[3];
+
+rtems_id   sem_id[2];
+rtems_name sem_name[2];
+
+rtems_task Init(rtems_task_argument ignored)
+{
+  rtems_status_code status;
+  rtems_attribute sem_attr;
+
+  printf("*** BEGIN OF TEST SPSEM02 ***\n");
+
+  sem_attr = RTEMS_INHERIT_PRIORITY | RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY;
+
+  sem_name[0] = rtems_build_name( 'S','0',' ',' ');
+  status = rtems_semaphore_create(
+    sem_name[0],
+    1,
+    sem_attr,
+    0,
+    &sem_id[0]
+  );
+  directive_failed( status, "rtems_semaphore_create of S0");
+  printf("init: S0 created\n");
+
+  sem_name[1] = rtems_build_name( 'S','1',' ',' ');
+  status = rtems_semaphore_create(
+    sem_name[1],
+    1,
+    sem_attr,
+    0,
+    &sem_id[1]
+  );
+  directive_failed( status, "rtems_semaphore_create of S1");
+  printf("init: S1 created\n");
+
+  Task_name[0] = rtems_build_name( 'T','A','0','1');
+  status = rtems_task_create(
+    Task_name[0],
+    36,
+    RTEMS_MINIMUM_STACK_SIZE,
+    RTEMS_DEFAULT_MODES,
+    RTEMS_DEFAULT_ATTRIBUTES,
+    &Task_id[0]
+  );
+  directive_failed( status, "rtems_task_create of TA01");
+  printf("init: TA01 created with priority 36\n");
+
+  Task_name[1] = rtems_build_name( 'T','A','0','2');
+  status = rtems_task_create(
+    Task_name[1],
+    34,
+    RTEMS_MINIMUM_STACK_SIZE,
+    RTEMS_DEFAULT_MODES,
+    RTEMS_DEFAULT_ATTRIBUTES,
+    &Task_id[1]
+  );
+  directive_failed( status , "rtems_task_create of TA02\n");
+  printf("init: TA02 created with priority 34\n");
+
+  Task_name[2] = rtems_build_name( 'T','A','0','3');
+  status = rtems_task_create(
+    Task_name[2],
+    32,
+    RTEMS_MINIMUM_STACK_SIZE,
+    RTEMS_DEFAULT_MODES,
+    RTEMS_DEFAULT_ATTRIBUTES,
+    &Task_id[2]
+  );
+  directive_failed( status , "rtems_task_create of TA03\n");
+  printf("init: TA03 created with priority 32\n");
+
+  status = rtems_task_start( Task_id[0], Task01, 0);
+  directive_failed( status, "rtems_task_start of TA01");
+
+  status = rtems_task_delete( RTEMS_SELF);
+  directive_failed( status, "rtems_task_delete of INIT");
+}
+
+/* Task01 starts with priority 36 */
+rtems_task Task01(rtems_task_argument ignored)
+{
+  rtems_status_code status;
+  printf("TA01: started with priority %d\n", getprio());
+
+  status = rtems_semaphore_obtain( sem_id[0], RTEMS_WAIT, 0 );
+  directive_failed( status, "rtems_semaphore_obtain of S0\n");
+  printf("TA01: priority %d, holding S0\n", getprio());
+
+  status = rtems_semaphore_obtain( sem_id[1], RTEMS_WAIT, 0 );
+  directive_failed( status, "rtems_semaphore_obtain of S1");
+  printf("TA01: priority %d, holding S0, S1\n", getprio());
+
+  /* Start Task 2 (TA02) with priority 34. It will run immediately. */
+  status = rtems_task_start( Task_id[1], Task02, 0);
+  directive_failed( status, "rtems_task_start of TA02\n");
+
+  /* Start Task 3 (TA03) with priority 32. It will run immediately. */
+  status = rtems_task_start( Task_id[2], Task03, 0);
+  directive_failed( status, "rtems_task_start of TA03\n");
+  printf("TA01: priority %d, holding S0, S1\n", getprio());
+
+  status = rtems_semaphore_release(sem_id[1]);
+  directive_failed( status, "rtems_semaphore_release of S1\n");
+  printf("TA01: priority %d, holding S0\n", getprio());
+
+  status = rtems_semaphore_release(sem_id[0]);
+  directive_failed( status, "rtems_semaphore_release of S0\n");
+  printf("TA01: priority %d\n", getprio());
+
+  printf("TA01: exiting\n");
+  printf("*** END OF TEST SPSEM02 ***\n");
+
+  rtems_test_exit(0);
+}
+
+/* TA02 starts at Task02 with priority 34 */
+rtems_task Task02(rtems_task_argument ignored)
+{
+  rtems_status_code status;
+
+  printf("TA02: started with priority %d\n", getprio());
+
+  /* Obtain S1, which should be held by TA01 by now */
+  status = rtems_semaphore_obtain( sem_id[1], RTEMS_WAIT, 0 );
+  directive_failed( status, " rtems_semaphore_obtain S1");
+  printf("TA02: priority %d, holding S1\n", getprio());
+
+  printf("TA02: suspending\n");
+  status = rtems_task_suspend( RTEMS_SELF);
+  directive_failed( status, "rtems_task_suspend TA02");
+}
+
+/* Task03 starts with priority 32 */
+rtems_task Task03(rtems_task_argument ignored)
+{
+  rtems_status_code status;
+  printf("TA03: started with priority %d\n", getprio());
+
+  status = rtems_semaphore_obtain( sem_id[0], RTEMS_WAIT, 0 );
+  directive_failed( status, "rtems_semaphore_obtain of S0\n");
+  printf("TA03: priority %d, holding S0\n", getprio());
+
+  status = rtems_semaphore_release(sem_id[0]);
+  directive_failed( status, "rtems_semaphore_release of S0\n");
+  printf("TA03: priority %d\n", getprio());
+
+  printf("TA03: exiting\n");
+  status = rtems_task_delete( RTEMS_SELF);
+  directive_failed( status, "rtems_task_delete TA03");
+}
diff --git a/testsuites/sptests/spsem02/spsem02.doc b/testsuites/sptests/spsem02/spsem02.doc
new file mode 100644
index 0000000..95ff65a
--- /dev/null
+++ b/testsuites/sptests/spsem02/spsem02.doc
@@ -0,0 +1,23 @@
+This test demonstrates priority inheritance with multiple locks and threads.
+
+The scenario consists of 3 tasks of different priority and 2 semaphore/mutexes
+using priority inheritance. The scenario is:
+
+Task 1 has priority 36. Task 2 has priority 34. Task 3 has priority 32.
+
+1. Task 1 obtains semaphore S1.
+2. Task 1 obtains semaphore S2.
+3. Task 2 preempts Task 1.
+4. Task 2 blocks on S2.  Task 1 inherits priority 34.
+5. Task 1 resumes.
+6. Task 3 preempts Task 1.
+7. Task 3 blocks on S1. Task 1 inherits priority 32.
+8. Task 1 resumes. Task 1 releases S2. Task 1 continues with priority 32.
+9. Task 1 releases S0.
+10. Task 3 resumes.
+11. Task 3 releases S0 and exits.
+12. Task 2 resumes.
+13. Task 2 releases S1 and exits.
+14. Task 1 resumes.
+15. Task 1 exits.
+
diff --git a/testsuites/sptests/spsem02/spsem02.scn b/testsuites/sptests/spsem02/spsem02.scn
new file mode 100644
index 0000000..ab8c7ce
--- /dev/null
+++ b/testsuites/sptests/spsem02/spsem02.scn
@@ -0,0 +1,21 @@
+*** BEGIN OF TEST SPSEM 2 ***
+init: S0 created
+init: S1 created
+init: TA01 created with priority 36
+init: TA02 created with priority 34
+init: TA03 created with priority 32
+TA01: started with priority 36
+TA01: priority 36, holding S0
+TA01: priority 36, holding S0, S1
+TA02: started with priority 34
+TA03: started with priority 32
+TA01: priority 32, holding S0, S1
+TA01: priority 32, holding S0
+TA03: priority 32, holding S0
+TA03: priority 32
+TA03: exiting
+TA02: priority 34, holding S1
+TA02: suspending
+TA01: priority 36
+TA01: exiting
+*** END OF TEST SPSEM 2 ***
diff --git a/testsuites/sptests/spsem03/Makefile.am b/testsuites/sptests/spsem03/Makefile.am
new file mode 100644
index 0000000..5c22740
--- /dev/null
+++ b/testsuites/sptests/spsem03/Makefile.am
@@ -0,0 +1,19 @@
+rtems_tests_PROGRAMS = spsem03
+spsem03_SOURCES = init.c
+
+dist_rtems_tests_DATA = spsem03.scn spsem03.doc
+
+include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP at .cfg
+include $(top_srcdir)/../automake/compile.am
+include $(top_srcdir)/../automake/leaf.am
+
+AM_CPPFLAGS += -I$(top_srcdir)/../support/include
+
+LINK_OBJS = $(spsem03_OBJECTS)
+LINK_LIBS = $(spsem03_LDLIBS)
+
+spsem03$(EXEEXT): $(spsem03_OBJECTS) $(spsem03_DEPENDENCIES)
+	@rm -f spsem03$(EXEEXT)
+	$(make-exe)
+
+include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/sptests/spsem03/init.c b/testsuites/sptests/spsem03/init.c
new file mode 100644
index 0000000..0a56d16
--- /dev/null
+++ b/testsuites/sptests/spsem03/init.c
@@ -0,0 +1,155 @@
+/*
+ * Copyright (c) 2014, 2016 embedded brains GmbH.  All rights reserved.
+ *
+ *  embedded brains GmbH
+ *  Dornierstr. 4
+ *  82178 Puchheim
+ *  Germany
+ *  <rtems at embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+  #include "config.h"
+#endif
+
+#include "tmacros.h"
+
+const char rtems_test_name[] = "SPSEM 3";
+
+typedef struct {
+  rtems_id low;
+  rtems_id mid;
+  rtems_id high;
+  rtems_id inversion;
+  rtems_id sem_a;
+  rtems_id sem_b;
+} test_context;
+
+static test_context test_instance;
+
+static void assert_prio(rtems_id task_id, rtems_task_priority expected_prio)
+{
+  rtems_status_code sc;
+  rtems_task_priority prio;
+
+  sc = rtems_task_set_priority(task_id, RTEMS_CURRENT_PRIORITY, &prio);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+  rtems_test_assert(prio == expected_prio);
+}
+
+static void create_task(rtems_id *id, rtems_task_priority prio)
+{
+  rtems_status_code sc;
+
+  sc = rtems_task_create(
+    rtems_build_name('T', 'A', 'S', 'K'),
+    prio,
+    RTEMS_MINIMUM_STACK_SIZE,
+    RTEMS_DEFAULT_MODES,
+    RTEMS_DEFAULT_ATTRIBUTES,
+    id
+  );
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+}
+
+static void start_task(rtems_id id, rtems_task_entry entry)
+{
+  rtems_status_code sc;
+
+  sc = rtems_task_start(id, entry, 0);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+}
+
+static void create_sema(rtems_id *id)
+{
+  rtems_status_code sc;
+
+  sc = rtems_semaphore_create(
+    rtems_build_name('S', 'E', 'M', 'A'),
+    1,
+    RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY,
+    0,
+    id
+  );
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+}
+
+static void obtain_sema(rtems_id id)
+{
+  rtems_status_code sc;
+
+  sc = rtems_semaphore_obtain(id, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+}
+
+static void inversion_task(rtems_task_argument arg)
+{
+  rtems_test_assert(0);
+}
+
+static void mid_task(rtems_task_argument arg)
+{
+  test_context *ctx = &test_instance;
+
+  obtain_sema(ctx->sem_b);
+  obtain_sema(ctx->sem_a);
+}
+
+static void high_task(rtems_task_argument arg)
+{
+  test_context *ctx = &test_instance;
+
+  start_task(ctx->inversion, inversion_task);
+  obtain_sema(ctx->sem_b);
+}
+
+static void Init(rtems_task_argument arg)
+{
+  test_context *ctx = &test_instance;
+
+  printf("*** BEGIN OF TEST SPSEM03 ***\n");
+
+  ctx->low = rtems_task_self();
+
+  create_task(&ctx->mid, 3);
+  create_task(&ctx->high, 1);
+  create_task(&ctx->inversion, 2);
+  create_sema(&ctx->sem_a);
+  create_sema(&ctx->sem_b);
+
+  obtain_sema(ctx->sem_a);
+  start_task(ctx->mid, mid_task);
+  start_task(ctx->high, high_task);
+
+  /*
+   * Here we see that the priority of the high priority task blocked on
+   * semaphore B propagated to the low priority task owning semaphore A
+   * on which the owner of semaphore B depends.
+   */
+  assert_prio(ctx->low, 1);
+  assert_prio(ctx->mid, 1);
+  assert_prio(ctx->high, 1);
+  assert_prio(ctx->inversion, 2);
+
+  printf("*** END OF TEST SPSEM03 ***\n");
+  rtems_test_exit(0);
+}
+
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+
+#define CONFIGURE_MAXIMUM_TASKS 4
+#define CONFIGURE_MAXIMUM_SEMAPHORES 2
+
+#define CONFIGURE_INIT_TASK_PRIORITY 4
+#define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_INIT
+
+#include <rtems/confdefs.h>
diff --git a/testsuites/sptests/spsem03/spsem03.doc b/testsuites/sptests/spsem03/spsem03.doc
new file mode 100644
index 0000000..a13430e
--- /dev/null
+++ b/testsuites/sptests/spsem03/spsem03.doc
@@ -0,0 +1,12 @@
+This file describes the directives and concepts tested by this test set.
+
+test set name: spsem03
+
+directives:
+
+  - rtems_semaphore_obtain()
+
+concepts:
+
+  - Demonstrate that the priority inheritance protocol works with indirectly
+    referenced semaphore owners.
diff --git a/testsuites/sptests/spsem03/spsem03.scn b/testsuites/sptests/spsem03/spsem03.scn
new file mode 100644
index 0000000..8ea4e86
--- /dev/null
+++ b/testsuites/sptests/spsem03/spsem03.scn
@@ -0,0 +1,2 @@
+*** BEGIN OF TEST SPSEM 3 ***
+*** END OF TEST SPSEM 3 ***
-- 
2.7.4



More information about the devel mailing list