diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2010-06-28 18:48:25 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2010-06-28 18:48:25 +0000 |
commit | 43efb633bafe8d413f9a0f76e140fde7d6d96311 (patch) | |
tree | a9bc294bee22d36dc65053add961a8c719ecace1 /testsuites/psxtests/psximfs01 | |
parent | 2010-06-28 Joel Sherrill <joel.sherrill@oarcorp.com> (diff) | |
download | rtems-43efb633bafe8d413f9a0f76e140fde7d6d96311.tar.bz2 |
2010-06-28 Joel Sherrill <joel.sherrill@oarcorp.com>
* Makefile.am, configure.ac: Add test to exercise IMFS behaviour with
files of maximum sizes.
* psximfs01/.cvsignore, psximfs01/Makefile.am, psximfs01/init.c,
psximfs01/psximfs01.doc, psximfs01/psximfs01.scn: New files.
Diffstat (limited to 'testsuites/psxtests/psximfs01')
-rw-r--r-- | testsuites/psxtests/psximfs01/.cvsignore | 2 | ||||
-rw-r--r-- | testsuites/psxtests/psximfs01/Makefile.am | 26 | ||||
-rw-r--r-- | testsuites/psxtests/psximfs01/init.c | 193 | ||||
-rw-r--r-- | testsuites/psxtests/psximfs01/psximfs01.doc | 35 | ||||
-rw-r--r-- | testsuites/psxtests/psximfs01/psximfs01.scn | 16 |
5 files changed, 272 insertions, 0 deletions
diff --git a/testsuites/psxtests/psximfs01/.cvsignore b/testsuites/psxtests/psximfs01/.cvsignore new file mode 100644 index 0000000000..282522db03 --- /dev/null +++ b/testsuites/psxtests/psximfs01/.cvsignore @@ -0,0 +1,2 @@ +Makefile +Makefile.in diff --git a/testsuites/psxtests/psximfs01/Makefile.am b/testsuites/psxtests/psximfs01/Makefile.am new file mode 100644 index 0000000000..d6b51337a9 --- /dev/null +++ b/testsuites/psxtests/psximfs01/Makefile.am @@ -0,0 +1,26 @@ +## +## $Id$ +## + +MANAGERS = all + +rtems_tests_PROGRAMS = psximfs01 +psximfs01_SOURCES = init.c + +dist_rtems_tests_DATA = psximfs01.scn +dist_rtems_tests_DATA += psximfs01.doc + +include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg +include $(top_srcdir)/../automake/compile.am +include $(top_srcdir)/../automake/leaf.am + +AM_CPPFLAGS += -I$(top_srcdir)/../support/include + +LINK_OBJS = $(psximfs01_OBJECTS) $(psximfs01_LDADD) +LINK_LIBS = $(psximfs01_LDLIBS) + +psximfs01$(EXEEXT): $(psximfs01_OBJECTS) $(psximfs01_DEPENDENCIES) + @rm -f psximfs01$(EXEEXT) + $(make-exe) + +include $(top_srcdir)/../automake/local.am diff --git a/testsuites/psxtests/psximfs01/init.c b/testsuites/psxtests/psximfs01/init.c new file mode 100644 index 0000000000..dcdd813e59 --- /dev/null +++ b/testsuites/psxtests/psximfs01/init.c @@ -0,0 +1,193 @@ +/* + * COPYRIGHT (c) 1989-2010. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#include <tmacros.h> +#include "test_support.h" + +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <errno.h> + +int TestFd; +uint8_t Buffer[256]; +ssize_t TotalWritten; + +#define FILE_NAME "biggie" + +void open_it(bool readOnly, bool create) +{ + int flag = 0; + + if ( readOnly ) + flag |= O_RDONLY; + else { + if ( create ) + flag |= O_CREAT; + flag |= O_RDWR; + } + + /* open the file */ + puts( "open(" FILE_NAME ") - OK " ); + TestFd = open( FILE_NAME, flag, 0777 ); + rtems_test_assert( TestFd != -1 ); +} + +void write_helper(void) +{ + ssize_t written; + + TotalWritten = 0; + puts( "write(" FILE_NAME ") - OK " ); + do { + written = write( TestFd, Buffer, sizeof(Buffer) ); + if ( written == -1 ) { + if ( errno == ENOSPC ) { + printf( "Total written = %d\n", TotalWritten ); + return; + } + fprintf( + stderr, + "Unable to create largest IMFS file (error=%s)\n", + strerror(errno) + ); + rtems_test_exit(0); + } + TotalWritten += written; + } while (1); + +} + +void read_helper(void) +{ + uint8_t ch; + ssize_t sc; + int i=0; + + puts( "read(" FILE_NAME ") - OK " ); + do { + sc = read( TestFd, &ch, sizeof(ch) ); + if ( sc == 1 ) { + if ( ch != (i%256) ) { + fprintf( + stderr, + "MISMATCH 0x%02x != 0x%02x at offset %d\n", + ch, + i % 256, + i + ); + rtems_test_exit(0); + } + i++; + continue; + } + /* Unsure if ENOSPC is the write error to be returned */ + if ( errno == ENOSPC && i == TotalWritten ) { + puts( "File correctly read until ENOSPC returned\n" ); + return; + } + fprintf( + stderr, + "ERROR - at offset %d - returned %d and error=%s\n", + i, + sc, + strerror( errno ) + ); + rtems_test_exit(0); + } while (1); +} + +void truncate_helper(void) +{ + off_t position; + off_t new; + off_t sc; + int rc; + + position = lseek( TestFd, 0, SEEK_END ); + printf( "Seek to end .. returned %d\n", (int) position ); + rtems_test_assert( position == TotalWritten ); + + puts( "lseek/ftruncate loop.." ); + new = position; + do { + sc = lseek( TestFd, new, SEEK_SET ); + rtems_test_assert( sc == new ); + + rc = ftruncate( TestFd, new ); + if ( rc != 0 ) { + fprintf( + stderr, + "ERROR - at offset %d - returned %d and error=%s\n", + (int) new, + rc, + strerror( errno ) + ); + } + rtems_test_assert( rc == 0 ); + --new; + } while (new > 0); +} + +void close_it(void) +{ + int rc; + + puts( "close(" FILE_NAME ") - OK " ); + rc = close( TestFd ); + rtems_test_assert( rc == 0 ); +} + +rtems_task Init( + rtems_task_argument argument +) +{ + int i; + puts( "\n\n*** TEST IMFS 01 ***" ); + + for (i=0 ; i<sizeof(Buffer) ; i++ ) + Buffer[i] = (uint8_t) i; + + open_it(false, true); + write_helper(); + close_it(); + + puts( "" ); + + open_it(true, false); + read_helper(); + close_it(); + + open_it(false, false); + truncate_helper(); + close_it(); + + + puts( "*** END OF TEST IMFS 01 ***" ); + + rtems_test_exit(0); +} + +/* configuration information */ + +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER + +#define CONFIGURE_MAXIMUM_TASKS 1 +#define CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK 16 +#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4 +#define CONFIGURE_RTEMS_INIT_TASKS_TABLE + +#define CONFIGURE_INIT + +#include <rtems/confdefs.h> +/* end of file */ diff --git a/testsuites/psxtests/psximfs01/psximfs01.doc b/testsuites/psxtests/psximfs01/psximfs01.doc new file mode 100644 index 0000000000..13125231a3 --- /dev/null +++ b/testsuites/psxtests/psximfs01/psximfs01.doc @@ -0,0 +1,35 @@ +# +# $Id$ +# +# COPYRIGHT (c) 1989-2010. +# On-Line Applications Research Corporation (OAR). +# +# The license and distribution terms for this file may be +# found in the file LICENSE in this distribution or at +# http://www.rtems.com/license/LICENSE. +# + +This file describes the directives and concepts tested by this test set. + +test set name: psximfs01 + +directives: + + + open + + close + + read + + write + + lseek + + ftruncate + +concepts: + ++ Create an IMFS instance with the smallest possible block size. This +ensures the maximum file size is relatively small. + ++ Create, write, and read a file of maximum size. + ++ Use ftruncate to shorten the file from the maximum size to 0. + ++ This should exercise much of the singly, doubly and triply indirect +block management code in the IMFS. diff --git a/testsuites/psxtests/psximfs01/psximfs01.scn b/testsuites/psxtests/psximfs01/psximfs01.scn new file mode 100644 index 0000000000..2d3b3877a4 --- /dev/null +++ b/testsuites/psxtests/psximfs01/psximfs01.scn @@ -0,0 +1,16 @@ +*** TEST IMFS 01 *** +open(biggie) - OK +write(biggie) - OK +Total written = 1280 +close(biggie) - OK + +open(biggie) - OK +read(biggie) - OK +File correctly read until ENOSPC returned + +close(biggie) - OK +open(biggie) - OK +Seek to end .. returned 1280 +lseek/ftruncate loop.. +close(biggie) - OK +*** END OF TEST IMFS 01 *** |