[PATCH 4/6] add smppflock02 test case
WeiY
wei.a.yang at gmail.com
Mon Aug 19 15:39:46 UTC 2013
---
testsuites/smptests/smppflock02/Makefile.am | 19 +++
testsuites/smptests/smppflock02/init.c | 173 +++++++++++++++++++++++
testsuites/smptests/smppflock02/smppflock02.doc | 17 +++
3 files changed, 209 insertions(+)
create mode 100644 testsuites/smptests/smppflock02/Makefile.am
create mode 100644 testsuites/smptests/smppflock02/init.c
create mode 100644 testsuites/smptests/smppflock02/smppflock02.doc
create mode 100644 testsuites/smptests/smppflock02/smppflock02.scn
diff --git a/testsuites/smptests/smppflock02/Makefile.am b/testsuites/smptests/smppflock02/Makefile.am
new file mode 100644
index 0000000..668a4df
--- /dev/null
+++ b/testsuites/smptests/smppflock02/Makefile.am
@@ -0,0 +1,19 @@
+rtems_tests_PROGRAMS = smppflock02
+smppflock02_SOURCES = init.c ../../support/src/locked_print.c
+
+dist_rtems_tests_DATA = smppflock02.scn smppflock02.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 = $(smppflock02_OBJECTS)
+LINK_LIBS = $(smppflock02_LDLIBS)
+
+smppflock02$(EXEEXT): $(smppflock02_OBJECTS) $(smppflock02_DEPENDENCIES)
+ @rm -f smppflock02$(EXEEXT)
+ $(make-exe)
+
+include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/smptests/smppflock02/init.c b/testsuites/smptests/smppflock02/init.c
new file mode 100644
index 0000000..50050f0
--- /dev/null
+++ b/testsuites/smptests/smppflock02/init.c
@@ -0,0 +1,173 @@
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/score/smprwlock.h>
+
+#include "tmacros.h"
+
+#define TASK_PRIORITY 1
+#define CPU_COUNT 32
+
+typedef enum {
+ INITIAL,
+ START_TEST,
+ STOP_TEST
+} states;
+
+typedef struct {
+ Atomic_Uint state;
+ rtems_id timer_id;
+ rtems_interval timeout;
+ unsigned long test_counter[CPU_COUNT];
+ SMP_rwlock_Control lock;
+} global_context;
+
+static global_context context = {
+ .state = ATOMIC_VAR_INITIALIZER(INITIAL),
+ .lock = SMP_RWLOCK_INITIALIZER
+};
+
+static void stop_test_timer(rtems_id timer_id, void *arg)
+{
+ global_context *ctx = arg;
+
+ _Atomic_Store_uint(&ctx->state, STOP_TEST, ATOMIC_ORDER_RELEASE);
+}
+
+static bool assert_state(global_context *ctx, uint_fast32_t desired_state)
+{
+ return _Atomic_Load_uint(&ctx->state, ATOMIC_ORDER_ACQUIRE) == desired_state;
+}
+
+static void task_write(rtems_task_argument arg)
+{
+ global_context *ctx = (global_context *) arg;
+ uint32_t cpu_count = rtems_smp_get_processor_count();
+ uint32_t cpu_self = rtems_smp_get_current_processor();
+ rtems_status_code sc;
+
+ while (assert_state(ctx, START_TEST)) {
+ _SMP_rwlock_Acquire_write(&ctx->lock);
+ ++ctx->test_counter[cpu_self];
+ _SMP_rwlock_Release_write(&ctx->lock);
+ }
+
+ sc = rtems_task_suspend(RTEMS_SELF);
+ rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+}
+
+static void task_read(rtems_task_argument arg)
+{
+ global_context *ctx = (global_context *) arg;
+ uint32_t cpu_count = rtems_smp_get_processor_count();
+ uint32_t cpu_self = rtems_smp_get_current_processor();
+ rtems_status_code sc;
+
+ while (assert_state(ctx, START_TEST)) {
+ _SMP_rwlock_Acquire_read(&ctx->lock);
+ ++ctx->test_counter[cpu_self];
+ _SMP_rwlock_Release_read(&ctx->lock);
+ }
+
+ sc = rtems_task_suspend(RTEMS_SELF);
+ rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+}
+
+static void test(void)
+{
+ global_context *ctx = &context;
+ uint32_t cpu_count = rtems_smp_get_processor_count();
+ uint32_t cpu_self = rtems_smp_get_current_processor();
+ uint32_t cpu;
+ rtems_status_code sc;
+
+ for (cpu = 0; cpu < cpu_count; ++cpu) {
+ if (cpu != cpu_self) {
+ rtems_id task_id;
+
+ sc = rtems_task_create(
+ rtems_build_name('T', 'A', 'S', 'K'),
+ TASK_PRIORITY,
+ RTEMS_MINIMUM_STACK_SIZE,
+ RTEMS_DEFAULT_MODES,
+ RTEMS_DEFAULT_ATTRIBUTES,
+ &task_id
+ );
+ rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+
+ sc = rtems_task_start(task_id, task_read, (rtems_task_argument) ctx);
+ rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+ }
+ }
+
+ ctx->timeout = 10 * rtems_clock_get_ticks_per_second();
+
+ sc = rtems_timer_create(rtems_build_name('T', 'I', 'M', 'R'), &ctx->timer_id);
+ rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+
+ sc = rtems_timer_fire_after(
+ ctx->timer_id,
+ ctx->timeout,
+ stop_test_timer,
+ ctx
+ );
+ rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+
+ _Atomic_Store_uint(&ctx->state, START_TEST, ATOMIC_ORDER_RELEASE);
+
+ task_write((rtems_task_argument) ctx);
+
+ for (cpu = 0; cpu < cpu_count; ++cpu) {
+ unsigned long local_counter = ctx->test_counter[cpu];
+
+ if (cpu != cpu_self) {
+ printf(
+ "\tprocessor %" PRIu32 ", read task local counter %lu\n",
+ cpu,
+ local_counter
+ );
+ } else {
+ printf(
+ "\tprocessor %" PRIu32 ", write task local counter %lu\n",
+ cpu,
+ local_counter
+ );
+ }
+ }
+}
+
+static void Init(rtems_task_argument arg)
+{
+ puts("\n\n*** TEST SMP phase_fair lock 2 ***");
+
+ test();
+
+ puts("*** END OF TEST SMP phase_fair lock 2 ***");
+
+ rtems_test_exit(0);
+}
+
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+
+#define CONFIGURE_SMP_APPLICATION
+
+#define CONFIGURE_SMP_MAXIMUM_PROCESSORS CPU_COUNT
+
+#define CONFIGURE_MAXIMUM_TASKS CPU_COUNT
+
+#define CONFIGURE_MAXIMUM_SEMAPHORES 1
+
+#define CONFIGURE_MAXIMUM_TIMERS 1
+
+#define CONFIGURE_INIT_TASK_PRIORITY TASK_PRIORITY
+#define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES
+#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_DEFAULT_ATTRIBUTES
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_INIT
+
+#include <rtems/confdefs.h>
diff --git a/testsuites/smptests/smppflock02/smppflock02.doc b/testsuites/smptests/smppflock02/smppflock02.doc
new file mode 100644
index 0000000..21323df
--- /dev/null
+++ b/testsuites/smptests/smppflock02/smppflock02.doc
@@ -0,0 +1,17 @@
+This file describes the directives and concepts tested by this test set.
+
+test set name: smppflock02
+
+The screen file was obtained on a PowerPC QorIQ P1020E target running with a
+processor frequency of 800MHz.
+
+directives:
+
+ - _SMP_rwlock_Acquire_write()
+ - _SMP_rwlock_Release_write()
+ - _SMP_rwlock_Acquire_read()
+ - _SMP_rwlock_Release_read()
+
+concepts:
+
+ - Valid the SMP phase_fair properties implementation
diff --git a/testsuites/smptests/smppflock02/smppflock02.scn b/testsuites/smptests/smppflock02/smppflock02.scn
new file mode 100644
index 0000000..e69de29
--
1.7.9.5
More information about the devel
mailing list