Files
rtems/testsuites/psxtests/psxchroot01/test.c
Joel Sherrill 33c46f1a70 2010-10-21 Joel Sherrill <joel.sherrill@oarcorp.com>
* psx02/init.c, psx02/task.c, psx03/init.c, psx04/init.c,
	psx04/task1.c, psx04/task2.c, psx04/task3.c, psx05/init.c,
	psx05/task.c, psx05/task2.c, psx05/task3.c, psx06/init.c,
	psx06/task.c, psx06/task2.c, psx07/init.c, psx08/init.c,
	psx08/task2.c, psx08/task3.c, psx09/init.c, psx10/init.c,
	psx10/task.c, psx10/task2.c, psx10/task3.c, psx11/init.c,
	psx11/task.c, psx12/init.c, psxalarm01/init.c, psxbarrier01/test.c,
	psxcancel01/init.c, psxchroot01/test.c, psxitimer/init.c,
	psxkey01/task.c, psxkey02/init.c, psxkey03/init.c, psxmount/test.c,
	psxmsgq01/init.c, psxmsgq03/init.c, psxmsgq04/init.c,
	psxrwlock01/test.c, psxsem01/init.c, psxsignal01/init.c,
	psxsignal01/task1.c, psxsignal02/init.c, psxsignal03/init.c,
	psxsignal05/init.c, psxspin01/test.c, psxspin02/test.c,
	psxstack01/init.c, psxstack02/init.c, psxualarm/init.c: Eliminate
	double space after parenthesis on rtems_test_assert().
2010-10-21 21:22:25 +00:00

144 lines
3.4 KiB
C

/*
* 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.
*
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#include <stdio.h>
#include <sys/types.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <rtems/libio.h>
#include <rtems/userenv.h>
#include <pmacros.h>
#include <rtems/libcsupport.h>
void touch( char *file )
{
int fd;
rtems_test_assert( file );
fd = open( file, O_RDWR|O_CREAT, 0777 );
rtems_test_assert( fd != -1 );
close( fd );
}
int fileexists( char *file )
{
int status;
struct stat statbuf;
rtems_test_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 status;
void *alloc_ptr = (void *)0;
/*
* This test is the C equivalent of this sequence.
#mkdir /one
#mkdir /one/one
#touch /one/one.test
#touch /one/two/two.test
# an error case to ENOTSUP from chroot
# chroot
#chroot /one
#if !fileexists(/one/one.test) echo "SUCCESSFUL"
#if fileexists(/two/two.test) echo "SUCCESSFUL"
#rtems_set_private_env() ! reset at the global environment
#if fileexists(/one/one.test) echo "SUCESSFUL"
#if !fileexists(/two/two.test) echo "SUCCESSFUL"
*/
printf( "\n\n*** CHROOT01 TEST ***\n" );
status = mkdir( "/one", 0777);
rtems_test_assert( status == 0 );
status = mkdir( "/one/one", 0777);
rtems_test_assert( status == 0 );
status = mkdir( "/one/two", 0777);
rtems_test_assert( status == 0 );
touch( "/one/one.test" );
touch( "/one/two/two.test" );
puts( "allocate most of memory - attempt to fail chroot - expect ENOTSUP" );
alloc_ptr = malloc( malloc_free_space() - 4 );
rtems_test_assert( alloc_ptr != NULL );
status = chroot( "/one" );
rtems_test_assert( status == -1 );
rtems_test_assert( errno == ENOTSUP );
puts( "freeing the allocated memory" );
free( alloc_ptr );
puts( "chroot with bad path - expect EFAULT" );
status = chroot( NULL );
rtems_test_assert( status == -1 );
rtems_test_assert( errno == EFAULT );
status = chroot( "/one" );
rtems_test_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" );
rtems_test_exit(0);
}