Mercurial > ecos
changeset 1857:36bcb84dd874
* fs/rom/current/tests/fileio1.c: Rename to romfs1.c.
* fs/rom/current/cdl/romfs.cdl: Build the renamed file.
* fs/ram/current/tests/fileio1.c: Rename to ramfs1.c.
* fs/ram/current/cdl/ramfs.cdl: Build the renamed file.
| author | jld |
|---|---|
| date | Mon, 13 Dec 2004 15:34:53 +0000 |
| parents | 15dd41bdd560 |
| children | ed77ba8848ad |
| files | packages/fs/ram/current/ChangeLog packages/fs/ram/current/cdl/ramfs.cdl packages/fs/ram/current/tests/fileio1.c packages/fs/ram/current/tests/ramfs1.c packages/fs/rom/current/ChangeLog packages/fs/rom/current/cdl/romfs.cdl packages/fs/rom/current/tests/fileio1.c packages/fs/rom/current/tests/romfs1.c |
| diffstat | 8 files changed, 1058 insertions(+), 1040 deletions(-) [+] |
line wrap: on
line diff
--- a/packages/fs/ram/current/ChangeLog +++ b/packages/fs/ram/current/ChangeLog @@ -1,3 +1,9 @@ +2004-12-13 John Dallaway <jld@ecoscentric.com> + + * tests/fileio1.c: Rename to ramfs1.c. eCos test names should be + unique. + * cdl/ramfs.cdl: Build the ramfs1 test. + 2004-03-29 Andrew Lunn <andrew.lunn@ascom.ch> * test/fseek1.c: Test the fseek/ftell functions @@ -72,6 +78,7 @@ 2000-08-18 Nick Garnett <nickg@cygnus. // ------------------------------------------- // This file is part of eCos, the Embedded Configurable Operating System. // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. +// Copyright (C) 2004 eCosCentric Limited // // eCos is free software; you can redistribute it and/or modify it under // the terms of the GNU General Public License as published by the Free
--- a/packages/fs/ram/current/cdl/ramfs.cdl +++ b/packages/fs/ram/current/cdl/ramfs.cdl @@ -9,6 +9,7 @@ ## ------------------------------------------- ## This file is part of eCos, the Embedded Configurable Operating System. ## Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. +## Copyright (C) 2004 eCosCentric Limited ## ## eCos is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free @@ -182,7 +183,7 @@ cdl_package CYGPKG_FS_RAM { display "RAM FS tests" flavor data no_define - calculated { "tests/fileio1.c tests/fseek1.c" } + calculated { "tests/ramfs1.c tests/fseek1.c" } description " This option specifies the set of tests for the RAM FS package." }
deleted file mode 100644 --- a/packages/fs/ram/current/tests/fileio1.c +++ /dev/null @@ -1,651 +0,0 @@ -//========================================================================== -// -// fileio1.c -// -// Test fileio system -// -//========================================================================== -//####ECOSGPLCOPYRIGHTBEGIN#### -// ------------------------------------------- -// This file is part of eCos, the Embedded Configurable Operating System. -// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. -// -// eCos is free software; you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation; either version 2 or (at your option) any later version. -// -// eCos is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License along -// with eCos; if not, write to the Free Software Foundation, Inc., -// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. -// -// As a special exception, if other files instantiate templates or use macros -// or inline functions from this file, or you compile this file and link it -// with other works to produce a work based on this file, this file does not -// by itself cause the resulting work to be covered by the GNU General Public -// License. However the source code for this file must still be made available -// in accordance with section (3) of the GNU General Public License. -// -// This exception does not invalidate any other reasons why a work based on -// this file might be covered by the GNU General Public License. -// -// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. -// at http://sources.redhat.com/ecos/ecos-license/ -// ------------------------------------------- -//####ECOSGPLCOPYRIGHTEND#### -//========================================================================== -//#####DESCRIPTIONBEGIN#### -// -// Author(s): nickg -// Contributors: nickg -// Date: 2000-05-25 -// Purpose: Test fileio system -// Description: This test uses the testfs to check out the initialization -// and basic operation of the fileio system -// -// -// -// -// -// -// -//####DESCRIPTIONEND#### -// -//========================================================================== - -#include <pkgconf/hal.h> -#include <pkgconf/kernel.h> -#include <pkgconf/io_fileio.h> - -#include <cyg/kernel/ktypes.h> // base kernel types -#include <cyg/infra/cyg_trac.h> // tracing macros -#include <cyg/infra/cyg_ass.h> // assertion macros - -#include <unistd.h> -#include <fcntl.h> -#include <sys/stat.h> -#include <errno.h> -#include <string.h> -#include <dirent.h> - -#include <cyg/fileio/fileio.h> - -#include <cyg/infra/testcase.h> -#include <cyg/infra/diag.h> // HAL polled output - -//========================================================================== - -#if 0 -MTAB_ENTRY( ramfs_mte1, - "/", - "ramfs", - "", - 0); -#endif - -//========================================================================== - -#define SHOW_RESULT( _fn, _res ) \ -diag_printf("<FAIL>: " #_fn "() returned %d %s\n", _res, _res<0?strerror(errno):""); - -//========================================================================== - -#define IOSIZE 100 - -#define LONGNAME1 "long_file_name_that_should_take_up_more_than_one_directory_entry_1" -#define LONGNAME2 "long_file_name_that_should_take_up_more_than_one_directory_entry_2" - - -//========================================================================== - -#ifndef CYGPKG_LIBC_STRING - -char *strcat( char *s1, const char *s2 ) -{ - char *s = s1; - while( *s1 ) s1++; - while( (*s1++ = *s2++) != 0); - return s; -} - -#endif - -//========================================================================== - -static void listdir( char *name, int statp, int numexpected, int *numgot ) -{ - int err; - DIR *dirp; - int num=0; - - diag_printf("<INFO>: reading directory %s\n",name); - - dirp = opendir( name ); - if( dirp == NULL ) SHOW_RESULT( opendir, -1 ); - - for(;;) - { - struct dirent *entry = readdir( dirp ); - - if( entry == NULL ) - break; - num++; - diag_printf("<INFO>: entry %14s",entry->d_name); - if( statp ) - { - char fullname[PATH_MAX]; - struct stat sbuf; - - if( name[0] ) - { - strcpy(fullname, name ); - if( !(name[0] == '/' && name[1] == 0 ) ) - strcat(fullname, "/" ); - } - else fullname[0] = 0; - - strcat(fullname, entry->d_name ); - - err = stat( fullname, &sbuf ); - if( err < 0 ) - { - if( errno == ENOSYS ) - diag_printf(" <no status available>"); - else SHOW_RESULT( stat, err ); - } - else - { - diag_printf(" [mode %08x ino %08x nlink %d size %d]", - sbuf.st_mode,sbuf.st_ino,sbuf.st_nlink,sbuf.st_size); - } - } - - diag_printf("\n"); - } - - err = closedir( dirp ); - if( err < 0 ) SHOW_RESULT( stat, err ); - if (numexpected >= 0 && num != numexpected) - CYG_TEST_FAIL("Wrong number of dir entries\n"); - if ( numgot != NULL ) - *numgot = num; -} - -//========================================================================== - -static void createfile( char *name, size_t size ) -{ - char buf[IOSIZE]; - int fd; - ssize_t wrote; - int i; - int err; - - diag_printf("<INFO>: create file %s size %d\n",name,size); - - err = access( name, F_OK ); - if( err < 0 && errno != EACCES ) SHOW_RESULT( access, err ); - - for( i = 0; i < IOSIZE; i++ ) buf[i] = i%256; - - fd = open( name, O_WRONLY|O_CREAT ); - if( fd < 0 ) SHOW_RESULT( open, fd ); - - while( size > 0 ) - { - ssize_t len = size; - if ( len > IOSIZE ) len = IOSIZE; - - wrote = write( fd, buf, len ); - if( wrote != len ) SHOW_RESULT( write, wrote ); - - size -= wrote; - } - - err = close( fd ); - if( err < 0 ) SHOW_RESULT( close, err ); -} - -//========================================================================== - -#if 0 -static void maxfile( char *name ) -{ - char buf[IOSIZE]; - int fd; - ssize_t wrote; - int i; - int err; - size_t size = 0; - - diag_printf("<INFO>: create maximal file %s\n",name); - - err = access( name, F_OK ); - if( err < 0 && errno != EACCES ) SHOW_RESULT( access, err ); - - for( i = 0; i < IOSIZE; i++ ) buf[i] = i%256; - - fd = open( name, O_WRONLY|O_CREAT ); - if( fd < 0 ) SHOW_RESULT( open, fd ); - - do - { - wrote = write( fd, buf, IOSIZE ); - if( wrote < 0 ) SHOW_RESULT( write, wrote ); - - size += wrote; - - } while( wrote == IOSIZE ); - - diag_printf("<INFO>: file size == %d\n",size); - - err = close( fd ); - if( err < 0 ) SHOW_RESULT( close, err ); -} -#endif - -//========================================================================== - -static void checkfile( char *name ) -{ - char buf[IOSIZE]; - int fd; - ssize_t done; - int i; - int err; - off_t pos = 0; - - diag_printf("<INFO>: check file %s\n",name); - - err = access( name, F_OK ); - if( err != 0 ) SHOW_RESULT( access, err ); - - fd = open( name, O_RDONLY ); - if( fd < 0 ) SHOW_RESULT( open, fd ); - - for(;;) - { - done = read( fd, buf, IOSIZE ); - if( done < 0 ) SHOW_RESULT( read, done ); - - if( done == 0 ) break; - - for( i = 0; i < done; i++ ) - if( buf[i] != i%256 ) - { - diag_printf("buf[%d+%d](%02x) != %02x\n",pos,i,buf[i],i%256); - CYG_TEST_FAIL("Data read not equal to data written\n"); - } - - pos += done; - } - - err = close( fd ); - if( err < 0 ) SHOW_RESULT( close, err ); -} - -//========================================================================== - -static void copyfile( char *name2, char *name1 ) -{ - - int err; - char buf[IOSIZE]; - int fd1, fd2; - ssize_t done, wrote; - - diag_printf("<INFO>: copy file %s -> %s\n",name2,name1); - - err = access( name1, F_OK ); - if( err < 0 && errno != EACCES ) SHOW_RESULT( access, err ); - - err = access( name2, F_OK ); - if( err != 0 ) SHOW_RESULT( access, err ); - - fd1 = open( name1, O_WRONLY|O_CREAT ); - if( fd1 < 0 ) SHOW_RESULT( open, fd1 ); - - fd2 = open( name2, O_RDONLY ); - if( fd2 < 0 ) SHOW_RESULT( open, fd2 ); - - for(;;) - { - done = read( fd2, buf, IOSIZE ); - if( done < 0 ) SHOW_RESULT( read, done ); - - if( done == 0 ) break; - - wrote = write( fd1, buf, done ); - if( wrote != done ) SHOW_RESULT( write, wrote ); - - if( wrote != done ) break; - } - - err = close( fd1 ); - if( err < 0 ) SHOW_RESULT( close, err ); - - err = close( fd2 ); - if( err < 0 ) SHOW_RESULT( close, err ); - -} - -//========================================================================== - -static void comparefiles( char *name2, char *name1 ) -{ - int err; - char buf1[IOSIZE]; - char buf2[IOSIZE]; - int fd1, fd2; - ssize_t done1, done2; - int i; - - diag_printf("<INFO>: compare files %s == %s\n",name2,name1); - - err = access( name1, F_OK ); - if( err != 0 ) SHOW_RESULT( access, err ); - - err = access( name1, F_OK ); - if( err != 0 ) SHOW_RESULT( access, err ); - - fd1 = open( name1, O_RDONLY ); - if( fd1 < 0 ) SHOW_RESULT( open, fd1 ); - - fd2 = open( name2, O_RDONLY ); - if( fd2 < 0 ) SHOW_RESULT( open, fd2 ); - - for(;;) - { - done1 = read( fd1, buf1, IOSIZE ); - if( done1 < 0 ) SHOW_RESULT( read, done1 ); - - done2 = read( fd2, buf2, IOSIZE ); - if( done2 < 0 ) SHOW_RESULT( read, done2 ); - - if( done1 != done2 ) - diag_printf("Files different sizes\n"); - - if( done1 == 0 ) break; - - for( i = 0; i < done1; i++ ) - if( buf1[i] != buf2[i] ) - { - diag_printf("buf1[%d](%02x) != buf1[%d](%02x)\n",i,buf1[i],i,buf2[i]); - CYG_TEST_FAIL("Data in files not equal\n"); - } - } - - err = close( fd1 ); - if( err < 0 ) SHOW_RESULT( close, err ); - - err = close( fd2 ); - if( err < 0 ) SHOW_RESULT( close, err ); - -} - -//========================================================================== - -void checkcwd( const char *cwd ) -{ - static char cwdbuf[PATH_MAX]; - char *ret; - - ret = getcwd( cwdbuf, sizeof(cwdbuf)); - if( ret == NULL ) SHOW_RESULT( getcwd, ret ); - - if( strcmp( cwdbuf, cwd ) != 0 ) - { - diag_printf( "cwdbuf %s cwd %s\n",cwdbuf, cwd ); - CYG_TEST_FAIL( "Current directory mismatch"); - } -} - -//========================================================================== -// main - -int main( int argc, char **argv ) -{ - int err; - int existingdirents=-1; - - CYG_TEST_INIT(); - - // -------------------------------------------------------------- - - err = mount( "", "/", "ramfs" ); - if( err < 0 ) SHOW_RESULT( mount, err ); - - err = chdir( "/" ); - if( err < 0 ) SHOW_RESULT( chdir, err ); - - checkcwd( "/" ); - - listdir( "/", true, -1, &existingdirents ); - if ( existingdirents < 2 ) - CYG_TEST_FAIL("Not enough dir entries\n"); - - // -------------------------------------------------------------- - - createfile( "/foo", 202 ); - checkfile( "foo" ); - copyfile( "foo", "fee"); - checkfile( "fee" ); - comparefiles( "foo", "/fee" ); - diag_printf("<INFO>: mkdir bar\n"); - err = mkdir( "/bar", 0 ); - if( err < 0 ) SHOW_RESULT( mkdir, err ); - - listdir( "/" , true, existingdirents+3, NULL ); - - copyfile( "fee", "/bar/fum" ); - checkfile( "bar/fum" ); - comparefiles( "/fee", "bar/fum" ); - - diag_printf("<INFO>: cd bar\n"); - err = chdir( "bar" ); - if( err < 0 ) SHOW_RESULT( chdir, err ); - - checkcwd( "/bar" ); - - diag_printf("<INFO>: rename /foo bundy\n"); - err = rename( "/foo", "bundy" ); - if( err < 0 ) SHOW_RESULT( rename, err ); - - listdir( "/", true, existingdirents+2, NULL ); - listdir( "" , true, 4, NULL ); - - checkfile( "/bar/bundy" ); - comparefiles("/fee", "bundy" ); - - // -------------------------------------------------------------- - - createfile( LONGNAME1, 123 ); - checkfile( LONGNAME1 ); - copyfile( LONGNAME1, LONGNAME2 ); - - listdir( "", false, 6, NULL ); - - diag_printf("<INFO>: unlink " LONGNAME1 "\n"); - err = unlink( LONGNAME1 ); - if( err < 0 ) SHOW_RESULT( unlink, err ); - - diag_printf("<INFO>: unlink " LONGNAME2 "\n"); - err = unlink( LONGNAME2 ); - if( err < 0 ) SHOW_RESULT( unlink, err ); - - - // -------------------------------------------------------------- - - diag_printf("<INFO>: unlink fee\n"); - err = unlink( "/fee" ); - if( err < 0 ) SHOW_RESULT( unlink, err ); - - diag_printf("<INFO>: unlink fum\n"); - err = unlink( "fum" ); - if( err < 0 ) SHOW_RESULT( unlink, err ); - - diag_printf("<INFO>: unlink /bar/bundy\n"); - err = unlink( "/bar/bundy" ); - if( err < 0 ) SHOW_RESULT( unlink, err ); - - diag_printf("<INFO>: cd /\n"); - err = chdir( "/" ); - if( err < 0 ) SHOW_RESULT( chdir, err ); - - checkcwd( "/" ); - - diag_printf("<INFO>: rmdir /bar\n"); - err = rmdir( "/bar" ); - if( err < 0 ) SHOW_RESULT( rmdir, err ); - - listdir( "/", false, existingdirents, NULL ); - - // -------------------------------------------------------------- - - diag_printf("<INFO>: mount /ram \n"); - err = mount( "", "/ram", "ramfs" ); - if( err < 0 ) SHOW_RESULT( mount, err ); - - createfile( "/ram/tinky", 456 ); - copyfile( "/ram/tinky", "/ram/laalaa" ); - checkfile( "/ram/tinky"); - checkfile( "/ram/laalaa"); - comparefiles( "/ram/tinky", "/ram/laalaa" ); - - diag_printf("<INFO>: cd /ram\n"); - err = chdir( "/ram" ); - if( err < 0 ) SHOW_RESULT( chdir, err ); - - checkcwd( "/ram" ); - - diag_printf("<INFO>: mkdir noonoo\n"); - err = mkdir( "noonoo", 0 ); - if( err < 0 ) SHOW_RESULT( mkdir, err ); - - listdir( "." , true, existingdirents+3, NULL); - - diag_printf("<INFO>: cd noonoo\n"); - err = chdir( "noonoo" ); - if( err < 0 ) SHOW_RESULT( chdir, err ); - - checkcwd( "/ram/noonoo" ); - - createfile( "tinky", 678 ); - checkfile( "tinky" ); - - createfile( "dipsy", 3456 ); - checkfile( "dipsy" ); - copyfile( "dipsy", "po" ); - checkfile( "po" ); - comparefiles( "dipsy", "po" ); - - listdir( ".", true, 5, NULL ); - listdir( "", true, 5, NULL ); - listdir( "..", true, existingdirents+3, NULL ); - - // -------------------------------------------------------------- - - diag_printf("<INFO>: unlink tinky\n"); - err = unlink( "tinky" ); - if( err < 0 ) SHOW_RESULT( unlink, err ); - - diag_printf("<INFO>: unlink dipsy\n"); - err = unlink( "dipsy" ); - if( err < 0 ) SHOW_RESULT( unlink, err ); - - diag_printf("<INFO>: unlink po\n"); - err = unlink( "po" ); - if( err < 0 ) SHOW_RESULT( unlink, err ); - - diag_printf("<INFO>: cd ..\n"); - err = chdir( ".." ); - if( err < 0 ) SHOW_RESULT( chdir, err ); - checkcwd( "/ram" ); - - diag_printf("<INFO>: rmdir noonoo\n"); - err = rmdir( "noonoo" ); - if( err < 0 ) SHOW_RESULT( rmdir, err ); - - // -------------------------------------------------------------- - - err = mkdir( "x", 0 ); - if( err < 0 ) SHOW_RESULT( mkdir, err ); - - err = mkdir( "x/y", 0 ); - if( err < 0 ) SHOW_RESULT( mkdir, err ); - - err = mkdir( "x/y/z", 0 ); - if( err < 0 ) SHOW_RESULT( mkdir, err ); - - err = mkdir( "x/y/z/w", 0 ); - if( err < 0 ) SHOW_RESULT( mkdir, err ); - - diag_printf("<INFO>: cd /ram/x/y/z/w\n"); - err = chdir( "/ram/x/y/z/w" ); - if( err < 0 ) SHOW_RESULT( chdir, err ); - checkcwd( "/ram/x/y/z/w" ); - - diag_printf("<INFO>: cd ..\n"); - err = chdir( ".." ); - if( err < 0 ) SHOW_RESULT( chdir, err ); - checkcwd( "/ram/x/y/z" ); - - diag_printf("<INFO>: cd .\n"); - err = chdir( "." ); - if( err < 0 ) SHOW_RESULT( chdir, err ); - checkcwd( "/ram/x/y/z" ); - - diag_printf("<INFO>: cd ../../y\n"); - err = chdir( "../../y" ); - if( err < 0 ) SHOW_RESULT( chdir, err ); - checkcwd( "/ram/x/y" ); - - diag_printf("<INFO>: cd ../..\n"); - err = chdir( "../.." ); - if( err < 0 ) SHOW_RESULT( chdir, err ); - checkcwd( "/ram" ); - - diag_printf("<INFO>: rmdir x/y/z/w\n"); - err = rmdir( "x/y/z/w" ); - if( err < 0 ) SHOW_RESULT( rmdir, err ); - - diag_printf("<INFO>: rmdir x/y/z\n"); - err = rmdir( "x/y/z" ); - if( err < 0 ) SHOW_RESULT( rmdir, err ); - - diag_printf("<INFO>: rmdir x/y\n"); - err = rmdir( "x/y" ); - if( err < 0 ) SHOW_RESULT( rmdir, err ); - - diag_printf("<INFO>: rmdir x\n"); - err = rmdir( "x" ); - if( err < 0 ) SHOW_RESULT( rmdir, err ); - - // -------------------------------------------------------------- - - diag_printf("<INFO>: unlink tinky\n"); - err = unlink( "tinky" ); - if( err < 0 ) SHOW_RESULT( unlink, err ); - - diag_printf("<INFO>: unlink laalaa\n"); - err = unlink( "laalaa" ); - if( err < 0 ) SHOW_RESULT( unlink, err ); - - diag_printf("<INFO>: cd /\n"); - err = chdir( "/" ); - if( err < 0 ) SHOW_RESULT( chdir, err ); - checkcwd( "/" ); - - diag_printf("<INFO>: umount /ram\n"); - err = umount( "/ram" ); - if( err < 0 ) SHOW_RESULT( umount, err ); - - CYG_TEST_PASS_FINISH("fileio1"); -} - -// ------------------------------------------------------------------------- -// EOF fileio1.c
new file mode 100644 --- /dev/null +++ b/packages/fs/ram/current/tests/ramfs1.c @@ -0,0 +1,652 @@ +//========================================================================== +// +// ramfs1.c +// +// Test fileio system +// +//========================================================================== +//####ECOSGPLCOPYRIGHTBEGIN#### +// ------------------------------------------- +// This file is part of eCos, the Embedded Configurable Operating System. +// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. +// Copyright (C) 2004 eCosCentric Limited +// +// eCos is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 2 or (at your option) any later version. +// +// eCos is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with eCos; if not, write to the Free Software Foundation, Inc., +// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +// +// As a special exception, if other files instantiate templates or use macros +// or inline functions from this file, or you compile this file and link it +// with other works to produce a work based on this file, this file does not +// by itself cause the resulting work to be covered by the GNU General Public +// License. However the source code for this file must still be made available +// in accordance with section (3) of the GNU General Public License. +// +// This exception does not invalidate any other reasons why a work based on +// this file might be covered by the GNU General Public License. +// +// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. +// at http://sources.redhat.com/ecos/ecos-license/ +// ------------------------------------------- +//####ECOSGPLCOPYRIGHTEND#### +//========================================================================== +//#####DESCRIPTIONBEGIN#### +// +// Author(s): nickg +// Contributors: nickg +// Date: 2000-05-25 +// Purpose: Test fileio system +// Description: This test uses the testfs to check out the initialization +// and basic operation of the fileio system +// +// +// +// +// +// +// +//####DESCRIPTIONEND#### +// +//========================================================================== + +#include <pkgconf/hal.h> +#include <pkgconf/kernel.h> +#include <pkgconf/io_fileio.h> + +#include <cyg/kernel/ktypes.h> // base kernel types +#include <cyg/infra/cyg_trac.h> // tracing macros +#include <cyg/infra/cyg_ass.h> // assertion macros + +#include <unistd.h> +#include <fcntl.h> +#include <sys/stat.h> +#include <errno.h> +#include <string.h> +#include <dirent.h> + +#include <cyg/fileio/fileio.h> + +#include <cyg/infra/testcase.h> +#include <cyg/infra/diag.h> // HAL polled output + +//========================================================================== + +#if 0 +MTAB_ENTRY( ramfs_mte1, + "/", + "ramfs", + "", + 0); +#endif + +//========================================================================== + +#define SHOW_RESULT( _fn, _res ) \ +diag_printf("<FAIL>: " #_fn "() returned %d %s\n", _res, _res<0?strerror(errno):""); + +//========================================================================== + +#define IOSIZE 100 + +#define LONGNAME1 "long_file_name_that_should_take_up_more_than_one_directory_entry_1" +#define LONGNAME2 "long_file_name_that_should_take_up_more_than_one_directory_entry_2" + + +//========================================================================== + +#ifndef CYGPKG_LIBC_STRING + +char *strcat( char *s1, const char *s2 ) +{ + char *s = s1; + while( *s1 ) s1++; + while( (*s1++ = *s2++) != 0); + return s; +} + +#endif + +//========================================================================== + +static void listdir( char *name, int statp, int numexpected, int *numgot ) +{ + int err; + DIR *dirp; + int num=0; + + diag_printf("<INFO>: reading directory %s\n",name); + + dirp = opendir( name ); + if( dirp == NULL ) SHOW_RESULT( opendir, -1 ); + + for(;;) + { + struct dirent *entry = readdir( dirp ); + + if( entry == NULL ) + break; + num++; + diag_printf("<INFO>: entry %14s",entry->d_name); + if( statp ) + { + char fullname[PATH_MAX]; + struct stat sbuf; + + if( name[0] ) + { + strcpy(fullname, name ); + if( !(name[0] == '/' && name[1] == 0 ) ) + strcat(fullname, "/" ); + } + else fullname[0] = 0; + + strcat(fullname, entry->d_name ); + + err = stat( fullname, &sbuf ); + if( err < 0 ) + { + if( errno == ENOSYS ) + diag_printf(" <no status available>"); + else SHOW_RESULT( stat, err ); + } + else + { + diag_printf(" [mode %08x ino %08x nlink %d size %d]", + sbuf.st_mode,sbuf.st_ino,sbuf.st_nlink,sbuf.st_size); + } + } + + diag_printf("\n"); + } + + err = closedir( dirp ); + if( err < 0 ) SHOW_RESULT( stat, err ); + if (numexpected >= 0 && num != numexpected) + CYG_TEST_FAIL("Wrong number of dir entries\n"); + if ( numgot != NULL ) + *numgot = num; +} + +//========================================================================== + +static void createfile( char *name, size_t size ) +{ + char buf[IOSIZE]; + int fd; + ssize_t wrote; + int i; + int err; + + diag_printf("<INFO>: create file %s size %d\n",name,size); + + err = access( name, F_OK ); + if( err < 0 && errno != EACCES ) SHOW_RESULT( access, err ); + + for( i = 0; i < IOSIZE; i++ ) buf[i] = i%256; + + fd = open( name, O_WRONLY|O_CREAT ); + if( fd < 0 ) SHOW_RESULT( open, fd ); + + while( size > 0 ) + { + ssize_t len = size; + if ( len > IOSIZE ) len = IOSIZE; + + wrote = write( fd, buf, len ); + if( wrote != len ) SHOW_RESULT( write, wrote ); + + size -= wrote; + } + + err = close( fd ); + if( err < 0 ) SHOW_RESULT( close, err ); +} + +//========================================================================== + +#if 0 +static void maxfile( char *name ) +{ + char buf[IOSIZE]; + int fd; + ssize_t wrote; + int i; + int err; + size_t size = 0; + + diag_printf("<INFO>: create maximal file %s\n",name); + + err = access( name, F_OK ); + if( err < 0 && errno != EACCES ) SHOW_RESULT( access, err ); + + for( i = 0; i < IOSIZE; i++ ) buf[i] = i%256; + + fd = open( name, O_WRONLY|O_CREAT ); + if( fd < 0 ) SHOW_RESULT( open, fd ); + + do + { + wrote = write( fd, buf, IOSIZE ); + if( wrote < 0 ) SHOW_RESULT( write, wrote ); + + size += wrote; + + } while( wrote == IOSIZE ); + + diag_printf("<INFO>: file size == %d\n",size); + + err = close( fd ); + if( err < 0 ) SHOW_RESULT( close, err ); +} +#endif + +//========================================================================== + +static void checkfile( char *name ) +{ + char buf[IOSIZE]; + int fd; + ssize_t done; + int i; + int err; + off_t pos = 0; + + diag_printf("<INFO>: check file %s\n",name); + + err = access( name, F_OK ); + if( err != 0 ) SHOW_RESULT( access, err ); + + fd = open( name, O_RDONLY ); + if( fd < 0 ) SHOW_RESULT( open, fd ); + + for(;;) + { + done = read( fd, buf, IOSIZE ); + if( done < 0 ) SHOW_RESULT( read, done ); + + if( done == 0 ) break; + + for( i = 0; i < done; i++ ) + if( buf[i] != i%256 ) + { + diag_printf("buf[%d+%d](%02x) != %02x\n",pos,i,buf[i],i%256); + CYG_TEST_FAIL("Data read not equal to data written\n"); + } + + pos += done; + } + + err = close( fd ); + if( err < 0 ) SHOW_RESULT( close, err ); +} + +//========================================================================== + +static void copyfile( char *name2, char *name1 ) +{ + + int err; + char buf[IOSIZE]; + int fd1, fd2; + ssize_t done, wrote; + + diag_printf("<INFO>: copy file %s -> %s\n",name2,name1); + + err = access( name1, F_OK ); + if( err < 0 && errno != EACCES ) SHOW_RESULT( access, err ); + + err = access( name2, F_OK ); + if( err != 0 ) SHOW_RESULT( access, err ); + + fd1 = open( name1, O_WRONLY|O_CREAT ); + if( fd1 < 0 ) SHOW_RESULT( open, fd1 ); + + fd2 = open( name2, O_RDONLY ); + if( fd2 < 0 ) SHOW_RESULT( open, fd2 ); + + for(;;) + { + done = read( fd2, buf, IOSIZE ); + if( done < 0 ) SHOW_RESULT( read, done ); + + if( done == 0 ) break; + + wrote = write( fd1, buf, done ); + if( wrote != done ) SHOW_RESULT( write, wrote ); + + if( wrote != done ) break; + } + + err = close( fd1 ); + if( err < 0 ) SHOW_RESULT( close, err ); + + err = close( fd2 ); + if( err < 0 ) SHOW_RESULT( close, err ); + +} + +//========================================================================== + +static void comparefiles( char *name2, char *name1 ) +{ + int err; + char buf1[IOSIZE]; + char buf2[IOSIZE]; + int fd1, fd2; + ssize_t done1, done2; + int i; + + diag_printf("<INFO>: compare files %s == %s\n",name2,name1); + + err = access( name1, F_OK ); + if( err != 0 ) SHOW_RESULT( access, err ); + + err = access( name1, F_OK ); + if( err != 0 ) SHOW_RESULT( access, err ); + + fd1 = open( name1, O_RDONLY ); + if( fd1 < 0 ) SHOW_RESULT( open, fd1 ); + + fd2 = open( name2, O_RDONLY ); + if( fd2 < 0 ) SHOW_RESULT( open, fd2 ); + + for(;;) + { + done1 = read( fd1, buf1, IOSIZE ); + if( done1 < 0 ) SHOW_RESULT( read, done1 ); + + done2 = read( fd2, buf2, IOSIZE ); + if( done2 < 0 ) SHOW_RESULT( read, done2 ); + + if( done1 != done2 ) + diag_printf("Files different sizes\n"); + + if( done1 == 0 ) break; + + for( i = 0; i < done1; i++ ) + if( buf1[i] != buf2[i] ) + { + diag_printf("buf1[%d](%02x) != buf1[%d](%02x)\n",i,buf1[i],i,buf2[i]); + CYG_TEST_FAIL("Data in files not equal\n"); + } + } + + err = close( fd1 ); + if( err < 0 ) SHOW_RESULT( close, err ); + + err = close( fd2 ); + if( err < 0 ) SHOW_RESULT( close, err ); + +} + +//========================================================================== + +void checkcwd( const char *cwd ) +{ + static char cwdbuf[PATH_MAX]; + char *ret; + + ret = getcwd( cwdbuf, sizeof(cwdbuf)); + if( ret == NULL ) SHOW_RESULT( getcwd, ret ); + + if( strcmp( cwdbuf, cwd ) != 0 ) + { + diag_printf( "cwdbuf %s cwd %s\n",cwdbuf, cwd ); + CYG_TEST_FAIL( "Current directory mismatch"); + } +} + +//========================================================================== +// main + +int main( int argc, char **argv ) +{ + int err; + int existingdirents=-1; + + CYG_TEST_INIT(); + + // -------------------------------------------------------------- + + err = mount( "", "/", "ramfs" ); + if( err < 0 ) SHOW_RESULT( mount, err ); + + err = chdir( "/" ); + if( err < 0 ) SHOW_RESULT( chdir, err ); + + checkcwd( "/" ); + + listdir( "/", true, -1, &existingdirents ); + if ( existingdirents < 2 ) + CYG_TEST_FAIL("Not enough dir entries\n"); + + // -------------------------------------------------------------- + + createfile( "/foo", 202 ); + checkfile( "foo" ); + copyfile( "foo", "fee"); + checkfile( "fee" ); + comparefiles( "foo", "/fee" ); + diag_printf("<INFO>: mkdir bar\n"); + err = mkdir( "/bar", 0 ); + if( err < 0 ) SHOW_RESULT( mkdir, err ); + + listdir( "/" , true, existingdirents+3, NULL ); + + copyfile( "fee", "/bar/fum" ); + checkfile( "bar/fum" ); + comparefiles( "/fee", "bar/fum" ); + + diag_printf("<INFO>: cd bar\n"); + err = chdir( "bar" ); + if( err < 0 ) SHOW_RESULT( chdir, err ); + + checkcwd( "/bar" ); + + diag_printf("<INFO>: rename /foo bundy\n"); + err = rename( "/foo", "bundy" ); + if( err < 0 ) SHOW_RESULT( rename, err ); + + listdir( "/", true, existingdirents+2, NULL ); + listdir( "" , true, 4, NULL ); + + checkfile( "/bar/bundy" ); + comparefiles("/fee", "bundy" ); + + // -------------------------------------------------------------- + + createfile( LONGNAME1, 123 ); + checkfile( LONGNAME1 ); + copyfile( LONGNAME1, LONGNAME2 ); + + listdir( "", false, 6, NULL ); + + diag_printf("<INFO>: unlink " LONGNAME1 "\n"); + err = unlink( LONGNAME1 ); + if( err < 0 ) SHOW_RESULT( unlink, err ); + + diag_printf("<INFO>: unlink " LONGNAME2 "\n"); + err = unlink( LONGNAME2 ); + if( err < 0 ) SHOW_RESULT( unlink, err ); + + + // -------------------------------------------------------------- + + diag_printf("<INFO>: unlink fee\n"); + err = unlink( "/fee" ); + if( err < 0 ) SHOW_RESULT( unlink, err ); + + diag_printf("<INFO>: unlink fum\n"); + err = unlink( "fum" ); + if( err < 0 ) SHOW_RESULT( unlink, err ); + + diag_printf("<INFO>: unlink /bar/bundy\n"); + err = unlink( "/bar/bundy" ); + if( err < 0 ) SHOW_RESULT( unlink, err ); + + diag_printf("<INFO>: cd /\n"); + err = chdir( "/" ); + if( err < 0 ) SHOW_RESULT( chdir, err ); + + checkcwd( "/" ); + + diag_printf("<INFO>: rmdir /bar\n"); + err = rmdir( "/bar" ); + if( err < 0 ) SHOW_RESULT( rmdir, err ); + + listdir( "/", false, existingdirents, NULL ); + + // -------------------------------------------------------------- + + diag_printf("<INFO>: mount /ram \n"); + err = mount( "", "/ram", "ramfs" ); + if( err < 0 ) SHOW_RESULT( mount, err ); + + createfile( "/ram/tinky", 456 ); + copyfile( "/ram/tinky", "/ram/laalaa" ); + checkfile( "/ram/tinky"); + checkfile( "/ram/laalaa"); + comparefiles( "/ram/tinky", "/ram/laalaa" ); + + diag_printf("<INFO>: cd /ram\n"); + err = chdir( "/ram" ); + if( err < 0 ) SHOW_RESULT( chdir, err ); + + checkcwd( "/ram" ); + + diag_printf("<INFO>: mkdir noonoo\n"); + err = mkdir( "noonoo", 0 ); + if( err < 0 ) SHOW_RESULT( mkdir, err ); + + listdir( "." , true, existingdirents+3, NULL); + + diag_printf("<INFO>: cd noonoo\n"); + err = chdir( "noonoo" ); + if( err < 0 ) SHOW_RESULT( chdir, err ); + + checkcwd( "/ram/noonoo" ); + + createfile( "tinky", 678 ); + checkfile( "tinky" ); + + createfile( "dipsy", 3456 ); + checkfile( "dipsy" ); + copyfile( "dipsy", "po" ); + checkfile( "po" ); + comparefiles( "dipsy", "po" ); + + listdir( ".", true, 5, NULL ); + listdir( "", true, 5, NULL ); + listdir( "..", true, existingdirents+3, NULL ); + + // -------------------------------------------------------------- + + diag_printf("<INFO>: unlink tinky\n"); + err = unlink( "tinky" ); + if( err < 0 ) SHOW_RESULT( unlink, err ); + + diag_printf("<INFO>: unlink dipsy\n"); + err = unlink( "dipsy" ); + if( err < 0 ) SHOW_RESULT( unlink, err ); + + diag_printf("<INFO>: unlink po\n"); + err = unlink( "po" ); + if( err < 0 ) SHOW_RESULT( unlink, err ); + + diag_printf("<INFO>: cd ..\n"); + err = chdir( ".." ); + if( err < 0 ) SHOW_RESULT( chdir, err ); + checkcwd( "/ram" ); + + diag_printf("<INFO>: rmdir noonoo\n"); + err = rmdir( "noonoo" ); + if( err < 0 ) SHOW_RESULT( rmdir, err ); + + // -------------------------------------------------------------- + + err = mkdir( "x", 0 ); + if( err < 0 ) SHOW_RESULT( mkdir, err ); + + err = mkdir( "x/y", 0 ); + if( err < 0 ) SHOW_RESULT( mkdir, err ); + + err = mkdir( "x/y/z", 0 ); + if( err < 0 ) SHOW_RESULT( mkdir, err ); + + err = mkdir( "x/y/z/w", 0 ); + if( err < 0 ) SHOW_RESULT( mkdir, err ); + + diag_printf("<INFO>: cd /ram/x/y/z/w\n"); + err = chdir( "/ram/x/y/z/w" ); + if( err < 0 ) SHOW_RESULT( chdir, err ); + checkcwd( "/ram/x/y/z/w" ); + + diag_printf("<INFO>: cd ..\n"); + err = chdir( ".." ); + if( err < 0 ) SHOW_RESULT( chdir, err ); + checkcwd( "/ram/x/y/z" ); + + diag_printf("<INFO>: cd .\n"); + err = chdir( "." ); + if( err < 0 ) SHOW_RESULT( chdir, err ); + checkcwd( "/ram/x/y/z" ); + + diag_printf("<INFO>: cd ../../y\n"); + err = chdir( "../../y" ); + if( err < 0 ) SHOW_RESULT( chdir, err ); + checkcwd( "/ram/x/y" ); + + diag_printf("<INFO>: cd ../..\n"); + err = chdir( "../.." ); + if( err < 0 ) SHOW_RESULT( chdir, err ); + checkcwd( "/ram" ); + + diag_printf("<INFO>: rmdir x/y/z/w\n"); + err = rmdir( "x/y/z/w" ); + if( err < 0 ) SHOW_RESULT( rmdir, err ); + + diag_printf("<INFO>: rmdir x/y/z\n"); + err = rmdir( "x/y/z" ); + if( err < 0 ) SHOW_RESULT( rmdir, err ); + + diag_printf("<INFO>: rmdir x/y\n"); + err = rmdir( "x/y" ); + if( err < 0 ) SHOW_RESULT( rmdir, err ); + + diag_printf("<INFO>: rmdir x\n"); + err = rmdir( "x" ); + if( err < 0 ) SHOW_RESULT( rmdir, err ); + + // -------------------------------------------------------------- + + diag_printf("<INFO>: unlink tinky\n"); + err = unlink( "tinky" ); + if( err < 0 ) SHOW_RESULT( unlink, err ); + + diag_printf("<INFO>: unlink laalaa\n"); + err = unlink( "laalaa" ); + if( err < 0 ) SHOW_RESULT( unlink, err ); + + diag_printf("<INFO>: cd /\n"); + err = chdir( "/" ); + if( err < 0 ) SHOW_RESULT( chdir, err ); + checkcwd( "/" ); + + diag_printf("<INFO>: umount /ram\n"); + err = umount( "/ram" ); + if( err < 0 ) SHOW_RESULT( umount, err ); + + CYG_TEST_PASS_FINISH("ramfs1"); +} + +// ------------------------------------------------------------------------- +// EOF ramfs1.c
--- a/packages/fs/rom/current/ChangeLog +++ b/packages/fs/rom/current/ChangeLog @@ -1,3 +1,9 @@ +2004-12-13 John Dallaway <jld@ecoscentric.com> + + * tests/fileio1.c: Rename to romfs1.c. eCos test names should be + unique. + * cdl/romfs.cdl: Build the romfs1 test. + 2004-10-04 Andrew Lunn <andrew.lunn@ascom.ch> * src/romfs.c (romfs_mount): Avoid a compiler warning about punned @@ -119,6 +125,7 @@ 2000-10-25 Richard Panton (richard.pant // ------------------------------------------- // This file is part of eCos, the Embedded Configurable Operating System. // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. +// Copyright (C) 2004 eCosCentric Limited // // eCos is free software; you can redistribute it and/or modify it under // the terms of the GNU General Public License as published by the Free
--- a/packages/fs/rom/current/cdl/romfs.cdl +++ b/packages/fs/rom/current/cdl/romfs.cdl @@ -9,6 +9,7 @@ ## ------------------------------------------- ## This file is part of eCos, the Embedded Configurable Operating System. ## Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. +## Copyright (C) 2004 eCosCentric Limited ## ## eCos is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free @@ -111,7 +112,7 @@ cdl_package CYGPKG_FS_ROM { display "ROM filesystem tests" flavor data no_define - calculated { "tests/fileio1" } + calculated { "tests/romfs1" } description " This option specifies the set of tests for the ROM filesystem package." }
deleted file mode 100644 --- a/packages/fs/rom/current/tests/fileio1.c +++ /dev/null @@ -1,387 +0,0 @@ -//========================================================================== -// -// fileio1.c -// -// Test fileio system -// -//========================================================================== -//####ECOSGPLCOPYRIGHTBEGIN#### -// ------------------------------------------- -// This file is part of eCos, the Embedded Configurable Operating System. -// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. -// -// eCos is free software; you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation; either version 2 or (at your option) any later version. -// -// eCos is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License along -// with eCos; if not, write to the Free Software Foundation, Inc., -// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. -// -// As a special exception, if other files instantiate templates or use macros -// or inline functions from this file, or you compile this file and link it -// with other works to produce a work based on this file, this file does not -// by itself cause the resulting work to be covered by the GNU General Public -// License. However the source code for this file must still be made available -// in accordance with section (3) of the GNU General Public License. -// -// This exception does not invalidate any other reasons why a work based on -// this file might be covered by the GNU General Public License. -// -// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. -// at http://sources.redhat.com/ecos/ecos-license/ -// ------------------------------------------- -//####ECOSGPLCOPYRIGHTEND#### -//========================================================================== -//#####DESCRIPTIONBEGIN#### -// -// Author(s): nickg -// Contributors: nickg, richard.panton@3glab.com, jlarmour -// Date: 2000-05-25 -// Purpose: Test fileio system -// Description: This test uses the testfs to check out the initialization -// and basic operation of the fileio system -// -//####DESCRIPTIONEND#### -// -//========================================================================== - -#include <pkgconf/hal.h> -#include <pkgconf/io_fileio.h> -#include <pkgconf/isoinfra.h> -#include <pkgconf/system.h> - -#include <unistd.h> -#include <fcntl.h> -#include <sys/stat.h> -#include <errno.h> -#include <string.h> -#include <dirent.h> -#include <stdio.h> - -#include <cyg/fileio/fileio.h> - -#include <cyg/infra/cyg_type.h> -#include <cyg/infra/testcase.h> -#include <cyg/infra/diag.h> // HAL polled output - -// Test ROMFS data. Two example data files are generated so that -// the test will work on both big-endian and little-endian targets. -#if (CYG_BYTEORDER == CYG_LSBFIRST) -# include <cyg/romfs/testromfs_le.h> -#else -# include <cyg/romfs/testromfs_be.h> -#endif - -//========================================================================== - -MTAB_ENTRY( romfs_mte1, - "/", - "romfs", - "", - (CYG_ADDRWORD) &filedata[0] ); - - -//========================================================================== - -#define SHOW_RESULT( _fn, _res ) \ -diag_printf("<FAIL>: " #_fn "() returned %d %s\n", _res, _res<0?strerror(errno):""); - -#define CHKFAIL_TYPE( _fn, _res, _type ) { \ -if ( _res != -1 ) \ - diag_printf("<FAIL>: " #_fn "() returned %d (expected -1)\n", _res); \ -else if ( errno != _type ) \ - diag_printf("<FAIL>: " #_fn "() failed with errno %d (%s),\n expected %d (%s)\n", errno, strerror(errno), _type, strerror(_type) ); \ -} - -//========================================================================== - -#define IOSIZE 100 - -#define LONGNAME1 "long_file_name_that_should_take_up_more_than_one_directory_entry_1" -#define LONGNAME2 "long_file_name_that_should_take_up_more_than_one_directory_entry_2" - - -//========================================================================== - -#ifndef CYGINT_ISO_STRING_STRFUNCS - -char *strcat( char *s1, const char *s2 ) -{ - char *s = s1; - while( *s1 ) s1++; - while( (*s1++ = *s2++) != 0); - return s; -} - -#endif - -//========================================================================== - -static void listdir( char *name, int statp ) -{ - int err; - DIR *dirp; - - diag_printf("<INFO>: reading directory %s\n",name); - - dirp = opendir( name ); - if( dirp == NULL ) SHOW_RESULT( opendir, -1 ); - - for(;;) - { - struct dirent *entry = readdir( dirp ); - - if( entry == NULL ) - break; - - diag_printf("<INFO>: entry %14s",entry->d_name); - if( statp ) - { - char fullname[PATH_MAX]; - struct stat sbuf; - - if( name[0] ) - { - strcpy(fullname, name ); - if( !(name[0] == '/' && name[1] == 0 ) ) - strcat(fullname, "/" ); - } - else fullname[0] = 0; - - strcat(fullname, entry->d_name ); - - err = stat( fullname, &sbuf ); - if( err < 0 ) - { - if( errno == ENOSYS ) - diag_printf(" <no status available>"); - else SHOW_RESULT( stat, err ); - } - else - { - diag_printf(" [mode %08x ino %08x nlink %d size %d]", - sbuf.st_mode,sbuf.st_ino,sbuf.st_nlink,sbuf.st_size); - } - } - - diag_printf("\n"); - } - - err = closedir( dirp ); - if( err < 0 ) SHOW_RESULT( stat, err ); -} - -//========================================================================== - -#ifdef CYGPKG_FS_RAM -static void copyfile( char *name2, char *name1 ) -{ - - int err; - char buf[IOSIZE]; - int fd1, fd2; - ssize_t done, wrote; - - diag_printf("<INFO>: copy file %s -> %s\n",name2,name1); - - err = access( name1, F_OK ); - if( err < 0 && errno != EACCES ) SHOW_RESULT( access, err ); - - err = access( name2, F_OK ); - if( err != 0 ) SHOW_RESULT( access, err ); - - fd1 = open( name1, O_WRONLY|O_CREAT ); - if( fd1 < 0 ) SHOW_RESULT( open, fd1 ); - - fd2 = open( name2, O_RDONLY ); - if( fd2 < 0 ) SHOW_RESULT( open, fd2 ); - - for(;;) - { - done = read( fd2, buf, IOSIZE ); - if( done < 0 ) SHOW_RESULT( read, done ); - - if( done == 0 ) break; - - wrote = write( fd1, buf, done ); - if( wrote != done ) SHOW_RESULT( write, wrote ); - - if( wrote != done ) break; - } - - err = close( fd1 ); - if( err < 0 ) SHOW_RESULT( close, err ); - - err = close( fd2 ); - if( err < 0 ) SHOW_RESULT( close, err ); - -} -#endif - -//========================================================================== - -static void comparefiles( char *name2, char *name1 ) -{ - int err; - char buf1[IOSIZE]; - char buf2[IOSIZE]; - int fd1, fd2; - ssize_t done1, done2; - int i; - - diag_printf("<INFO>: compare files %s == %s\n",name2,name1); - - err = access( name1, F_OK ); - if( err != 0 ) SHOW_RESULT( access, err ); - - err = access( name1, F_OK ); - if( err != 0 ) SHOW_RESULT( access, err ); - - fd1 = open( name1, O_RDONLY ); - if( fd1 < 0 ) SHOW_RESULT( open, fd1 ); - - fd2 = open( name2, O_RDONLY ); - if( fd2 < 0 ) SHOW_RESULT( open, fd2 ); - - for(;;) - { - done1 = read( fd1, buf1, IOSIZE ); - if( done1 < 0 ) SHOW_RESULT( read, done1 ); - - done2 = read( fd2, buf2, IOSIZE ); - if( done2 < 0 ) SHOW_RESULT( read, done2 ); - - if( done1 != done2 ) - diag_printf("Files different sizes\n"); - - if( done1 == 0 ) break; - - for( i = 0; i < done1; i++ ) - if( buf1[i] != buf2[i] ) - { - diag_printf("buf1[%d](%02x) != buf1[%d](%02x)\n",i,buf1[i],i,buf2[i]); - CYG_TEST_FAIL("Data in files not equal\n"); - } - } - - err = close( fd1 ); - if( err < 0 ) SHOW_RESULT( close, err ); - - err = close( fd2 ); - if( err < 0 ) SHOW_RESULT( close, err ); - -} - -//========================================================================== -// main - -int main( int argc, char **argv ) -{ - int err; - char address[16]; - - CYG_TEST_INIT(); - - // -------------------------------------------------------------- - - diag_printf("<INFO>: ROMFS root follows\n"); - listdir( "/", true ); - - diag_printf("<INFO>: cd /etc\n" ); - err = chdir( "/etc" ); - if ( err < 0 ) { - SHOW_RESULT( chdir, err ); - CYG_TEST_FAIL_FINISH("fileio1"); - } - - diag_printf("<INFO>: ROMFS list of '' follows\n"); - listdir( "", true ); - - diag_printf("<INFO>: ROMFS list of /etc follows\n"); - listdir( "/etc", true ); - - diag_printf("<INFO>: ROMFS list of . follows\n"); - listdir( ".", true ); - -#ifdef CYGPKG_FS_RAM - err = mount( "", "/var", "ramfs" ); - if( err < 0 ) SHOW_RESULT( mount, err ); - - copyfile( "/etc/passwd", "/var/passwd_copy" ); - - comparefiles( "/etc/passwd", "/var/passwd_copy" ); -#endif - - diag_printf("<INFO>: ROMFS list of / follows\n"); -#ifdef CYGPKG_FS_RAM - diag_printf("<INFO>: Note that /var now gives stat() info for RAMFS\n"); -#endif - listdir( "/", true ); - - diag_printf("<INFO>: Mount ROMFS again onto /mnt\n"); - sprintf( address, "%p", (void*)&filedata[0] ); - err = mount( address, "/mnt", "romfs" ); - if( err < 0 ) SHOW_RESULT( mount, err ); - - comparefiles( "/etc/passwd", "/mnt/etc/passwd" ); - - - err = mkdir( "/foo", 0 ); - CHKFAIL_TYPE( mkdir, err, EROFS ); - - err = rename( "/var", "/tmp" ); // RAMFS is mounted here -#ifdef CYGPKG_FS_RAM - CHKFAIL_TYPE( rename, err, EXDEV ); -#else - CHKFAIL_TYPE( rename, err, EROFS ); -#endif - - err = rename( "/var/passwd_copy", "/mnt/etc/passwd_copy" ); - CHKFAIL_TYPE( rename, err, EXDEV ); - - err = rename( "/etc", "/tmp" ); - CHKFAIL_TYPE( rename, err, EROFS ); - - diag_printf("<INFO>: cd /etc\n"); - err = chdir( "/etc" ); - if( err < 0 ) SHOW_RESULT( chdir, err ); - - err = chdir( "/mnt/etc" ); - if( err < 0 ) SHOW_RESULT( chdir, err ); - - listdir( ".", true ); - - diag_printf("<INFO>: unlink /tmp\n"); - err = unlink( "/tmp" ); - CHKFAIL_TYPE( unlink, err, EROFS ); - - diag_printf("<INFO>: mount random area\n"); - sprintf(address, "%p", (void*)(&filedata[0] + 0x100)); - err = mount( address, "/tmp", "romfs" ); - CHKFAIL_TYPE( mount, err, ENOENT ); - - err = umount( "/mnt" ); - if( err < 0 ) SHOW_RESULT( umount, err ); - - err = umount( "/var" ); -#ifdef CYGPKG_FS_RAM - if( err < 0 ) SHOW_RESULT( umount, err ); -#else - CHKFAIL_TYPE( umount, err, EINVAL ); -#endif - - err = umount( "/" ); - if( err < 0 ) SHOW_RESULT( umount, err ); - - - CYG_TEST_PASS_FINISH("fileio1"); -} - -// ------------------------------------------------------------------------- -// EOF fileio1.c
new file mode 100644 --- /dev/null +++ b/packages/fs/rom/current/tests/romfs1.c @@ -0,0 +1,388 @@ +//========================================================================== +// +// romfs1.c +// +// Test fileio system +// +//========================================================================== +//####ECOSGPLCOPYRIGHTBEGIN#### +// ------------------------------------------- +// This file is part of eCos, the Embedded Configurable Operating System. +// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. +// Copyright (C) 2004 eCosCentric Limited +// +// eCos is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 2 or (at your option) any later version. +// +// eCos is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with eCos; if not, write to the Free Software Foundation, Inc., +// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +// +// As a special exception, if other files instantiate templates or use macros +// or inline functions from this file, or you compile this file and link it +// with other works to produce a work based on this file, this file does not +// by itself cause the resulting work to be covered by the GNU General Public +// License. However the source code for this file must still be made available +// in accordance with section (3) of the GNU General Public License. +// +// This exception does not invalidate any other reasons why a work based on +// this file might be covered by the GNU General Public License. +// +// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. +// at http://sources.redhat.com/ecos/ecos-license/ +// ------------------------------------------- +//####ECOSGPLCOPYRIGHTEND#### +//========================================================================== +//#####DESCRIPTIONBEGIN#### +// +// Author(s): nickg +// Contributors: nickg, richard.panton@3glab.com, jlarmour +// Date: 2000-05-25 +// Purpose: Test fileio system +// Description: This test uses the testfs to check out the initialization +// and basic operation of the fileio system +// +//####DESCRIPTIONEND#### +// +//========================================================================== + +#include <pkgconf/hal.h> +#include <pkgconf/io_fileio.h> +#include <pkgconf/isoinfra.h> +#include <pkgconf/system.h> + +#include <unistd.h> +#include <fcntl.h> +#include <sys/stat.h> +#include <errno.h> +#include <string.h> +#include <dirent.h> +#include <stdio.h> + +#include <cyg/fileio/fileio.h> + +#include <cyg/infra/cyg_type.h> +#include <cyg/infra/testcase.h> +#include <cyg/infra/diag.h> // HAL polled output + +// Test ROMFS data. Two example data files are generated so that +// the test will work on both big-endian and little-endian targets. +#if (CYG_BYTEORDER == CYG_LSBFIRST) +# include <cyg/romfs/testromfs_le.h> +#else +# include <cyg/romfs/testromfs_be.h> +#endif + +//========================================================================== + +MTAB_ENTRY( romfs_mte1, + "/", + "romfs", + "", + (CYG_ADDRWORD) &filedata[0] ); + + +//========================================================================== + +#define SHOW_RESULT( _fn, _res ) \ +diag_printf("<FAIL>: " #_fn "() returned %d %s\n", _res, _res<0?strerror(errno):""); + +#define CHKFAIL_TYPE( _fn, _res, _type ) { \ +if ( _res != -1 ) \ + diag_printf("<FAIL>: " #_fn "() returned %d (expected -1)\n", _res); \ +else if ( errno != _type ) \ + diag_printf("<FAIL>: " #_fn "() failed with errno %d (%s),\n expected %d (%s)\n", errno, strerror(errno), _type, strerror(_type) ); \ +} + +//========================================================================== + +#define IOSIZE 100 + +#define LONGNAME1 "long_file_name_that_should_take_up_more_than_one_directory_entry_1" +#define LONGNAME2 "long_file_name_that_should_take_up_more_than_one_directory_entry_2" + + +//========================================================================== + +#ifndef CYGINT_ISO_STRING_STRFUNCS + +char *strcat( char *s1, const char *s2 ) +{ + char *s = s1; + while( *s1 ) s1++; + while( (*s1++ = *s2++) != 0); + return s; +} + +#endif + +//========================================================================== + +static void listdir( char *name, int statp ) +{ + int err; + DIR *dirp; + + diag_printf("<INFO>: reading directory %s\n",name); + + dirp = opendir( name ); + if( dirp == NULL ) SHOW_RESULT( opendir, -1 ); + + for(;;) + { + struct dirent *entry = readdir( dirp ); + + if( entry == NULL ) + break; + + diag_printf("<INFO>: entry %14s",entry->d_name); + if( statp ) + { + char fullname[PATH_MAX]; + struct stat sbuf; + + if( name[0] ) + { + strcpy(fullname, name ); + if( !(name[0] == '/' && name[1] == 0 ) ) + strcat(fullname, "/" ); + } + else fullname[0] = 0; + + strcat(fullname, entry->d_name ); + + err = stat( fullname, &sbuf ); + if( err < 0 ) + { + if( errno == ENOSYS ) + diag_printf(" <no status available>"); + else SHOW_RESULT( stat, err ); + } + else + { + diag_printf(" [mode %08x ino %08x nlink %d size %d]", + sbuf.st_mode,sbuf.st_ino,sbuf.st_nlink,sbuf.st_size); + } + } + + diag_printf("\n"); + } + + err = closedir( dirp ); + if( err < 0 ) SHOW_RESULT( stat, err ); +} + +//========================================================================== + +#ifdef CYGPKG_FS_RAM +static void copyfile( char *name2, char *name1 ) +{ + + int err; + char buf[IOSIZE]; + int fd1, fd2; + ssize_t done, wrote; + + diag_printf("<INFO>: copy file %s -> %s\n",name2,name1); + + err = access( name1, F_OK ); + if( err < 0 && errno != EACCES ) SHOW_RESULT( access, err ); + + err = access( name2, F_OK ); + if( err != 0 ) SHOW_RESULT( access, err ); + + fd1 = open( name1, O_WRONLY|O_CREAT ); + if( fd1 < 0 ) SHOW_RESULT( open, fd1 ); + + fd2 = open( name2, O_RDONLY ); + if( fd2 < 0 ) SHOW_RESULT( open, fd2 ); + + for(;;) + { + done = read( fd2, buf, IOSIZE ); + if( done < 0 ) SHOW_RESULT( read, done ); + + if( done == 0 ) break; + + wrote = write( fd1, buf, done ); + if( wrote != done ) SHOW_RESULT( write, wrote ); + + if( wrote != done ) break; + } + + err = close( fd1 ); + if( err < 0 ) SHOW_RESULT( close, err ); + + err = close( fd2 ); + if( err < 0 ) SHOW_RESULT( close, err ); + +} +#endif + +//========================================================================== + +static void comparefiles( char *name2, char *name1 ) +{ + int err; + char buf1[IOSIZE]; + char buf2[IOSIZE]; + int fd1, fd2; + ssize_t done1, done2; + int i; + + diag_printf("<INFO>: compare files %s == %s\n",name2,name1); + + err = access( name1, F_OK ); + if( err != 0 ) SHOW_RESULT( access, err ); + + err = access( name1, F_OK ); + if( err != 0 ) SHOW_RESULT( access, err ); + + fd1 = open( name1, O_RDONLY ); + if( fd1 < 0 ) SHOW_RESULT( open, fd1 ); + + fd2 = open( name2, O_RDONLY ); + if( fd2 < 0 ) SHOW_RESULT( open, fd2 ); + + for(;;) + { + done1 = read( fd1, buf1, IOSIZE ); + if( done1 < 0 ) SHOW_RESULT( read, done1 ); + + done2 = read( fd2, buf2, IOSIZE ); + if( done2 < 0 ) SHOW_RESULT( read, done2 ); + + if( done1 != done2 ) + diag_printf("Files different sizes\n"); + + if( done1 == 0 ) break; + + for( i = 0; i < done1; i++ ) + if( buf1[i] != buf2[i] ) + { + diag_printf("buf1[%d](%02x) != buf1[%d](%02x)\n",i,buf1[i],i,buf2[i]); + CYG_TEST_FAIL("Data in files not equal\n"); + } + } + + err = close( fd1 ); + if( err < 0 ) SHOW_RESULT( close, err ); + + err = close( fd2 ); + if( err < 0 ) SHOW_RESULT( close, err ); + +} + +//========================================================================== +// main + +int main( int argc, char **argv ) +{ + int err; + char address[16]; + + CYG_TEST_INIT(); + + // -------------------------------------------------------------- + + diag_printf("<INFO>: ROMFS root follows\n"); + listdir( "/", true ); + + diag_printf("<INFO>: cd /etc\n" ); + err = chdir( "/etc" ); + if ( err < 0 ) { + SHOW_RESULT( chdir, err ); + CYG_TEST_FAIL_FINISH("romfs1"); + } + + diag_printf("<INFO>: ROMFS list of '' follows\n"); + listdir( "", true ); + + diag_printf("<INFO>: ROMFS list of /etc follows\n"); + listdir( "/etc", true ); + + diag_printf("<INFO>: ROMFS list of . follows\n"); + listdir( ".", true ); + +#ifdef CYGPKG_FS_RAM + err = mount( "", "/var", "ramfs" ); + if( err < 0 ) SHOW_RESULT( mount, err ); + + copyfile( "/etc/passwd", "/var/passwd_copy" ); + + comparefiles( "/etc/passwd", "/var/passwd_copy" ); +#endif + + diag_printf("<INFO>: ROMFS list of / follows\n"); +#ifdef CYGPKG_FS_RAM + diag_printf("<INFO>: Note that /var now gives stat() info for RAMFS\n"); +#endif + listdir( "/", true ); + + diag_printf("<INFO>: Mount ROMFS again onto /mnt\n"); + sprintf( address, "%p", (void*)&filedata[0] ); + err = mount( address, "/mnt", "romfs" ); + if( err < 0 ) SHOW_RESULT( mount, err ); + + comparefiles( "/etc/passwd", "/mnt/etc/passwd" ); + + + err = mkdir( "/foo", 0 ); + CHKFAIL_TYPE( mkdir, err, EROFS ); + + err = rename( "/var", "/tmp" ); // RAMFS is mounted here +#ifdef CYGPKG_FS_RAM + CHKFAIL_TYPE( rename, err, EXDEV ); +#else + CHKFAIL_TYPE( rename, err, EROFS ); +#endif + + err = rename( "/var/passwd_copy", "/mnt/etc/passwd_copy" ); + CHKFAIL_TYPE( rename, err, EXDEV ); + + err = rename( "/etc", "/tmp" ); + CHKFAIL_TYPE( rename, err, EROFS ); + + diag_printf("<INFO>: cd /etc\n"); + err = chdir( "/etc" ); + if( err < 0 ) SHOW_RESULT( chdir, err ); + + err = chdir( "/mnt/etc" ); + if( err < 0 ) SHOW_RESULT( chdir, err ); + + listdir( ".", true ); + + diag_printf("<INFO>: unlink /tmp\n"); + err = unlink( "/tmp" ); + CHKFAIL_TYPE( unlink, err, EROFS ); + + diag_printf("<INFO>: mount random area\n"); + sprintf(address, "%p", (void*)(&filedata[0] + 0x100)); + err = mount( address, "/tmp", "romfs" ); + CHKFAIL_TYPE( mount, err, ENOENT ); + + err = umount( "/mnt" ); + if( err < 0 ) SHOW_RESULT( umount, err ); + + err = umount( "/var" ); +#ifdef CYGPKG_FS_RAM + if( err < 0 ) SHOW_RESULT( umount, err ); +#else + CHKFAIL_TYPE( umount, err, EINVAL ); +#endif + + err = umount( "/" ); + if( err < 0 ) SHOW_RESULT( umount, err ); + + + CYG_TEST_PASS_FINISH("romfs1"); +} + +// ------------------------------------------------------------------------- +// EOF romfs1.c
