source: rtems/testsuites/psxtests/psxmutexattr01/init.c

Last change on this file was c4b8b147, checked in by Sebastian Huber <sebastian.huber@…>, on Nov 3, 2017 at 7:35:38 AM

tests: Use simple console driver

Update #3170.
Update #3199.

  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2012.
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.org/license/LICENSE.
8 */
9
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#include <tmacros.h>
15#include <errno.h>
16#include <pthread.h>
17
18const char rtems_test_name[] = "PSXMUTEXATTR 1";
19
20/* forward declarations to avoid warnings */
21void *POSIX_Init(void *argument);
22
23#if defined(_UNIX98_THREAD_MUTEX_ATTRIBUTES)
24typedef struct {
25  const char *name;
26  int type;
27  int status;
28} ToCheck_t;
29
30ToCheck_t TypesToCheck[] = {
31  { "bad type - EINVAL",             -1,                       EINVAL },
32  { "PTHREAD_MUTEX_NORMAL - OK",     PTHREAD_MUTEX_NORMAL,     0 },
33  { "PTHREAD_MUTEX_RECURSIVE - OK",  PTHREAD_MUTEX_RECURSIVE,  0 },
34  { "PTHREAD_MUTEX_ERRORCHECK - OK", PTHREAD_MUTEX_ERRORCHECK, 0 },
35  { "PTHREAD_MUTEX_DEFAULT - OK",    PTHREAD_MUTEX_DEFAULT,    0 },
36};
37
38#define TO_CHECK sizeof(TypesToCheck) / sizeof(ToCheck_t)
39#endif
40
41void *POSIX_Init(
42  void *ignored
43)
44{
45  int                 sc;
46  pthread_mutexattr_t attr;
47  int                 type;
48  int                 i;
49
50  TEST_BEGIN();
51
52#if defined(_UNIX98_THREAD_MUTEX_ATTRIBUTES)
53  puts( "Init - pthread_mutexattr_gettype - attr NULL - EINVAL" );
54  sc = pthread_mutexattr_gettype( NULL, &type );
55  rtems_test_assert( sc == EINVAL );
56
57  puts( "Init - pthread_mutexattr_gettype - type NULL - EINVAL" );
58  sc = pthread_mutexattr_gettype( &attr, NULL );
59  rtems_test_assert( sc == EINVAL );
60
61  memset( &attr, 0, sizeof(attr) );
62  puts( "Init - pthread_mutexattr_gettype - attr not initialized - EINVAL" );
63  sc = pthread_mutexattr_gettype( &attr, &type );
64  rtems_test_assert( sc == EINVAL );
65
66  puts( "Init - pthread_mutexattr_init - OK" );
67  sc = pthread_mutexattr_init( &attr );
68  rtems_test_assert( sc == 0 );
69
70  puts( "Init - pthread_mutexattr_gettype - OK" );
71  sc = pthread_mutexattr_gettype( &attr, &type );
72  rtems_test_assert( sc == 0 );
73
74  /* now do settype */
75  puts( "Init - pthread_mutexattr_settype - type NULL - EINVAL" );
76  sc = pthread_mutexattr_settype( NULL, PTHREAD_MUTEX_NORMAL );
77  rtems_test_assert( sc == EINVAL );
78
79  memset( &attr, 0, sizeof(attr) );
80  puts( "Init - pthread_mutexattr_settype - attr not initialized - EINVAL" );
81  sc = pthread_mutexattr_settype( NULL, PTHREAD_MUTEX_NORMAL );
82  rtems_test_assert( sc == EINVAL );
83
84  /* iterate over good/bad get sets */
85
86  for (i=0 ; i<TO_CHECK ; i++ ) {
87    puts( "Init - pthread_mutexattr_init - OK" );
88    sc = pthread_mutexattr_init( &attr );
89    rtems_test_assert( sc == 0 );
90
91    printf( "Init - pthread_mutexattr_settype - %s\n", TypesToCheck[i].name );
92    sc = pthread_mutexattr_settype( &attr, TypesToCheck[i].type );
93    rtems_test_assert( sc == TypesToCheck[i].status );
94
95    type = -2;
96
97    if ( TypesToCheck[i].status == 0 ) {
98      printf( "Init - pthread_mutexattr_gettype - %s\n", TypesToCheck[i].name );
99      sc = pthread_mutexattr_gettype( &attr, &type );
100      rtems_test_assert( sc == 0 );
101      rtems_test_assert( type == TypesToCheck[i].type );
102    }
103  }
104#else
105  puts( "POSIX Mutex Attribute Type Not Supported in Tools" );
106#endif
107
108  TEST_END();
109  rtems_test_exit(0);
110}
111
112/* configuration information */
113
114#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
115#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
116
117#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
118
119#define CONFIGURE_MAXIMUM_POSIX_THREADS  1
120
121#define CONFIGURE_POSIX_INIT_THREAD_TABLE
122
123#define CONFIGURE_INIT
124#include <rtems/confdefs.h>
125
126/* global variables */
Note: See TracBrowser for help on using the repository browser.