source: rtems/testsuites/psxtests/psxchroot01/test.c @ 38cc1e1b

4.115
Last change on this file since 38cc1e1b was 38cc1e1b, checked in by Joel Sherrill <joel.sherrill@…>, on 08/09/10 at 14:29:33

2010-08-09 Joel Sherrill <joel.sherrill@…>

PR 1661/testing

  • psxchroot01/test.c, psximfs01/init.c, psximfs02/init.c, psxpipe01/init.c: Eliminate most references to RTEMS_Malloc_Heap.
  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*
2 *  This is a native test to explore how the readdir() family works.
3 *  Newlib supports the following readdir() family members:
4 *
5 *    closedir()   -
6 *    readdir()    -
7 *    scandir()    -
8 *    opendir()    -
9 *    rewinddir()  -
10 *    telldir()    - BSD not in POSIX
11 *    seekdir()    - BSD not in POSIX
12 *
13 *
14 *  seekdir() takes an offset which is a byte offset.  The Linux
15 *  implementation of this appears to seek to the ((off/DIRENT_SIZE) + 1)
16 *  record where DIRENT_SIZE seems to be 12 bytes.
17 *
18 *  COPYRIGHT (c) 1989-2010.
19 *  On-Line Applications Research Corporation (OAR).
20 *
21 *  The license and distribution terms for this file may be
22 *  found in the file LICENSE in this distribution or at
23 *  http://www.rtems.com/license/LICENSE.
24 *
25 *  $Id$
26 */
27
28#include <stdio.h>
29#include <sys/types.h>
30#include <fcntl.h>
31#include <string.h>
32#include <unistd.h>
33#include <errno.h>
34#include <rtems/libio.h>
35#include <rtems/userenv.h>
36#include <pmacros.h>
37#include <rtems/libcsupport.h>
38
39void touch( char *file )
40{
41  int fd;
42
43  rtems_test_assert(  file );
44
45  fd = open( file, O_RDWR|O_CREAT, 0777 );
46  rtems_test_assert(  fd != -1 );
47  close( fd );
48}
49
50int fileexists( char *file )
51{
52  int         status;
53  struct stat statbuf;
54
55  rtems_test_assert(  file );
56
57  status = stat( file, &statbuf );
58
59  if ( status == -1 ) {
60    /* printf( ": %s\n", strerror( errno ) ); */
61    return 0;
62  }
63  return 1;
64}
65
66#if defined(__rtems__)
67int test_main(void)
68#else
69int main(
70  int argc,
71  char **argv
72)
73#endif
74{
75  int status;
76  void *alloc_ptr = (void *)0;
77/*
78 *  This test is the C equivalent of this sequence.
79#mkdir /one
80#mkdir /one/one
81#touch /one/one.test
82#touch /one/two/two.test
83# an error case to ENOTSUP from chroot
84# chroot
85#chroot /one
86#if !fileexists(/one/one.test) echo "SUCCESSFUL"
87#if fileexists(/two/two.test) echo "SUCCESSFUL"
88#rtems_set_private_env() ! reset at the global environment
89#if fileexists(/one/one.test) echo "SUCESSFUL"
90#if !fileexists(/two/two.test) echo "SUCCESSFUL"
91*/
92
93  printf( "\n\n*** CHROOT01 TEST ***\n" );
94
95  status = mkdir( "/one", 0777);
96  rtems_test_assert(  status == 0 );
97
98  status = mkdir( "/one/one", 0777);
99  rtems_test_assert(  status == 0 );
100
101  status = mkdir( "/one/two", 0777);
102  rtems_test_assert(  status == 0 );
103
104  touch( "/one/one.test" );
105  touch( "/one/two/two.test" );
106
107  puts( "allocate most of memory - attempt to fail chroot - expect ENOTSUP" );
108  alloc_ptr = malloc( malloc_free_space() - 4 );
109  rtems_test_assert( alloc_ptr != NULL );
110
111  status = chroot( "/one" );
112  rtems_test_assert( status == -1 );
113  rtems_test_assert( errno == ENOTSUP );
114
115  puts( "freeing the allocated memory" );
116  free( alloc_ptr );
117
118  puts( "chroot with bad path - expect EFAULT" );
119  status = chroot( NULL );
120  rtems_test_assert( status == -1 );
121  rtems_test_assert( errno == EFAULT );
122
123  status = chroot( "/one" );
124  rtems_test_assert( status == 0 );
125
126  status = fileexists( "/one/one.test" );
127  printf( "%s on /one/one.test\n", (!status) ? "SUCCESS" : "FAILURE" );
128
129  status = fileexists( "/two/two.test" );
130  printf( "%s on /two/two.test\n", (status) ? "SUCCESS" : "FAILURE" );
131
132  puts( "Reset the private environment" );
133  rtems_libio_set_private_env();
134
135  status = fileexists( "/one/one.test" );
136  printf( "%s on /one/one.test\n", ( status) ? "SUCCESS" : "FAILURE" );
137
138  status = fileexists( "/two/two.test" );
139  printf( "%s on /two/two.test\n", (!status) ? "SUCCESS" : "FAILURE" );
140
141  printf( "*** END OF CHROOT01 TEST ***\n" );
142  rtems_test_exit(0);
143}
Note: See TracBrowser for help on using the repository browser.