source: rtems/testsuites/psxtests/psxchroot01/test.c @ 990235d

5
Last change on this file since 990235d was 990235d, checked in by Sebastian Huber <sebastian.huber@…>, on 01/22/18 at 13:13:11

psxchroot01: Force release of global locations

Free deferred locations before the greedy memory allocation. This test
fails on powerpc/qoriq_e6500_64 otherwise.

  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2012.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  Modifications to support reference counting in the file system are
6 *  Copyright (c) 2012 embedded brains GmbH.
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.rtems.org/license/LICENSE.
11 */
12
13#ifdef HAVE_CONFIG_H
14#include "config.h"
15#endif
16
17#include <stdio.h>
18#include <sys/types.h>
19#include <fcntl.h>
20#include <string.h>
21#include <unistd.h>
22#include <errno.h>
23#include <rtems/libio.h>
24#include <rtems/userenv.h>
25#include <rtems/malloc.h>
26#include <pmacros.h>
27#include <rtems/libcsupport.h>
28
29const char rtems_test_name[] = "PSXCHROOT 1";
30
31/* forward declarations to avoid warnings */
32int test_main(void);
33
34static void touch( char *file )
35{
36  int fd;
37
38  rtems_test_assert( file );
39
40  fd = open( file, O_RDWR|O_CREAT, 0777 );
41  rtems_test_assert( fd != -1 );
42  close( fd );
43}
44
45static int fileexists( char *file )
46{
47  int         status;
48  struct stat statbuf;
49
50  rtems_test_assert( file );
51
52  status = stat( file, &statbuf );
53
54  if ( status == -1 ) {
55    /* printf( ": %s\n", strerror( errno ) ); */
56    return 0;
57  }
58  return 1;
59}
60
61#if defined(__rtems__)
62int test_main(void)
63#else
64int main(
65  int argc,
66  char **argv
67)
68#endif
69{
70  static const uintptr_t global_location_size [] = {
71    sizeof(rtems_filesystem_global_location_t)
72  };
73
74  int status;
75  void *opaque;
76  struct stat st;
77
78/*
79 *  This test is the C equivalent of this sequence.
80#mkdir /one
81#mkdir /one/one
82#touch /one/one.test
83#touch /one/two/two.test
84# an error case to ENOTSUP from chroot
85# chroot
86#chroot /one
87#if !fileexists(/one/one.test) echo "SUCCESSFUL"
88#if fileexists(/two/two.test) echo "SUCCESSFUL"
89#rtems_set_private_env() ! reset at the global environment
90#if fileexists(/one/one.test) echo "SUCESSFUL"
91#if !fileexists(/two/two.test) echo "SUCCESSFUL"
92*/
93
94  TEST_BEGIN();
95
96  status = mkdir( "/one", 0777);
97  rtems_test_assert( status == 0 );
98
99  status = mkdir( "/one/one", 0777);
100  rtems_test_assert( status == 0 );
101
102  status = mkdir( "/one/two", 0777);
103  rtems_test_assert( status == 0 );
104
105  touch( "/one/one.test" );
106  touch( "/one/two/two.test" );
107
108  puts( "chroot with bad path - expect ENOENT" );
109  status = chroot( "/three" );
110  rtems_test_assert( status == -1 );
111  rtems_test_assert( errno == ENOENT );
112
113  puts( "chroot with file - expect ENOTDIR" );
114  status = chroot( "/one/one.test" );
115  rtems_test_assert( status == -1 );
116  rtems_test_assert( errno == ENOTDIR );
117
118  /* Perform deferred global location releases */
119  status = stat( ".", &st );
120  rtems_test_assert( status == 0 );
121
122  puts( "allocate most of memory - attempt to fail chroot - expect ENOMEM" );
123  opaque = rtems_heap_greedy_allocate( global_location_size, 1 );
124
125  status = chroot( "/one" );
126  rtems_test_assert( status == -1 );
127  rtems_test_assert( errno == ENOMEM );
128
129  puts( "freeing the allocated memory" );
130  rtems_heap_greedy_free( opaque );
131
132  status = chroot( "/one" );
133  rtems_test_assert( status == 0 );
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  puts( "Go back to global environment" );
142  rtems_libio_use_global_env();
143
144  status = fileexists( "/one/one.test" );
145  printf( "%s on /one/one.test\n", ( status) ? "SUCCESS" : "FAILURE" );
146
147  status = fileexists( "/two/two.test" );
148  printf( "%s on /two/two.test\n", (!status) ? "SUCCESS" : "FAILURE" );
149
150  TEST_END();
151  rtems_test_exit(0);
152}
Note: See TracBrowser for help on using the repository browser.