[PATCH] sptests: add test for priority inversion with nested locks.

Gedare Bloom gedare at rtems.org
Sat May 18 16:50:05 UTC 2013


I have a couple of changes to make, but this test implements the scenario
presented on the rtems-users ml that is fixed by strict order mutex. With
strict order the .scn output should be correct though I have not verified
it yet. Without strict order the output differs and a priority inversion
bug occurs. We should have strict order on by default to fix this bug.

I will work on another test that exposes a different bug when strict order
is used and three tasks vie for two semaphores.

-Gedare
On May 18, 2013 10:17 AM, "Gedare Bloom" <gedare at rtems.org> wrote:

> ---
>  testsuites/sptests/Makefile.am                   |    2 +-
>  testsuites/sptests/configure.ac                  |    1 +
>  testsuites/sptests/spsemaphore01/Makefile.am     |   21 +++
>  testsuites/sptests/spsemaphore01/init.c          |  155
> ++++++++++++++++++++++
>  testsuites/sptests/spsemaphore01/spsemaphore.doc |    1 +
>  testsuites/sptests/spsemaphore01/spsemaphore.scn |   15 ++
>  6 files changed, 194 insertions(+), 1 deletions(-)
>  create mode 100644 testsuites/sptests/spsemaphore01/Makefile.am
>  create mode 100644 testsuites/sptests/spsemaphore01/init.c
>  create mode 100644 testsuites/sptests/spsemaphore01/spsemaphore.doc
>  create mode 100644 testsuites/sptests/spsemaphore01/spsemaphore.scn
>
> diff --git a/testsuites/sptests/Makefile.am
> b/testsuites/sptests/Makefile.am
> index 4b0fff6..5c2300f 100644
> --- a/testsuites/sptests/Makefile.am
> +++ b/testsuites/sptests/Makefile.am
> @@ -25,7 +25,7 @@ SUBDIRS = \
>      spintrcritical09 spintrcritical10 spintrcritical11 spintrcritical12 \
>      spintrcritical13 spintrcritical14 spintrcritical15 spintrcritical16 \
>      spintrcritical17 spintrcritical18 spmkdir spmountmgr01 spheapprot \
> -    spsimplesched01 spsimplesched02 spsimplesched03 spnsext01 \
> +    spsemaphore01 spsimplesched01 spsimplesched02 spsimplesched03
> spnsext01 \
>      spedfsched01 spedfsched02 spedfsched03 \
>      spcbssched01 spcbssched02 spcbssched03 spqreslib sptimespec01 \
>      spatomic01 spatomic02 spatomic03 spatomic04 spatomic05 \
> diff --git a/testsuites/sptests/configure.ac b/testsuites/sptests/
> configure.ac
> index ba3aa92..8a60767 100644
> --- a/testsuites/sptests/configure.ac
> +++ b/testsuites/sptests/configure.ac
> @@ -188,6 +188,7 @@ spprintk/Makefile
>  spprivenv01/Makefile
>  spqreslib/Makefile
>  sprbtree01/Makefile
> +spsemaphore01/Makefile
>  spsimplesched01/Makefile
>  spsimplesched02/Makefile
>  spsimplesched03/Makefile
> diff --git a/testsuites/sptests/spsemaphore01/Makefile.am
> b/testsuites/sptests/spsemaphore01/Makefile.am
> new file mode 100644
> index 0000000..c3638ba
> --- /dev/null
> +++ b/testsuites/sptests/spsemaphore01/Makefile.am
> @@ -0,0 +1,21 @@
> +
> +rtems_tests_PROGRAMS = spsemaphore
> +spsemaphore_SOURCES = init.c
> +
> +dist_rtems_tests_DATA = spsemaphore.scn
> +dist_rtems_tests_DATA += spsemaphore.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 = $(spsemaphore_OBJECTS)
> +LINK_LIBS = $(spsemaphore_LDLIBS)
> +
> +spsemaphore$(EXEEXT): $(spsemaphore_OBJECTS) $(spsemaphore_DEPENDENCIES)
> +       @rm -f spsemaphore$(EXEEXT)
> +       $(make-exe)
> +
> +include $(top_srcdir)/../automake/local.am
> diff --git a/testsuites/sptests/spsemaphore01/init.c
> b/testsuites/sptests/spsemaphore01/init.c
> new file mode 100644
> index 0000000..2f38baf
> --- /dev/null
> +++ b/testsuites/sptests/spsemaphore01/init.c
> @@ -0,0 +1,155 @@
> +/*
> + * 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.com/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_EXTRA_TASK_STACKS (RTEMS_MINIMUM_STACK_SIZE * 3)
> +#define CONFIGURE_MAXIMUM_TASKS 3
> +#define CONFIGURE_MAXIMUM_SEMAPHORES 2
> +#define CONFIGURE_INIT
> +#include <rtems/confdefs.h>
> +
> +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("\n*** TEST SEMAPHORE01 ***\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*2,
> +    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*2,
> +    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: 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 SEMAPHORE01 ***\n");
> +  status = rtems_task_delete( RTEMS_SELF);
> +  directive_failed( status, "rtems_task_delete TA01");
> +}
> +
> +/* TA02 starts at Task02 with priority 34 */
> +rtems_task Task02(rtems_task_argument ignored)
> +{
> +  rtems_status_code status;
> +
> +  printf("TA02: 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: exiting\n");
> +  status = rtems_task_delete( RTEMS_SELF);
> +  directive_failed( status, "rtems_task_delete TA02");
> +}
> +
> +
> diff --git a/testsuites/sptests/spsemaphore01/spsemaphore.doc
> b/testsuites/sptests/spsemaphore01/spsemaphore.doc
> new file mode 100644
> index 0000000..8b13789
> --- /dev/null
> +++ b/testsuites/sptests/spsemaphore01/spsemaphore.doc
> @@ -0,0 +1 @@
> +
> diff --git a/testsuites/sptests/spsemaphore01/spsemaphore.scn
> b/testsuites/sptests/spsemaphore01/spsemaphore.scn
> new file mode 100644
> index 0000000..977af61
> --- /dev/null
> +++ b/testsuites/sptests/spsemaphore01/spsemaphore.scn
> @@ -0,0 +1,15 @@
> +*** TEST SEMAPHORE01 ***
> +init: S0 created
> +init: S1 created
> +init: TA01 created with priority 36
> +init: TA02 created with priority 34
> +TA01: priority 36
> +TA01: priority 36, holding S0
> +TA01: priority 36, holding S0, S1
> +TA02: priority 34
> +TA02: priority 34, holding S1
> +TA02: exiting
> +TA01: priority 34, holding S0
> +TA01: priority 36
> +TA01: exiting
> +*** END OF SEMAPHORE01 ***
> --
> 1.7.1
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/devel/attachments/20130518/cb152f02/attachment-0001.html>


More information about the devel mailing list