<p dir="ltr"><br>
On Mar 11, 2014 7:18 AM, Sebastian Huber <sebastian.huber@embedded-brains.de> wrote:<br>
><br>
> On 2014-03-07 20:13, Joel Sherrill wrote:<br>
> > diff --git a/testsuites/psxtests/psxkey07/init.c b/testsuites/psxtests/psxkey07/init.c<br>
> > index e911dc7..b2aabb7 100644<br>
> > --- a/testsuites/psxtests/psxkey07/init.c<br>
> > +++ b/testsuites/psxtests/psxkey07/init.c<br>
> > @@ -1,6 +1,6 @@<br>
> > /*<br>
> > * Copyright (c) 2012 Zhongwei Yao.<br>
> > - * COPYRIGHT (c) 1989-2012.<br>
> > + * COPYRIGHT (c) 1989-2014.<br>
> > * On-Line Applications Research Corporation (OAR).<br>
> > *<br>
> > * The license and distribution terms for this file may be<br>
> > @@ -19,8 +19,8 @@<br>
> > #include "pmacros.h"<br>
> ><br>
> > /* forward declarations to avoid warnings */<br>
> > -void *POSIX_Init(void *argument);<br>
> > -void *Test_Thread(void *argument);<br>
> > +rtems_task Init(rtems_task_argument argument);<br>
> > +rtems_task Test_Thread(rtems_task_argument argument);<br>
> ><br>
> > pthread_key_t Key;<br>
> > int created_thread_count, setted_thread_count, got_thread_count;<br>
> > @@ -28,17 +28,15 @@ int all_thread_created;<br>
> > pthread_mutex_t mutex1, mutex2;<br>
> > pthread_cond_t create_condition_var, set_condition_var;<br>
> ><br>
> > -void *Test_Thread(<br>
> > - void *argument<br>
> > -)<br>
> > +rtems_task Test_Thread(rtems_task_argument argument)<br>
> > {<br>
> > int sc;<br>
> > int *value_p, *value_p2;<br>
> ><br>
> > value_p = malloc( sizeof( int ) );<br>
> > - //printf( "Test_Thread%d - Key pthread_setspecific - OK\n", (int)pthread_self() );<br>
> > sc = pthread_setspecific( Key, value_p );<br>
> > rtems_test_assert( !sc );<br>
> > +<br>
> > pthread_mutex_lock( &mutex1 );<br>
> > ++setted_thread_count;<br>
> > pthread_cond_signal( &set_condition_var );<br>
> > @@ -52,21 +50,20 @@ void *Test_Thread(<br>
> > pthread_cond_wait( &create_condition_var, &mutex2 );<br>
> > pthread_mutex_unlock( &mutex2 );<br>
> ><br>
> > - //printf( "Test_Thread%d - Key pthread_getspecific - OK\n", (int)pthread_self() );<br>
> > value_p2 = pthread_getspecific( Key );<br>
> > rtems_test_assert( value_p == value_p2 );<br>
> > ++got_thread_count;<br>
> ><br>
> > - return NULL;<br>
> > + rtems_task_delete( RTEMS_SELF );<br>
> > }<br>
> ><br>
> > -void *POSIX_Init(<br>
> > - void *ignored<br>
> > -)<br>
> > +rtems_task Init(rtems_task_argument argument)<br>
> > {<br>
> > - pthread_t *thread_p;<br>
> > - int sc;<br>
> > - struct timespec delay_request;<br>
> > + rtems_id *thread_p;<br>
> > + rtems_status_code rc;<br>
> > + int sc;<br>
> > + struct timespec delay_request;<br>
> > +<br>
> > all_thread_created = 0;<br>
> ><br>
> > puts( "\n\n*** TEST KEY 07 ***" );<br>
> > @@ -74,12 +71,15 @@ void *POSIX_Init(<br>
> > puts( "Init - Mutex 1 create - OK" );<br>
> > sc = pthread_mutex_init( &mutex1, NULL );<br>
> > rtems_test_assert( !sc );<br>
> > +<br>
> > puts( "Init - Mutex 2 create - OK" );<br>
> > sc = pthread_mutex_init( &mutex2, NULL );<br>
> > rtems_test_assert( !sc );<br>
> > +<br>
> > puts( "Init - Condition variable 1 create - OK" );<br>
> > sc = pthread_cond_init( &create_condition_var, NULL );<br>
> > rtems_test_assert( !sc );<br>
> > +<br>
> > puts( "Init - Condition variable 2 create - OK" );<br>
> > sc = pthread_cond_init( &set_condition_var, NULL );<br>
> > rtems_test_assert( !sc );<br>
> > @@ -88,34 +88,54 @@ void *POSIX_Init(<br>
> > sc = pthread_key_create( &Key, NULL );<br>
> > rtems_test_assert( !sc );<br>
> ><br>
> > - for( ; ; )<br>
> > - {<br>
> > - thread_p = malloc( sizeof( pthread_t ) );<br>
> > - rtems_test_assert( thread_p );<br>
> > - pthread_mutex_lock( &mutex1 );<br>
> > - sc = pthread_create( thread_p, NULL, Test_Thread, NULL );<br>
> > - rtems_test_assert( ( sc == 0 ) || ( sc == EAGAIN ) );<br>
> > - /**<br>
> > - * check if return is EAGAIN, it means RTEMS Workspace RAM<br>
> > - * have been exhausted.<br>
> > - */<br>
> > - if ( sc == EAGAIN )<br>
> > - {<br>
> > - pthread_mutex_unlock( &mutex1 );<br>
> > - break;<br>
> > - }<br>
> > - ++created_thread_count;<br>
> > - /**<br>
> > - * wait for test thread set key, the while loop here is used to<br>
> > - * avoid suprious wakeup.<br>
> > - */<br>
> > - while( created_thread_count > setted_thread_count )<br>
> > - pthread_cond_wait( &set_condition_var, &mutex1 );<br>
> > + for ( ; ; ) {<br>
> > + thread_p = malloc( sizeof( rtems_id ) );<br>
> > + rtems_test_assert( thread_p );<br>
> > + pthread_mutex_lock( &mutex1 );<br>
> > +<br>
> > + rc = rtems_task_create(<br>
> > + rtems_build_name( 'T', 'E', 'S', 'T' ),<br>
> > + 1,<br>
> > + RTEMS_MINIMUM_STACK_SIZE,<br>
> > + RTEMS_DEFAULT_MODES,<br>
> > + RTEMS_DEFAULT_ATTRIBUTES,<br>
> > + thread_p<br>
> > + );<br>
> > + rtems_test_assert(<br>
> > + ( rc == RTEMS_SUCCESSFUL ) || ( rc == RTEMS_UNSATISFIED )<br>
> > + );<br>
> > +<br>
> > + if ( rc == RTEMS_SUCCESSFUL ) {<br>
> > + rc = rtems_task_start( *thread_p, Test_Thread, 0 );<br>
> > + rtems_test_assert( rc == RTEMS_SUCCESSFUL );<br>
> > + }<br>
> > +<br>
> > + /**<br>
> > + * check if return is EAGAIN, it means RTEMS Workspace RAM<br>
> > + * have been exhausted.<br>
> > + */<br>
> > + if ( rc == RTEMS_UNSATISFIED ) {<br>
> > pthread_mutex_unlock( &mutex1 );<br>
> > + break;<br>
> > }<br>
> > - printf( "Init - %d pthreads have been created - OK\n", created_thread_count );<br>
> > - printf( "Init - %d pthreads have been setted key data - OK\n", setted_thread_count );<br>
> > + ++created_thread_count;<br>
> > +<br>
> > + /**<br>
> > + * wait for test thread set key, the while loop here is used to<br>
> > + * avoid suprious wakeup.<br>
> > + */<br>
> > + while( created_thread_count > setted_thread_count )<br>
> > + pthread_cond_wait( &set_condition_var, &mutex1 );<br>
> > + pthread_mutex_unlock( &mutex1 );<br>
> > + }<br>
> > + printf(<br>
> > + "Init - %d pthreads have been created - OK\n"<br>
> > + "Init - %d pthreads have been setted key data - OK\n",<br>
> > + created_thread_count,<br>
> > + setted_thread_count<br>
> > + );<br>
> > rtems_test_assert( created_thread_count == setted_thread_count );<br>
><br>
> Why did you convert this test to Classic API tasks? It uses POSIX condition <br>
> variables and mutexes. I would change it back.</p>
<p dir="ltr">If this test serves any useful purpose for covering POSIX key code, then it must be building and executable when POSIX threads are disabled.</p>
<p dir="ltr">Thus if we are to fully test keys with POSIX disabled, all key tests had to become Classic API tests.<br></p>
<p dir="ltr">> The following patch is necessary if we want to keep the current version:</p>
<p dir="ltr">Ok. Commit it.</p>
<p dir="ltr"> <br>
> @@ -104,6 +116,7 @@ rtems_task Init(rtems_task_argument argument)<br>
> );<br>
> rtems_test_assert(<br>
> ( rc == RTEMS_SUCCESSFUL ) || ( rc == RTEMS_UNSATISFIED )<br>
> + || ( rc == RTEMS_TOO_MANY )<br>
> );<br>
><br>
> if ( rc == RTEMS_SUCCESSFUL ) {<br>
> @@ -112,10 +125,10 @@ rtems_task Init(rtems_task_argument argument)<br>
> }<br>
><br>
> /**<br>
> - * check if return is EAGAIN, it means RTEMS Workspace RAM<br>
> + * check if return is not successful, it means RTEMS Workspace RAM<br>
> * have been exhausted.<br>
> */<br>
> - if ( rc == RTEMS_UNSATISFIED ) {<br>
> + if ( rc != RTEMS_SUCCESSFUL ) {<br>
> pthread_mutex_unlock( &mutex1 );<br>
> break;<br>
> }<br>
><br>
><br>
> -- <br>
> Sebastian Huber, embedded brains GmbH<br>
><br>
> Address : Dornierstr. 4, D-82178 Puchheim, Germany<br>
> Phone : +49 89 189 47 41-16<br>
> Fax : +49 89 189 47 41-09<br>
> E-Mail : sebastian.huber@embedded-brains.de<br>
> PGP : Public key available on request.<br>
><br>
> Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.<br>
</p>