source: rtems/testsuites/psxtests/psxmutexattr01/init.c @ 5d6e8c88

4.104.11
Last change on this file since 5d6e8c88 was 5d6e8c88, checked in by Joel Sherrill <joel.sherrill@…>, on Jul 17, 2009 at 4:17:14 PM

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

  • Makefile.am, configure.ac: Add test to exercise pthread_mutexattr_gettype and pthread_mutexattr_settype now that the toolset enables the feature.
  • psxmutexattr01/.cvsignore, psxmutexattr01/Makefile.am, psxmutexattr01/init.c, psxmutexattr01/psxmutexattr01.doc, psxmutexattr01/psxmutexattr01.scn: New files.
  • Property mode set to 100644
File size: 3.2 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
16typedef struct {
17  const char *name;
18  int type;
19  int status;
20} ToCheck_t;
21
22ToCheck_t TypesToCheck[] = {
23  { "bad type - EINVAL",             -1,                       EINVAL },
24  { "PTHREAD_MUTEX_NORMAL - OK",     PTHREAD_MUTEX_NORMAL,     0 },
25  { "PTHREAD_MUTEX_RECURSIVE - OK",  PTHREAD_MUTEX_RECURSIVE,  0 },
26  { "PTHREAD_MUTEX_ERRORCHECK - OK", PTHREAD_MUTEX_ERRORCHECK, 0 },
27  { "PTHREAD_MUTEX_DEFAULT - OK",    PTHREAD_MUTEX_DEFAULT,    0 },
28};
29
30#define TO_CHECK sizeof(TypesToCheck) / sizeof(ToCheck_t)
31
32void *POSIX_Init(
33  void *ignored
34)
35{
36  int                 sc;
37  pthread_mutexattr_t attr;
38  int                 type;
39  int                 i;
40
41  puts( "\n\n*** POSIX MUTEX ATTRIBUTE TEST 1 ***" );
42
43  puts( "Init - pthread_mutexattr_gettype - attr NULL - EINVAL" );
44  sc = pthread_mutexattr_gettype( NULL, &type );
45  rtems_test_assert( sc == EINVAL );
46
47  puts( "Init - pthread_mutexattr_gettype - type NULL - EINVAL" );
48  sc = pthread_mutexattr_gettype( &attr, NULL );
49  rtems_test_assert( sc == EINVAL );
50
51  memset( &attr, 0, sizeof(attr) );
52  puts( "Init - pthread_mutexattr_gettype - attr not initialized - EINVAL" );
53  sc = pthread_mutexattr_gettype( &attr, &type );
54  rtems_test_assert( sc == EINVAL );
55
56  puts( "Init - pthread_mutexattr_init - OK" );
57  sc = pthread_mutexattr_init( &attr );
58  rtems_test_assert( sc == 0 );
59
60  puts( "Init - pthread_mutexattr_gettype - OK" );
61  sc = pthread_mutexattr_gettype( &attr, &type );
62  rtems_test_assert( sc == 0 );
63
64  /* now do settype */
65  puts( "Init - pthread_mutexattr_settype - type NULL - EINVAL" );
66  sc = pthread_mutexattr_settype( NULL, PTHREAD_MUTEX_NORMAL );
67  rtems_test_assert( sc == EINVAL );
68
69  memset( &attr, 0, sizeof(attr) );
70  puts( "Init - pthread_mutexattr_settype - attr not initialized - EINVAL" );
71  sc = pthread_mutexattr_settype( NULL, PTHREAD_MUTEX_NORMAL );
72  rtems_test_assert( sc == EINVAL );
73
74  /* iterate over good/bad get sets */
75
76  for (i=0 ; i<TO_CHECK ; i++ ) {
77    puts( "Init - pthread_mutexattr_init - OK" );
78    sc = pthread_mutexattr_init( &attr );
79    rtems_test_assert( sc == 0 );
80
81    printf( "Init - pthread_mutexattr_settype - %s\n", TypesToCheck[i].name );
82    sc = pthread_mutexattr_settype( &attr, TypesToCheck[i].type );
83    rtems_test_assert( sc == TypesToCheck[i].status );
84   
85    type = -2;
86
87    if ( TypesToCheck[i].status == 0 ) {
88      printf( "Init - pthread_mutexattr_gettype - %s\n", TypesToCheck[i].name );
89      sc = pthread_mutexattr_gettype( &attr, &type );
90      rtems_test_assert( sc == 0 );
91      rtems_test_assert( type == TypesToCheck[i].type );
92    }
93  }
94
95  puts( "*** END OF POSIX MUTEX ATTRIBUTE TEST 1 ***" );
96  rtems_test_exit(0);
97}
98
99/* configuration information */
100
101#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
102#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
103
104#define CONFIGURE_MAXIMUM_POSIX_THREADS  1
105
106#define CONFIGURE_POSIX_INIT_THREAD_TABLE
107
108#define CONFIGURE_INIT
109#include <rtems/confdefs.h>
110
111/* global variables */
Note: See TracBrowser for help on using the repository browser.