Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  Copyright (c) 2012 Zhongwei Yao.
0005  *  COPYRIGHT (c) 1989-2014.
0006  *  On-Line Applications Research Corporation (OAR).
0007  *
0008  * Redistribution and use in source and binary forms, with or without
0009  * modification, are permitted provided that the following conditions
0010  * are met:
0011  * 1. Redistributions of source code must retain the above copyright
0012  *    notice, this list of conditions and the following disclaimer.
0013  * 2. Redistributions in binary form must reproduce the above copyright
0014  *    notice, this list of conditions and the following disclaimer in the
0015  *    documentation and/or other materials provided with the distribution.
0016  *
0017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0027  * POSSIBILITY OF SUCH DAMAGE.
0028  */
0029 
0030 #ifdef HAVE_CONFIG_H
0031 #include "config.h"
0032 #endif
0033 
0034 #include <pthread.h>
0035 #include <errno.h>
0036 #include "tmacros.h"
0037 #include "pmacros.h"
0038 
0039 const char rtems_test_name[] = "PSXKEY 5";
0040 
0041 /* forward declarations to avoid warnings */
0042 rtems_task Init( rtems_task_argument ignored );
0043 
0044 rtems_task Init( rtems_task_argument ignored )
0045 {
0046   pthread_key_t    key1, key2;
0047   int              sc, *value;
0048   int Data_array[2] = {1, 2};
0049 
0050   TEST_BEGIN();
0051 
0052   puts( "Init - pthread key1 create - OK" );
0053   sc = pthread_key_create( &key1, NULL );
0054   rtems_test_assert( !sc );
0055 
0056   puts( "Init - pthread key2 create - OK" );
0057   sc = pthread_key_create( &key2, NULL );
0058   rtems_test_assert( !sc );
0059 
0060   puts( "Init - key1 pthread_setspecific - OK" );
0061   sc = pthread_setspecific( key1, &Data_array[0] );
0062   rtems_test_assert( !sc );
0063 
0064   puts( "Init - key2 pthread_setspecific - OK" );
0065   sc = pthread_setspecific( key2, &Data_array[1] );
0066   rtems_test_assert( !sc );
0067 
0068   puts( "Init - key1 pthread_getspecific - OK" );
0069   value = pthread_getspecific( key1 );
0070   rtems_test_assert( *value == Data_array[0] );
0071 
0072   puts( "Init - key2 pthread_getspecific - OK" );
0073   value = pthread_getspecific( key2 );
0074   rtems_test_assert( *value == Data_array[1] );
0075 
0076   puts( "Init - key1 pthread_setspecific - OK" );
0077   sc = pthread_setspecific( key1, &Data_array[1] );
0078   rtems_test_assert( !sc );
0079 
0080   puts( "Init - key1 pthread_getspecific - OK" );
0081   value = pthread_getspecific( key1 );
0082   rtems_test_assert( *value == Data_array[1] );
0083 
0084   puts( "Init - pthread key1 delete - OK" );
0085   sc = pthread_key_delete( key1 );
0086   rtems_test_assert( sc == 0 );
0087 
0088   puts( "Init - pthread key2 delete - OK" );
0089   sc = pthread_key_delete( key2 );
0090   rtems_test_assert( sc == 0 );
0091 
0092   TEST_END();
0093   rtems_test_exit(0);
0094 }
0095 
0096 /* configuration information */
0097 
0098 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0099 #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
0100 
0101 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0102 
0103 #define CONFIGURE_MAXIMUM_TASKS          1
0104 #define CONFIGURE_MAXIMUM_POSIX_KEYS     2
0105 
0106 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0107 
0108 
0109 #define CONFIGURE_INIT
0110 #include <rtems/confdefs.h>
0111 
0112 /* global variables */