[PATCH v2] rtems:modify spthread01 testsuites for cond variable signal and broadcast intf rtems:making rectification according to Sebastian Huber's opinions

tianye at sugon.com tianye at sugon.com
Thu Jul 8 05:49:55 UTC 2021


From: tianye <tianye at sugon.com>

---
 testsuites/sptests/spthread01/init.c | 86 +++++++++++++++++++++++++++++++-----
 1 file changed, 74 insertions(+), 12 deletions(-)

diff --git a/testsuites/sptests/spthread01/init.c b/testsuites/sptests/spthread01/init.c
index 9044ca2..b64d0a5 100644
--- a/testsuites/sptests/spthread01/init.c
+++ b/testsuites/sptests/spthread01/init.c
@@ -165,6 +165,7 @@ static void test_recursive_mutex(void)
 typedef struct {
   rtems_mutex mtx;
   rtems_condition_variable cnd;
+  unsigned int exeting_task_cnt;
 } signal_context;
 
 static void signal_task(rtems_task_argument arg)
@@ -173,8 +174,10 @@ static void signal_task(rtems_task_argument arg)
 
   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);
+  s->exeting_task_cnt++;
+  rtems_task_exit();
 }
 
 static void test_condition_variable(void)
@@ -183,7 +186,9 @@ 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;
+  rtems_task_priority task_priority;
 
   name = rtems_condition_variable_get_name(&a);
   rtems_test_assert(strcmp(name, "a") == 0);
@@ -201,34 +206,91 @@ 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);
+  s.exeting_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, (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, (rtems_task_argument) &s);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
 
-  rtems_condition_variable_broadcast(&s.cnd);
+  sc = rtems_task_set_priority(rtems_task_self(), RTEMS_MAXIMUM_PRIORITY - 1, &task_priority);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+  sc = rtems_task_wake_after(0);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
 
   rtems_mutex_lock(&s.mtx);
+  rtems_condition_variable_signal(&s.cnd);
+  rtems_mutex_unlock(&s.mtx);
+  sc = rtems_task_wake_after(0);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+
+  rtems_test_assert(s.exeting_task_cnt == 1);
+  sc = rtems_task_delete(id1);
+  sc = rtems_task_delete(id2);
+  rtems_condition_variable_destroy(&s.cnd);
+  rtems_mutex_destroy(&s.mtx);
+  sc = rtems_task_set_priority(rtems_task_self(), task_priority, &task_priority);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
 
+  s.exeting_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, (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, (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_set_priority(rtems_task_self(), RTEMS_MAXIMUM_PRIORITY - 1, &task_priority);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+  sc = rtems_task_wake_after(0);
   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
 
+  rtems_mutex_lock(&s.mtx);
+  rtems_condition_variable_broadcast(&s.cnd);
   rtems_mutex_unlock(&s.mtx);
+  sc = rtems_task_wake_after(0);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
 
+  rtems_test_assert(s.exeting_task_cnt == 2);
+  sc = rtems_task_delete(id1);
+  sc = rtems_task_delete(id2);
   rtems_condition_variable_destroy(&s.cnd);
   rtems_mutex_destroy(&s.mtx);
+  sc = rtems_task_set_priority(rtems_task_self(), task_priority, &task_priority);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
 }
 
 static void test_counting_semaphore(void)
@@ -319,7 +381,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