[PATCH] implementation of smp test smpmrsp02

Ricardo Gomes (1161078) 1161078 at isep.ipp.pt
Tue Sep 24 17:08:34 UTC 2019


---
 testsuites/smptests/Makefile.am             |  16 ++
 testsuites/smptests/configure.ac            |   2 +
 testsuites/smptests/smpmrsp02/init.c        | 231 ++++++++++++++++++++
 testsuites/smptests/smpmrsp02/smpmrsp02.doc |  15 ++
 4 files changed, 264 insertions(+)
 create mode 100755 testsuites/smptests/smpmrsp02/init.c
 create mode 100644 testsuites/smptests/smpmrsp02/smpmrsp02.doc

diff --git a/testsuites/smptests/Makefile.am b/testsuites/smptests/Makefile.am
index 38cc87e3c5..edb6478b8f 100644
--- a/testsuites/smptests/Makefile.am
+++ b/testsuites/smptests/Makefile.am
@@ -314,6 +314,18 @@ smpmrsp01_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_smpmrsp01) \
 endif
 endif
 
+if HAS_SMP
+if TEST_smpmrsp02
+smp_tests += smpmrsp02
+smp_screens += smpmrsp02/smpmrsp02.scn
+smp_docs += smpmrsp02/smpmrsp02.doc
+smpmrsp02_SOURCES = smpmrsp02/init.c
+smpmrsp02_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_smpmrsp02) \
+	$(support_includes)
+endif
+endif
+
+
 if HAS_SMP
 if TEST_smpmulticast01
 smp_tests += smpmulticast01
@@ -670,4 +682,8 @@ smpwakeafter01_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_smpwakeafter01) \
 endif
 endif
 
+
+
+
 noinst_PROGRAMS = $(smp_tests)
+
diff --git a/testsuites/smptests/configure.ac b/testsuites/smptests/configure.ac
index 83b5b9fe41..6336b4e481 100644
--- a/testsuites/smptests/configure.ac
+++ b/testsuites/smptests/configure.ac
@@ -60,6 +60,7 @@ RTEMS_TEST_CHECK([smplock01])
 RTEMS_TEST_CHECK([smpmigration01])
 RTEMS_TEST_CHECK([smpmigration02])
 RTEMS_TEST_CHECK([smpmrsp01])
+RTEMS_TEST_CHECK([smpmrsp02])
 RTEMS_TEST_CHECK([smpmulticast01])
 RTEMS_TEST_CHECK([smpmutex01])
 RTEMS_TEST_CHECK([smpmutex02])
@@ -93,5 +94,6 @@ RTEMS_TEST_CHECK([smpthreadpin01])
 RTEMS_TEST_CHECK([smpunsupported01])
 RTEMS_TEST_CHECK([smpwakeafter01])
 
+
 AC_CONFIG_FILES([Makefile])
 AC_OUTPUT
