[PATCH] rtems:modify spthread01 testsuites for cond variable signal and broadcast intf

Sebastian Huber sebastian.huber at embedded-brains.de
Wed Jul 7 18:14:57 UTC 2021


Hello,

thanks for your new test case.

On 06/07/2021 02:55, tianye at sugon.com wrote:
> 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;

I suggest to add this new variable to signal_context.

> +
> +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();
>   }

What is the difference between signal_task_1() and signal_task_2()? You 
can use the same task body function for multiple tasks.

>   
>   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);

Could you rewrite the test so that this magic wait is unnecessary? For 
example using task priorities. Test cases depend on magic waits may 
cause sporadic failures, for example on simulators.

-- 
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.huber at embedded-brains.de
phone: +49-89-18 94 741 - 16
fax:   +49-89-18 94 741 - 08

Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/


More information about the devel mailing list