source: rtems/testsuites/fstests/fsnofs01/init.c @ 191d39a

5
Last change on this file since 191d39a was 24d0ee57, checked in by Chris Johns <chrisj@…>, on 05/20/16 at 08:39:50

cpukit, testsuite: Add rtems_printf and rtems_printer support.

This change adds rtems_printf and related functions and wraps the
RTEMS print plugin support into a user API. All references to the
plugin are removed and replaced with the rtems_printer interface.

Printk and related functions are made to return a valid number of
characters formatted and output.

The function attribute to check printf functions has been added
to rtems_printf and printk. No changes to remove warrnings are part
of this patch set.

The testsuite has been moved over to the rtems_printer. The testsuite
has a mix of rtems_printer access and direct print control via the
tmacros.h header file. The support for begink/endk has been removed
as it served no purpose and only confused the code base. The testsuite
has not been refactored to use rtems_printf. This is future work.

  • Property mode set to 100644
File size: 13.5 KB
Line 
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.org/license/LICENSE.
13 */
14
15#ifdef HAVE_CONFIG_H
16  #include "config.h"
17#endif
18
19#define TESTS_USE_PRINTK
20#include "tmacros.h"
21
22#include <sys/stat.h>
23#include <sys/statvfs.h>
24#include <errno.h>
25#include <fcntl.h>
26#include <stdio.h>
27#include <stdlib.h>
28#include <utime.h>
29
30#include <rtems/libio_.h>
31
32const char rtems_test_name[] = "FSNOFS 1";
33
34static int node_count(const rtems_chain_control *chain)
35{
36  int count = 0;
37  const rtems_chain_node *current = rtems_chain_immutable_first(chain);
38  const rtems_chain_node *tail = rtems_chain_immutable_tail(chain);
39
40  while (current != tail) {
41    ++count;
42
43    current = rtems_chain_immutable_next(current);
44  }
45
46  return count;
47}
48
49static void rtems_test_assert_equal_to_null_loc(
50  const rtems_filesystem_location_info_t *local_loc
51)
52{
53  rtems_filesystem_global_location_t *null_loc =
54    &rtems_filesystem_global_location_null;
55
56  rtems_test_assert(null_loc->location.node_access == local_loc->node_access);
57  rtems_test_assert(null_loc->location.node_access_2 == local_loc->node_access_2);
58  rtems_test_assert(null_loc->location.handlers == local_loc->handlers);
59  rtems_test_assert(null_loc->location.mt_entry == local_loc->mt_entry);
60}
61
62static void test_initial_values(void)
63{
64  rtems_filesystem_global_location_t *null_loc =
65    &rtems_filesystem_global_location_null;
66  rtems_filesystem_mount_table_entry_t *null_mt = null_loc->location.mt_entry;
67  rtems_chain_control *loc_chain = &null_mt->location_chain;
68  rtems_chain_node *loc_node = &null_loc->location.mt_entry_node;
69
70  rtems_test_assert(node_count(loc_chain) == 1);
71  rtems_test_assert(rtems_chain_previous(loc_node) == rtems_chain_head(loc_chain));
72  rtems_test_assert(rtems_chain_next(loc_node) == rtems_chain_tail(loc_chain));
73  rtems_test_assert(null_mt->mt_point_node == null_loc);
74  rtems_test_assert(null_mt->mt_fs_root == null_loc);
75  rtems_test_assert(!null_mt->mounted);
76  rtems_test_assert(!null_mt->writeable);
77  rtems_test_assert(null_loc->reference_count == 6);
78  rtems_test_assert(null_loc->deferred_released_next == NULL);
79  rtems_test_assert(null_loc->deferred_released_count == 2);
80}
81
82static void test_location_obtain(void)
83{
84  rtems_filesystem_global_location_t *global_loc = NULL;
85  rtems_filesystem_global_location_t *null_loc =
86    rtems_filesystem_global_location_obtain(&global_loc);
87  rtems_filesystem_mount_table_entry_t *null_mt = null_loc->location.mt_entry;
88  rtems_chain_control *loc_chain = &null_mt->location_chain;
89
90  rtems_test_assert(node_count(loc_chain) == 1);
91  rtems_test_assert(null_loc->reference_count == 5);
92
93  rtems_filesystem_global_location_release(null_loc);
94
95  rtems_test_assert(node_count(loc_chain) == 1);
96  rtems_test_assert(null_loc->reference_count == 4);
97}
98
99static void test_null_location_obtain(void)
100{
101  rtems_filesystem_global_location_t *null_loc =
102    rtems_filesystem_global_location_obtain_null();
103  rtems_filesystem_mount_table_entry_t *null_mt = null_loc->location.mt_entry;
104  rtems_chain_control *loc_chain = &null_mt->location_chain;
105
106  rtems_test_assert(node_count(loc_chain) == 1);
107  rtems_test_assert(null_loc->reference_count == 5);
108
109  rtems_filesystem_global_location_release(null_loc);
110
111  rtems_test_assert(node_count(loc_chain) == 1);
112  rtems_test_assert(null_loc->reference_count == 4);
113}
114
115static void test_null_location_replace(void)
116{
117  rtems_filesystem_global_location_t *null_loc =
118    &rtems_filesystem_global_location_null;
119  rtems_filesystem_mount_table_entry_t *null_mt = null_loc->location.mt_entry;
120  rtems_chain_control *loc_chain = &null_mt->location_chain;
121  rtems_filesystem_location_info_t local_loc;
122
123  rtems_test_assert(node_count(loc_chain) == 1);
124  rtems_test_assert(null_loc->reference_count == 4);
125  rtems_test_assert(rtems_filesystem_global_location_is_null(null_loc));
126
127  rtems_filesystem_location_copy(&local_loc, &null_loc->location);
128
129  rtems_test_assert(node_count(loc_chain) == 2);
130  rtems_test_assert(null_loc->reference_count == 4);
131
132  rtems_filesystem_location_detach(&local_loc);
133
134  rtems_test_assert(node_count(loc_chain) == 2);
135  rtems_test_assert(null_loc->reference_count == 4);
136  rtems_test_assert(rtems_filesystem_location_is_null(&local_loc));
137  rtems_test_assert_equal_to_null_loc(&local_loc);
138
139  rtems_filesystem_location_free(&local_loc);
140
141  rtems_test_assert(node_count(loc_chain) == 1);
142  rtems_test_assert(null_loc->reference_count == 4);
143}
144
145static void test_null_location_get_and_replace(void)
146{
147  rtems_filesystem_global_location_t *null_loc =
148    &rtems_filesystem_global_location_null;
149  rtems_filesystem_mount_table_entry_t *null_mt = null_loc->location.mt_entry;
150  rtems_chain_control *loc_chain = &null_mt->location_chain;
151  rtems_filesystem_location_info_t local_loc_0;
152  rtems_filesystem_location_info_t local_loc_1;
153
154  rtems_test_assert(node_count(loc_chain) == 1);
155  rtems_test_assert(null_loc->reference_count == 4);
156
157  rtems_filesystem_location_copy(&local_loc_0, &null_loc->location);
158
159  rtems_test_assert(node_count(loc_chain) == 2);
160  rtems_test_assert(null_loc->reference_count == 4);
161  rtems_test_assert_equal_to_null_loc(&local_loc_0);
162
163  rtems_filesystem_location_copy_and_detach(&local_loc_1, &local_loc_0);
164
165  rtems_test_assert(node_count(loc_chain) == 3);
166  rtems_test_assert(null_loc->reference_count == 4);
167  rtems_test_assert_equal_to_null_loc(&local_loc_0);
168  rtems_test_assert_equal_to_null_loc(&local_loc_1);
169
170  rtems_filesystem_location_free(&local_loc_0);
171
172  rtems_test_assert(node_count(loc_chain) == 2);
173  rtems_test_assert(null_loc->reference_count == 4);
174  rtems_test_assert_equal_to_null_loc(&local_loc_1);
175
176  rtems_filesystem_location_free(&local_loc_1);
177
178  rtems_test_assert(node_count(loc_chain) == 1);
179  rtems_test_assert(null_loc->reference_count == 4);
180}
181
182static void test_path_ops(void)
183{
184  int rv = 0;
185  long lrv = 0;
186  struct stat st;
187  struct statvfs stvfs;
188  char buf [32];
189  ssize_t n = 0;
190  const char *path = "/";
191  const struct utimbuf times;
192
193  errno = 0;
194  rv = open(path, O_RDONLY);
195  rtems_test_assert(rv == -1);
196  rtems_test_assert(errno == ENXIO);
197
198  errno = 0;
199  rv = chdir(path);
200  rtems_test_assert(rv == -1);
201  rtems_test_assert(errno == ENXIO);
202
203  errno = 0;
204  rv = chroot(path);
205  rtems_test_assert(rv == -1);
206  rtems_test_assert(errno == ENXIO);
207
208  errno = 0;
209  rv = mknod(path, S_IFREG, 0);
210  rtems_test_assert(rv == -1);
211  rtems_test_assert(errno == ENXIO);
212
213  errno = 0;
214  rv = mkdir(path, 0);
215  rtems_test_assert(rv == -1);
216  rtems_test_assert(errno == ENXIO);
217
218  errno = 0;
219  rv = mkfifo(path, 0);
220  rtems_test_assert(rv == -1);
221  rtems_test_assert(errno == ENXIO);
222
223  errno = 0;
224  rv = stat(path, &st);
225  rtems_test_assert(rv == -1);
226  rtems_test_assert(errno == ENXIO);
227
228  errno = 0;
229  rv = lstat(path, &st);
230  rtems_test_assert(rv == -1);
231  rtems_test_assert(errno == ENXIO);
232
233  errno = 0;
234  rv = statvfs(path, &stvfs);
235  rtems_test_assert(rv == -1);
236  rtems_test_assert(errno == ENXIO);
237
238  errno = 0;
239  n = readlink(path, buf, sizeof(buf));
240  rtems_test_assert(n == -1);
241  rtems_test_assert(errno == ENXIO);
242
243  errno = 0;
244  rv = chmod(path, 0);
245  rtems_test_assert(rv == -1);
246  rtems_test_assert(errno == ENXIO);
247
248  errno = 0;
249  rv = chown(path, 0, 0);
250  rtems_test_assert(rv == -1);
251  rtems_test_assert(errno == ENXIO);
252
253  errno = 0;
254  rv = lchown(path, 0, 0);
255  rtems_test_assert(rv == -1);
256  rtems_test_assert(errno == ENXIO);
257
258  errno = 0;
259  rv = rmdir(path);
260  rtems_test_assert(rv == -1);
261  rtems_test_assert(errno == ENXIO);
262
263  errno = 0;
264  rv = unlink(path);
265  rtems_test_assert(rv == -1);
266  rtems_test_assert(errno == ENXIO);
267
268  errno = 0;
269  rv = truncate(path, 0);
270  rtems_test_assert(rv == -1);
271  rtems_test_assert(errno == ENXIO);
272
273  errno = 0;
274  rv = access(path, 0);
275  rtems_test_assert(rv == -1);
276  rtems_test_assert(errno == ENXIO);
277
278  errno = 0;
279  lrv = pathconf(path, _PC_LINK_MAX);
280  rtems_test_assert(lrv == -1);
281  rtems_test_assert(errno == ENXIO);
282
283  errno = 0;
284  rv = link(path, path);
285  rtems_test_assert(rv == -1);
286  rtems_test_assert(errno == ENXIO);
287
288  errno = 0;
289  rv = symlink(path, path);
290  rtems_test_assert(rv == -1);
291  rtems_test_assert(errno == ENXIO);
292
293  errno = 0;
294  rv = rename(path, path);
295  rtems_test_assert(rv == -1);
296  rtems_test_assert(errno == ENXIO);
297
298  errno = 0;
299  rv = utime(path, &times);
300  rtems_test_assert(rv == -1);
301  rtems_test_assert(errno == ENXIO);
302}
303
304static void test_user_env(void)
305{
306  rtems_status_code sc = RTEMS_SUCCESSFUL;
307  rtems_filesystem_global_location_t *null_loc =
308    &rtems_filesystem_global_location_null;
309  rtems_filesystem_mount_table_entry_t *null_mt = null_loc->location.mt_entry;
310  rtems_chain_control *loc_chain = &null_mt->location_chain;
311
312  rtems_test_assert(node_count(loc_chain) == 1);
313  rtems_test_assert(null_loc->reference_count == 4);
314
315  sc = rtems_libio_set_private_env();
316  rtems_test_assert(sc == RTEMS_UNSATISFIED);
317
318  rtems_test_assert(node_count(loc_chain) == 1);
319  rtems_test_assert(null_loc->reference_count == 4);
320
321  rtems_libio_use_global_env();
322
323  rtems_test_assert(node_count(loc_chain) == 1);
324  rtems_test_assert(null_loc->reference_count == 4);
325}
326
327typedef struct {
328  int flags;
329  mode_t object_mode;
330  uid_t object_uid;
331  gid_t object_gid;
332  bool expected_ok;
333} check_access_case;
334
335#define FR RTEMS_FS_PERMS_READ
336#define FW RTEMS_FS_PERMS_WRITE
337#define FX RTEMS_FS_PERMS_EXEC
338
339#define UR S_IRUSR
340#define UW S_IWUSR
341#define UX S_IXUSR
342
343#define GR S_IRGRP
344#define GW S_IWGRP
345#define GX S_IXGRP
346
347#define OR S_IROTH
348#define OW S_IWOTH
349#define OX S_IXOTH
350
351static const check_access_case check_access_euid_0_cases[] = {
352  { 0,   0, 6, 7, true },
353  { FR,  0, 6, 7, false },
354  { FW,  0, 6, 7, false },
355  { FX,  0, 6, 7, false },
356  { FR, UR, 6, 7, true },
357  { FW, UW, 6, 7, true },
358  { FX, UX, 6, 7, true },
359  { FR, GR, 6, 7, false },
360  { FW, GW, 6, 7, false },
361  { FX, GX, 6, 7, false },
362  { FR, OR, 6, 7, false },
363  { FW, OW, 6, 7, false },
364  { FX, OX, 6, 7, false }
365};
366
367static const check_access_case check_access_egid_0_cases[] = {
368  { 0,   0, 6, 7, true },
369  { FR,  0, 6, 7, false },
370  { FW,  0, 6, 7, false },
371  { FX,  0, 6, 7, false },
372  { FR, UR, 6, 7, false },
373  { FW, UW, 6, 7, false },
374  { FX, UX, 6, 7, false },
375  { FR, GR, 6, 7, true },
376  { FW, GW, 6, 7, true },
377  { FX, GX, 6, 7, true },
378  { FR, OR, 6, 7, false },
379  { FW, OW, 6, 7, false },
380  { FX, OX, 6, 7, false }
381};
382
383static const check_access_case check_access_other_cases[] = {
384  { 0,   0, 3, 7, true },
385  { FR,  0, 3, 7, false },
386  { FW,  0, 3, 7, false },
387  { FX,  0, 3, 7, false },
388  { FR, UR, 3, 7, true },
389  { FW, UW, 3, 7, true },
390  { FX, UX, 3, 7, true },
391  { FR, GR, 3, 7, false },
392  { FW, GW, 3, 7, false },
393  { FX, GX, 3, 7, false },
394  { FR, OR, 3, 7, false },
395  { FW, OW, 3, 7, false },
396  { FX, OX, 3, 7, false },
397  { 0,   0, 6, 4, true },
398  { FR,  0, 6, 4, false },
399  { FW,  0, 6, 4, false },
400  { FX,  0, 6, 4, false },
401  { FR, UR, 6, 4, false },
402  { FW, UW, 6, 4, false },
403  { FX, UX, 6, 4, false },
404  { FR, GR, 6, 4, true },
405  { FW, GW, 6, 4, true },
406  { FX, GX, 6, 4, true },
407  { FR, OR, 6, 4, false },
408  { FW, OW, 6, 4, false },
409  { FX, OX, 6, 4, false },
410  { 0,   0, 6, 5, true },
411  { FR,  0, 6, 5, false },
412  { FW,  0, 6, 5, false },
413  { FX,  0, 6, 5, false },
414  { FR, UR, 6, 5, false },
415  { FW, UW, 6, 5, false },
416  { FX, UX, 6, 5, false },
417  { FR, GR, 6, 5, true },
418  { FW, GW, 6, 5, true },
419  { FX, GX, 6, 5, true },
420  { FR, OR, 6, 5, false },
421  { FW, OW, 6, 5, false },
422  { FX, OX, 6, 5, false },
423  { 0,   0, 6, 7, true },
424  { FR,  0, 6, 7, false },
425  { FW,  0, 6, 7, false },
426  { FX,  0, 6, 7, false },
427  { FR, UR, 6, 7, false },
428  { FW, UW, 6, 7, false },
429  { FX, UX, 6, 7, false },
430  { FR, GR, 6, 7, false },
431  { FW, GW, 6, 7, false },
432  { FX, GX, 6, 7, false },
433  { FR, OR, 6, 7, true },
434  { FW, OW, 6, 7, true },
435  { FX, OX, 6, 7, true }
436};
437
438static void check_access(const check_access_case *table, size_t n)
439{
440  size_t i;
441
442  for (i = 0; i < n; ++i) {
443    const check_access_case *cac = &table[i];
444    bool ok = rtems_filesystem_check_access(
445      cac->flags,
446      cac->object_mode,
447      cac->object_uid,
448      cac->object_gid
449    );
450
451    rtems_test_assert(ok == cac->expected_ok);
452  }
453}
454
455static void test_check_access(void)
456{
457  rtems_user_env_t *uenv = rtems_current_user_env_get();
458
459  rtems_test_assert(uenv->uid == 0);
460  rtems_test_assert(uenv->gid == 0);
461  rtems_test_assert(uenv->euid == 0);
462  rtems_test_assert(uenv->egid == 0);
463  rtems_test_assert(uenv->ngroups == 0);
464
465  uenv->uid = 1;
466  uenv->gid = 2;
467
468  check_access(
469    &check_access_euid_0_cases[0],
470    RTEMS_ARRAY_SIZE(check_access_euid_0_cases)
471  );
472
473  uenv->euid = 3;
474
475  check_access(
476    &check_access_egid_0_cases[0],
477    RTEMS_ARRAY_SIZE(check_access_egid_0_cases)
478  );
479
480  uenv->egid = 4;
481  uenv->ngroups = 1;
482  uenv->groups[0] = 5;
483
484  check_access(
485    &check_access_other_cases[0],
486    RTEMS_ARRAY_SIZE(check_access_other_cases)
487  );
488
489  uenv->uid = 0;
490  uenv->gid = 0;
491  uenv->euid = 0;
492  uenv->egid = 0;
493  uenv->ngroups = 0;
494}
495
496static void Init(rtems_task_argument arg)
497{
498  TEST_BEGIN();
499
500  test_initial_values();
501  test_location_obtain();
502  test_null_location_obtain();
503  test_null_location_replace();
504  test_null_location_get_and_replace();
505  test_path_ops();
506  test_user_env();
507  test_check_access();
508
509  TEST_END();
510  exit(0);
511}
512
513#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
514
515#define CONFIGURE_APPLICATION_DISABLE_FILESYSTEM
516
517#define CONFIGURE_MAXIMUM_TASKS 1
518
519#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
520
521#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
522
523#define CONFIGURE_INIT
524
525#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.