source: rtems/testsuites/sptests/spfifo04/test.c @ cfde6479

4.115
Last change on this file since cfde6479 was cfde6479, checked in by Jennifer Averett <Jennifer.Averett@…>, on Jun 7, 2010 at 7:09:28 PM

2010-06-07 Bharath Suri <bharath.s.jois@…>

PR PR1542

  • Makefile.am, configure.ac: Coverage improvement: fifo_open.
  • spfifo01/spfifo01.doc, spfifo01/spfifo01.scn, spfifo01/test.c, spfifo02/Makefile.am, spfifo02/main.c, spfifo02/spfifo02.doc, spfifo02/spfifo02.scn, spfifo02/test.c, spfifo03/Makefile.am, spfifo03/main.c, spfifo03/spfifo03.doc, spfifo03/spfifo03.scn, spfifo03/test.c, spfifo04/Makefile.am, spfifo04/main.c, spfifo04/spfifo04.doc, spfifo04/spfifo04.scn, spfifo04/test.c: New files.
  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*  test_main
2 *
3 *  This routine serves as a test routine.
4 *  Exercises the fifo_open
5 *
6 *  Input parameters:   NONE
7 *
8 *  Output parameters:  NONE
9 *
10 *  COPYRIGHT (c) 1989-1999.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.com/license/LICENSE.
16 *
17 *  $Id$
18 */
19
20/* Includes */
21
22#include <stdio.h>
23#include <sys/types.h>
24#include <sys/stat.h>
25#include <fcntl.h>
26#include <unistd.h>
27#include <errno.h>
28
29#include <tmacros.h>
30#include <rtems.h>
31#include <rtems/libio.h>
32
33#define NUM_OPEN_REQ        26
34
35void test_main(void)
36{
37
38  int status = -1;
39  int fd = 0;
40  int index = 0;
41  int num_opens = 0;
42
43  puts("\n\n*** FIFO / PIPE OPEN TEST - 4 ***");
44  puts(
45"\n\nConfiguration: Pipes configured, \
46but number of barriers configured = 2\n"
47       );
48
49  puts("\n\nCreating directory /tmp");
50  status = mkdir("/tmp", 0777);
51  rtems_test_assert(status == 0);
52
53  puts("\n\nCreating fifo /tmp/fifo");
54  status = mkfifo("/tmp/fifo01", 0777);
55  rtems_test_assert(status == 0);
56
57  puts("\n\nAttempt to open the fifo file in RDWR mode\n");
58  puts("Should be successful and non-negative\
59file descriptor expected");
60
61  fd = open("/tmp/fifo01", O_RDWR);
62  rtems_test_assert(fd > 0);
63  ++num_opens;
64
65  puts("\n\nClosing the fifo file");
66  status = close(fd);
67  rtems_test_assert(status == 0);
68
69  puts("\n\nAttempt to open the fifo file in \
70RDONLY and NONBLOCK mode\n");
71  puts("Should be successful and non-negative\
72file descriptor expected");
73
74  fd = open("/tmp/fifo01", O_RDONLY | O_NONBLOCK);
75  rtems_test_assert(fd > 0);
76  ++num_opens;
77
78  puts("\n\nClosing the fifo file");
79  status = close(fd);
80  rtems_test_assert(status == 0);
81 
82  puts("\n\nAttempt to open the fifo file in \
83WRONLY and NONBLOCK mode\n");
84  puts("Should return with an error ENXIO");
85
86  fd = open("/tmp/fifo01", O_WRONLY | O_NONBLOCK);
87  rtems_test_assert(fd == -1);
88  rtems_test_assert(errno == ENXIO);
89  ++num_opens;
90
91  // Number of attempts to open fifo till now = 3
92  // Number of attempts to move the static char
93  // from 'a' -> 'z' = 26
94  // => Number of opens required = 23
95  puts("\n\nMultiple opens\n");
96  for(index = 0; index < NUM_OPEN_REQ - num_opens; ++index) {
97
98    fd = open("/tmp/fifo01", O_RDONLY | O_NONBLOCK);
99    rtems_test_assert(fd > 0);
100
101    status = close(fd);
102    rtems_test_assert(status == 0);
103
104    printf("%d... ", index+1);
105  }
106
107  puts("\n\nRemove the entry /tmp/fifo01");
108  status = unlink("/tmp/fifo01");
109  rtems_test_assert(status == 0);
110
111  puts("\n\nRemove directory /tmp");
112  status = rmdir("/tmp");
113  rtems_test_assert(status == 0);
114
115  puts("\n\n*** END OF FIFO / PIPE OPEN TEST - 4 ***");
116}
117
Note: See TracBrowser for help on using the repository browser.