[3b7c123] | 1 | /* |
---|
| 2 | * Copyright (c) 2012 embedded brains GmbH. All rights reserved. |
---|
| 3 | * |
---|
| 4 | * embedded brains GmbH |
---|
| 5 | * Obere Lagerstr. 30 |
---|
| 6 | * 82178 Puchheim |
---|
| 7 | * Germany |
---|
| 8 | * <rtems@embedded-brains.de> |
---|
| 9 | * |
---|
| 10 | * The license and distribution terms for this file may be |
---|
| 11 | * found in the file LICENSE in this distribution or at |
---|
| 12 | * http://www.rtems.com/license/LICENSE. |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | #ifdef HAVE_CONFIG_H |
---|
| 16 | #include "config.h" |
---|
| 17 | #endif |
---|
| 18 | |
---|
| 19 | #include "tmacros.h" |
---|
| 20 | |
---|
| 21 | #include <sys/stat.h> |
---|
| 22 | #include <sys/statvfs.h> |
---|
| 23 | #include <errno.h> |
---|
| 24 | #include <fcntl.h> |
---|
| 25 | #include <stdio.h> |
---|
| 26 | #include <stdlib.h> |
---|
| 27 | #include <utime.h> |
---|
| 28 | |
---|
| 29 | #include <rtems/libio_.h> |
---|
| 30 | |
---|
[bc75887] | 31 | const char rtems_test_name[] = "FSNOFS 1"; |
---|
| 32 | |
---|
[3b7c123] | 33 | static int node_count(const rtems_chain_control *chain) |
---|
| 34 | { |
---|
| 35 | int count = 0; |
---|
| 36 | const rtems_chain_node *current = rtems_chain_immutable_first(chain); |
---|
| 37 | const rtems_chain_node *tail = rtems_chain_immutable_tail(chain); |
---|
| 38 | |
---|
| 39 | while (current != tail) { |
---|
| 40 | ++count; |
---|
| 41 | |
---|
| 42 | current = rtems_chain_immutable_next(current); |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | return count; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | static void rtems_test_assert_equal_to_null_loc( |
---|
| 49 | const rtems_filesystem_location_info_t *local_loc |
---|
| 50 | ) |
---|
| 51 | { |
---|
| 52 | rtems_filesystem_global_location_t *null_loc = |
---|
| 53 | &rtems_filesystem_global_location_null; |
---|
| 54 | |
---|
| 55 | rtems_test_assert(null_loc->location.node_access == local_loc->node_access); |
---|
| 56 | rtems_test_assert(null_loc->location.node_access_2 == local_loc->node_access_2); |
---|
| 57 | rtems_test_assert(null_loc->location.handlers == local_loc->handlers); |
---|
| 58 | rtems_test_assert(null_loc->location.mt_entry == local_loc->mt_entry); |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | static void test_initial_values(void) |
---|
| 62 | { |
---|
| 63 | rtems_filesystem_global_location_t *null_loc = |
---|
| 64 | &rtems_filesystem_global_location_null; |
---|
| 65 | rtems_filesystem_mount_table_entry_t *null_mt = null_loc->location.mt_entry; |
---|
| 66 | rtems_chain_control *loc_chain = &null_mt->location_chain; |
---|
| 67 | rtems_chain_node *loc_node = &null_loc->location.mt_entry_node; |
---|
| 68 | |
---|
| 69 | rtems_test_assert(node_count(loc_chain) == 1); |
---|
| 70 | rtems_test_assert(rtems_chain_previous(loc_node) == rtems_chain_head(loc_chain)); |
---|
| 71 | rtems_test_assert(rtems_chain_next(loc_node) == rtems_chain_tail(loc_chain)); |
---|
| 72 | rtems_test_assert(null_mt->mt_point_node == null_loc); |
---|
| 73 | rtems_test_assert(null_mt->mt_fs_root == null_loc); |
---|
| 74 | rtems_test_assert(!null_mt->mounted); |
---|
| 75 | rtems_test_assert(!null_mt->writeable); |
---|
| 76 | rtems_test_assert(null_loc->reference_count == 4); |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | static void test_location_obtain(void) |
---|
| 80 | { |
---|
| 81 | rtems_filesystem_global_location_t *global_loc = NULL; |
---|
| 82 | rtems_filesystem_global_location_t *null_loc = |
---|
| 83 | rtems_filesystem_global_location_obtain(&global_loc); |
---|
| 84 | rtems_filesystem_mount_table_entry_t *null_mt = null_loc->location.mt_entry; |
---|
| 85 | rtems_chain_control *loc_chain = &null_mt->location_chain; |
---|
| 86 | |
---|
| 87 | rtems_test_assert(node_count(loc_chain) == 1); |
---|
| 88 | rtems_test_assert(null_loc->reference_count == 5); |
---|
| 89 | |
---|
| 90 | rtems_filesystem_global_location_release(null_loc); |
---|
| 91 | |
---|
| 92 | rtems_test_assert(node_count(loc_chain) == 1); |
---|
| 93 | rtems_test_assert(null_loc->reference_count == 4); |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | static void test_null_location_obtain(void) |
---|
| 97 | { |
---|
| 98 | rtems_filesystem_global_location_t *null_loc = |
---|
| 99 | rtems_filesystem_global_location_obtain_null(); |
---|
| 100 | rtems_filesystem_mount_table_entry_t *null_mt = null_loc->location.mt_entry; |
---|
| 101 | rtems_chain_control *loc_chain = &null_mt->location_chain; |
---|
| 102 | |
---|
| 103 | rtems_test_assert(node_count(loc_chain) == 1); |
---|
| 104 | rtems_test_assert(null_loc->reference_count == 5); |
---|
| 105 | |
---|
| 106 | rtems_filesystem_global_location_release(null_loc); |
---|
| 107 | |
---|
| 108 | rtems_test_assert(node_count(loc_chain) == 1); |
---|
| 109 | rtems_test_assert(null_loc->reference_count == 4); |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | static void test_null_location_replace(void) |
---|
| 113 | { |
---|
| 114 | rtems_filesystem_global_location_t *null_loc = |
---|
| 115 | &rtems_filesystem_global_location_null; |
---|
| 116 | rtems_filesystem_mount_table_entry_t *null_mt = null_loc->location.mt_entry; |
---|
| 117 | rtems_chain_control *loc_chain = &null_mt->location_chain; |
---|
| 118 | rtems_filesystem_location_info_t local_loc; |
---|
| 119 | |
---|
| 120 | rtems_test_assert(node_count(loc_chain) == 1); |
---|
| 121 | rtems_test_assert(null_loc->reference_count == 4); |
---|
| 122 | rtems_test_assert(rtems_filesystem_global_location_is_null(null_loc)); |
---|
| 123 | |
---|
| 124 | rtems_filesystem_location_copy(&local_loc, &null_loc->location); |
---|
| 125 | |
---|
| 126 | rtems_test_assert(node_count(loc_chain) == 2); |
---|
| 127 | rtems_test_assert(null_loc->reference_count == 4); |
---|
| 128 | |
---|
| 129 | rtems_filesystem_location_detach(&local_loc); |
---|
| 130 | |
---|
| 131 | rtems_test_assert(node_count(loc_chain) == 2); |
---|
| 132 | rtems_test_assert(null_loc->reference_count == 4); |
---|
| 133 | rtems_test_assert(rtems_filesystem_location_is_null(&local_loc)); |
---|
| 134 | rtems_test_assert_equal_to_null_loc(&local_loc); |
---|
| 135 | |
---|
| 136 | rtems_filesystem_location_free(&local_loc); |
---|
| 137 | |
---|
| 138 | rtems_test_assert(node_count(loc_chain) == 1); |
---|
| 139 | rtems_test_assert(null_loc->reference_count == 4); |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | static void test_null_location_get_and_replace(void) |
---|
| 143 | { |
---|
| 144 | rtems_filesystem_global_location_t *null_loc = |
---|
| 145 | &rtems_filesystem_global_location_null; |
---|
| 146 | rtems_filesystem_mount_table_entry_t *null_mt = null_loc->location.mt_entry; |
---|
| 147 | rtems_chain_control *loc_chain = &null_mt->location_chain; |
---|
| 148 | rtems_filesystem_location_info_t local_loc_0; |
---|
| 149 | rtems_filesystem_location_info_t local_loc_1; |
---|
| 150 | |
---|
| 151 | rtems_test_assert(node_count(loc_chain) == 1); |
---|
| 152 | rtems_test_assert(null_loc->reference_count == 4); |
---|
| 153 | |
---|
| 154 | rtems_filesystem_location_copy(&local_loc_0, &null_loc->location); |
---|
| 155 | |
---|
| 156 | rtems_test_assert(node_count(loc_chain) == 2); |
---|
| 157 | rtems_test_assert(null_loc->reference_count == 4); |
---|
| 158 | rtems_test_assert_equal_to_null_loc(&local_loc_0); |
---|
| 159 | |
---|
| 160 | rtems_filesystem_location_copy_and_detach(&local_loc_1, &local_loc_0); |
---|
| 161 | |
---|
| 162 | rtems_test_assert(node_count(loc_chain) == 3); |
---|
| 163 | rtems_test_assert(null_loc->reference_count == 4); |
---|
| 164 | rtems_test_assert_equal_to_null_loc(&local_loc_0); |
---|
| 165 | rtems_test_assert_equal_to_null_loc(&local_loc_1); |
---|
| 166 | |
---|
| 167 | rtems_filesystem_location_free(&local_loc_0); |
---|
| 168 | |
---|
| 169 | rtems_test_assert(node_count(loc_chain) == 2); |
---|
| 170 | rtems_test_assert(null_loc->reference_count == 4); |
---|
| 171 | rtems_test_assert_equal_to_null_loc(&local_loc_1); |
---|
| 172 | |
---|
| 173 | rtems_filesystem_location_free(&local_loc_1); |
---|
| 174 | |
---|
| 175 | rtems_test_assert(node_count(loc_chain) == 1); |
---|
| 176 | rtems_test_assert(null_loc->reference_count == 4); |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | static void test_path_ops(void) |
---|
| 180 | { |
---|
| 181 | int rv = 0; |
---|
| 182 | long lrv = 0; |
---|
| 183 | struct stat st; |
---|
| 184 | struct statvfs stvfs; |
---|
| 185 | char buf [32]; |
---|
| 186 | ssize_t n = 0; |
---|
| 187 | const char *path = "/"; |
---|
| 188 | const struct utimbuf times; |
---|
| 189 | |
---|
| 190 | errno = 0; |
---|
| 191 | rv = open(path, O_RDONLY); |
---|
| 192 | rtems_test_assert(rv == -1); |
---|
| 193 | rtems_test_assert(errno == ENXIO); |
---|
| 194 | |
---|
| 195 | errno = 0; |
---|
| 196 | rv = chdir(path); |
---|
| 197 | rtems_test_assert(rv == -1); |
---|
| 198 | rtems_test_assert(errno == ENXIO); |
---|
| 199 | |
---|
| 200 | errno = 0; |
---|
| 201 | rv = chroot(path); |
---|
| 202 | rtems_test_assert(rv == -1); |
---|
| 203 | rtems_test_assert(errno == ENXIO); |
---|
| 204 | |
---|
| 205 | errno = 0; |
---|
| 206 | rv = mknod(path, S_IFREG, 0); |
---|
| 207 | rtems_test_assert(rv == -1); |
---|
| 208 | rtems_test_assert(errno == ENXIO); |
---|
| 209 | |
---|
| 210 | errno = 0; |
---|
| 211 | rv = mkdir(path, 0); |
---|
| 212 | rtems_test_assert(rv == -1); |
---|
| 213 | rtems_test_assert(errno == ENXIO); |
---|
| 214 | |
---|
| 215 | errno = 0; |
---|
| 216 | rv = mkfifo(path, 0); |
---|
| 217 | rtems_test_assert(rv == -1); |
---|
| 218 | rtems_test_assert(errno == ENXIO); |
---|
| 219 | |
---|
| 220 | errno = 0; |
---|
| 221 | rv = stat(path, &st); |
---|
| 222 | rtems_test_assert(rv == -1); |
---|
| 223 | rtems_test_assert(errno == ENXIO); |
---|
| 224 | |
---|
| 225 | errno = 0; |
---|
| 226 | rv = lstat(path, &st); |
---|
| 227 | rtems_test_assert(rv == -1); |
---|
| 228 | rtems_test_assert(errno == ENXIO); |
---|
| 229 | |
---|
| 230 | errno = 0; |
---|
| 231 | rv = statvfs(path, &stvfs); |
---|
| 232 | rtems_test_assert(rv == -1); |
---|
| 233 | rtems_test_assert(errno == ENXIO); |
---|
| 234 | |
---|
| 235 | errno = 0; |
---|
| 236 | n = readlink(path, buf, sizeof(buf)); |
---|
| 237 | rtems_test_assert(n == -1); |
---|
| 238 | rtems_test_assert(errno == ENXIO); |
---|
| 239 | |
---|
| 240 | errno = 0; |
---|
| 241 | rv = chmod(path, 0); |
---|
| 242 | rtems_test_assert(rv == -1); |
---|
| 243 | rtems_test_assert(errno == ENXIO); |
---|
| 244 | |
---|
| 245 | errno = 0; |
---|
| 246 | rv = chown(path, 0, 0); |
---|
| 247 | rtems_test_assert(rv == -1); |
---|
| 248 | rtems_test_assert(errno == ENXIO); |
---|
| 249 | |
---|
| 250 | errno = 0; |
---|
| 251 | rv = lchown(path, 0, 0); |
---|
| 252 | rtems_test_assert(rv == -1); |
---|
| 253 | rtems_test_assert(errno == ENXIO); |
---|
| 254 | |
---|
| 255 | errno = 0; |
---|
| 256 | rv = rmdir(path); |
---|
| 257 | rtems_test_assert(rv == -1); |
---|
| 258 | rtems_test_assert(errno == ENXIO); |
---|
| 259 | |
---|
| 260 | errno = 0; |
---|
| 261 | rv = unlink(path); |
---|
| 262 | rtems_test_assert(rv == -1); |
---|
| 263 | rtems_test_assert(errno == ENXIO); |
---|
| 264 | |
---|
| 265 | errno = 0; |
---|
| 266 | rv = truncate(path, 0); |
---|
| 267 | rtems_test_assert(rv == -1); |
---|
| 268 | rtems_test_assert(errno == ENXIO); |
---|
| 269 | |
---|
| 270 | errno = 0; |
---|
| 271 | rv = access(path, 0); |
---|
| 272 | rtems_test_assert(rv == -1); |
---|
| 273 | rtems_test_assert(errno == ENXIO); |
---|
| 274 | |
---|
| 275 | errno = 0; |
---|
| 276 | lrv = pathconf(path, _PC_LINK_MAX); |
---|
| 277 | rtems_test_assert(lrv == -1); |
---|
| 278 | rtems_test_assert(errno == ENXIO); |
---|
| 279 | |
---|
| 280 | errno = 0; |
---|
| 281 | rv = link(path, path); |
---|
| 282 | rtems_test_assert(rv == -1); |
---|
| 283 | rtems_test_assert(errno == ENXIO); |
---|
| 284 | |
---|
| 285 | errno = 0; |
---|
| 286 | rv = symlink(path, path); |
---|
| 287 | rtems_test_assert(rv == -1); |
---|
| 288 | rtems_test_assert(errno == ENXIO); |
---|
| 289 | |
---|
| 290 | errno = 0; |
---|
| 291 | rv = rename(path, path); |
---|
| 292 | rtems_test_assert(rv == -1); |
---|
| 293 | rtems_test_assert(errno == ENXIO); |
---|
| 294 | |
---|
| 295 | errno = 0; |
---|
| 296 | rv = utime(path, ×); |
---|
| 297 | rtems_test_assert(rv == -1); |
---|
| 298 | rtems_test_assert(errno == ENXIO); |
---|
| 299 | } |
---|
| 300 | |
---|
| 301 | static void test_user_env(void) |
---|
| 302 | { |
---|
| 303 | rtems_status_code sc = RTEMS_SUCCESSFUL; |
---|
| 304 | rtems_filesystem_global_location_t *null_loc = |
---|
| 305 | &rtems_filesystem_global_location_null; |
---|
| 306 | rtems_filesystem_mount_table_entry_t *null_mt = null_loc->location.mt_entry; |
---|
| 307 | rtems_chain_control *loc_chain = &null_mt->location_chain; |
---|
| 308 | |
---|
| 309 | rtems_test_assert(node_count(loc_chain) == 1); |
---|
| 310 | rtems_test_assert(null_loc->reference_count == 4); |
---|
| 311 | |
---|
| 312 | sc = rtems_libio_set_private_env(); |
---|
| 313 | rtems_test_assert(sc == RTEMS_UNSATISFIED); |
---|
| 314 | |
---|
| 315 | rtems_test_assert(node_count(loc_chain) == 1); |
---|
| 316 | rtems_test_assert(null_loc->reference_count == 4); |
---|
| 317 | |
---|
| 318 | sc = rtems_libio_share_private_env(RTEMS_SELF); |
---|
| 319 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
| 320 | |
---|
| 321 | rtems_test_assert(node_count(loc_chain) == 1); |
---|
| 322 | rtems_test_assert(null_loc->reference_count == 4); |
---|
| 323 | |
---|
| 324 | sc = rtems_libio_share_private_env(rtems_task_self()); |
---|
| 325 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
| 326 | |
---|
| 327 | rtems_test_assert(node_count(loc_chain) == 1); |
---|
| 328 | rtems_test_assert(null_loc->reference_count == 4); |
---|
| 329 | |
---|
| 330 | rtems_libio_use_global_env(); |
---|
| 331 | |
---|
| 332 | rtems_test_assert(node_count(loc_chain) == 1); |
---|
| 333 | rtems_test_assert(null_loc->reference_count == 4); |
---|
| 334 | } |
---|
| 335 | |
---|
| 336 | static void Init(rtems_task_argument arg) |
---|
| 337 | { |
---|
[bc75887] | 338 | rtems_test_begink(); |
---|
[3b7c123] | 339 | |
---|
| 340 | rtems_libio_init(); |
---|
| 341 | |
---|
| 342 | test_initial_values(); |
---|
| 343 | test_location_obtain(); |
---|
| 344 | test_null_location_obtain(); |
---|
| 345 | test_null_location_replace(); |
---|
| 346 | test_null_location_get_and_replace(); |
---|
| 347 | test_path_ops(); |
---|
| 348 | test_user_env(); |
---|
| 349 | |
---|
[bc75887] | 350 | rtems_test_endk(); |
---|
[3b7c123] | 351 | exit(0); |
---|
| 352 | } |
---|
| 353 | |
---|
| 354 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
| 355 | |
---|
| 356 | #define CONFIGURE_APPLICATION_DISABLE_FILESYSTEM |
---|
| 357 | |
---|
| 358 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
| 359 | |
---|
[bc75887] | 360 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
| 361 | |
---|
[3b7c123] | 362 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
| 363 | |
---|
| 364 | #define CONFIGURE_INIT |
---|
| 365 | |
---|
| 366 | #include <rtems/confdefs.h> |
---|