Ejemplo n.º 1
0
Archivo: init.c Proyecto: gedare/rtems
static void test_device_install_remove(void)
{
  static const rtems_termios_device_handler handler;
  static const char dev[] = "/foobar";

  rtems_resource_snapshot snapshot;
  rtems_status_code sc;
  void *greedy;
  int rv;

  rtems_resource_snapshot_take( &snapshot );

  greedy = rtems_heap_greedy_allocate( NULL, 0 );

  sc = rtems_termios_device_install( "/", &handler, NULL, NULL );
  rtems_test_assert( sc == RTEMS_NO_MEMORY );

  rtems_heap_greedy_free( greedy );

  rtems_test_assert( rtems_resource_snapshot_check( &snapshot ) );

  sc = rtems_termios_device_install( "/", &handler, NULL, NULL );
  rtems_test_assert( sc == RTEMS_UNSATISFIED );

  rtems_test_assert( rtems_resource_snapshot_check( &snapshot ) );

  sc = rtems_termios_device_install( &dev[0], &handler, NULL, NULL );
  rtems_test_assert( sc == RTEMS_SUCCESSFUL );

  rv = unlink( &dev[0] );
  rtems_test_assert( rv == 0 );

  rtems_test_assert( rtems_resource_snapshot_check( &snapshot ) );
}
Ejemplo n.º 2
0
rtems_task Init(
  rtems_task_argument argument
)
{
  int status;
  rtems_filesystem_location_info_t *rootloc = &rtems_filesystem_root->location;
  const devFS_data *data = rootloc->mt_entry->immutable_fs_info;
  devFS_data zero_count_data = {
    .nodes = data->nodes,
    .count = 0
  };
  void *opaque;

  puts( "\n\n*** TEST DEVFS02 ***" );

  puts( "Init - attempt to create a fifo - expect ENOTSUP" );
  status = mkfifo( "/fifo01", 0 );
  rtems_test_assert( status == -1 );
  rtems_test_assert( errno == ENOTSUP );

  /* Manipulate the device table size */
  puts( "Init - set device table size to zero" );
  rootloc->mt_entry->immutable_fs_info = &zero_count_data;

  puts( "Init - attempt to create a node - expect ENOSPC" );
  status = mknod( "/node", S_IFBLK, 0LL );
  rtems_test_assert( status == -1 );
  rtems_test_assert( errno == ENOSPC );

  /* Now restore */
  puts( "Init - restore device table size" );
  rootloc->mt_entry->immutable_fs_info = data;

  opaque = rtems_heap_greedy_allocate( NULL, 0 );

  puts( "Init - attempt to create a node - expect ENOMEM" );
  status = mknod( "/node", S_IFBLK, 0LL );
  rtems_test_assert( status == -1 );
  rtems_test_assert( errno == ENOMEM );

  rtems_heap_greedy_free( opaque );

  puts( "Init - attempt to create /node -- OK" );
  status = mknod( "/node", S_IFBLK, 0LL );
  rtems_test_assert( status == 0 );

  puts( "Init - attempt to create /node - expect EEXIST" );
  status = mknod( "/node", S_IFBLK, 0LL );
  rtems_test_assert( status == -1 );
  rtems_test_assert( errno == EEXIST );

  puts( "*** END OF TEST DEVFS02 ***" );

  rtems_test_exit(0);
}
Ejemplo n.º 3
0
static void test_imfs_make_generic_node_errors(void)
{
  int rv = 0;
  const char *path = "generic";
  rtems_chain_control *chain = &rtems_filesystem_mount_table;
  rtems_filesystem_mount_table_entry_t *mt_entry =
    (rtems_filesystem_mount_table_entry_t *) rtems_chain_first(chain);
  const char *type = mt_entry->type;
  void *opaque = NULL;

  errno = 0;
  rv = IMFS_make_generic_node(
    path,
    S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO,
    &node_invalid_control,
    NULL
  );
  rtems_test_assert(rv == -1);
  rtems_test_assert(errno == EINVAL);

  errno = 0;
  rv = IMFS_make_generic_node(
    path,
    S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO,
    &node_control,
    NULL
  );
  rtems_test_assert(rv == -1);
  rtems_test_assert(errno == EINVAL);

  mt_entry->type = "XXX";
  errno = 0;
  rv = IMFS_make_generic_node(
    path,
    S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO,
    &node_control,
    NULL
  );
  rtems_test_assert(rv == -1);
  rtems_test_assert(errno == ENOTSUP);
  mt_entry->type = type;

  opaque = rtems_heap_greedy_allocate(NULL, 0);
  errno = 0;
  rv = IMFS_make_generic_node(
    path,
    S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO,
    &node_control,
    NULL
  );
  rtems_test_assert(rv == -1);
  rtems_test_assert(errno == ENOMEM);
  rtems_heap_greedy_free(opaque);
}
Ejemplo n.º 4
0
static void open_failure(void){

  rtems_rfs_file_system     fs;
  rtems_rfs_bitmap_control  control;
  rtems_rfs_buffer_handle   handle;
  int                       rc;
  void                     *opaque;

  /* Attempt to get ENOMEM while open bitmap */
  printf("\n Allocate most of memory - attempt to fail while open bitmap - expect ENOMEM\n" );

  opaque = rtems_heap_greedy_allocate( NULL, 0 );

  memset (&fs, 0, sizeof (fs));

  rc = rtems_rfs_buffer_handle_open (&fs, &handle);
  rtems_test_assert( rc == 0 );

  rc = rtems_rfs_bitmap_open (&control, &fs, &handle, 0, 0);
  rtems_test_assert( rc == ENOMEM );
  printf( " Attempt to open bitmap returned: %s\n", strerror(rc));
  puts( " Freeing the allocated memory" );
  rtems_heap_greedy_free( opaque );
}
Ejemplo n.º 5
0
static void test_blkdev_imfs_errors(void)
{
  static uintptr_t disk_size [] = { sizeof(rtems_disk_device) + sizeof(int) };

  rtems_status_code sc;
  int rv;
  ramdisk *rd;
  void *opaque;

  rd = ramdisk_allocate(NULL, BLOCK_SIZE, BLOCK_COUNT, false);
  rtems_test_assert(rd != NULL);

  ramdisk_enable_free_at_delete_request(rd);

  sc = rtems_blkdev_create(
    rda,
    0,
    BLOCK_COUNT,
    ramdisk_ioctl,
    rd
  );
  rtems_test_assert(sc == RTEMS_INVALID_NUMBER);

  sc = rtems_blkdev_create(
    rda,
    BLOCK_SIZE,
    0,
    ramdisk_ioctl,
    rd
  );
  rtems_test_assert(sc == RTEMS_INVALID_NUMBER);

  opaque = rtems_heap_greedy_allocate(NULL, 0);
  sc = rtems_blkdev_create(
    rda,
    BLOCK_SIZE,
    BLOCK_COUNT,
    ramdisk_ioctl,
    rd
  );
  rtems_test_assert(sc == RTEMS_NO_MEMORY);
  rtems_heap_greedy_free(opaque);

  opaque = rtems_heap_greedy_allocate(disk_size, 1);
  sc = rtems_blkdev_create(
    rda,
    BLOCK_SIZE,
    BLOCK_COUNT,
    ramdisk_ioctl,
    rd
  );
  rtems_test_assert(sc == RTEMS_UNSATISFIED);
  rtems_heap_greedy_free(opaque);

  sc = rtems_blkdev_create(
    rda,
    BLOCK_SIZE,
    BLOCK_COUNT,
    ramdisk_ioctl,
    rd
  );
  ASSERT_SC(sc);

  sc = rtems_blkdev_create_partition(
    rda1,
    not_exist,
    0,
    BLOCK_COUNT
  );
  rtems_test_assert(sc == RTEMS_INVALID_ID);

  rv = mknod(not_blkdev, S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO, 0);
  rtems_test_assert(rv == 0);

  sc = rtems_blkdev_create_partition(
    rda1,
    not_blkdev,
    0,
    BLOCK_COUNT
  );
  rtems_test_assert(sc == RTEMS_INVALID_NODE);

  rv = mknod(invalid_blkdev, S_IFBLK | S_IRWXU | S_IRWXG | S_IRWXO, 0);
  rtems_test_assert(rv == 0);

  sc = rtems_blkdev_create_partition(
    rda1,
    invalid_blkdev,
    0,
    BLOCK_COUNT
  );
  rtems_test_assert(sc == RTEMS_NOT_IMPLEMENTED);

  sc = rtems_blkdev_create_partition(
    rda1,
    rda,
    0,
    0
  );
  rtems_test_assert(sc == RTEMS_INVALID_NUMBER);

  sc = rtems_blkdev_create_partition(
    rda1,
    rda,
    BLOCK_COUNT,
    BLOCK_COUNT
  );
  rtems_test_assert(sc == RTEMS_INVALID_NUMBER);

  sc = rtems_blkdev_create_partition(
    rda1,
    rda,
    0,
    BLOCK_COUNT + 1
  );
  rtems_test_assert(sc == RTEMS_INVALID_NUMBER);

  opaque = rtems_heap_greedy_allocate(NULL, 0);
  sc = rtems_blkdev_create_partition(
    rda1,
    rda,
    0,
    BLOCK_COUNT
  );
  rtems_test_assert(sc == RTEMS_NO_MEMORY);
  rtems_heap_greedy_free(opaque);

  opaque = rtems_heap_greedy_allocate(disk_size, 1);
  sc = rtems_blkdev_create_partition(
    rda1,
    rda,
    0,
    BLOCK_COUNT
  );
  rtems_test_assert(sc == RTEMS_UNSATISFIED);
  rtems_heap_greedy_free(opaque);

  rv = unlink(rda);
  rtems_test_assert(rv == 0);
}
Ejemplo n.º 6
0
rtems_task Init(
  rtems_task_argument argument
)
{
  rtems_status_code       sc;
  void                   *opaque;
  rtems_id                current_task_id;
  rtems_id                task_id;
  rtems_name              another_task_name;
  Heap_Information_block  Info;
  
  puts( "\n\n*** TEST USER ENVIRONMENT ROUTINE - 01 ***" );

  puts( "Init - allocating most of heap -- OK" );
  opaque = rtems_heap_greedy_allocate( 0 );

  puts( "Init - attempt to reset env - expect RTEMS_NO_MEMORY" );
  sc = rtems_libio_set_private_env();
  rtems_test_assert( sc == RTEMS_NO_MEMORY );

  puts( "Init - freeing the allocated memory" );
  rtems_heap_greedy_free( opaque );

  puts( "Init - allocating most of workspace memory" );
  opaque = rtems_workspace_greedy_allocate( 0 );
  
  puts( "Init - attempt to reset env - expect RTEMS_TOO_MANY" );
  sc = rtems_libio_set_private_env();
  rtems_test_assert( sc == RTEMS_TOO_MANY );

  puts( "Init - freeing the workspace memory" );
  rtems_workspace_greedy_free( opaque );

  puts( "Init - creating a task name and a task -- OK" );

  another_task_name = 
    rtems_build_name( 'T','S','K','D' );

  sc = rtems_task_create( another_task_name,
			  1,
			  RTEMS_MINIMUM_STACK_SIZE * 2,
			  RTEMS_INTERRUPT_LEVEL(31),
			  RTEMS_DEFAULT_ATTRIBUTES,
			  &task_id
			  );

  puts( "Init - starting the task_routine, to set its private environment" );
  sc = rtems_task_start( task_id, task_routine, 0);
  rtems_test_assert( sc == RTEMS_SUCCESSFUL );

  puts( "Init - attempt to share the env with another task -- Expect error" );
  sc = rtems_libio_share_private_env( task_id );
  rtems_test_assert( sc == RTEMS_UNSATISFIED );

  sleep( 1 );

  puts( "Init - attempt to share the env with another task -- OK" );
  sc = rtems_libio_share_private_env( task_id );
  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
  rtems_test_assert( rtems_current_user_env->task_id == task_id );

  puts( "Init - Get current task id" );
  current_task_id = rtems_task_self();

  puts( "Init - Attempt to reset current task's environment" );
  sc = rtems_libio_set_private_env();
  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
  rtems_test_assert( rtems_current_user_env->task_id == current_task_id );
  
  puts( "Init - attempt to share the env with another task -- OK" );
  sc = rtems_libio_share_private_env( task_id );
  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
  rtems_test_assert( rtems_current_user_env->task_id == task_id );

  puts( "Init - attempt to share with self -- OK" );
  sc = rtems_libio_share_private_env( task_id );
  rtems_test_assert( sc == RTEMS_SUCCESSFUL );

  puts( "*** END OF TEST USER ENVIRONMENT ROUTINE - 01 ***" );

  rtems_test_exit(0);
}
Ejemplo n.º 7
0
rtems_task Init(
  rtems_task_argument argument
)
{
  static const char mount_point [] = "dir01";
  static const char fs_type [] = RTEMS_FILESYSTEM_TYPE_IMFS;
  static const char slink_2_name [] = "node-slink-2";
  static const uintptr_t mount_table_entry_size [] = {
    sizeof( rtems_filesystem_mount_table_entry_t )
      + sizeof( fs_type )
      + sizeof( rtems_filesystem_global_location_t )
  };
  static const uintptr_t slink_2_name_size [] = {
    sizeof( slink_2_name )
  };

  int status = 0;
  void *opaque;
  char linkname_n[20] = {0};
  char linkname_p[20] = {0};
  int i;
  struct stat stat_buf;

  TEST_BEGIN();

  puts( "Creating directory /dir00" );
  status = mkdir( "/dir00", S_IRWXU );
  rtems_test_assert( status == 0 );

  puts( "Creating directory /dir00/dir01" );
  status = mkdir( "/dir00/dir01", S_IRWXU );
  rtems_test_assert( status == 0 );

  puts( "Changing directory to /dir00" );
  status = chdir( "/dir00" );
  rtems_test_assert( status == 0 );

  puts( "Creating link dir01-link0 for dir01" );
  status = link( "dir01", "dir01-link0" );
  rtems_test_assert( status == 0 );

  for( i = 1 ; ; ++i ) {
    sprintf( linkname_p, "dir01-link%d", i-1 );
    sprintf( linkname_n, "dir01-link%d", i );
    printf( "\nCreating link %s for %s\n", linkname_n, linkname_p );
    status = link( linkname_p, linkname_n );
    if( status != 0 ) {
      puts("Link creation failed" );
      break;
    }
  }

  puts( "Creating a regular node /node, RDONLY" );
  status = mknod( "/node", S_IFREG | S_IRUSR, 0LL );
  rtems_test_assert( status == 0 );

  puts( "Creating link /node-link for /node" );
  status = link( "/node" , "/node-link" );
  rtems_test_assert( status == 0 );

  puts( "Opening /node-link in WRONLY mode -- expect EACCES" );
  status = open( "/node-link", O_WRONLY );
  rtems_test_assert( status == -1 );
  rtems_test_assert( errno == EACCES );

  puts( "Creating a symlink /node-slink for /node" );
  status = symlink( "/node" , "/node-slink" );
  rtems_test_assert( status == 0 );

  puts( "Opening /node-slink in WRONLY mode -- expect EACCES" );  
  status = open( "/node-slink", O_WRONLY );
  rtems_test_assert( status == -1 );
  rtems_test_assert( errno == EACCES );

  puts( "Allocate most of heap" );
  opaque = rtems_heap_greedy_allocate( mount_table_entry_size, 1 );

  printf( "Attempt to mount a fs at %s -- expect ENOMEM", mount_point );
  status = mount( NULL,
		  mount_point,
		  fs_type,
		  RTEMS_FILESYSTEM_READ_WRITE,
		  NULL );
  rtems_test_assert( status == -1 );
  rtems_test_assert( errno == ENOMEM );

  puts( "Freeing allocated memory" );
  rtems_heap_greedy_free( opaque );

  puts( "Changing directory to /" );
  status = chdir( "/" );
  rtems_test_assert( status == 0 );

  puts( "Allocate most of heap" );
  opaque = rtems_heap_greedy_allocate( NULL, 0 );

  puts( "Attempt to create /node-link-2 for /node -- expect ENOMEM" );
  status = link( "/node", "/node-link-2" );
  rtems_test_assert( status == -1 );
  rtems_test_assert( errno == ENOMEM );

  puts( "Attempt to create /node-slink-2 for /node -- expect ENOMEM" );
  status = symlink( "/node", "node-slink-2" );
  rtems_test_assert( status == -1 );
  rtems_test_assert( errno == ENOMEM );

  puts( "Freeing allocated memory" );
  rtems_heap_greedy_free( opaque );

  puts( "Allocate most of heap" );
  opaque = rtems_heap_greedy_allocate( slink_2_name_size, 1 );

  printf( "Attempt to create %s for /node -- expect ENOMEM", slink_2_name );
  status = symlink( "/node", slink_2_name );
  rtems_test_assert( status == -1 );
  rtems_test_assert( errno == ENOMEM );

  puts( "Freeing allocated memory" );
  rtems_heap_greedy_free( opaque );

  puts( "Attempt to stat a hardlink" );
  status = lstat( "/node-link", &stat_buf );
  rtems_test_assert( status == 0 );

  puts( "Changing euid to 10" );
  status = seteuid( 10 );
  rtems_test_assert( status == 0 );

#if defined(RTEMS_POSIX_API)
  puts( "Attempt chmod on /node -- expect EPERM" );
  status = chmod( "/node", S_IRUSR );
  rtems_test_assert( status == -1 );
  rtems_test_assert( errno == EPERM );

  puts( "Attempt chown on /node -- expect EPERM" );
  status = chown( "/node", 10, 10 );
  rtems_test_assert( status == -1 );
  rtems_test_assert( errno == EPERM );
#else
  puts( "Attempt chmod on /node -- EPERM only when POSIX enabled" );
  puts( "Attempt chown on /node -- EPERM only when POSIX enabled" );
#endif

  puts( "Changing euid back to 0 [root]" );
  status = seteuid( 0 );
  rtems_test_assert( status == 0 );

  puts( "Creating a fifo -- OK" );
  status = mkfifo( "/fifo", S_IRWXU );
  rtems_test_assert( status == 0 );

  IMFS_dump();
  
  puts( "chown /fifo to 10 -- OK" );
  status = chown( "/fifo", 10, 10 );
  rtems_test_assert( status == 0 );

  puts( "Changing euid to 10" );
  status = seteuid( 10 );
  rtems_test_assert( status == 0 );

  puts( "chmod /fifo -- OK" );
  status = chmod( "/fifo", S_IRWXU );
  rtems_test_assert( status == 0 );

  printf( "chown /fifo to %o -- OK\n", 0 );
  status = chown( "/fifo", 0, 0 );
  rtems_test_assert( status == 0 );

  TEST_END();
  rtems_test_exit(0);
}
Ejemplo n.º 8
0
rtems_task Init(
  rtems_task_argument ignored
)
{
  int fd[2] = {0,0};
  int dummy_fd[2] = {0,0};
  int status = 0;
  void *opaque = NULL;

  TEST_BEGIN();

  puts( "Init - attempt to create pipe -- expect EFAULT" );
  status = pipe( NULL );
  rtems_test_assert( status == -1 );
  rtems_test_assert( errno == EFAULT );

  puts( "Init - create pipe -- OK" );
  status = pipe( fd );
  rtems_test_assert( status == 0 );

  status = close( fd[0] );
  status |= close( fd[1] );
  rtems_test_assert( status == 0 );

  puts( "Init - create pipe -- OK" );
  status = pipe( fd );
  rtems_test_assert( status == 0 );

  status = close( fd[0] );
  status |= close( fd[1] );
  rtems_test_assert( status == 0 );

  opaque = rtems_heap_greedy_allocate( NULL, 0 );

  /* case where mkfifo fails */
  puts( "Init - attempt to create pipe -- expect ENOMEM" );
  status = pipe( fd );
  rtems_test_assert( status == -1 );
  rtems_test_assert( errno == ENOMEM );

  rtems_heap_greedy_free( opaque );
  
  dummy_fd[0] = open( "/file01", O_RDONLY | O_CREAT, S_IRWXU );
  rtems_test_assert( dummy_fd[0] != -1 );
  dummy_fd[1] = open( "/file02", O_RDONLY | O_CREAT, S_IRWXU );
  rtems_test_assert( dummy_fd[1] != -1 );

  /* case where fifo_open for read => open fails */
  puts( "Init - create pipe -- expect ENFILE" );
  status = pipe( fd );
  rtems_test_assert( status == -1 );
  rtems_test_assert( errno == ENFILE );

  status = close( dummy_fd[1] );
  status |= unlink( "/file02" );
  rtems_test_assert( status == 0 );

  /* case where fifo_open for write => open fails */
  puts( "Init - create pipe -- expect ENFILE" );
  status = pipe( fd );
  rtems_test_assert( status == -1 );
  rtems_test_assert( errno == ENFILE );

  status = close( dummy_fd[0] );
  status |= unlink( "/file01" );
  rtems_test_assert( status == 0 );

  TEST_END();
  rtems_test_exit( 0 );
}
Ejemplo n.º 9
0
rtems_device_driver termios_test_driver_open(
  rtems_device_major_number major,
  rtems_device_minor_number minor,
  void                    * arg
)
{
  rtems_status_code sc;
  int               rc;
  rtems_libio_open_close_args_t *args = arg;
  static bool firstCall = true;

  static const rtems_termios_callbacks Callbacks = {
    NULL,                                    /* firstOpen */
    NULL,                                    /* lastClose */
    termios_test_driver_inbyte_nonblocking,  /* pollRead */
    termios_test_driver_write_support,       /* write */
    termios_test_driver_set_attributes,      /* setAttributes */
    NULL,                                    /* stopRemoteTx */
    NULL,                                    /* startRemoteTx */
    0                                        /* outputUsesInterrupts */
  };

  if ( minor > 2 ) {
    puts( "ERROR - Termios_testdriver - only 1 minor supported" );
    rtems_test_exit(0);
  }

  if( firstCall ) {
    static const uintptr_t allocSizes [] = {
      sizeof( struct rtems_termios_tty ),
      128,
      64,
      256
    };

    size_t i;

    firstCall = false;

    for (i = 0; i < sizeof( allocSizes ) / sizeof( allocSizes [0] ); ++i) {
      void *opaque = rtems_heap_greedy_allocate( allocSizes, i );

      sc = rtems_termios_open( major, minor, arg, &Callbacks );
      rtems_test_assert( sc == RTEMS_NO_MEMORY );

      rtems_heap_greedy_free( opaque );
    }
  }
  
  sc = rtems_termios_open (major, minor, arg, &Callbacks);
  directive_failed( sc, "rtems_termios_open" );

  puts( "Termios_test_driver - rtems_set_initial_baud - bad baud - OK" );
  rc = rtems_termios_set_initial_baud( args->iop->data1, 5000 );
  if ( rc != -1 ) {
    printf( "ERROR - return %d\n", rc );
    rtems_test_exit(0);
  }

  puts( "Termios_test_driver - rtems_set_initial_baud - 38400 - OK" );
  rc = rtems_termios_set_initial_baud( args->iop->data1, 38400 );
  if ( rc ) {
    printf( "ERROR - return %d\n", rc );
    rtems_test_exit(0);
  }

  return RTEMS_SUCCESSFUL;
}
Ejemplo n.º 10
0
int main(
  int argc,
  char **argv
)
#endif
{
  static const uintptr_t global_location_size [] = {
    sizeof(rtems_filesystem_global_location_t)
  };

  int status;
  void *opaque;
/*
 *  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"
*/

  TEST_BEGIN();

  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( "chroot with bad path - expect ENOENT" );
  status = chroot( "/three" );
  rtems_test_assert( status == -1 );
  rtems_test_assert( errno == ENOENT );

  puts( "chroot with file - expect ENOTDIR" );
  status = chroot( "/one/one.test" );
  rtems_test_assert( status == -1 );
  rtems_test_assert( errno == ENOTDIR );

  puts( "allocate most of memory - attempt to fail chroot - expect ENOMEM" );
  opaque = rtems_heap_greedy_allocate( global_location_size, 1 );

  status = chroot( "/one" );
  rtems_test_assert( status == -1 );
  rtems_test_assert( errno == ENOMEM );

  puts( "freeing the allocated memory" );
  rtems_heap_greedy_free( opaque );

  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( "Go back to global environment" );
  rtems_libio_use_global_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" );

  TEST_END();
  rtems_test_exit(0);
}