Ignore:
Timestamp:
Jun 24, 2010, 7:46:40 PM (10 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.11, master
Children:
2d1994c9
Parents:
eb8c45d
Message:

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

  • Makefile.am, configure.ac: Removed some fifo tests.
  • spfifo01/Makefile.am, spfifo01/init.c: Minor changes to avoid excessive new lines in the output.

spfifo02/Makefile.am, spfifo02/init.c, spfifo02/spfifo02.doc,
spfifo02/spfifo02.scn, spfifo03/Makefile.am: Merge from spfifo08.
Also added a few more cases, mostly from spfifo04/init.c.

  • spfifo03/init.c, spfifo03/spfifo03.doc, spfifo03/spfifo03.scn: Previously was spfifo06. Configure parameter for pipes is used now.
  • spfifo04/.cvsignore, spfifo04/Makefile.am, spfifo04/init.c, spfifo04/spfifo04.doc, spfifo04/spfifo04.scn, spfifo08/.cvsignore, spfifo08/Makefile.am, spfifo08/init.c, spfifo08/spfifo08.doc, spfifo08/spfifo08.scn: Removed.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • testsuites/sptests/spfifo02/init.c

    reb8c45d r287febb5  
    11/*
    2  *  COPYRIGHT (c) 2010
    3  *  Bharath Suri<bharath.s.jois@gmail.com>.
     2 *  COPYRIGHT (c) 1989-2010.
     3 *  On-Line Applications Research Corporation (OAR).
    44 *
    55 *  The license and distribution terms for this file may be
     
    1010 */
    1111
    12 /* Includes */
    13 #include <bsp.h>
    1412#include <tmacros.h>
    15 
    16 /* Includes */
    17 #include <stdio.h>
     13#include "test_support.h"
     14
    1815#include <sys/types.h>
    1916#include <sys/stat.h>
     
    2118#include <unistd.h>
    2219#include <errno.h>
    23 
    24 #include <rtems.h>
    25 #include <rtems/libio.h>
    26 
    27 
    28 void test_main(void)
    29 {
    30 
    31   int status = -1;
    32   int fd = 0;
    33 
    34   puts("\n\n*** FIFO / PIPE OPEN TEST - 2 ***");
    35   puts(
    36 "\n\nConfiguration: Pipes configured, \
    37 but number of barriers configured = 0"
    38        );
    39 
    40   puts("\n\nCreating directory /tmp");
    41   status = mkdir("/tmp", 0777);
     20#include <rtems/score/heap.h>
     21
     22#define MAXIMUM 10
     23#define NUM_OPEN_REQ 26
     24
     25rtems_id Barriers[MAXIMUM];
     26int BarrierCount;
     27
     28rtems_id Semaphores[MAXIMUM];
     29int SemaphoreCount;
     30
     31extern Heap_Control  *RTEMS_Malloc_Heap;
     32
     33void create_all_barriers(void)
     34{
     35  rtems_status_code status;
     36  int               i;
     37
     38  BarrierCount = 0;
     39
     40  memset( Barriers, 0, sizeof(Barriers) );
     41  for ( i=0 ; i<MAXIMUM ; i++ ) {
     42    status = rtems_barrier_create(
     43      rtems_build_name( 'B', 'A', 'R', 0x30+i ),
     44      RTEMS_BARRIER_MANUAL_RELEASE,
     45      0,
     46      &Barriers[i]
     47    );
     48    if ( status == RTEMS_TOO_MANY ) {
     49      printf( "%d Barriers created\n", BarrierCount+1 );
     50      return;
     51    }
     52
     53    directive_failed( status, "barrier create" );
     54    BarrierCount++;
     55  }
     56}
     57
     58void create_all_semaphores(void)
     59{
     60  rtems_status_code status;
     61  int               i;
     62
     63  SemaphoreCount = 0;
     64
     65  for ( i=0 ; i<MAXIMUM ; i++ ) {
     66    status = rtems_semaphore_create(
     67      rtems_build_name( 'S', 'E', 'M', 0x30+i ),
     68      0,
     69      RTEMS_DEFAULT_ATTRIBUTES,
     70      0,
     71      &Semaphores[i]
     72    );
     73    if ( status == RTEMS_TOO_MANY ) {
     74      printf( "%d Semaphores created\n", SemaphoreCount+1 );
     75      return;
     76    }
     77
     78    directive_failed( status, "semaphore create" );
     79    SemaphoreCount++;
     80  }
     81}
     82
     83void delete_barrier(void)
     84{
     85  rtems_status_code status;
     86 
     87  BarrierCount--;
     88  printf( "Deleting barrier id=0x%08x\n",
     89    (unsigned int)Barriers[BarrierCount] );
     90  status = rtems_barrier_delete( Barriers[BarrierCount] );
     91  directive_failed( status, "barrier delete" );
     92}
     93
     94void delete_semaphore(void)
     95{
     96  rtems_status_code status;
     97 
     98  SemaphoreCount--;
     99  printf( "Deleting semaphore id=0x%08x\n",
     100    (unsigned int) Semaphores[SemaphoreCount] );
     101  status = rtems_semaphore_delete( Semaphores[SemaphoreCount] );
     102  directive_failed( status, "semaphore delete" );
     103}
     104
     105void create_fifo(void)
     106{
     107  int status;
     108
     109  status = mkfifo("/fifo01", 0777);
    42110  rtems_test_assert(status == 0);
    43 
    44   puts("\n\nCreating fifo /tmp/fifo");
    45   status = mkfifo("/tmp/fifo01", 0777);
    46   rtems_test_assert(status == 0);
    47 
    48   puts("\n\nAttempt to open the fifo file\n");
    49   puts(
    50 "Must result in failure since \n\
    51 number of barriers = 0 => not all resources\n\
    52 were acquired"
    53        );
    54 
    55   fd = open("/tmp/fifo01", O_RDONLY);
    56   rtems_test_assert(fd == -1);
    57   rtems_test_assert(errno == EINTR); // Should this
    58                                      // be ENOMEM?
    59   puts("\n\nRemove the entry /tmp/fifo01");
    60   status = unlink("/tmp/fifo01");
    61   rtems_test_assert(status == 0);
    62 
    63   puts("\n\nRemove directory /tmp");
    64   status = rmdir("/tmp");
    65   rtems_test_assert(status == 0);
    66 
    67   puts("\n\n*** END OF FIFO / PIPE OPEN TEST - 2 ***");
    68 }
     111}
     112
     113void open_fifo(int expected, int flags)
     114{
     115  int fd;
     116
     117  fd = open("/fifo01", flags);
     118  printf( "status=%d errno=%d/(%s)\n", fd, errno, strerror(errno) );
     119  if ( expected ) {
     120    rtems_test_assert(fd == -1);
     121    rtems_test_assert(errno == expected);
     122  } else {
     123    rtems_test_assert(fd != -1);
     124    close( fd );
     125  }
     126}
     127
     128rtems_task Init(
     129  rtems_task_argument argument
     130)
     131{
     132  void *alloc_ptr = (void *)0;
     133  int num_opens = 0;
     134  int index = 0;
     135  Heap_Information_block Info;
     136
     137  puts( "\n\n*** TEST FIFO 08 ***" );
     138
     139  puts( "Creating all barriers" );
     140  create_all_barriers();
     141
     142  puts( "Creating all semaphores" );
     143  create_all_semaphores();
     144
     145  puts( "Creating FIFO" );
     146  create_fifo();
    69147 
    70 rtems_task Init(
    71   rtems_task_argument not_used
    72 )
    73 {
    74   test_main();
     148  puts( "Opening FIFO.. expect ENFILE (semaphore @ open could not be created)" );
     149  open_fifo(ENFILE, O_RDWR);
     150
     151  delete_semaphore();
     152  puts( "Opening FIFO.. expect ENOMEM (semaphore for pipe could not be created)" );
     153  open_fifo(ENOMEM, O_RDWR);
     154
     155  delete_semaphore();
     156
     157  _Heap_Get_information(RTEMS_Malloc_Heap, &Info);
     158  alloc_ptr = malloc(Info.Free.largest-4);
     159  puts("Opening FIFO.. expect ENOMEM since no memory is available");
     160  open_fifo(ENOMEM, O_RDWR);
     161
     162  free(alloc_ptr);
     163  puts( "Opening FIFO.. expect ENOMEM (barrier-1 for pipe could not be created)" );
     164  open_fifo(ENOMEM, O_RDWR);
     165
     166  delete_barrier();
     167  puts( "Opening FIFO.. expect ENOMEM (barrier-2 for pipe could not be created" );
     168  open_fifo(ENOMEM, O_RDWR);
     169
     170  delete_barrier();
     171  puts( "Opening FIFO.. expect ENOMEM (semaphore-1 for pipe could not be created" );
     172  open_fifo(ENOMEM, O_RDWR);
     173
     174  delete_semaphore();
     175  puts( "Opening FIFO in RDWR mode. Expect OK" );
     176  open_fifo(0, O_RDWR);
     177  ++num_opens;
     178
     179  puts( "Opening FIFO in non blocking RDONLY mode. Expect OK");
     180  open_fifo(0, O_RDONLY | O_NONBLOCK);
     181  ++num_opens;
     182
     183  puts( "Opening FIFO in non blocking WRONLY mode. Expect ENXIO");
     184  open_fifo(ENXIO, O_WRONLY | O_NONBLOCK);
     185  ++num_opens;
     186
     187  puts("\nMultiple opens\n");
     188  for(index = 0; index < NUM_OPEN_REQ - num_opens; ++index) {
     189
     190    open_fifo(0, O_RDONLY | O_NONBLOCK);
     191    printf("%d... ", index+1);
     192  }
     193
     194  puts( "*** END OF TEST FIFO 08 ***" );
     195
    75196  rtems_test_exit(0);
    76197}
     198
     199/* configuration information */
    77200
    78201#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
    79202#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
    80203
     204#define CONFIGURE_MAXIMUM_TASKS             1
     205#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
     206
    81207#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
    82 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 6
    83 
    84 #define CONFIGURE_PIPES_ENABLED
    85 #define CONFIGURE_MAXIMUM_PIPES 1
    86 #define CONFIGURE_MAXIMUM_TASKS 1
    87 
    88 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
     208#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 5
     209#define CONFIGURE_FIFOS_ENABLED
     210#define CONFIGURE_MAXIMUM_FIFOS 1
     211
    89212#define CONFIGURE_INIT
    90213
    91214#include <rtems/confdefs.h>
    92 
    93215/* end of file */
Note: See TracChangeset for help on using the changeset viewer.