Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:36

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2009.
0005  *  On-Line Applications Research Corporation (OAR).
0006  *
0007  * Redistribution and use in source and binary forms, with or without
0008  * modification, are permitted provided that the following conditions
0009  * are met:
0010  * 1. Redistributions of source code must retain the above copyright
0011  *    notice, this list of conditions and the following disclaimer.
0012  * 2. Redistributions in binary form must reproduce the above copyright
0013  *    notice, this list of conditions and the following disclaimer in the
0014  *    documentation and/or other materials provided with the distribution.
0015  *
0016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0026  * POSSIBILITY OF SUCH DAMAGE.
0027  */
0028 
0029 #ifdef HAVE_CONFIG_H
0030 #include "config.h"
0031 #endif
0032 
0033 #define CONFIGURE_INIT
0034 #include "system.h"
0035 #include <errno.h>
0036 
0037 const char rtems_test_name[] = "PSX 6";
0038 
0039 extern void Key_destructor( void *key_data );
0040 
0041 void Key_destructor(
0042  void *key_data
0043 )
0044 {
0045   Destructor_invoked++;
0046 
0047   /*
0048    *  This checks out that we only run the destructor multiple times
0049    *  when the key data is non null.
0050    */
0051 
0052   if ( Destructor_invoked == 5 )
0053      (void) pthread_setspecific( Key_id, NULL );
0054 }
0055 
0056 void *POSIX_Init(
0057   void *argument
0058 )
0059 {
0060   int               status;
0061   unsigned int      remaining;
0062   uint32_t   *key_data;
0063 
0064   TEST_BEGIN();
0065 
0066   /* set the time of day, and print our buffer in multiple ways */
0067 
0068   set_time( TM_FRIDAY, TM_MAY, 24, 96, 11, 5, 0 );
0069 
0070   /* get id of this thread */
0071 
0072   Init_id = pthread_self();
0073   printf( "Init's ID is 0x%08" PRIxpthread_t "\n", Init_id );
0074 
0075   /* create a couple of threads */
0076 
0077   status = pthread_create( &Task_id, NULL, Task_1, NULL );
0078   rtems_test_assert( !status );
0079 
0080   status = pthread_create( &Task2_id, NULL, Task_2, NULL );
0081   rtems_test_assert( !status );
0082 
0083   /* create a key */
0084 
0085   empty_line();
0086 
0087   Destructor_invoked = 0;
0088   puts( "Init: pthread_key_create - SUCCESSFUL" );
0089   status = pthread_key_create( &Key_id, Key_destructor );
0090   if ( status )
0091     printf( "status = %d\n", status );
0092   rtems_test_assert( !status );
0093 
0094   printf( "Destructor invoked %d times\n", Destructor_invoked );
0095 
0096   puts( "Init: pthread_key_create - EAGAIN (too many keys)" );
0097   status = pthread_key_create( &Key_id, Key_destructor );
0098   rtems_test_assert( status == EAGAIN );
0099 
0100   puts( "Init: pthread_setspecific - EINVAL (invalid key)" );
0101   status = pthread_setspecific( (pthread_t) -1, &Data_array[ 0 ] );
0102   rtems_test_assert( status == EINVAL );
0103 
0104   puts( "Init: pthread_getspecific - EINVAL (invalid key)" );
0105   key_data = pthread_getspecific( (pthread_t) -1 );
0106   rtems_test_assert( !key_data );
0107 
0108   puts( "Init: pthread_key_delete - EINVAL (invalid key)" );
0109   status = pthread_key_delete( (pthread_t) -1 );
0110   rtems_test_assert( status == EINVAL );
0111 
0112   printf( "Init: Setting the key to %d\n", 0 );
0113   status = pthread_setspecific( Key_id, &Data_array[ 0 ] );
0114   if ( status )
0115     printf( "status = %d\n", status );
0116   rtems_test_assert( !status );
0117 
0118      /* switch to task 1 */
0119 
0120   key_data = pthread_getspecific( Key_id );
0121   printf( "Init: Got the key value of %ld\n",
0122           (unsigned long) ((uint32_t   *)key_data - Data_array) );
0123 
0124   remaining = sleep( 3 );
0125   if ( remaining )
0126      printf( "seconds remaining = %d\n", remaining );
0127   rtems_test_assert( !remaining );
0128 
0129      /* switch to task 1 */
0130 
0131   /* delete the key */
0132 
0133   puts( "Init: pthread_key_delete - SUCCESSFUL" );
0134   status = pthread_key_delete( Key_id );
0135   if ( status )
0136     printf( "status = %d\n", status );
0137   rtems_test_assert( !status );
0138 
0139   printf( "Destructor invoked %d times\n", Destructor_invoked );
0140 
0141   TEST_END();
0142   rtems_test_exit( 0 );
0143 
0144   return NULL; /* just so the compiler thinks we returned something */
0145 }