[rtems commit] smptests: Add smpaffinity01
Jennifer Averett
jennifer at rtems.org
Fri Mar 7 15:08:50 UTC 2014
Module: rtems
Branch: master
Commit: a3e055fe8ae9bcad75bd57126ece854e75ff578a
Changeset: http://git.rtems.org/rtems/commit/?id=a3e055fe8ae9bcad75bd57126ece854e75ff578a
Author: Jennifer Averett <jennifer.averett at oarcorp.com>
Date: Mon Feb 10 12:31:59 2014 -0600
smptests: Add smpaffinity01
This test exercises the new Classic API task affinity methods.
---
testsuites/smptests/Makefile.am | 1 +
testsuites/smptests/configure.ac | 1 +
testsuites/smptests/smpaffinity01/Makefile.am | 19 ++
testsuites/smptests/smpaffinity01/init.c | 249 ++++++++++++++++++++
.../smptests/smpaffinity01/smpaffinity01.doc | 21 ++
.../smptests/smpaffinity01/smpaffinity01.scn | 16 ++
6 files changed, 307 insertions(+), 0 deletions(-)
diff --git a/testsuites/smptests/Makefile.am b/testsuites/smptests/Makefile.am
index b15bad5..42f1451 100644
--- a/testsuites/smptests/Makefile.am
+++ b/testsuites/smptests/Makefile.am
@@ -10,6 +10,7 @@ SUBDIRS += smp05
SUBDIRS += smp07
SUBDIRS += smp08
SUBDIRS += smp09
+SUBDIRS += smpaffinity01
SUBDIRS += smpatomic01
SUBDIRS += smpfatal01
SUBDIRS += smpfatal02
diff --git a/testsuites/smptests/configure.ac b/testsuites/smptests/configure.ac
index 95d082b..5eac44e 100644
--- a/testsuites/smptests/configure.ac
+++ b/testsuites/smptests/configure.ac
@@ -64,6 +64,7 @@ smp05/Makefile
smp07/Makefile
smp08/Makefile
smp09/Makefile
+smpaffinity01/Makefile
smpatomic01/Makefile
smpfatal01/Makefile
smpfatal02/Makefile
diff --git a/testsuites/smptests/smpaffinity01/Makefile.am b/testsuites/smptests/smpaffinity01/Makefile.am
new file mode 100644
index 0000000..d58940a
--- /dev/null
+++ b/testsuites/smptests/smpaffinity01/Makefile.am
@@ -0,0 +1,19 @@
+rtems_tests_PROGRAMS = smpaffinity01
+smpaffinity01_SOURCES = init.c
+
+dist_rtems_tests_DATA = smpaffinity01.scn smpaffinity01.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 = $(smpaffinity01_OBJECTS)
+LINK_LIBS = $(smpaffinity01_LDLIBS)
+
+smpaffinity01$(EXEEXT): $(smpaffinity01_OBJECTS) $(smpaffinity01_DEPENDENCIES)
+ @rm -f smpaffinity01$(EXEEXT)
+ $(make-exe)
+
+include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/smptests/smpaffinity01/init.c b/testsuites/smptests/smpaffinity01/init.c
new file mode 100644
index 0000000..c7ccf7e
--- /dev/null
+++ b/testsuites/smptests/smpaffinity01/init.c
@@ -0,0 +1,249 @@
+/*
+ * COPYRIGHT (c) 1989-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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define NUM_CPUS 4
+
+#include "tmacros.h"
+
+#if defined(__RTEMS_HAVE_SYS_CPUSET_H__)
+
+rtems_id Init_id;
+rtems_id Med_id[NUM_CPUS-1];
+rtems_id Low_id[NUM_CPUS];
+
+/* forward declarations to avoid warnings */
+void Task_1(rtems_task_argument arg);
+void Validate_setaffinity_errors(void);
+void Validate_getaffinity_errors(void);
+void Validate_affinity(void);
+
+void Task_1(rtems_task_argument arg)
+{
+ while(1);
+}
+
+void Validate_setaffinity_errors(void)
+{
+ int sc;
+ cpu_set_t cpuset;
+
+ /* Verify rtems_task_set_affinity checks that all cpu's exist. */
+ /* Note this check assumes you are running with less than 32 CPUs */
+ CPU_FILL(&cpuset);
+ puts( "Init - rtems_task_set_affinity - Invalid cpu - RTEMS_INVALID_NUMBER" );
+ sc = rtems_task_set_affinity( Init_id, sizeof(cpu_set_t), &cpuset );
+ rtems_test_assert( sc == RTEMS_INVALID_NUMBER );
+
+ /* Verify rtems_task_set_affinity checks that at least one cpu is set */
+ CPU_ZERO(&cpuset);
+ puts( "Init - rtems_task_set_affinity - no cpu - RTEMS_INVALID_NUMBER" );
+ sc = rtems_task_set_affinity( Init_id, sizeof(cpu_set_t), &cpuset );
+ rtems_test_assert( sc == RTEMS_INVALID_NUMBER );
+
+ /* Verify rtems_task_set_affinity checks that at thread id is valid */
+ CPU_SET(0, &cpuset);
+ puts( "Init - rtems_task_set_affinity - Invalid thread - RTEMS_INVALID_ID" );
+ sc = rtems_task_set_affinity( 999, sizeof(cpu_set_t), &cpuset );
+ rtems_test_assert( sc == RTEMS_INVALID_ID );
+
+ /* Verify rtems_task_set_affinity validates cpusetsize */
+ puts( "Init - rtems_task_set_affinity - Invalid cpusetsize - RTEMS_INVALID_NUMBER" );
+ sc = rtems_task_set_affinity( Init_id, sizeof(cpu_set_t) * 2, &cpuset );
+ rtems_test_assert( sc == RTEMS_INVALID_NUMBER );
+
+ /* Verifyrtems_task_set_affinity validates cpuset */
+ puts( "Init - rtems_task_set_affinity - Invalid cpuset - RTEMS_INVALID_ADDRESS" );
+ sc = rtems_task_set_affinity( Init_id, sizeof(cpu_set_t), NULL );
+ rtems_test_assert( sc == RTEMS_INVALID_ADDRESS );
+}
+
+void Validate_getaffinity_errors(void)
+{
+ int sc;
+ cpu_set_t cpuset;
+
+ /* Verify rtems_task_get_affinity checks that at thread id is valid */
+ CPU_SET(0, &cpuset);
+ puts( "Init - rtems_task_get_affinity - Invalid thread - RTEMS_INVALID_ID" );
+ sc = rtems_task_get_affinity( 999, sizeof(cpu_set_t), &cpuset );
+ rtems_test_assert( sc == RTEMS_INVALID_ID );
+
+ /* Verify rtems_task_get_affinity validates cpusetsize */
+ puts(
+ "Init - rtems_task_get_affinity - Invalid cpusetsize - RTEMS_INVALID_NUMBER"
+ );
+ sc = rtems_task_get_affinity( Init_id, sizeof(cpu_set_t) * 2, &cpuset );
+ rtems_test_assert( sc == RTEMS_INVALID_NUMBER );
+
+ /* Verify rtems_task_get_affinity validates cpuset */
+ puts("Init - rtems_task_get_affinity - Invalid cpuset - RTEMS_INVALID_ADDRESS");
+ sc = rtems_task_get_affinity( Init_id, sizeof(cpu_set_t), NULL );
+ rtems_test_assert( sc == RTEMS_INVALID_ADDRESS );
+}
+
+void Validate_affinity(void )
+{
+ cpu_set_t cpuset0;
+ cpu_set_t cpuset1;
+ cpu_set_t cpuset2;
+ uint32_t i;
+ int sc;
+ int cpu_count;
+ rtems_task_priority priority;
+ char ch[2];
+
+
+ puts( "Init - Set Init priority to high");
+ sc = rtems_task_set_priority( Init_id, 1, &priority );
+ directive_failed( sc, "Set Init Priority" );
+
+ sc = rtems_task_get_affinity( Init_id, sizeof(cpu_set_t), &cpuset0 );
+ directive_failed( sc, "Get Affinity of Init Task" );
+
+ /* Get the number of processors that we are using. */
+ cpu_count = rtems_smp_get_processor_count();
+
+ /* Fill the remaining cpus with med priority tasks */
+ puts( "Init - Create Medium priority tasks");
+ for (i=0; i<(cpu_count-1); i++){
+ sprintf(ch, "%01" PRId32, i+1 );
+ sc = rtems_task_create(
+ rtems_build_name( 'C', 'P', 'U', ch[0] ),
+ 2,
+ RTEMS_MINIMUM_STACK_SIZE,
+ RTEMS_DEFAULT_MODES,
+ RTEMS_DEFAULT_ATTRIBUTES,
+ &Med_id[i]
+ );
+ directive_failed( sc, "task create" );
+
+ sc = rtems_task_start( Med_id[i], Task_1, i+1 );
+ directive_failed( sc, "task start" );
+
+ sc = rtems_task_get_affinity( Med_id[i], sizeof(cpu_set_t), &cpuset2 );
+ directive_failed( sc, "Get Affinity of Medium Priority Task" );
+ rtems_test_assert( CPU_EQUAL(&cpuset0, &cpuset2) );
+ }
+
+ /*
+ * Create low priority thread for each remaining cpu with the affinity
+ * set to only run on one cpu.
+ */
+ puts( "Init - Create Low priority tasks");
+ for (i=0; i<cpu_count; i++){
+ CPU_ZERO(&cpuset1);
+ CPU_SET(i, &cpuset1);
+
+ sprintf(ch, "%01" PRId32, (uint32_t) 0 );
+ sc = rtems_task_create(
+ rtems_build_name( 'X', 'T', 'R', ch[0] ),
+ 10,
+ RTEMS_MINIMUM_STACK_SIZE,
+ RTEMS_DEFAULT_MODES,
+ RTEMS_DEFAULT_ATTRIBUTES,
+ &Low_id[i]
+ );
+ directive_failed( sc, "task create" );
+
+ sc = rtems_task_set_affinity( Low_id[i], sizeof(cpu_set_t), &cpuset1 );
+ directive_failed( sc, "Low priority task set affinity" );
+
+ sc = rtems_task_start( Low_id[i], Task_1, i+1 );
+ directive_failed( sc, "task start" );
+ }
+
+
+ /* Verify affinity on low priority tasks */
+ puts("Init - Verify affinity on Low priority tasks");
+ for (i=0; i<cpu_count; i++){
+ CPU_ZERO(&cpuset1);
+ CPU_SET(i, &cpuset1);
+
+ sc = rtems_task_get_affinity( Low_id[i], sizeof(cpu_set_t), &cpuset2 );
+ directive_failed( sc, "Low priority task get affinity" );
+ rtems_test_assert( CPU_EQUAL(&cpuset1, &cpuset2) );
+ }
+
+ /* Change the affinity for each low priority task */
+ puts("Init - Change affinity on Low priority tasks");
+ CPU_COPY(&cpuset1, &cpuset0);
+ for (i=0; i<cpu_count; i++){
+
+ CPU_CLR(i, &cpuset1);
+ sc = rtems_task_set_affinity( Low_id[i], sizeof(cpu_set_t), &cpuset1 );
+
+ /* Verify no cpu's are now set in the cpuset */
+ if (i== (cpu_count-1)) {
+ rtems_test_assert( sc == RTEMS_INVALID_NUMBER );
+ sc = rtems_task_set_affinity( Low_id[i], sizeof(cpu_set_t), &cpuset0 );
+ }
+
+ directive_failed( sc, "Low priority task set affinity" );
+ }
+
+ puts("Init - Validate affinity on Low priority tasks");
+ CPU_COPY(&cpuset1, &cpuset0);
+ for (i=0; i<cpu_count; i++){
+ CPU_CLR(i, &cpuset1);
+
+ sc = rtems_task_get_affinity( Low_id[i], sizeof(cpu_set_t), &cpuset2 );
+ directive_failed( sc, "Low priority task get affinity" );
+ if (i== (cpu_count-1))
+ rtems_test_assert( CPU_EQUAL(&cpuset0, &cpuset2) );
+ else
+ rtems_test_assert( CPU_EQUAL(&cpuset1, &cpuset2) );
+ }
+}
+
+static void Init(rtems_task_argument arg)
+{
+ int sc;
+
+ puts( "\n\n*** SMP AFFINITY 1 ***" );
+
+ /* Initialize thread id */
+ sc = rtems_task_ident( RTEMS_SELF, RTEMS_SEARCH_ALL_NODES, &Init_id );
+ directive_failed( sc, "Identify Init Task" );
+
+ Validate_setaffinity_errors();
+ Validate_getaffinity_errors();
+ Validate_affinity();
+
+ puts( "*** END OF SMP AFFINITY TEST 1 ***" );
+ rtems_test_exit(0);
+}
+
+#else
+static void Init(rtems_task_argument arg)
+{
+ puts( "\n\n*** SMP AFFINITY TEST 1 ***" );
+ puts( " Affinity NOT Supported");
+ puts( "*** END OF SMP AFFINITY TEST 1 ***" );
+ rtems_test_exit(0);
+}
+
+#endif
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+
+#define CONFIGURE_SMP_APPLICATION
+
+#define CONFIGURE_SMP_MAXIMUM_PROCESSORS NUM_CPUS
+
+#define CONFIGURE_MAXIMUM_TASKS (NUM_CPUS*2)
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_INIT
+
+#include <rtems/confdefs.h>
diff --git a/testsuites/smptests/smpaffinity01/smpaffinity01.doc b/testsuites/smptests/smpaffinity01/smpaffinity01.doc
new file mode 100644
index 0000000..c79d6fe
--- /dev/null
+++ b/testsuites/smptests/smpaffinity01/smpaffinity01.doc
@@ -0,0 +1,21 @@
+# COPYRIGHT (c) 1989-2014.
+# 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: smpaffinity01
+
+directives:
+
+ - rtems_task_get_affinity()
+ - rtems_task_set_affinity()
+
+concepts:
+
+ - Ensure that classic get and set affinity work SMP.
+ Note: This does not test scheduling
diff --git a/testsuites/smptests/smpaffinity01/smpaffinity01.scn b/testsuites/smptests/smpaffinity01/smpaffinity01.scn
new file mode 100644
index 0000000..6e7eefd
--- /dev/null
+++ b/testsuites/smptests/smpaffinity01/smpaffinity01.scn
@@ -0,0 +1,16 @@
+*** SMP AFFINITY 1 ***
+Init - rtems_task_set_affinity - Invalid cpu - RTEMS_UNSATISFIED
+Init - rtems_task_set_affinity - no cpu - RTEMS_UNSATISFIED
+Init - rtems_task_set_affinity - Invalid thread - RTEMS_INVALID_ID
+Init - rtems_task_set_affinity - Invalid cpusetsize - RTEMS_UNSATISFIED
+Init - rtems_task_set_affinity - Invalid cpuset - RTEMS_UNSATISFIED
+Init - rtems_task_get_affinity - Invalid thread - RTEMS_INVALID_ID
+Init - rtems_task_get_affinity - Invalid cpusetsize - RTEMS_UNSATISFIED
+Init - rtems_task_get_affinity - Invalid cpuset - RTEMS_UNSATISFIED
+Init - Set Init priority to high
+Init - Create Medium priority tasks
+Init - Create Low priority tasks
+Init - Verify affinity on Low priority tasks
+Init - Change affinity on Low priority tasks
+Init - Validate affinity on Low priority tasks
+*** END OF SMP AFFINITY TEST 1 ***
More information about the vc
mailing list