diff --git a/testsuites/smptests/smpmrsp02/init.c b/testsuites/smptests/smpmrsp02/init.c
new file mode 100755
index 0000000000..c097fde50b
--- /dev/null
+++ b/testsuites/smptests/smpmrsp02/init.c
@@ -0,0 +1,231 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (C) 2019 Ricardo Gomes
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/param.h>
+#include <stdio.h>
+#include <inttypes.h>
+#include <rtems.h>
+#include <rtems/libcsupport.h>
+#include <rtems/score/schedulersmpimpl.h>
+#include "tmacros.h"
+
+const char rtems_test_name[] = "SMPMRSP 2";
+
+#define CPU_COUNT 2
+
+typedef struct
+{
+  rtems_id init_id;
+  rtems_id scheduler_ids[CPU_COUNT];
+  rtems_id mrsp_id;
+  rtems_id task_id;
+} test_context;
+
+static test_context test_instance;
+
+static void assert_priority(rtems_id task_id, rtems_task_priority priority)
+{
+  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(priority == prio);
+}
+
+/*
+ * Verifying if it is possible to define a priority ceiling 
+ * on each scheduler instance 
+ */
+static void create_semaphore(test_context *ctx, rtems_id *id, rtems_task_priority prio)
+{
+  uint32_t index;
+  rtems_status_code sc;
+
+  sc = rtems_semaphore_create(
+      rtems_build_name('M', 'R', 'S', 'P'),
+      1,
+      RTEMS_MULTIPROCESSOR_RESOURCE_SHARING | RTEMS_BINARY_SEMAPHORE,
+      prio,
+      id);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+
+  rtems_task_priority old_prio;
+
+  old_prio = 1;
+  sc = rtems_semaphore_set_priority(
+      *id,
+      ctx->scheduler_ids[1],
+      prio + 1,
+      &old_prio);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+
+  prio = 2;
+  for (index = 0; index < CPU_COUNT; index++)
+  {
+    rtems_task_priority pr = RTEMS_CURRENT_PRIORITY;
+    sc = rtems_semaphore_set_priority(*id, ctx->scheduler_ids[index], pr, &pr);
+    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+    rtems_test_assert(prio == pr);
+    printf("CPU %d CEILING PRIORITY = %" PRIu32 "\n", index, pr);
+    prio++;
+  }
+}
+
+static void test_prio_per_proc(test_context *ctx)
+{
+  printf("\n--TESTING IF THERE IS ONE CEILING PER PROCESSOR--\n\n");
+  rtems_task_priority prio = 2;
+
+  create_semaphore(ctx, &ctx->mrsp_id, prio);
+
+  printf("\n-------------------------------------------------\n");
+}
+
+/*
+* Verification of the priority changes 
+* when a task tries to obtain a MrsP semaphore
+*/
+static void high_task_prio_obtain(rtems_task_argument arg)
+{
+  test_context *ctx = &test_instance;
+  rtems_status_code sc;
+
+  printf("TASK - before obtain the priority should be 6\n");
+  assert_priority(RTEMS_SELF, 6);
+
+  sc = rtems_semaphore_obtain(ctx->mrsp_id, RTEMS_WAIT, RTEMS_NO_TIMEOUT); 
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+  printf("TASK - after obtain the priority should be 3\n");
+  assert_priority(RTEMS_SELF, 3);
+
+  sc = rtems_semaphore_release(ctx->mrsp_id);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+  printf("TASK - after release the priority should be 6\n");
+  assert_priority(RTEMS_SELF, 6);
+
+  rtems_task_exit();
+
+  printf("\n-------------------------------------------------\n");
+}
+
+static void test_prio_raise(test_context *ctx)
+{
+  printf("\n--TESTING IF THERE IS PRIORITY RAISE OBTAINING THE RESOURCE--\n");
+  rtems_status_code sc = rtems_task_create(
+      rtems_build_name('T', 'A', 'S', 'K'),
+      6,
+      RTEMS_MINIMUM_STACK_SIZE,
+      RTEMS_DEFAULT_MODES,
+      RTEMS_DEFAULT_ATTRIBUTES,
+      &ctx->task_id);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+
+  sc = rtems_task_set_scheduler(ctx->task_id, ctx->scheduler_ids[1], 6);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+
+  printf("\nINIT- obtains the resource \n\n");
+  sc = rtems_semaphore_obtain(ctx->mrsp_id, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+
+  sc = rtems_task_start(ctx->task_id, high_task_prio_obtain, 0);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+
+  sc = rtems_task_wake_after(2 * rtems_clock_get_ticks_per_second());
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+  printf("TASK - trying to obtain on CPU 1, the priority should be 3\n");
+  assert_priority(ctx->task_id, 3);
+
+  printf("\nINIT- releases the resource \n\n");
+  sc = rtems_semaphore_release(ctx->mrsp_id);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+
+  sc = rtems_task_wake_after(5 * rtems_clock_get_ticks_per_second());
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+}
+
+static void Init(rtems_task_argument arg)
+{
+  TEST_BEGIN();
+  test_context *ctx = &test_instance;
+  uint32_t cpu_index;
+  rtems_status_code sc;
+  ctx->init_id = rtems_task_self();
+
+  for (cpu_index = 0; cpu_index < CPU_COUNT; ++cpu_index)
+  {
+    sc = rtems_scheduler_ident(cpu_index, &ctx->scheduler_ids[cpu_index]);
+    rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+  }
+
+  sc = rtems_task_set_scheduler(RTEMS_SELF, ctx->scheduler_ids[0], 4);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+
+  test_prio_per_proc(ctx);
+  test_prio_raise(ctx);
+  TEST_END();
+  rtems_test_exit(0);
+}
+
+#define CONFIGURE_MICROSECONDS_PER_TICK 1000
+
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
+
+#define CONFIGURE_MAXIMUM_TASKS 2
+#define CONFIGURE_MAXIMUM_SEMAPHORES 1
+
+#define CONFIGURE_MAXIMUM_PROCESSORS CPU_COUNT
+
+#define CONFIGURE_SCHEDULER_SIMPLE_SMP
+
+#include <rtems/scheduler.h>
+
+RTEMS_SCHEDULER_SIMPLE_SMP(0);
+RTEMS_SCHEDULER_SIMPLE_SMP(1);
+
+#define CONFIGURE_SCHEDULER_TABLE_ENTRIES \
+  RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(0, 0), \
+      RTEMS_SCHEDULER_TABLE_SIMPLE_SMP(1, 1)
+
+#define CONFIGURE_SCHEDULER_ASSIGNMENTS \
+  RTEMS_SCHEDULER_ASSIGN(0, 0),         \
+      RTEMS_SCHEDULER_ASSIGN(1, 1)
+
+#define CONFIGURE_INIT_TASK_NAME rtems_build_name('M', 'A', 'I', 'N')
+#define CONFIGURE_INIT_TASK_PRIORITY 4
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_INIT
+
+#include <rtems/confdefs.h>
diff --git a/testsuites/smptests/smpmrsp02/smpmrsp02.doc b/testsuites/smptests/smpmrsp02/smpmrsp02.doc
new file mode 100644
index 0000000000..184f404643
--- /dev/null
+++ b/testsuites/smptests/smpmrsp02/smpmrsp02.doc
@@ -0,0 +1,15 @@
+This file describes the directives and concepts tested by this test set.
+
+test set name:  smpmrsp02
+
+directives:
+  rtems_semaphore_create
+  rtems_semaphore_obtain
+  rtems_semaphore_release
+  rtems_semaphore_set_priority
+
+concepts:
+
++ verify if a MrsP semaphore may have a set of priority ceilings, one per scheduler instance.
+
++ Verify if, when a task tries or obtains a MrsP semaphore, its priority is immediatly raised to the priority ceiling defined to that semaphore, on its own scheduler instance.
-- 
2.17.1



More information about the devel mailing list