source: rtems/testsuites/psxtests/psxaio03/init.c @ 6c2de60

4.115
Last change on this file since 6c2de60 was 6c2de60, checked in by Joel Sherrill <joel.sherrill@…>, on 05/11/12 at 19:12:11

psxtests - Eliminate missing prototype warnings

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/*
2 * Copyright 2011, 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 */
9
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#define CONFIGURE_INIT
15#include "system.h"
16#include <rtems.h>
17#include "tmacros.h"
18#include <rtems/posix/aio_misc.h>
19#include <aio.h>
20#include <stdlib.h>
21#include <unistd.h>
22#include <stdio.h>
23#include <sched.h>
24#include <fcntl.h>
25#include <rtems/chain.h>
26
27/* forward declarations to avoid warnings */
28struct aiocb *create_aiocb(int fd);
29void free_aiocb(struct aiocb *aiocbp);
30
31#define MAX 6
32#define BUFSIZE 128
33
34struct aiocb *
35create_aiocb (int fd)
36{
37  struct aiocb *aiocbp;
38
39  aiocbp = malloc (sizeof (struct aiocb));
40  memset (aiocbp, 0, sizeof (struct aiocb));
41  aiocbp->aio_buf = malloc (BUFSIZE * sizeof (char));
42  aiocbp->aio_nbytes = BUFSIZE;
43  aiocbp->aio_offset = 0;
44  aiocbp->aio_reqprio = 0;
45  aiocbp->aio_fildes = fd;
46
47  return aiocbp;
48}
49
50void
51free_aiocb (struct aiocb *aiocbp)
52{
53  free ((char*) aiocbp->aio_buf);
54  free (aiocbp);
55}
56
57
58void *
59POSIX_Init (void *argument)
60{
61  int fd[MAX];
62  struct aiocb *aiocbp[MAX+1];
63  int status, i, policy = SCHED_FIFO;
64  char filename[BUFSIZE];
65  struct sched_param param;
66
67  status = rtems_aio_init ();
68  rtems_test_assert (status == 0);
69
70  param.sched_priority = 30;
71  status = pthread_setschedparam (pthread_self(), policy, &param);
72  rtems_test_assert (status == 0);
73
74  status = mkdir ("/tmp", S_IRWXU);
75  rtems_test_assert (!status);
76
77  puts ("\n\n*** POSIX AIO TEST 03 ***");
78
79  puts (" Init: Open files ");
80
81  for (i=0; i<MAX; i++)
82    {
83      sprintf (filename, "/tmp/aio_fildes%d",i);
84      fd[i] = open (filename, O_RDWR|O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO);
85      rtems_test_assert ( fd[i] != -1);
86    }
87 
88  puts (" Init: [WQ] aio_write on 1st file ");
89  aiocbp[0] = create_aiocb (fd[0]);
90  status = aio_write (aiocbp[0]);
91  rtems_test_assert (status != -1);
92 
93  puts (" Init: [WQ] aio_write on 2nd file ");
94  aiocbp[1] = create_aiocb (fd[1]);
95  status = aio_write (aiocbp[1]);
96  rtems_test_assert (status != -1);
97
98  puts (" Init: [WQ] aio_read on 2nd file add by priority ");
99  aiocbp[2] = create_aiocb (fd[1]);
100  status = aio_read (aiocbp[2]);
101  rtems_test_assert (status != -1);
102 
103  puts (" Init: [WQ] aio_write on 3rd file ");
104  aiocbp[3] = create_aiocb (fd[2]);
105  status = aio_write (aiocbp[3]);
106  rtems_test_assert (status != -1);
107 
108  puts (" Init: [WQ] aio_write on 4th file ");
109  aiocbp[4] = create_aiocb (fd[3]);
110  status = aio_write (aiocbp[4]);
111  rtems_test_assert (status != -1);
112 
113  puts (" Init: [WQ] aio_write on 5th file  -- [WQ] full ");
114  aiocbp[5] = create_aiocb (fd[4]);
115  status = aio_write (aiocbp[5]);
116  rtems_test_assert (status != -1);
117
118  puts (" Init: [IQ] aio_write on 6th file ");
119  aiocbp[6] = create_aiocb (fd[5]);
120  status = aio_read (aiocbp[6]);
121  rtems_test_assert (status != -1);
122 
123  puts (" Init: going to sleep for 5 sec ");
124  sleep (5);
125  puts (" Init: going to sleep again for 5 sec ");
126  sleep (5);
127  puts (" Init: going to sleep again for 5 sec ");
128  sleep (5);
129 
130  puts ("*** END OF POSIX AIO TEST 03 ***");
131 
132  for (i = 0; i < MAX; i++)
133    {
134      close (fd[i]);
135      free_aiocb (aiocbp[i]);
136    }
137  free_aiocb (aiocbp[i]);
138  rtems_test_exit (0);
139 
140  return NULL;
141 
142}
143
Note: See TracBrowser for help on using the repository browser.