summaryrefslogtreecommitdiff
path: root/tests/Aio_Platform_Test.cpp
blob: faeb27527c62e1b8cd1ddf4079cd0d3a38ec8574 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
// $Id$
// ============================================================================
//
// = FILENAME
//    aio_platform_test.cpp
//
// =  DESCRITPTION
//     Testing the platform for POSIX Asynchronous I/O.
//
// = AUTHOR
//    Programming for the Real World. Bill O. GallMeister.
//    Modified by Alexander Babu Arulanthu <alex@cs.wustl.edu>
//
// =====================================================================

#include "test_config.h"
#include "ace/OS.h"

// Define old style feature selector.
//#define _POSIX_SOURCE

// Use 9/93 POSIX.1 .2 and .4 definitions only.
//#define _POSIX_C_SOURCE 199309L

#if defined _POSIX_ASYNCHRONOUS_IO

#if defined _POSIX_ASYNC_IO

#if _POSIX_ASYNC_IO == -1

int
have_asynchio (void)
{
  ACE_DEBUG ((LM_DEBUG,
              "_POSIX_ASYNC_IO = -1.. Not supported at all\n"));
  return 0;
}

#else /* _POSIX_ASYNC_IO is != -1 */
// Supported everywhere.
int
have_asynchio (void)
{
  ACE_DEBUG ((LM_DEBUG, "_POSIX_ASYNC_IO is != -1..AIO is supported everywhere\n"));
  ACE_DEBUG ((LM_DEBUG, "System claims to have  POSIX_ASYNCHRONOUS_IO\n"));
  ACE_DEBUG ((LM_DEBUG, "_POSIX_AIO_LISTIO_MAX = %d\n", _POSIX_AIO_LISTIO_MAX));
  ACE_DEBUG ((LM_DEBUG, "_POSIX_AIO_MAX = %d\n", _POSIX_AIO_MAX));

  // Call sysconf to find out runtime values.
  errno = 0;
  ACE_ERROR ((LM_ERROR,
#if defined (_SC_LISTIO_AIO_MAX)
              "Runtime value of LISTIO_AIO_MAX is %d, errno = %d\n",
              sysconf(_SC_LISTIO_AIO_MAX),
#else
              "Runtime value of AIO_LISTIO_MAX is %d, errno = %d\n",
              sysconf(_SC_AIO_LISTIO_MAX),
#endif
              errno));

  errno = 0;
  ACE_ERROR ((LM_ERROR,
              "Runtime value of AIO_MAX is %d, errno = %d\n",
              sysconf (_SC_AIO_MAX),
              errno));

  errno = 0;
  ACE_ERROR ((LM_ERROR,
              "Runtime value of _POSIX_ASYNCHRONOUS_IO is %d, errno = %d\n",
              sysconf (_SC_ASYNCHRONOUS_IO),
              errno));

  errno = 0;
  ACE_ERROR ((LM_ERROR,
              "Runtime value of _POSIX_REALTIME_SIGNALS is %d, errno = %d\n",
              sysconf (_SC_REALTIME_SIGNALS),
              errno));

  errno = 0;
  ACE_ERROR ((LM_ERROR,
              "Runtime value of RTSIG_MAX %d\n",
              sysconf (_SC_RTSIG_MAX)));
  return 1;
}

#endif /* _POSIX_ASYNC_IO == -1 */

#else /* _POSIX_ASYNC_IO_ is not defined */


char *
asynch_io_files[] =
{
  "/tmp/fu",
  "/fu",
  "./fu",
  "/mnt/fu",
  "/dev/tty",
  "dev/dsk/c2t0ds0",
  NULL
};

int
have_asynchio (void)
{
  int i, res, num_ok;

  ACE_ERROR ((LM_DEBUG,
              "_POSIX_ASYNC_IO_ is not defined.\n"));
  ACE_DEBUG ((LM_DEBUG,
              "AIO might *not* be supported everwhere.\n"));

  ACE_DEBUG ((LM_DEBUG, "System claims to have  POSIX_ASYNCHRONOUS_IO\n"));
  ACE_DEBUG ((LM_DEBUG, "_POSIX_AIO_LISTIO_MAX = %d\n", _POSIX_AIO_LISTIO_MAX));
  ACE_DEBUG ((LM_DEBUG, "_POSIX_AIO_MAX = %d\n", _POSIX_AIO_MAX));

  // Call sysconf to find out runtime values.
  errno = 0;
  ACE_ERROR ((LM_ERROR,
              "Runtime value of AIO_LISTIO_MAX is %d, errno = %d\n",
              sysconf(_SC_AIO_LISTIO_MAX),
              errno));

  errno = 0;
  ACE_ERROR ((LM_ERROR,
              "Runtime value of AIO_MAX is %d, errno = %d\n",
              sysconf (_SC_AIO_MAX),
              errno));

  errno = 0;
  ACE_ERROR ((LM_ERROR,
              "Runtime value of _POSIX_ASYNCHRONOUS_IO is %d\n",
              sysconf (_SC_ASYNCHRONOUS_IO)));

  errno = 0;
  ACE_ERROR ((LM_ERROR,
              "Runtime value of _POSIX_REALTIME_SIGNALS is %d\n",
              sysconf (_SC_REALTIME_SIGNALS)));

  errno = 0;
  ACE_ERROR ((LM_ERROR,
              "Runtime value of RTSIG_MAX %d\n",
              sysconf (_SC_RTSIG_MAX)));

  ACE_DEBUG ((LM_DEBUG,
              "Checking individual files using pathconf \n"));

  for (i = num_ok = 0;
       asynch_io_files[i];
       i++)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "Checking on path %s\n", asynch_io_files [i]));
      errno = 0;
      res = pathconf (asynch_io_files [i], _PC_ASYNC_IO);
      if ((res == -1) && (!errno))
        {
          ACE_DEBUG ((LM_DEBUG,
                      "\tAsynch IO is allowed :-)\n"));
          num_ok++;
        }
      else if (res < 0)
        {
          ACE_ERROR ((LM_ERROR,
                      "(%p)\n", "Asynch I/O is not allowed >:-<"));
        }
      else
        {
          ACE_ERROR ((LM_ERROR,
                      "Asynch. I/O is allowed :-), res = %d, errno = %d\n",
                      res,
                      errno));
          num_ok++;
        }
    }
  if (num_ok == i)
    return 1;
  else
    return 0;
}
#endif /* _POSIX_ASYNC_IO_ */

#else  /* _POSIX_ASYNCHRONOUS_IO is not defined*/
int
have_asynchio (void)
{
  ACE_DEBUG ((LM_DEBUG,
              "_POSIX_ASYNCHRONOUS_IO itself is not defined\n"));
  return 0;
}
#endif /* _POSIX_ASYNCHRONOUS_IO */

int
main (int, char *[])
{
  ACE_START_TEST ("Aio_Platform_Test");

  int ret_val = have_asynchio ();

  if (ret_val == 1)
    ACE_DEBUG ((LM_DEBUG, "POSIX Asynchronous IO is supported\n"));
  else
    ACE_DEBUG ((LM_DEBUG, "POSIX Asynchronous IO is not supported\n"));

  ACE_END_TEST;
  return 0;
}