Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2012.
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 #include <tmacros.h>
0034 #include <errno.h>
0035 #include <pthread.h>
0036 
0037 const char rtems_test_name[] = "PSXMUTEXATTR 1";
0038 
0039 /* forward declarations to avoid warnings */
0040 void *POSIX_Init(void *argument);
0041 
0042 #if defined(_UNIX98_THREAD_MUTEX_ATTRIBUTES)
0043 typedef struct {
0044   const char *name;
0045   int type;
0046   int status;
0047 } ToCheck_t;
0048 
0049 ToCheck_t TypesToCheck[] = {
0050   { "bad type - EINVAL",             -1,                       EINVAL },
0051   { "PTHREAD_MUTEX_NORMAL - OK",     PTHREAD_MUTEX_NORMAL,     0 },
0052   { "PTHREAD_MUTEX_RECURSIVE - OK",  PTHREAD_MUTEX_RECURSIVE,  0 },
0053   { "PTHREAD_MUTEX_ERRORCHECK - OK", PTHREAD_MUTEX_ERRORCHECK, 0 },
0054   { "PTHREAD_MUTEX_DEFAULT - OK",    PTHREAD_MUTEX_DEFAULT,    0 },
0055 };
0056 
0057 #define TO_CHECK sizeof(TypesToCheck) / sizeof(ToCheck_t)
0058 #endif
0059 
0060 void *POSIX_Init(
0061   void *ignored
0062 )
0063 {
0064   int                 sc;
0065   pthread_mutexattr_t attr;
0066   int                 type;
0067   int                 i;
0068 
0069   TEST_BEGIN();
0070 
0071 #if defined(_UNIX98_THREAD_MUTEX_ATTRIBUTES)
0072   puts( "Init - pthread_mutexattr_gettype - attr NULL - EINVAL" );
0073   sc = pthread_mutexattr_gettype( NULL, &type );
0074   rtems_test_assert( sc == EINVAL );
0075 
0076   puts( "Init - pthread_mutexattr_gettype - type NULL - EINVAL" );
0077   sc = pthread_mutexattr_gettype( &attr, NULL );
0078   rtems_test_assert( sc == EINVAL );
0079 
0080   memset( &attr, 0, sizeof(attr) );
0081   puts( "Init - pthread_mutexattr_gettype - attr not initialized - EINVAL" );
0082   sc = pthread_mutexattr_gettype( &attr, &type );
0083   rtems_test_assert( sc == EINVAL );
0084 
0085   puts( "Init - pthread_mutexattr_init - OK" );
0086   sc = pthread_mutexattr_init( &attr );
0087   rtems_test_assert( sc == 0 );
0088 
0089   puts( "Init - pthread_mutexattr_gettype - OK" );
0090   sc = pthread_mutexattr_gettype( &attr, &type );
0091   rtems_test_assert( sc == 0 );
0092 
0093   /* now do settype */
0094   puts( "Init - pthread_mutexattr_settype - type NULL - EINVAL" );
0095   sc = pthread_mutexattr_settype( NULL, PTHREAD_MUTEX_NORMAL );
0096   rtems_test_assert( sc == EINVAL );
0097 
0098   memset( &attr, 0, sizeof(attr) );
0099   puts( "Init - pthread_mutexattr_settype - attr not initialized - EINVAL" );
0100   sc = pthread_mutexattr_settype( NULL, PTHREAD_MUTEX_NORMAL );
0101   rtems_test_assert( sc == EINVAL );
0102 
0103   /* iterate over good/bad get sets */
0104 
0105   for (i=0 ; i<TO_CHECK ; i++ ) {
0106     puts( "Init - pthread_mutexattr_init - OK" );
0107     sc = pthread_mutexattr_init( &attr );
0108     rtems_test_assert( sc == 0 );
0109 
0110     printf( "Init - pthread_mutexattr_settype - %s\n", TypesToCheck[i].name );
0111     sc = pthread_mutexattr_settype( &attr, TypesToCheck[i].type );
0112     rtems_test_assert( sc == TypesToCheck[i].status );
0113 
0114     type = -2;
0115 
0116     if ( TypesToCheck[i].status == 0 ) {
0117       printf( "Init - pthread_mutexattr_gettype - %s\n", TypesToCheck[i].name );
0118       sc = pthread_mutexattr_gettype( &attr, &type );
0119       rtems_test_assert( sc == 0 );
0120       rtems_test_assert( type == TypesToCheck[i].type );
0121     }
0122   }
0123 #else
0124   puts( "POSIX Mutex Attribute Type Not Supported in Tools" );
0125 #endif
0126 
0127   TEST_END();
0128   rtems_test_exit(0);
0129 }
0130 
0131 /* configuration information */
0132 
0133 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0134 #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
0135 
0136 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0137 
0138 #define CONFIGURE_MAXIMUM_POSIX_THREADS  1
0139 
0140 #define CONFIGURE_POSIX_INIT_THREAD_TABLE
0141 
0142 #define CONFIGURE_INIT
0143 #include <rtems/confdefs.h>
0144 
0145 /* global variables */