[PATCH] rtems:modify spthread01 testsuites for cond variable signal and broadcast intf
tianye at sugon.com
tianye at sugon.com
Tue Jul 6 00:55:35 UTC 2021
From: tianye <tianye at sugon.com>
---
testsuites/sptests/spthread01/init.c | 90 ++++++++++++++++++++++++++++++------
1 file changed, 75 insertions(+), 15 deletions(-)
diff --git a/testsuites/sptests/spthread01/init.c b/testsuites/sptests/spthread01/init.c
index 9044ca2..63cc7b8 100644
--- a/testsuites/sptests/spthread01/init.c
+++ b/testsuites/sptests/spthread01/init.c
@@ -167,14 +167,30 @@ typedef struct {
rtems_condition_variable cnd;
} signal_context;
-static void signal_task(rtems_task_argument arg)
+static unsigned int g_exeing_task_cnt = 0;
+
+static void signal_task_1(rtems_task_argument arg)
+{
+ signal_context *s;
+
+ s = (signal_context *) arg;
+ rtems_mutex_lock(&s->mtx);
+ rtems_condition_variable_wait(&s->cnd, &s->mtx);
+ rtems_mutex_unlock(&s->mtx);
+ g_exeing_task_cnt++;
+ rtems_task_exit();
+}
+
+static void signal_task_2(rtems_task_argument arg)
{
signal_context *s;
s = (signal_context *) arg;
rtems_mutex_lock(&s->mtx);
- rtems_condition_variable_signal(&s->cnd);
+ rtems_condition_variable_wait(&s->cnd, &s->mtx);
rtems_mutex_unlock(&s->mtx);
+ g_exeing_task_cnt++;
+ rtems_task_exit();
}
static void test_condition_variable(void)
@@ -183,7 +199,8 @@ static void test_condition_variable(void)
signal_context s;
const char *name;
rtems_status_code sc;
- rtems_id id;
+ rtems_id id1;
+ rtems_id id2;
name = rtems_condition_variable_get_name(&a);
rtems_test_assert(strcmp(name, "a") == 0);
@@ -201,32 +218,75 @@ static void test_condition_variable(void)
name = rtems_condition_variable_get_name(&s.cnd);
rtems_test_assert(strcmp(name, "c") == 0);
- rtems_condition_variable_signal(&s.cnd);
-
- rtems_condition_variable_broadcast(&s.cnd);
+ g_exeing_task_cnt = 0;
+ sc = rtems_task_create(
+ rtems_build_name('C', 'O', 'D', '1'),
+ 2,
+ RTEMS_MINIMUM_STACK_SIZE,
+ RTEMS_DEFAULT_MODES,
+ RTEMS_DEFAULT_ATTRIBUTES,
+ &id1
+ );
+ rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+ sc = rtems_task_start(id1, signal_task_1, (rtems_task_argument) &s);
+ rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+ sc = rtems_task_create(
+ rtems_build_name('C', 'O', 'D', '2'),
+ 2,
+ RTEMS_MINIMUM_STACK_SIZE,
+ RTEMS_DEFAULT_MODES,
+ RTEMS_DEFAULT_ATTRIBUTES,
+ &id2
+ );
+ rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+ sc = rtems_task_start(id2, signal_task_2, (rtems_task_argument) &s);
+ rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+ rtems_task_wake_after(3);
rtems_mutex_lock(&s.mtx);
+ rtems_condition_variable_signal(&s.cnd);
+ rtems_mutex_unlock(&s.mtx);
+ rtems_task_wake_after(3);
+ rtems_test_assert(g_exeing_task_cnt == 1);
+
+ sc = rtems_task_delete(id1);
+ sc = rtems_task_delete(id2);
+ rtems_condition_variable_destroy(&s.cnd);
+ rtems_mutex_destroy(&s.mtx);
+ g_exeing_task_cnt = 0;
sc = rtems_task_create(
- rtems_build_name('C', 'O', 'N', 'D'),
+ rtems_build_name('C', 'O', 'D', '1'),
2,
RTEMS_MINIMUM_STACK_SIZE,
RTEMS_DEFAULT_MODES,
RTEMS_DEFAULT_ATTRIBUTES,
- &id
+ &id1
);
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
-
- sc = rtems_task_start(id, signal_task, (rtems_task_argument) &s);
+ sc = rtems_task_start(id1, signal_task_1, (rtems_task_argument) &s);
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
-
- rtems_condition_variable_wait(&s.cnd, &s.mtx);
-
- sc = rtems_task_delete(id);
+ sc = rtems_task_create(
+ rtems_build_name('C', 'O', 'D', '2'),
+ 2,
+ RTEMS_MINIMUM_STACK_SIZE,
+ RTEMS_DEFAULT_MODES,
+ RTEMS_DEFAULT_ATTRIBUTES,
+ &id2
+ );
+ rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+ sc = rtems_task_start(id2, signal_task_2, (rtems_task_argument) &s);
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+ rtems_task_wake_after(3);
+ rtems_mutex_lock(&s.mtx);
+ rtems_condition_variable_broadcast(&s.cnd);
rtems_mutex_unlock(&s.mtx);
+ rtems_task_wake_after(3);
+ rtems_test_assert(g_exeing_task_cnt == 2);
+ sc = rtems_task_delete(id1);
+ sc = rtems_task_delete(id2);
rtems_condition_variable_destroy(&s.cnd);
rtems_mutex_destroy(&s.mtx);
}
@@ -319,7 +379,7 @@ static void Init(rtems_task_argument arg)
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
-#define CONFIGURE_MAXIMUM_TASKS 2
+#define CONFIGURE_MAXIMUM_TASKS 3
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
--
1.8.3.1
More information about the devel
mailing list