source: rtems/testsuites/psxtests/psxmutexattr01/init.c @ 56864ff

4.104.11
Last change on this file since 56864ff was 56864ff, checked in by Joel Sherrill <joel.sherrill@…>, on Jul 21, 2009 at 5:25:46 PM

2009-07-21 Joel Sherrill <joel.sherrill@…>

  • psxmutexattr01/init.c: Make test optional if tools do not support posix mutex type attribute.
  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2009.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.com/license/LICENSE.
8 *
9 *  $Id$
10 */
11
12#include <tmacros.h>
13#include <errno.h>
14#include <pthread.h>
15
16#if defined(_UNIX98_THREAD_MUTEX_ATTRIBUTES)
17typedef struct {
18  const char *name;
19  int type;
20  int status;
21} ToCheck_t;
22
23ToCheck_t TypesToCheck[] = {
24  { "bad type - EINVAL",             -1,                       EINVAL },
25  { "PTHREAD_MUTEX_NORMAL - OK",     PTHREAD_MUTEX_NORMAL,     0 },
26  { "PTHREAD_MUTEX_RECURSIVE - OK",  PTHREAD_MUTEX_RECURSIVE,  0 },
27  { "PTHREAD_MUTEX_ERRORCHECK - OK", PTHREAD_MUTEX_ERRORCHECK, 0 },
28  { "PTHREAD_MUTEX_DEFAULT - OK",    PTHREAD_MUTEX_DEFAULT,    0 },
29};
30
31#define TO_CHECK sizeof(TypesToCheck) / sizeof(ToCheck_t)
32#endif
33
34void *POSIX_Init(
35  void *ignored
36)
37{
38  int                 sc;
39  pthread_mutexattr_t attr;
40  int                 type;
41  int                 i;
42
43  puts( "\n\n*** POSIX MUTEX ATTRIBUTE TEST 1 ***" );
44
45#if defined(_UNIX98_THREAD_MUTEX_ATTRIBUTES)
46  puts( "Init - pthread_mutexattr_gettype - attr NULL - EINVAL" );
47  sc = pthread_mutexattr_gettype( NULL, &type );
48  rtems_test_assert( sc == EINVAL );
49
50  puts( "Init - pthread_mutexattr_gettype - type NULL - EINVAL" );
51  sc = pthread_mutexattr_gettype( &attr, NULL );
52  rtems_test_assert( sc == EINVAL );
53
54  memset( &attr, 0, sizeof(attr) );
55  puts( "Init - pthread_mutexattr_gettype - attr not initialized - EINVAL" );
56  sc = pthread_mutexattr_gettype( &attr, &type );
57  rtems_test_assert( sc == EINVAL );
58
59  puts( "Init - pthread_mutexattr_init - OK" );
60  sc = pthread_mutexattr_init( &attr );
61  rtems_test_assert( sc == 0 );
62
63  puts( "Init - pthread_mutexattr_gettype - OK" );
64  sc = pthread_mutexattr_gettype( &attr, &type );
65  rtems_test_assert( sc == 0 );
66
67  /* now do settype */
68  puts( "Init - pthread_mutexattr_settype - type NULL - EINVAL" );
69  sc = pthread_mutexattr_settype( NULL, PTHREAD_MUTEX_NORMAL );
70  rtems_test_assert( sc == EINVAL );
71
72  memset( &attr, 0, sizeof(attr) );
73  puts( "Init - pthread_mutexattr_settype - attr not initialized - EINVAL" );
74  sc = pthread_mutexattr_settype( NULL, PTHREAD_MUTEX_NORMAL );
75  rtems_test_assert( sc == EINVAL );
76
77  /* iterate over good/bad get sets */
78
79  for (i=0 ; i<TO_CHECK ; i++ ) {
80    puts( "Init - pthread_mutexattr_init - OK" );
81    sc = pthread_mutexattr_init( &attr );
82    rtems_test_assert( sc == 0 );
83
84    printf( "Init - pthread_mutexattr_settype - %s\n", TypesToCheck[i].name );
85    sc = pthread_mutexattr_settype( &attr, TypesToCheck[i].type );
86    rtems_test_assert( sc == TypesToCheck[i].status );
87   
88    type = -2;
89
90    if ( TypesToCheck[i].status == 0 ) {
91      printf( "Init - pthread_mutexattr_gettype - %s\n", TypesToCheck[i].name );
92      sc = pthread_mutexattr_gettype( &attr, &type );
93      rtems_test_assert( sc == 0 );
94      rtems_test_assert( type == TypesToCheck[i].type );
95    }
96  }
97#else
98  puts( "POSIX Mutex Attribute Type Not Supported in Tools" );
99#endif
100
101  puts( "*** END OF POSIX MUTEX ATTRIBUTE TEST 1 ***" );
102  rtems_test_exit(0);
103}
104
105/* configuration information */
106
107#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
108#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
109
110#define CONFIGURE_MAXIMUM_POSIX_THREADS  1
111
112#define CONFIGURE_POSIX_INIT_THREAD_TABLE
113
114#define CONFIGURE_INIT
115#include <rtems/confdefs.h>
116
117/* global variables */
Note: See TracBrowser for help on using the repository browser.