From 6287b5773f610368df70df3127586b9440e7b802 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Fri, 25 May 2001 13:29:38 +0000 Subject: 2001-05-25 Joel Sherrill * Added once version of psxchroot01 test for user review. * psxchroot01: New directory. * psxchroot01/Makefile.am, psxchroot01/main.c, psxchroot01/test.c, psxchroot01/psxchroot01.scn, psxchroot01/.cvsignore: New files. * configure.in, Makefile.am: Modified to reflect above. --- testsuites/psxtests/psxchroot01/test.c | 122 +++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 testsuites/psxtests/psxchroot01/test.c (limited to 'testsuites/psxtests/psxchroot01/test.c') diff --git a/testsuites/psxtests/psxchroot01/test.c b/testsuites/psxtests/psxchroot01/test.c new file mode 100644 index 0000000000..cc759a2dc2 --- /dev/null +++ b/testsuites/psxtests/psxchroot01/test.c @@ -0,0 +1,122 @@ +/* + * This is a native test to explore how the readdir() family works. + * Newlib supports the following readdir() family members: + * + * closedir() - + * readdir() - + * scandir() - + * opendir() - + * rewinddir() - + * telldir() - BSD not in POSIX + * seekdir() - BSD not in POSIX + * + * + * seekdir() takes an offset which is a byte offset. The Linux + * implementation of this appears to seek to the ((off/DIRENT_SIZE) + 1) + * record where DIRENT_SIZE seems to be 12 bytes. + * + * + * + * $Id$ + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +void touch( char *file ) +{ + int fd; + + assert( file ); + + fd = open( file, O_RDWR|O_CREAT, 0777 ); + assert( fd != -1 ); + close( fd ); +} + +int fileexists( char *file ) +{ + int status; + struct stat statbuf; + + assert( file ); + + status = stat( file, &statbuf ); + + if ( status == -1 ) { + /* printf( ": %s\n", strerror( errno ) ); */ + return 0; + } + return 1; +} + +#if defined(__rtems__) +int test_main(void) +#else +int main( + int argc, + char **argv +) +#endif +{ + int fd; + int i; + int status; + struct stat s; + +/* + * This test is the C equivalent of this sequence. +#mkdir /one +#mkdir /one/one +#touch /one/one.test +#touch /one/two/two.test +#chroot /one +#if !fileexits(/one/one.test) echo "FAIL" +#if fileexits(/two/two.test) echo "SUCCESSFUL" +#rtems_set_private_env() ! reset at the global environment +#if !fileexits(/one/one.test) echo "SUCESSFUL" +#if fileexits(/two/two.test) echo "FAIL" +*/ + + printf( "\n\n*** CHROOT01 TEST ***\n" ); + + status = mkdir( "/one", 0777); + assert( status == 0 ); + + status = mkdir( "/one/one", 0777); + assert( status == 0 ); + + status = mkdir( "/one/two", 0777); + assert( status == 0 ); + + touch( "/one/one.test" ); + touch( "/one/two/two.test" ); + + status = chroot( "/one" ); + assert( status == 0 ); + + status = fileexists( "/one/one.test" ); + printf( "%s on /one/one.test\n", (!status) ? "SUCCESS" : "FAILURE" ); + + status = fileexists( "/two/two.test" ); + printf( "%s on /two/two.test\n", (status) ? "SUCCESS" : "FAILURE" ); + + puts( "Reset the private environment" ); + rtems_libio_set_private_env(); + + status = fileexists( "/one/one.test" ); + printf( "%s on /one/one.test\n", (!status) ? "SUCCESS" : "FAILURE" ); + + status = fileexists( "/two/two.test" ); + printf( "%s on /two/two.test\n", (status) ? "SUCCESS" : "FAILURE" ); + + printf( "*** END OF CHROOT01 TEST ***\n" ); + exit(0); +} + -- cgit v1.2.3