From 0895bdb89c1674d01ecb9886a0624096ef939ad1 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Mon, 23 Nov 1998 18:57:48 +0000 Subject: Added tests in support of the file system infrastructure. --- c/src/tests/psxtests/psxfile01/Makefile.in | 63 ++++ c/src/tests/psxtests/psxfile01/main.c | 40 +++ c/src/tests/psxtests/psxfile01/psxfile01.scn | 168 ++++++++++ c/src/tests/psxtests/psxfile01/test.c | 475 +++++++++++++++++++++++++++ 4 files changed, 746 insertions(+) create mode 100644 c/src/tests/psxtests/psxfile01/Makefile.in create mode 100644 c/src/tests/psxtests/psxfile01/main.c create mode 100644 c/src/tests/psxtests/psxfile01/psxfile01.scn create mode 100644 c/src/tests/psxtests/psxfile01/test.c (limited to 'c/src/tests/psxtests/psxfile01') diff --git a/c/src/tests/psxtests/psxfile01/Makefile.in b/c/src/tests/psxtests/psxfile01/Makefile.in new file mode 100644 index 0000000000..bedede978e --- /dev/null +++ b/c/src/tests/psxtests/psxfile01/Makefile.in @@ -0,0 +1,63 @@ +# +# $Id$ +# + +@SET_MAKE@ +srcdir = @srcdir@ +VPATH = @srcdir@:@srcdir@/../filesupp +RTEMS_ROOT = @top_srcdir@ +PROJECT_ROOT = @PROJECT_ROOT@ + +TEST=file01 + +MANAGERS=all + +# C source names, if any, go here -- minus the .c +C_PIECES=main test test_cat test_extend test_write +C_FILES=$(C_PIECES:%=%.c) +C_O_FILES=$(C_PIECES:%=${ARCH}/%.o) + +H_FILES= + +DOCTYPES=scn +DOCS=$(DOCTYPES:%=$(TEST).%) + +SRCS=$(DOCS) $(C_FILES) $(H_FILES) +OBJS=$(C_O_FILES) + +PRINT_SRCS=$(DOCS) + +PGM=${ARCH}/$(TEST).exe + +include $(RTEMS_ROOT)/make/custom/$(RTEMS_BSP).cfg +include $(RTEMS_ROOT)/make/leaf.cfg + +# +# (OPTIONAL) Add local stuff here using += +# + +DEFINES += +CPPFLAGS += +CFLAGS += + +LD_PATHS += +LD_LIBS += +LDFLAGS += + +# +# Add your list of files to delete here. The config files +# already know how to delete some stuff, so you may want +# to just run 'make clean' first to see what gets missed. +# 'make clobber' already includes 'make clean' +# + +CLEAN_ADDITIONS += +CLOBBER_ADDITIONS += + +all: ${ARCH} $(SRCS) $(PGM) + $(INSTALL_VARIANT) -m 555 ${PGM} ${PROJECT_RELEASE}/tests + $(INSTALL) $(srcdir)/$(TEST).scn \ + ${PROJECT_RELEASE}/tests/screens/psxtests/$(TEST).scn + +${PGM}: $(OBJS) $(LINK_FILES) + $(make-exe) diff --git a/c/src/tests/psxtests/psxfile01/main.c b/c/src/tests/psxtests/psxfile01/main.c new file mode 100644 index 0000000000..37658f4feb --- /dev/null +++ b/c/src/tests/psxtests/psxfile01/main.c @@ -0,0 +1,40 @@ +/* + * Simple test program -- simplified version of sample test hello. + * + * COPYRIGHT (c) 1989-1998. + * On-Line Applications Research Corporation (OAR). + * Copyright assigned to U.S. Government, 1994. + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.OARcorp.com/rtems/license.html. + * + * $Id$ + */ + +#define TEST_INIT + +#include + +void test_main( void ); + +rtems_task Init( + rtems_task_argument ignored +) +{ + test_main(); + exit( 0 ); +} + +/* configuration information */ + +#define CONFIGURE_TEST_NEEDS_CONSOLE_DRIVER +#define CONFIGURE_TEST_NEEDS_CLOCK_DRIVER + +#define CONFIGURE_RTEMS_INIT_TASKS_TABLE + +#define CONFIGURE_INIT + +#include + +/* end of file */ diff --git a/c/src/tests/psxtests/psxfile01/psxfile01.scn b/c/src/tests/psxtests/psxfile01/psxfile01.scn new file mode 100644 index 0000000000..e105dafb89 --- /dev/null +++ b/c/src/tests/psxtests/psxfile01/psxfile01.scn @@ -0,0 +1,168 @@ + + +*** FILE TEST 1 *** +*************** Dump of Entire IMFS *************** +/ + dev/ + console (device 0, 0) +*************** End of Dump *************** +stat of /dev/console + st_dev (0x0:0x0) + st_ino 3 + mode = 00020771 + nlink = 1 + uid = 0 + gid = 0 + atime = Fri Jan 01 00:00:00 1988 + mtime = Fri Jan 01 00:00:00 1988 + ctime = Fri Jan 01 00:00:00 1988 + +mkdir /dev/tty + +mkdir /usr +mkdir /etc +mkdir /tmp +mkdir /tmp/.. +mkdir /tmp/ +mkdir /j/j1 +mkdir tmp + +rmdir /usr +mkdir /etc/passwd/j +open /tmp/joel - should fail with ENOENT +open /tmp/j +open returned file descriptor 3 +close /tmp/j +unlink /tmp/j +(0)the first write!!! + +(10)the first write!!! + +stat( /tmp/joel ) returned st_dev (0x1a7f8:0x3e86f0) + st_ino d + mode = 00100700 + nlink = 1 + uid = 0 + gid = 0 + atime = Sat Dec 31 09:00:00 1988 + mtime = Sat Dec 31 09:00:00 1988 + ctime = Sat Dec 31 09:00:00 1988 +(514)the first write!!! + +(513)the first write!!! + +(24)the first write!!! + +(2)the first write!!! + +(1)the first write!!! + +(0)the first write!!! + +(0)rst write!!! + +(513)the first write!!! + +(139743) +stat( /tmp/joel ) returned st_dev (0x1a7f8:0x3e86f0) + st_ino e + mode = 00100700 + nlink = 1 + uid = 0 + gid = 0 + atime = Sat Dec 31 09:00:00 1988 + mtime = Sat Dec 31 09:00:00 1988 + ctime = Sat Dec 31 09:00:00 1988 +stat of /tmp/j +stat(/tmp/j) returned -1 (errno=2) + st_dev (0x0:0x0) + st_ino 3 + mode = 00020771 + nlink = 1 + uid = 0 + gid = 0 + atime = Fri Jan 01 00:00:00 1988 + mtime = Fri Jan 01 00:00:00 1988 + ctime = Fri Jan 01 00:00:00 1988 +fopen of /tmp/j +fprintf to /tmp/j +(1) 26 characters written to the file +(2) 26 characters written to the file +(3) 26 characters written to the file +(4) 26 characters written to the file +(5) 26 characters written to the file + st_dev (0x0:0x0) + st_ino f + mode = 00100660 + nlink = 1 + uid = 0 + gid = 0 + atime = Sat Dec 31 09:00:00 1988 + mtime = Sat Dec 31 09:00:00 1988 + ctime = Sat Dec 31 09:00:00 1988 +This is call 1 to fprintf +This is call 2 to fprintf +This is call 3 to fprintf +This is call 4 to fprintf +This is call 5 to fprintf + st_dev (0x0:0x0) + st_ino f + mode = 00100660 + nlink = 1 + uid = 0 + gid = 0 + atime = Sat Dec 31 09:00:01 1988 + mtime = Sat Dec 31 09:00:00 1988 + ctime = Sat Dec 31 09:00:00 1988 +*************** Dump of Entire IMFS *************** +/ + dev/ + console (device 0, 0) + tty/ + S3 (device 255, 128) + test_console (device 0, 0) + etc/ + passwd (file 0 0x0 0x0 0x0) + tmp/ + joel (file 279487 0x3d5ac0 0x3d5570 0x3d5020) + j (file 130 0x37f530 0x0 0x0) +*************** End of Dump *************** +truncate /tmp/j to length of 40 + st_dev (0x0:0x0) + st_ino f + mode = 00100660 + nlink = 1 + uid = 0 + gid = 0 + atime = Sat Dec 31 09:00:02 1988 + mtime = Sat Dec 31 09:00:00 1988 + ctime = Sat Dec 31 09:00:00 1988 +*************** Dump of Entire IMFS *************** +/ + dev/ + console (device 0, 0) + tty/ + S3 (device 255, 128) + test_console (device 0, 0) + etc/ + passwd (file 0 0x0 0x0 0x0) + tmp/ + j (file 40 0x37f530 0x0 0x0) +*************** End of Dump *************** +truncate /tmp/j to length of 0 +truncate /tmp to length of 0 should fail with EISDIR + +21: Is a directory +*************** Dump of Entire IMFS *************** +/ + dev/ + console (device 0, 0) + tty/ + S3 (device 255, 128) + test_console (device 0, 0) + etc/ + passwd (file 0 0x0 0x0 0x0) + tmp/ + j (file 0 0x37f530 0x0 0x0) +*************** End of Dump *************** +*** END OF FILE TEST 1 *** diff --git a/c/src/tests/psxtests/psxfile01/test.c b/c/src/tests/psxtests/psxfile01/test.c new file mode 100644 index 0000000000..ef0d737d44 --- /dev/null +++ b/c/src/tests/psxtests/psxfile01/test.c @@ -0,0 +1,475 @@ +/* + * Simple test program to exercise some of the basic functionality of + * POSIX Files and Directories Support. + * + * This test assumes that the file system is initialized with the + * following directory structure: + * + * XXXX fill this in. + * / + * /dev + * /dev/XXX [where XXX includes at least console] + * + * COPYRIGHT (c) 1989-1998. + * On-Line Applications Research Corporation (OAR). + * Copyright assigned to U.S. Government, 1994. + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.OARcorp.com/rtems/license.html. + * + * $Id$ + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +char test_write_buffer[ 1024 ]; + +/* + * File test support routines. + */ + +void test_cat( + char *file, + int offset_arg, + int length +); + +void test_write( + char *file, + off_t offset, + char *buffer +); + +void test_extend( + char *file, + off_t new_len +); + +void IMFS_dump( void ); +int IMFS_memfile_maximum_size( void ); + +/* + * dump_statbuf + */ + +void dump_statbuf( struct stat *buf ) +{ + int major1; + int minor1; + int major2; + int minor2; + + rtems_filesystem_split_dev_t( buf->st_dev, major1, minor1 ); + rtems_filesystem_split_dev_t( buf->st_rdev, major2, minor2 ); + + printf( " st_dev (0x%x:0x%x)\n", major1, minor1 ); + printf( " st_ino %x\n", buf->st_ino ); + printf( " mode = %08o\n", buf->st_mode ); + printf( " nlink = %d\n", buf->st_nlink ); + + printf( " uid = %d\n", buf->st_uid ); + printf( " gid = %d\n", buf->st_gid ); + + printf( " atime = %s", ctime(&buf->st_atime) ); + printf( " mtime = %s", ctime(&buf->st_mtime) ); + printf( " ctime = %s", ctime(&buf->st_ctime) ); + +#if defined(__svr4__) && !defined(__PPC__) && !defined(__sun__) + printf( " st_blksize %x\n", buf.st_blksize ); + printf( " st_blocks %x\n", buf.st_blocks ); +#endif + +} + +void stat_a_file( + const char *file +) +{ + int status; + struct stat statbuf; + + assert( file ); + + printf( "stat( %s ) returned ", file ); + fflush( stdout ); + + status = stat( file, &statbuf ); + + if ( status == -1 ) { + printf( ": %s\n", strerror( errno ) ); + } else { + dump_statbuf( &statbuf ); + } + +} + + +/* + * Main entry point of the test + */ + +#if defined(__rtems__) +int test_main(void) +#else +int main( + int argc, + char **argv +) +#endif +{ + int status; + int max_size; + int fd, fd1; + int i; + struct stat buf; + char buffer[128]; + FILE *file; + time_t atime1; + time_t mtime1; + time_t ctime1; + time_t atime2; + time_t mtime2; + time_t ctime2; + rtems_status_code rtems_status; + rtems_time_of_day time; + + printf( "\n\n*** FILE TEST 1 ***\n" ); + + /* + * Grab the maximum size of an in-memory file. + */ + + max_size = IMFS_memfile_maximum_size(); + + build_time( &time, 12, 31, 1988, 9, 0, 0, 0 ); + rtems_status = rtems_clock_set( &time ); + + /* + * Dump an empty file system + */ + + IMFS_dump(); + + /* + * Simple stat() of /dev/console. + */ + + puts( "stat of /dev/console" ); + status = stat( "/dev/console", &buf ); + assert( !status ); + + dump_statbuf( &buf ); + + /* + * Exercise mkdir() and some path evaluation. + */ + + puts( "" ); + puts( "mkdir /dev/tty" ); + status = mkdir( "/dev/tty", S_IRWXU ); + assert( !status ); + + puts( "" ); + puts( "mkdir /usr" ); + status = mkdir( "/usr", S_IRWXU ); + assert( !status ); + puts( "mkdir /etc" ); + status = mkdir( "/etc", S_IRWXU ); + assert( !status ); + + puts( "mkdir /tmp" ); + status = mkdir( "/tmp", S_IRWXU ); + assert( !status ); + + /* this tests the ".." path in path name evaluation */ + puts( "mkdir /tmp/.." ); + status = mkdir( "/tmp/..", S_IRWXU ); + assert( status == -1 ); + assert( errno == EEXIST ); + + /* now check out trailing separators */ + puts( "mkdir /tmp/" ); + status = mkdir( "/tmp/", S_IRWXU ); + assert( status == -1 ); + assert( errno == EEXIST ); + + /* try to make a directory under a non-existent subdirectory */ + puts( "mkdir /j/j1" ); + status = mkdir( "/j/j1", S_IRWXU ); + assert( status == -1 ); + assert( errno == ENOENT ); + + /* this tests the ability to make a directory in the current one */ + puts( "mkdir tmp" ); + status = mkdir( "tmp", S_IRWXU ); + assert( status == -1 ); + assert( errno == EEXIST ); + + /* test rtems_filesystem_evaluate_path by sending NULL path */ + status = chdir( NULL ); + assert( status == -1 ); + + /* + * Now switch gears and exercise rmdir(). + */ + + puts( "" ); + puts( "rmdir /usr" ); + status = rmdir( "/usr" ); + assert( !status ); + + status = rmdir( "/dev" ); + assert( status == -1 ); + assert( errno == ENOTEMPTY); + + status = rmdir ("/fred"); + assert (status == -1); + + status = mknod( "/dev/test_console", S_IFCHR, 0LL ); + assert( !status ); + status = mknod( "/dev/tty/S3", S_IFCHR, 0xFF00000080LL ); + assert( !status ); + status = mknod( "/etc/passwd", (S_IFREG | S_IRWXU), 0LL ); + assert( !status ); + + status = mkdir( "/tmp/my_dir", S_IRWXU ); + assert( status == 0 ); + + status = mkfifo( "/c/my_dir", S_IRWXU ); + assert( status == -1 ); + + /* + * Try to make a directory under a file -- ERROR + */ + + puts( "mkdir /etc/passwd/j" ); + status = mkdir( "/etc/passwd/j", S_IRWXU ); + assert( status == -1 ); + assert( errno == ENOTDIR ); + + /* + * Simple open failure case on non-existent file + */ + + puts( "open /tmp/joel - should fail with ENOENT" ); + fd = open( "/tmp/joel", O_RDONLY ); + assert( fd == -1 ); + assert( errno == ENOENT ); + + /* + * Simple open case where the file is created. + */ + + puts( "open /tmp/j" ); + fd = open( "/tmp/j", O_RDWR|O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO ); + assert( fd != -1 ); + + printf( "open returned file descriptor %d\n", fd ); + + puts( "close /tmp/j" ); + status = close( fd ); + assert( !status ); + + status = close( fd ); + assert( status == -1 ); + + puts( "unlink /tmp/j" ); + status = unlink( "/tmp/j" ); + assert( !status ); + + status = unlink( "/tmp" ); + assert( status ); + + /* + * Simple open failure. Trying to create an existing file. + */ + + fd = open( "/tmp/tom", O_CREAT ); + status = close( fd ); + fd1 = open( "/tmp/tom", O_CREAT ); + assert( fd1 == -1 ); + + fd = open( "/tmp/john", O_CREAT ); + assert( fd != -1 ); + status = tcdrain( fd ); + assert( status == 0 ); + + /* + * Test simple write to a file at offset 0 + */ + + status = mknod( "/tmp/joel", (S_IFREG | S_IRWXU), 0LL ); + test_write( "/tmp/joel", 0, "the first write!!!\n" ); + test_cat( "/tmp/joel", 0, 0 ); + + /* + * Test simple write to a file at a non-0 offset in the first block + */ + + status = unlink( "/tmp/joel" ); + assert( !status ); + + status = mknod( "/tmp/joel", (S_IFREG | S_IRWXU), 0LL ); + assert( !status ); + + test_write( "/tmp/joel", 10, "the first write!!!\n" ); + test_cat( "/tmp/joel", 0, 0 ); + stat_a_file( "/tmp/joel" ); + + /* + * Test simple write to a file at a non-0 offset in the second block. Then + * try to read from various offsets and lengths. + */ + + status = unlink( "/tmp/joel" ); + assert( !status ); + + /* Test a failure path */ + + status = unlink( "/tmp/joel" ); + assert( status == -1 ); + + status = mknod( "/tmp/joel", (S_IFREG | S_IRWXU), 0LL ); + assert( !status ); + + test_write( "/tmp/joel", 514, "the first write!!!\n" ); + test_write( "/tmp/joel", 1, test_write_buffer ); + test_write( "/tmp/joel", 63, test_write_buffer ); + test_cat( "/tmp/joel", 0, 1 ); + test_cat( "/tmp/joel", 1, 1 ); + test_cat( "/tmp/joel", 490, 1 ); + test_cat( "/tmp/joel", 512, 1 ); + test_cat( "/tmp/joel", 513, 1 ); + test_cat( "/tmp/joel", 514, 1 ); + test_cat( "/tmp/joel", 520, 1 ); + test_cat( "/tmp/joel", 1, 1024 ); + + /* + * Read from a much longer file so we can descend into doubly and + * triply indirect blocks. + */ + + test_extend( "/tmp/joel", max_size - 1 ); + test_cat( "/tmp/joel", max_size / 2, 1024 ); + + stat_a_file( "/tmp/joel" ); + + /* + * Now try to use a FILE * descriptor + * + * /tmp/j should not exist at this point. + */ + + puts( "stat of /tmp/j" ); + errno = 0; + status = stat( "/tmp/j", &buf ); + printf( "stat(/tmp/j) returned %d (errno=%d)\n", status, errno ); + dump_statbuf( &buf ); + + puts( "fopen of /tmp/j" ); + file = fopen( "/tmp/j", "w+" ); + assert( file ); + + puts( "fprintf to /tmp/j" ); + for (i=1 ; i<=5 ; i++) { + status = fprintf( file, "This is call %d to fprintf\n", i ); + assert( status ); + printf( "(%d) %d characters written to the file\n", i, status ); + } + + fflush( file ); + + status = stat( "/tmp/j", &buf ); + assert( !status ); + dump_statbuf( &buf ); + atime2 = buf.st_atime; + mtime2 = buf.st_mtime; + ctime2 = buf.st_ctime; + + + status = rtems_task_wake_after( 1 * TICKS_PER_SECOND ); + rewind( file ); + while ( fgets(buffer, 128, file) ) + printf( buffer ); + + /* + * Verify only atime changed for a read. + */ + status = stat( "/tmp/j", &buf ); + assert( !status ); + dump_statbuf( &buf ); + atime1 = buf.st_atime; + mtime1 = buf.st_mtime; + ctime1 = buf.st_ctime; + assert( atime1 != atime2); + assert( mtime1 == mtime2); + assert( ctime1 == ctime2); + + IMFS_dump(); + + unlink( "/tmp/joel" ); + + /* + * Now truncate a file + */ + + status = rtems_task_wake_after( 1 * TICKS_PER_SECOND ); + puts( "truncate /tmp/j to length of 40" ); + status = truncate( "/tmp/j", 40 ); + assert( !status ); + + /* + * Verify truncate changed only atime. + */ + status = stat( "/tmp/j", &buf ); + assert( !status ); + dump_statbuf( &buf ); + atime2 = buf.st_atime; + mtime2 = buf.st_mtime; + ctime2 = buf.st_ctime; + assert( atime1 != atime2); + assert( mtime1 == mtime2); + assert( ctime1 == ctime2); + + IMFS_dump(); + + /* try to truncate the console and see what happens */ + status = truncate( "/dev/console", 40 ); + assert(status == -1 ); + + puts( "truncate /tmp/j to length of 0" ); + status = truncate( "/tmp/j", 0 ); + assert( !status ); + + puts( "truncate /tmp to length of 0 should fail with EISDIR\n"); + status = truncate( "/tmp", 0 ); + assert( status == -1 ); + printf( "%d: %s\n", errno, strerror( errno ) ); + assert( errno == EISDIR ); + + IMFS_dump(); + + status = truncate( "/tmp/fred", 10 ); + assert( status == -1); + + rtems_status = rtems_io_register_name( "/dev/console", 0, 0 ); + + printf( "*** END OF FILE TEST 1 ***\n" ); + exit( 0 ); +} + + -- cgit v1.2.3