2010-07-17 Bharath Suri <bharath.s.jois@gmail.com>

PR 1622/testing
	* psxchroot01/test.c, psxchroot01/psxchroot01.scn: Added two test
	cases to completely cover chroot().
This commit is contained in:
Joel Sherrill
2010-07-16 19:19:09 +00:00
parent 917e4b4781
commit 24db9ba8bb
3 changed files with 35 additions and 4 deletions

View File

@@ -1,3 +1,9 @@
2010-07-17 Bharath Suri <bharath.s.jois@gmail.com>
PR 1622/testing
* psxchroot01/test.c, psxchroot01/psxchroot01.scn: Added two test
cases to completely cover chroot().
2010-07-16 Sebastian Huber <Sebastian.Huber@embedded-brains.de>
* psxfile01/test.c: Avoid NULL pointer access.

View File

@@ -1,6 +1,8 @@
*** CHROOT01 TEST ***
allocate most of memory - attempt to fail chroot - expect ENOTSUP
freeing the allocated memory
chroot with bad path - expect EFAULT
SUCCESS on /one/one.test
SUCCESS on /two/two.test
Reset the private environment

View File

@@ -15,7 +15,7 @@
* implementation of this appears to seek to the ((off/DIRENT_SIZE) + 1)
* record where DIRENT_SIZE seems to be 12 bytes.
*
* COPYRIGHT (c) 1989-2009.
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -34,6 +34,7 @@
#include <rtems/libio.h>
#include <rtems/userenv.h>
#include <pmacros.h>
#include <rtems/score/heap.h>
void touch( char *file )
{
@@ -63,6 +64,8 @@ int fileexists( char *file )
}
#if defined(__rtems__)
extern Heap_Control *RTEMS_Malloc_Heap;
int test_main(void)
#else
int main(
@@ -72,13 +75,16 @@ int main(
#endif
{
int status;
void *alloc_ptr = (void *)0;
Heap_Information_block Info;
/*
* 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"
@@ -101,6 +107,23 @@ int main(
touch( "/one/one.test" );
touch( "/one/two/two.test" );
puts( "allocate most of memory - attempt to fail chroot - expect ENOTSUP" );
_Heap_Get_information(RTEMS_Malloc_Heap, &Info);
alloc_ptr = malloc( Info.Free.largest - 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 );