Ticket #1262: psxrdwrv.diff

File psxrdwrv.diff, 16.0 KB (added by Joel Sherrill, on 09/24/07 at 20:27:42)

Test case for readv and writev

  • testsuites/psxtests/Makefile.am

    ? testsuites/psxtests/.Makefile.am.swp
    RCS file: /usr1/CVS/rtems/testsuites/psxtests/Makefile.am,v
    retrieving revision 1.22
    diff -u -r1.22 Makefile.am
     
    88    psx10 psx11 psx12 psxtime psxtimer psxcancel psxbarrier01 psxmsgq01 \
    99    psxrwlock01 psxsem01 psxspin01
    1010
     11## File IO tests
    1112SUBDIRS += psxfile01 psxreaddir psxstat psxmount psx13 psxchroot01
    1213
     14## Until sys/uio.h is moved to libcsupport, we have to have networking
     15## enabled to support readv and writev.  Hopefully this is a temporary
     16## situation.
     17if LIBNETWORKING
     18SUBDIRS += psxrdwrv
     19endif
     20
     21
    1322include $(top_srcdir)/../automake/subdirs.am
    1423include $(top_srcdir)/../automake/local.am
  • testsuites/psxtests/configure.ac

    RCS file: /usr1/CVS/rtems/testsuites/psxtests/configure.ac,v
    retrieving revision 1.21
    diff -u -r1.21 configure.ac
     
    4747psxmount/Makefile
    4848psxmsgq01/Makefile
    4949psxreaddir/Makefile
     50psxrdwrv/Makefile
    5051psxrwlock01/Makefile
    5152psxsem01/Makefile
    5253psxspin01/Makefile
  • testsuites/psxtests/include/pmacros.h

    RCS file: /usr1/CVS/rtems/testsuites/psxtests/include/pmacros.h,v
    retrieving revision 1.6
    diff -u -r1.6 pmacros.h
     
    55#ifndef __POSIX_TEST_MACROS_h
    66#define __POSIX_TEST_MACROS_h
    77
     8#if defined(__rtems__)
    89#include <bsp.h>
     10#endif
    911#include <pthread.h>
    1012#include <assert.h>
    1113#include <stdio.h>
  • new file testsuites/psxtests/psxrdwrv/.cvsignore

    RCS file: testsuites/psxtests/psxrdwrv/.cvsignore
    diff -N testsuites/psxtests/psxrdwrv/.cvsignore
    - +  
     1Makefile
     2Makefile.in
  • new file testsuites/psxtests/psxrdwrv/Makefile.am

    RCS file: testsuites/psxtests/psxrdwrv/Makefile.am
    diff -N testsuites/psxtests/psxrdwrv/Makefile.am
    - +  
     1##
     2## $Id: Makefile.am,v 1.23 2006/07/11 04:50:25 ralf Exp $
     3##
     4
     5MANAGERS = all
     6
     7rtems_tests_PROGRAMS = psxrdwrv.exe
     8psxrdwrv_exe_SOURCES = main.c test.c ../include/pmacros.h
     9
     10dist_rtems_tests_DATA = psxrdwrv.scn
     11
     12include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg
     13include $(top_srcdir)/../automake/compile.am
     14include $(top_srcdir)/../automake/leaf.am
     15
     16psxrdwrv_exe_LDADD = $(MANAGERS_NOT_WANTED:%=$(PROJECT_LIB)/no-%.rel)
     17
     18AM_CPPFLAGS += -I$(top_srcdir)/include
     19AM_CPPFLAGS += -I$(top_srcdir)/../support/include
     20
     21LINK_OBJS = $(psxrdwrv_exe_OBJECTS) $(psxrdwrv_exe_LDADD)
     22LINK_LIBS = $(psxrdwrv_exe_LDLIBS)
     23
     24psxrdwrv.exe$(EXEEXT): $(psxrdwrv_exe_OBJECTS) $(psxrdwrv_exe_DEPENDENCIES)
     25        @rm -f psxrdwrv.exe$(EXEEXT)
     26        $(make-exe)
     27
     28include $(top_srcdir)/../automake/local.am
  • new file testsuites/psxtests/psxrdwrv/main.c

    RCS file: testsuites/psxtests/psxrdwrv/main.c
    diff -N testsuites/psxtests/psxrdwrv/main.c
    - +  
     1/*
     2 *  Simple test program -- simplified version of sample test hello.
     3 *
     4 *  COPYRIGHT (c) 1989-1999.
     5 *  On-Line Applications Research Corporation (OAR).
     6 *
     7 *  The license and distribution terms for this file may be
     8 *  found in the file LICENSE in this distribution or at
     9 *  http://www.rtems.com/license/LICENSE.
     10 *
     11 *  $Id: main.c,v 1.6 2004/04/01 15:16:20 ralf Exp $
     12 */
     13
     14#define TEST_INIT
     15
     16#include <bsp.h>
     17#include <pmacros.h>
     18
     19void test_main( void );
     20
     21rtems_task Init(
     22  rtems_task_argument ignored
     23)
     24{
     25  test_main();
     26  rtems_test_exit( 0 );
     27}
     28
     29/* configuration information */
     30
     31#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
     32#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
     33
     34#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
     35#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 6
     36
     37#define CONFIGURE_MAXIMUM_TASKS 1
     38
     39#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
     40
     41#define CONFIGURE_INIT
     42
     43#include <rtems/confdefs.h>
     44
     45/* end of file */
  • new file testsuites/psxtests/psxrdwrv/psxrdwrv.scn

    RCS file: testsuites/psxtests/psxrdwrv/psxrdwrv.scn
    diff -N testsuites/psxtests/psxrdwrv/psxrdwrv.scn
    - +  
     1*** POSIX TEST READV/WRITEV ***
     2writev bad file descriptor -- EBADF
     3readv bad file descriptor -- EBADF
     4writev bad iovec pointer -- EINVAL
     5readv bad iovec pointer -- EINVAL
     6readv bad iovcnt of 0 -- EINVAL
     7readv bad iovcnt of 0 -- EINVAL
     8writev bad iovcnt negative -- EINVAL
     9readv bad iovcnt negative -- EINVAL
     10writev bad iov[i].iov_base -- EINVAL
     11readv bad iov[i].iov_base -- EINVAL
     12writev bad iov[i].iov_len < 0 -- EINVAL
     13readv bad iov[i].iov_len = 0 -- EINVAL
     14writev iov_len total overflows -- EINVAL
     15readv iov_len total overflows -- EINVAL
     16File written using writev .. OK
     17File read using readv .. OK
     18*** END OF TEST PSXRDWRV ***
  • new file testsuites/psxtests/psxrdwrv/test.c

    RCS file: testsuites/psxtests/psxrdwrv/test.c
    diff -N testsuites/psxtests/psxrdwrv/test.c
    - +  
     1/*
     2 *  Psx13
     3 *
     4 *  This test exercises the following routines:
     5 *
     6 *  readv - implemented
     7 *  writev - implemented
     8 *
     9 *
     10 *  COPYRIGHT (c) 1989-2007.
     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: test.c,v 1.10 2004/04/16 09:23:25 ralf Exp $
     18 */
     19
     20
     21#include <fcntl.h>
     22#include <unistd.h>
     23#include <errno.h>
     24#include <utime.h>
     25#include <string.h>
     26#include <inttypes.h>
     27
     28#include <stdio.h>
     29#include <unistd.h>
     30#include <sys/uio.h>
     31
     32#if defined(__rtems__)
     33  #include <rtems.h>
     34  #include <rtems/libio.h>
     35  #include <pmacros.h>
     36#else
     37  #define TRUE  1
     38  #define FALSE 0
     39  #include <stdlib.h>
     40  #define rtems_test_exit(_s) exit(_s)
     41#endif
     42
     43#define TESTFILE "testfile1.tst"
     44
     45
     46/* This buffer size is assumed in the iovec initialization below */
     47#define MAX_BUFFER 1000
     48unsigned char PatternBuffer[MAX_BUFFER];
     49unsigned char ReadBuffer[MAX_BUFFER];
     50
     51/*
     52 * fillPatternBuffer function
     53 *
     54 * Fill the test buffer.
     55 *
     56 * Returns: TRUE if buffer filled
     57 *          FALSE if buffer failed to fill
     58 *
     59 */
     60
     61int fillPatternBuffer(void)
     62{
     63  int retval = TRUE;
     64  int i;
     65
     66  for (i=0 ; i<200  ; i++ ) PatternBuffer[i] = 'a';
     67  for (    ; i<400  ; i++ ) PatternBuffer[i] = 'b';
     68  for (    ; i<600  ; i++ ) PatternBuffer[i] = 'c';
     69  for (    ; i<800  ; i++ ) PatternBuffer[i] = 'd';
     70  for (    ; i<1000 ; i++ ) PatternBuffer[i] = 'e';
     71  return retval;
     72}
     73
     74/*
     75 * doFunctionalTest function
     76 *
     77 * Write a file with writev and then read it back with readv.
     78 *
     79 * Returns: TRUE if all operations worked as expected
     80 *          FALSE if an operation did not work as expected.
     81 *
     82 */
     83
     84int doFunctionalTest(void) {
     85  FILE         *fp;
     86  int           fd;
     87  struct iovec  rdvec[4];
     88  struct iovec  wrvec[4];
     89  int           rc;
     90
     91 
     92  /*
     93   * Setup the iovec
     94   */
     95  wrvec[0].iov_base = &PatternBuffer[0];
     96  wrvec[0].iov_len  = 100;
     97  wrvec[1].iov_base = &PatternBuffer[100];
     98  wrvec[1].iov_len  = 200;
     99  wrvec[2].iov_base = &PatternBuffer[300];
     100  wrvec[2].iov_len  = 300;
     101  wrvec[3].iov_base = &PatternBuffer[600];
     102  wrvec[3].iov_len  = 400;
     103
     104  rdvec[0].iov_base = &ReadBuffer[0];
     105  rdvec[0].iov_len  = 400;
     106  rdvec[1].iov_base = &ReadBuffer[400];
     107  rdvec[1].iov_len  = 300;
     108  rdvec[2].iov_base = &ReadBuffer[700];
     109  rdvec[2].iov_len  = 200;
     110  rdvec[3].iov_base = &ReadBuffer[900];
     111  rdvec[3].iov_len  = 100;
     112
     113  /*
     114   * Write the File
     115   */
     116  fp = fopen(TESTFILE, "wt");
     117  if ( fp == NULL ) {
     118    printf( "fopen for write: %d=%s\n", errno, strerror(errno));
     119    return FALSE;
     120  }
     121  fd = fileno(fp);
     122
     123  rc = writev(fd, wrvec, 4);
     124  if ( rc <= 0 ) {
     125    printf( "writev: %d=%s\n", errno, strerror(errno) );
     126    return FALSE;
     127  }
     128
     129  fclose(fp);
     130
     131  puts("File written using writev .. OK");
     132
     133  /*
     134   * Now read it back and check it
     135   */
     136
     137  fp = fopen(TESTFILE, "rt");
     138  if ( fp == NULL ) {
     139    printf( "fopen for write: %d=%s\n", errno, strerror(errno));
     140    return FALSE;
     141  }
     142  fd = fileno(fp);
     143
     144  rc = readv(fd, rdvec, 4);
     145  if ( rc <= 0 ) {
     146    printf( "rd: %d=%s\n", errno, strerror(errno) );
     147    return FALSE;
     148  }
     149
     150  if ( memcmp( PatternBuffer, ReadBuffer, MAX_BUFFER ) ) {
     151    puts("readv .. Buffers do not match");
     152    return FALSE;
     153  }
     154
     155  puts("File read using readv .. OK");
     156
     157  return TRUE;
     158}
     159
     160/*
     161 * doErrorTest function
     162 *
     163 * Hit all the error cases in readv/writev.
     164 *
     165 * Returns: TRUE if all operations worked as expected
     166 *          FALSE if an operation did not work as expected.
     167 *
     168 */
     169
     170int doErrorTest(void)
     171{
     172  FILE         *fp;
     173  int           fd;
     174  struct iovec  vec[4];
     175  int           rc;
     176
     177  /*
     178   * Open and close the file to get a bad file descriptor
     179   */
     180  fp = fopen(TESTFILE, "wt");
     181  if ( fp == NULL ) {
     182    printf( "fopen for error 1: %d=%s\n", errno, strerror(errno));
     183    return FALSE;
     184  }
     185  fd = fileno(fp);
     186  fclose(fp);
     187
     188  /* writev -- bad file descriptor */
     189  puts("writev bad file descriptor -- EBADF");
     190  rc = writev(fd, vec, 4);
     191  if ( (rc != -1) || (errno != EBADF) ) {
     192    printf( "writev error 1: %d=%s\n", errno, strerror(errno) );
     193    return FALSE;
     194  }
     195
     196  /* readv -- bad file descriptor */
     197  puts("readv bad file descriptor -- EBADF");
     198  rc = read(fd, vec, 4);
     199  if ( (rc != -1) || (errno != EBADF) ) {
     200    printf( "readv error 1: %d=%s\n", errno, strerror(errno) );
     201    return FALSE;
     202  }
     203
     204  /*
     205   * Open the file for the rest of the tests
     206   */
     207  fp = fopen(TESTFILE, "wt");
     208  if ( fp == NULL ) {
     209    printf( "fopen for error 2: %d=%s\n", errno, strerror(errno));
     210    return FALSE;
     211  }
     212  fd = fileno(fp);
     213
     214  /* writev --  bad iovec pointer */
     215  puts("writev bad iovec pointer -- EINVAL");
     216  rc = writev(fd, NULL, 4);
     217  if ( (rc != -1) || (errno != EINVAL) ) {
     218    printf( "writev error 2: %d=%s\n", errno, strerror(errno) );
     219    fclose(fp);
     220    return FALSE;
     221  }
     222
     223  /* readv --  bad iovec pointer */
     224  puts("readv bad iovec pointer -- EINVAL");
     225  rc = readv(fd, NULL, 4);
     226  if ( (rc != -1) || (errno != EINVAL) ) {
     227    printf( "readv error 2: %d=%s\n", errno, strerror(errno) );
     228    fclose(fp);
     229    return FALSE;
     230  }
     231
     232  /* writev --  bad iovcnt 0 */
     233  puts("readv bad iovcnt of 0 -- EINVAL");
     234  rc = writev(fd, vec, 0);
     235  if ( (rc != -1) || (errno != EINVAL) ) {
     236    printf( "writev error 3: %d=%s\n", errno, strerror(errno) );
     237    fclose(fp);
     238    return FALSE;
     239  }
     240
     241  /* readv --  bad iovcnt 0 */
     242  puts("readv bad iovcnt of 0 -- EINVAL");
     243  rc = readv(fd, vec, 0);
     244  if ( (rc != -1) || (errno != EINVAL) ) {
     245    printf( "readv error 3: %d=%s\n", errno, strerror(errno) );
     246    fclose(fp);
     247    return FALSE;
     248  }
     249
     250  /* writev --  bad iovcnt negative */
     251  puts("writev bad iovcnt negative -- EINVAL");
     252  rc = writev(fd, vec, -2);
     253  if ( (rc != -1) || (errno != EINVAL) ) {
     254    printf( "writev error 4: %d=%s\n", errno, strerror(errno) );
     255    fclose(fp);
     256    return FALSE;
     257  }
     258
     259  /* readv --  bad iovcnt negative */
     260  puts("readv bad iovcnt negative -- EINVAL");
     261  rc = readv(fd, vec, -100);
     262  if ( (rc != -1) || (errno != EINVAL) ) {
     263    printf( "readv error 4: %d=%s\n", errno, strerror(errno) );
     264    fclose(fp);
     265    return FALSE;
     266  }
     267
     268  /* writev --  bad iov[i].iov_base */
     269  vec[0].iov_base = vec;
     270  vec[0].iov_len = 100;
     271  vec[1].iov_base = NULL;
     272  vec[1].iov_len = 100;
     273  puts("writev bad iov[i].iov_base -- EINVAL");
     274  rc = writev(fd, vec, 2);
     275  if ( (rc != -1) || (errno != EINVAL) ) {
     276    printf( "writev error 5: %d=%s\n", errno, strerror(errno) );
     277    fclose(fp);
     278    return FALSE;
     279  }
     280
     281  /*  readv --  bad iov[i].iov_base */
     282  vec[0].iov_base = vec;
     283  vec[0].iov_len = 100;
     284  vec[1].iov_base = NULL;
     285  vec[1].iov_len = 100;
     286  puts("readv bad iov[i].iov_base -- EINVAL");
     287  rc = readv(fd, vec, 2);
     288  if ( (rc != -1) || (errno != EINVAL) ) {
     289    printf( "readv error 5: %d=%s\n", errno, strerror(errno) );
     290    fclose(fp);
     291    return FALSE;
     292  }
     293
     294  /*  writev --  bad iov[i].iov_len < 0 */
     295  vec[0].iov_base = vec;
     296  vec[0].iov_len = 100;
     297  vec[1].iov_base = vec;
     298  vec[1].iov_len = -10;
     299  puts("writev bad iov[i].iov_len < 0 -- EINVAL");
     300  rc = writev(fd, vec, 2);
     301  if ( (rc != -1) || (errno != EINVAL) ) {
     302    printf( "writev error 6: %d=%s\n", errno, strerror(errno) );
     303    fclose(fp);
     304    return FALSE;
     305  }
     306
     307  /*  readv --  bad iov[i].iov_len = 0 */
     308  vec[0].iov_base = vec;
     309  vec[0].iov_len = 100;
     310  vec[1].iov_base = vec;
     311  vec[1].iov_len = -1024;
     312  puts("readv bad iov[i].iov_len = 0 -- EINVAL");
     313  rc = readv(fd, vec, 2);
     314  if ( (rc != -1) || (errno != EINVAL) ) {
     315    printf( "readv error 6: %d=%s\n", errno, strerror(errno) );
     316    fclose(fp);
     317    return FALSE;
     318  }
     319
     320  /*  writev --  iov_len total overflows */
     321  vec[0].iov_base = vec;
     322  vec[0].iov_len = SSIZE_MAX;
     323  vec[1].iov_base = vec;
     324  vec[1].iov_len = SSIZE_MAX;
     325  vec[2].iov_base = vec;
     326  vec[2].iov_len = SSIZE_MAX;
     327  puts("writev iov_len total overflows -- EINVAL");
     328  rc = writev(fd, vec, 3);
     329  if ( (rc != -1) || (errno != EINVAL) ) {
     330    printf( "writev error 7: %d=%s\n", errno, strerror(errno) );
     331    fclose(fp);
     332    return FALSE;
     333  }
     334
     335  /*  readv --  iov_len total overflows */
     336  vec[0].iov_base = vec;
     337  vec[0].iov_len = SSIZE_MAX;
     338  vec[1].iov_base = vec;
     339  vec[1].iov_len = SSIZE_MAX;
     340  puts("readv iov_len total overflows -- EINVAL");
     341  rc = readv(fd, vec, 2);
     342  if ( (rc != -1) || (errno != EINVAL) ) {
     343    printf( "readv error 7: %d=%s\n", errno, strerror(errno) );
     344    fclose(fp);
     345    return FALSE;
     346  }
     347
     348  /*  writev --  all zero length buffers */
     349  vec[0].iov_base = vec;
     350  vec[0].iov_len = 0;
     351  vec[1].iov_base = vec;
     352  vec[1].iov_len = 0;
     353  puts("writev iov_len works with no effect -- OK");
     354  rc = writev(fd, vec, 2);
     355  if ( (rc != 0) ) {
     356    printf( "writev error 8: %d=%s\n", errno, strerror(errno) );
     357    fclose(fp);
     358    return FALSE;
     359  }
     360
     361  /*  readv --  all zero length buffers */
     362  vec[0].iov_base = vec;
     363  vec[0].iov_len = 0;
     364  vec[1].iov_base = vec;
     365  vec[1].iov_len = 0;
     366  puts("readv iov_len works with no effect -- OK");
     367  rc = readv(fd, vec, 2);
     368  if ( (rc != 0) ) {
     369    printf( "readv error 8: %d=%s\n", errno, strerror(errno) );
     370    fclose(fp);
     371    return FALSE;
     372  }
     373
     374  fclose(fp);
     375  return TRUE;
     376}
     377
     378
     379/* ---------------------------------------------------------------
     380 * Main function
     381 *
     382 *  main entry point to the test
     383 *
     384 * ---------------------------------------------------------------
     385 */
     386
     387#if defined(__rtems__)
     388int test_main(void)
     389#else
     390int main(
     391  int    argc,
     392  char **argv
     393)
     394#endif
     395{
     396  puts( "*** POSIX TEST READV/WRITEV ***" );
     397
     398  if ( fillPatternBuffer() != TRUE ) {
     399    puts("Error filling pattern buffer" );
     400    rtems_test_exit(0);
     401  }
     402
     403  if (doErrorTest() != TRUE) {
     404    puts("Error during error test!!!!");
     405    rtems_test_exit(0);
     406  }
     407  if (doFunctionalTest() != TRUE) {
     408    puts("Error during functional test!!!!");
     409    rtems_test_exit(0);
     410  }
     411
     412  unlink(TESTFILE);
     413  puts( "*** END OF TEST PSXRDWRV ***" );
     414  rtems_test_exit(0);
     415}