diff options
author | Ralf Corsepius <ralf.corsepius@rtems.org> | 2003-11-11 00:59:49 +0000 |
---|---|---|
committer | Ralf Corsepius <ralf.corsepius@rtems.org> | 2003-11-11 00:59:49 +0000 |
commit | ff6ab1b594d9f073ece9b7fedf1f6977f52aeee5 (patch) | |
tree | f0b2e3afb63f53a922a0c42137a6d6763548edc5 /c/src/tests/psxtests/psxfile01/test.c | |
parent | 2003-11-10 Ralf Corsepius <corsepiu@faw.uni-ulm.de> (diff) | |
download | rtems-ff6ab1b594d9f073ece9b7fedf1f6977f52aeee5.tar.bz2 |
2003-11-10 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
* .cvsignore: Remove.
* ChangeLog: Remove.
* Makefile.am: Remove.
* configure.ac: Remove.
* psxtests.am: Remove.
* include/.cvsignore: Remove.
* include/Makefile.am: Remove.
* include/pmacros.h: Remove.
* psx01/.cvsignore: Remove.
* psx01/Makefile.am: Remove.
* psx01/init.c: Remove.
* psx01/psx01.scn: Remove.
* psx01/system.h: Remove.
* psx01/task.c: Remove.
* psx02/.cvsignore: Remove.
* psx02/Makefile.am: Remove.
* psx02/init.c: Remove.
* psx02/psx02.scn: Remove.
* psx02/system.h: Remove.
* psx02/task.c: Remove.
* psx03/.cvsignore: Remove.
* psx03/Makefile.am: Remove.
* psx03/init.c: Remove.
* psx03/psx03.scn: Remove.
* psx03/system.h: Remove.
* psx03/task.c: Remove.
* psx04/.cvsignore: Remove.
* psx04/Makefile.am: Remove.
* psx04/init.c: Remove.
* psx04/psx04.scn: Remove.
* psx04/system.h: Remove.
* psx04/task1.c: Remove.
* psx04/task2.c: Remove.
* psx04/task3.c: Remove.
* psx05/.cvsignore: Remove.
* psx05/Makefile.am: Remove.
* psx05/init.c: Remove.
* psx05/psx05.scn: Remove.
* psx05/system.h: Remove.
* psx05/task.c: Remove.
* psx05/task2.c: Remove.
* psx05/task3.c: Remove.
* psx06/.cvsignore: Remove.
* psx06/Makefile.am: Remove.
* psx06/init.c: Remove.
* psx06/psx06.scn: Remove.
* psx06/system.h: Remove.
* psx06/task.c: Remove.
* psx06/task2.c: Remove.
* psx07/.cvsignore: Remove.
* psx07/Makefile.am: Remove.
* psx07/init.c: Remove.
* psx07/psx07.scn: Remove.
* psx07/system.h: Remove.
* psx07/task.c: Remove.
* psx08/.cvsignore: Remove.
* psx08/Makefile.am: Remove.
* psx08/init.c: Remove.
* psx08/psx08.scn: Remove.
* psx08/system.h: Remove.
* psx08/task1.c: Remove.
* psx08/task2.c: Remove.
* psx08/task3.c: Remove.
* psx09/.cvsignore: Remove.
* psx09/Makefile.am: Remove.
* psx09/init.c: Remove.
* psx09/psx09.scn: Remove.
* psx09/system.h: Remove.
* psx10/.cvsignore: Remove.
* psx10/Makefile.am: Remove.
* psx10/init.c: Remove.
* psx10/psx10.scn: Remove.
* psx10/system.h: Remove.
* psx10/task.c: Remove.
* psx10/task2.c: Remove.
* psx10/task3.c: Remove.
* psx11/.cvsignore: Remove.
* psx11/Makefile.am: Remove.
* psx11/init.c: Remove.
* psx11/psx11.scn: Remove.
* psx11/system.h: Remove.
* psx11/task.c: Remove.
* psx12/.cvsignore: Remove.
* psx12/Makefile.am: Remove.
* psx12/init.c: Remove.
* psx12/psx12.scn: Remove.
* psx12/system.h: Remove.
* psx12/task.c: Remove.
* psx13/.cvsignore: Remove.
* psx13/Makefile.am: Remove.
* psx13/main.c: Remove.
* psx13/psx13.scn: Remove.
* psx13/test.c: Remove.
* psxcancel/.cvsignore: Remove.
* psxcancel/Makefile.am: Remove.
* psxcancel/init.c: Remove.
* psxcancel/psxcancel.scn: Remove.
* psxchroot01/.cvsignore: Remove.
* psxchroot01/Makefile.am: Remove.
* psxchroot01/main.c: Remove.
* psxchroot01/psxchroot01.scn: Remove.
* psxchroot01/test.c: Remove.
* psxfile01/.cvsignore: Remove.
* psxfile01/Makefile.am: Remove.
* psxfile01/main.c: Remove.
* psxfile01/psxfile01.scn: Remove.
* psxfile01/test.c: Remove.
* psxfile01/test_cat.c: Remove.
* psxfile01/test_extend.c: Remove.
* psxfile01/test_write.c: Remove.
* psxhdrs/.cvsignore: Remove.
* psxhdrs/Makefile.am: Remove.
* psxhdrs/clock01.c: Remove.
* psxhdrs/clock02.c: Remove.
* psxhdrs/clock03.c: Remove.
* psxhdrs/clock04.c: Remove.
* psxhdrs/clock05.c: Remove.
* psxhdrs/clock06.c: Remove.
* psxhdrs/cond01.c: Remove.
* psxhdrs/cond02.c: Remove.
* psxhdrs/cond03.c: Remove.
* psxhdrs/cond04.c: Remove.
* psxhdrs/cond05.c: Remove.
* psxhdrs/cond06.c: Remove.
* psxhdrs/cond07.c: Remove.
* psxhdrs/cond08.c: Remove.
* psxhdrs/cond09.c: Remove.
* psxhdrs/cond10.c: Remove.
* psxhdrs/key01.c: Remove.
* psxhdrs/key02.c: Remove.
* psxhdrs/key03.c: Remove.
* psxhdrs/key04.c: Remove.
* psxhdrs/mutex01.c: Remove.
* psxhdrs/mutex02.c: Remove.
* psxhdrs/mutex03.c: Remove.
* psxhdrs/mutex04.c: Remove.
* psxhdrs/mutex05.c: Remove.
* psxhdrs/mutex06.c: Remove.
* psxhdrs/mutex07.c: Remove.
* psxhdrs/mutex08.c: Remove.
* psxhdrs/mutex09.c: Remove.
* psxhdrs/mutex10.c: Remove.
* psxhdrs/mutex11.c: Remove.
* psxhdrs/mutex12.c: Remove.
* psxhdrs/mutex13.c: Remove.
* psxhdrs/mutex14.c: Remove.
* psxhdrs/mutex15.c: Remove.
* psxhdrs/mutex16.c: Remove.
* psxhdrs/proc01.c: Remove.
* psxhdrs/proc02.c: Remove.
* psxhdrs/proc03.c: Remove.
* psxhdrs/proc04.c: Remove.
* psxhdrs/proc05.c: Remove.
* psxhdrs/proc06.c: Remove.
* psxhdrs/proc07.c: Remove.
* psxhdrs/proc08.c: Remove.
* psxhdrs/proc09.c: Remove.
* psxhdrs/proc10.c: Remove.
* psxhdrs/proc11.c: Remove.
* psxhdrs/proc12.c: Remove.
* psxhdrs/proc13.c: Remove.
* psxhdrs/proc14.c: Remove.
* psxhdrs/pthread01.c: Remove.
* psxhdrs/pthread02.c: Remove.
* psxhdrs/pthread03.c: Remove.
* psxhdrs/pthread04.c: Remove.
* psxhdrs/pthread05.c: Remove.
* psxhdrs/pthread06.c: Remove.
* psxhdrs/pthread07.c: Remove.
* psxhdrs/pthread08.c: Remove.
* psxhdrs/pthread09.c: Remove.
* psxhdrs/pthread10.c: Remove.
* psxhdrs/pthread11.c: Remove.
* psxhdrs/pthread12.c: Remove.
* psxhdrs/pthread13.c: Remove.
* psxhdrs/pthread14.c: Remove.
* psxhdrs/pthread15.c: Remove.
* psxhdrs/pthread16.c: Remove.
* psxhdrs/pthread17.c: Remove.
* psxhdrs/pthread18.c: Remove.
* psxhdrs/pthread19.c: Remove.
* psxhdrs/pthread20.c: Remove.
* psxhdrs/pthread21.c: Remove.
* psxhdrs/pthread22.c: Remove.
* psxhdrs/pthread23.c: Remove.
* psxhdrs/pthread24.c: Remove.
* psxhdrs/pthread25.c: Remove.
* psxhdrs/pthread26.c: Remove.
* psxhdrs/pthread27.c: Remove.
* psxhdrs/pthread28.c: Remove.
* psxhdrs/pthread29.c: Remove.
* psxhdrs/pthread30.c: Remove.
* psxhdrs/pthread31.c: Remove.
* psxhdrs/pthread32.c: Remove.
* psxhdrs/pthread33.c: Remove.
* psxhdrs/pthread34.c: Remove.
* psxhdrs/pthread35.c: Remove.
* psxhdrs/pthread36.c: Remove.
* psxhdrs/sched01.c: Remove.
* psxhdrs/sched02.c: Remove.
* psxhdrs/sched03.c: Remove.
* psxhdrs/sched04.c: Remove.
* psxhdrs/sched05.c: Remove.
* psxhdrs/sched06.c: Remove.
* psxhdrs/sched07.c: Remove.
* psxhdrs/sched08.c: Remove.
* psxhdrs/signal01.c: Remove.
* psxhdrs/signal02.c: Remove.
* psxhdrs/signal03.c: Remove.
* psxhdrs/signal04.c: Remove.
* psxhdrs/signal05.c: Remove.
* psxhdrs/signal06.c: Remove.
* psxhdrs/signal07.c: Remove.
* psxhdrs/signal08.c: Remove.
* psxhdrs/signal09.c: Remove.
* psxhdrs/signal10.c: Remove.
* psxhdrs/signal11.c: Remove.
* psxhdrs/signal12.c: Remove.
* psxhdrs/signal13.c: Remove.
* psxhdrs/signal14.c: Remove.
* psxhdrs/signal15.c: Remove.
* psxhdrs/signal16.c: Remove.
* psxhdrs/signal17.c: Remove.
* psxhdrs/signal18.c: Remove.
* psxhdrs/signal19.c: Remove.
* psxhdrs/signal20.c: Remove.
* psxhdrs/signal21.c: Remove.
* psxhdrs/signal22.c: Remove.
* psxhdrs/signal23.c: Remove.
* psxhdrs/sync01.c: Remove.
* psxhdrs/sync02.c: Remove.
* psxhdrs/sync03.c: Remove.
* psxhdrs/time01.c: Remove.
* psxhdrs/time02.c: Remove.
* psxhdrs/time03.c: Remove.
* psxhdrs/time04.c: Remove.
* psxhdrs/time05.c: Remove.
* psxhdrs/time06.c: Remove.
* psxhdrs/time07.c: Remove.
* psxhdrs/time08.c: Remove.
* psxhdrs/time09.c: Remove.
* psxhdrs/time10.c: Remove.
* psxhdrs/time11.c: Remove.
* psxhdrs/time12.c: Remove.
* psxhdrs/time13.c: Remove.
* psxhdrs/timer01.c: Remove.
* psxhdrs/timer02.c: Remove.
* psxhdrs/timer03.c: Remove.
* psxhdrs/timer04.c: Remove.
* psxhdrs/timer05.c: Remove.
* psxhdrs/timer06.c: Remove.
* psxhdrs/timer07.c: Remove.
* psxmount/.cvsignore: Remove.
* psxmount/Makefile.am: Remove.
* psxmount/main.c: Remove.
* psxmount/psxmount.scn: Remove.
* psxmount/test.c: Remove.
* psxmsgq01/.cvsignore: Remove.
* psxmsgq01/Makefile.am: Remove.
* psxmsgq01/init.c: Remove.
* psxmsgq01/psxmsgq01.scn: Remove.
* psxmsgq01/system.h: Remove.
* psxreaddir/.cvsignore: Remove.
* psxreaddir/Makefile.am: Remove.
* psxreaddir/main.c: Remove.
* psxreaddir/psxreaddir.scn: Remove.
* psxreaddir/test.c: Remove.
* psxsem01/.cvsignore: Remove.
* psxsem01/Makefile.am: Remove.
* psxsem01/init.c: Remove.
* psxsem01/psxsem01.scn: Remove.
* psxsem01/system.h: Remove.
* psxstat/.cvsignore: Remove.
* psxstat/Makefile.am: Remove.
* psxstat/main.c: Remove.
* psxstat/psxstat.scn: Remove.
* psxstat/test.c: Remove.
* psxtime/.cvsignore: Remove.
* psxtime/Makefile.am: Remove.
* psxtime/main.c: Remove.
* psxtime/psxtime.scn: Remove.
* psxtime/test.c: Remove.
* psxtimer/.cvsignore: Remove.
* psxtimer/Makefile.am: Remove.
* psxtimer/psxtimer.c: Remove.
* psxtimer/psxtimer.scn: Remove.
* psxtimer/system.h: Remove.
Diffstat (limited to 'c/src/tests/psxtests/psxfile01/test.c')
-rw-r--r-- | c/src/tests/psxtests/psxfile01/test.c | 547 |
1 files changed, 0 insertions, 547 deletions
diff --git a/c/src/tests/psxtests/psxfile01/test.c b/c/src/tests/psxtests/psxfile01/test.c deleted file mode 100644 index 1e61fef2b8..0000000000 --- a/c/src/tests/psxtests/psxfile01/test.c +++ /dev/null @@ -1,547 +0,0 @@ -/* - * 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-1999. - * 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 <stdio.h> - -#include <tmacros.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <unistd.h> -#include <errno.h> -#include <string.h> -#include <ctype.h> - -#include <assert.h> -#include <rtems.h> -#include <rtems/libio.h> - -void test_case_reopen_append(void); - -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 may vary by small amount\n", - (unsigned int) 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 { - puts(""); - 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; - 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 ); - - puts( "rmdir /dev" ); - status = rmdir( "/dev" ); - assert( status == -1 ); - assert( errno == ENOTEMPTY); - - puts( "rmdir /fred" ); - status = rmdir ("/fred"); - assert (status == -1); - assert( errno == ENOENT ); - - puts( "mknod /dev/test_console" ); - status = mknod( "/dev/test_console", S_IFCHR, 0LL ); - assert( !status ); - - puts( "mknod /dev/tty/S3" ); - status = mknod( "/dev/tty/S3", S_IFCHR, 0xFF00000080LL ); - assert( !status ); - - puts ("mknod /etc/passwd"); - status = mknod( "/etc/passwd", (S_IFREG | S_IRWXU), 0LL ); - assert( !status ); - - puts( "mkdir /tmp/my_dir"); - status = mkdir( "/tmp/my_dir", S_IRWXU ); - assert( status == 0 ); - - puts("mkfifo /c/my_dir" ); - 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 ); - - puts( "close /tmp/j again" ); - status = close( fd ); - assert( status == -1 ); - - puts( "unlink /tmp/j" ); - status = unlink( "/tmp/j" ); - assert( !status ); - - puts( "unlink /tmp" ); - status = unlink( "/tmp" ); - assert( status ); - - /* - * Simple open failure. Trying to create an existing file. - */ - - puts("create and close /tmp/tom"); - fd = open( "/tmp/tom", O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO ); - assert( fd != -1 ); - status = close( fd ); - assert( status == 0 ); - - puts("Attempt to recreate /tmp/tom"); - fd = open( "/tmp/tom", O_CREAT | O_EXCL, S_IRWXU|S_IRWXG|S_IRWXO ); - assert( fd == -1 ); - assert( errno == EEXIST ); - - puts("create /tmp/john"); - fd = open( "/tmp/john", O_RDWR|O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO ); - assert( fd != -1 ); - - puts("tcdrain /tmp/john" ); - status = tcdrain( fd ); - assert( status == 0 ); - - /* - * Test simple write to a file at offset 0 - */ - - puts( "mknod /tmp/joel" ); - 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. - */ - - puts("unlink /tmp/joel"); - status = unlink( "/tmp/joel" ); - assert( !status ); - - /* Test a failure path */ - - puts( "unlink /tmp/joel" ); - status = unlink( "/tmp/joel" ); - assert( status == -1 ); - - puts( "mknod /tmp/joel"); - 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. - */ - - if ( max_size < 300 * 1024 ) { - test_extend( "/tmp/joel", max_size - 1 ); - test_cat( "/tmp/joel", max_size / 2, 1024 ); - } else { - printf( "Skipping maximum file size test since max_size is %d bytes\n", max_size ); - puts("That is likely to be bigger than the available RAM on many targets." ); - } - - 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( "%s", 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 ); - - test_case_reopen_append(); - - printf( "*** END OF FILE TEST 1 ***\n" ); - rtems_test_exit( 0 ); -} - -/* - * Open/Create a File and write to it - * - * Test case submitted by Andrew Bythell <abythell@nortelnetworks.com>. - * - */ - -void test_file (char *filename, char *mode); - -void test_case_reopen_append(void) -{ - printf ("Writing First File\n"); - test_file ("/one.txt", "a"); - test_file ("/one.txt", "a"); - - /* but not the second time - this will insert junk. - the number of ^@'s seems to equal the number of - actual characters in the file */ - - printf ("Writing Second File\n"); - test_file ("/two.txt", "a"); - test_file ("/two.txt", "a"); - - test_cat( "/one.txt", 0, 1024 ); - test_cat( "/two.txt", 0, 1024 ); -} - -void test_file (char *filename, char *mode) -{ - FILE *fp; - fp = fopen (filename, mode); - if (!fp) - perror ("fopen"); - fprintf (fp, "this is a test line\n"); - if (fclose (fp)) - perror ("fclose"); -} - - |