source: rtems/testsuites/psxtests/psxaio02/init.c @ 9a4eca5

5
Last change on this file since 9a4eca5 was 11925eef, checked in by Sebastian Huber <sebastian.huber@…>, on 11/21/14 at 07:49:57

Delete or rename MIN/MAX macros and defines

Include <sys/param.h> if necessary to get the MIN()/MAX() macros.

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