source: rtems/testsuites/psxtests/psxaio02/init.c @ 1b8f204f

4.115
Last change on this file since 1b8f204f was cafefbf, checked in by Ralf Corsepius <ralf.corsepius@…>, on 02/22/11 at 09:47:36

Add HAVE_CONFIG_H.

  • Property mode set to 100644
File size: 4.9 KB
Line 
1/*
2 * Copyright 2010, Alin Rus <alin.codejunkie@gmail.com>
3 *
4 * The license and distribution terms for this file may be
5 * found in the file LICENSE in this distribution or at
6 * http://www.rtems.com/license/LICENSE.
7 *
8 * $Id$
9 */
10
11#ifdef HAVE_CONFIG_H
12#include "config.h"
13#endif
14
15#define CONFIGURE_INIT
16#include "system.h"
17#include <rtems.h>
18#include "tmacros.h"
19#include <rtems/posix/aio_misc.h>
20#include <aio.h>
21#include <stdlib.h>
22#include <unistd.h>
23#include <stdio.h>
24#include <sched.h>
25#include <fcntl.h>
26#include <rtems/chain.h>
27
28#define BUFSIZE 32
29#define MAX 10
30#define WRONG_FD 666
31
32struct aiocb *
33create_aiocb (int fd)
34{
35  struct aiocb *aiocbp;
36
37  aiocbp = malloc (sizeof (struct aiocb));
38  memset (aiocbp, 0, sizeof (struct aiocb));
39  aiocbp->aio_buf = malloc (BUFSIZE * sizeof (char));
40  aiocbp->aio_nbytes = BUFSIZE;
41  aiocbp->aio_offset = 0;
42  aiocbp->aio_reqprio = 0;
43  aiocbp->aio_fildes = fd;
44
45  return aiocbp;
46}
47
48void
49free_aiocb (struct aiocb *aiocbp)
50{
51  free ((char*) aiocbp->aio_buf);
52  free (aiocbp);
53}
54
55void *
56POSIX_Init (void *argument)
57{
58  int fd[MAX];
59  struct aiocb *aiocbp[MAX+1];
60  int status, i, policy = SCHED_FIFO;
61  char filename[BUFSIZE];
62  struct sched_param param;
63
64  status = rtems_aio_init ();
65  rtems_test_assert (status == 0);
66
67  param.sched_priority = 30;
68  status = pthread_setschedparam (pthread_self(), policy, &param);
69  rtems_test_assert (status == 0);
70 
71  status = mkdir ("/tmp", S_IRWXU);
72  rtems_test_assert (!status);
73 
74  puts ("\n\n*** POSIX AIO TEST 02 ***");
75 
76  puts (" Init: Open files ");
77
78  for (i=0; i<MAX; i++)
79    {
80      sprintf (filename, "/tmp/aio_fildes%d",i);
81      fd[i] = open (filename, O_RDWR|O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO);
82      rtems_test_assert ( fd[i] != -1);
83    }
84 
85  puts (" Init: [WQ] aio_write on 1st file ");
86  aiocbp[0] = create_aiocb (fd[0]);
87  status = aio_write (aiocbp[0]);
88  rtems_test_assert (status != -1);
89
90  puts (" Init: [WQ] aio_write on 2nd file ");
91  aiocbp[1] = create_aiocb (fd[1]);
92  status = aio_write (aiocbp[1]);
93  rtems_test_assert (status != -1);
94 
95  puts (" Init: [WQ] aio_read on 2nd file add by priority ");
96  aiocbp[2] = create_aiocb (fd[1]);
97  status = aio_read (aiocbp[2]);
98  rtems_test_assert (status != -1);
99 
100  puts (" Init: [WQ] aio_write on 3rd file ");
101  aiocbp[3] = create_aiocb (fd[2]);
102  status = aio_write (aiocbp[3]);
103  rtems_test_assert (status != -1);
104 
105  puts (" Init: [WQ] aio_write on 4th file ");
106  aiocbp[4] = create_aiocb (fd[3]);
107  status = aio_write (aiocbp[4]);
108  rtems_test_assert (status != -1);
109 
110  puts (" Init: [WQ] aio_write on 5th file  -- [WQ] full ");
111  aiocbp[5] = create_aiocb (fd[4]);
112  status = aio_write (aiocbp[5]);
113  rtems_test_assert (status != -1);
114 
115  puts (" Init: [IQ] aio_write on 6th file ");
116  aiocbp[6] = create_aiocb (fd[5]);
117  status = aio_write (aiocbp[6]);
118  rtems_test_assert (status != -1);
119 
120  puts (" Init: [IQ] aio_write on 7th file ");
121  aiocbp[7] = create_aiocb (fd[6]);
122  status = aio_write (aiocbp[7]);
123  rtems_test_assert (status != -1);
124
125  puts (" Init: [IQ] aio_read on 7th file add by priority ");
126  aiocbp[8] = create_aiocb (fd[6]);
127  status = aio_read (aiocbp[8]);
128  rtems_test_assert (status != -1);
129
130  puts (" Init: [WQ] aio_sync on 1st file add by priority ");
131  aiocbp[9] = create_aiocb (fd[0]);
132  status = aio_fsync (O_SYNC, aiocbp[9]);
133  rtems_test_assert (status != -1);
134
135  puts (" Init: [NONE] aio_cancel aiocbp=NULL and invalid fildes ");
136  status = aio_cancel (WRONG_FD, NULL);
137  rtems_test_assert (status == -1);
138
139  puts (" Init: [NONE] aio_cancel aiocbp=NULL valid fildes not in queue ");
140  status = aio_cancel (fd[7], NULL);
141  rtems_test_assert (status == AIO_ALLDONE);
142
143  puts (" Init: [WQ] aio_cancel aiocbp=NULL fildes=fd[1] ");
144  status = aio_cancel (fd[1], NULL);
145  rtems_test_assert (status == AIO_CANCELED);
146
147  puts (" Init: [IQ] aio_cancel aiocbp=NULL fildes=fd[6] ");
148  status = aio_cancel (fd[6], NULL);
149  rtems_test_assert (status == AIO_CANCELED);
150
151  puts (" Init: [NONE] aio_cancel aiocbp->aio_fildes != fildes ");
152  status = aio_cancel (fd[4],aiocbp[4]);
153  rtems_test_assert (status == -1 );
154 
155  puts (" Init: [NONE] aio_cancel FD on [IQ], aiocb not on chain ");
156  aiocbp[10] = create_aiocb (fd[9]);
157  status = aio_cancel (fd[9], aiocbp[10]);
158  rtems_test_assert (status == -1);
159
160  puts (" Init: [IQ] aio_cancel 6th file only one request ");
161  status = aio_cancel (fd[5], aiocbp[6]);
162  rtems_test_assert (status == AIO_CANCELED);
163
164  puts (" Init: [WQ] aio_cancel 1st file only one request ");
165  status = aio_cancel (fd[0], aiocbp[9]);
166  rtems_test_assert (status == AIO_CANCELED);
167
168  puts (" Init: [NONE] aio_cancel empty [IQ] ");
169  status = aio_cancel (fd[5], aiocbp[6]);
170  rtems_test_assert (status == AIO_ALLDONE);
171
172  puts ("\n\n*** POSIX AIO TEST 02 ***");
173
174  puts ("*** END OF POSIX AIO TEST 01 ***");
175
176  for (i = 0; i < MAX; i++)
177    {
178      close (fd[i]);
179      free_aiocb (aiocbp[i]);     
180    }
181  free_aiocb (aiocbp[i]);
182  rtems_test_exit (0);
183
184  return NULL;
185
186}
Note: See TracBrowser for help on using the repository browser.