Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:47

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2012.
0005  *  On-Line Applications Research Corporation (OAR).
0006  *
0007  * Redistribution and use in source and binary forms, with or without
0008  * modification, are permitted provided that the following conditions
0009  * are met:
0010  * 1. Redistributions of source code must retain the above copyright
0011  *    notice, this list of conditions and the following disclaimer.
0012  * 2. Redistributions in binary form must reproduce the above copyright
0013  *    notice, this list of conditions and the following disclaimer in the
0014  *    documentation and/or other materials provided with the distribution.
0015  *
0016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0026  * POSSIBILITY OF SUCH DAMAGE.
0027  */
0028 
0029 #ifdef HAVE_CONFIG_H
0030 #include "config.h"
0031 #endif
0032 
0033 #include <bsp.h>
0034 #include <tmacros.h>
0035 #include <stdio.h>
0036 #include <sys/types.h>
0037 #include <sys/stat.h>
0038 #include <sys/ioctl.h>
0039 #include <fcntl.h>
0040 #include <unistd.h>
0041 #include <errno.h>
0042 
0043 #include <rtems.h>
0044 #include <rtems/libio.h>
0045 
0046 const char rtems_test_name[] = "SPFIFO 4";
0047 
0048 /* forward declarations to avoid warnings */
0049 rtems_task Init(rtems_task_argument argument);
0050 
0051 #define SEND_RCV_BUFSIZ 12
0052 
0053 rtems_task Init(
0054   rtems_task_argument not_used
0055 )
0056 {
0057   int fd = -1;
0058   int status = -1;
0059   off_t offset = 4;
0060   int pipe_length = -1;
0061   int flag = 1;
0062 
0063   TEST_BEGIN();
0064 
0065   puts( "Init - Creating /fifo" );
0066   status = mkfifo( "/fifo", 0777 );
0067   rtems_test_assert( status == 0 );
0068   
0069   puts( "Init - Opening /fifo in readonly, non-blocking mode" );
0070   fd = open( "/fifo", O_RDONLY | O_NONBLOCK );
0071   rtems_test_assert( fd != -1 );
0072   
0073   puts( "Init - Attempt to lseek on fifo -- Expected ESPIPE" );
0074   offset = lseek( fd, offset, SEEK_CUR );
0075   rtems_test_assert( offset == -1 );
0076   rtems_test_assert( errno == ESPIPE );
0077 
0078   puts( "Init - ioctl: FIONBIO -- Expected EFAULT" );
0079   status = ioctl( fd, FIONBIO, NULL );
0080   rtems_test_assert( status == -1 );
0081   rtems_test_assert( errno == EFAULT );
0082 
0083   puts( "Init - ioctl: FIONBIO -- OK" );
0084   status = ioctl( fd, FIONBIO, &flag );
0085   rtems_test_assert( status == 0 );
0086  
0087   flag = 0;
0088   puts( "Init - ioctl: FIONBIO -- OK" );
0089   status = ioctl( fd, FIONBIO, &flag );
0090   rtems_test_assert( status == 0 );
0091 
0092   puts( "Init - ioctl: Dummy Command -- Expected EINVAL" );
0093   status = ioctl( fd, -1, NULL );
0094   rtems_test_assert( status == -1 );
0095   rtems_test_assert( errno == EINVAL );
0096 
0097   puts( "Init - ioctl: FIONREAD -- Expected EFAULT" );
0098   status = ioctl( fd, FIONREAD, NULL );
0099   rtems_test_assert( status == -1 );
0100   rtems_test_assert( errno == EFAULT );
0101 
0102   puts( "Init - ioctl: FIONREAD -- OK" );
0103   status = ioctl( fd, FIONREAD, &pipe_length );
0104   rtems_test_assert( status == 0 );
0105   rtems_test_assert( pipe_length == 0 );
0106   
0107   puts( "Init - closing /fifo" );
0108   status = close( fd );
0109   rtems_test_assert( status == 0 );
0110   
0111   puts( "Init - removing /fifo" );
0112   status = unlink( "/fifo" );
0113   rtems_test_assert( status == 0 );
0114 
0115   TEST_END();
0116   rtems_test_exit(0);
0117 }
0118 
0119 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0120 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0121 
0122 #define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 6
0123 
0124 #define CONFIGURE_MAXIMUM_TASKS 3
0125 
0126 #define CONFIGURE_IMFS_ENABLE_MKFIFO
0127 
0128 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0129 
0130 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0131 
0132 #define CONFIGURE_INIT
0133 #include <rtems/confdefs.h>
0134 /* end of file */