source: rtems/testsuites/sptests/spintrcritical24/init.c @ c4b8b147

5
Last change on this file since c4b8b147 was c4b8b147, checked in by Sebastian Huber <sebastian.huber@…>, on 11/03/17 at 07:35:38

tests: Use simple console driver

Update #3170.
Update #3199.

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*
2 * Copyright (c) 2017 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
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#include <sys/stat.h>
20#include <fcntl.h>
21#include <unistd.h>
22#include <errno.h>
23
24#include <rtems/imfs.h>
25
26#include <tmacros.h>
27#include <intrcritical.h>
28
29const char rtems_test_name[] = "SPINTRCRITICAL 24";
30
31typedef struct {
32  int fd;
33  long append_count;
34  long no_append_count;
35} test_context;
36
37static test_context test_instance;
38
39static const char path[] = "generic";
40
41static int handler_close(rtems_libio_t *iop)
42{
43  test_context *ctx;
44
45  ctx = IMFS_generic_get_context_by_iop(iop);
46
47  if (rtems_libio_iop_is_append(iop)) {
48    ++ctx->append_count;
49  } else {
50    ++ctx->no_append_count;
51  }
52
53  return 0;
54}
55
56static const rtems_filesystem_file_handlers_r node_handlers = {
57  .open_h = rtems_filesystem_default_open,
58  .close_h = handler_close,
59  .fstat_h = rtems_filesystem_default_fstat,
60  .fcntl_h = rtems_filesystem_default_fcntl
61};
62
63static const IMFS_node_control node_control = {
64  .handlers = &node_handlers,
65  .node_initialize = IMFS_node_initialize_generic,
66  .node_remove = IMFS_node_remove_default,
67  .node_destroy = IMFS_node_destroy_default
68};
69
70static void do_fcntl(rtems_id timer, void *arg)
71{
72  /* The arg is NULL */
73  test_context *ctx;
74  int rv;
75
76  ctx = &test_instance;
77
78  rv = fcntl(ctx->fd, F_SETFL, O_APPEND);
79
80  if (rv != 0) {
81    rtems_test_assert(rv == -1);
82    rtems_test_assert(errno == EBADF);
83  }
84}
85
86static bool test_body(void *arg)
87{
88  test_context *ctx;
89  int rv;
90
91  ctx = arg;
92
93  ctx->fd = open(path, O_RDWR);
94  rtems_test_assert(ctx->fd >= 0);
95
96  rv = close(ctx->fd);
97  rtems_test_assert(rv == 0);
98
99  return false;
100}
101
102static void test(test_context *ctx)
103{
104  const char *path = "generic";
105  int rv;
106
107  rv = IMFS_make_generic_node(
108    path,
109    S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO,
110    &node_control,
111    ctx
112  );
113  rtems_test_assert(rv == 0);
114
115  interrupt_critical_section_test(test_body, ctx, do_fcntl);
116
117  /* There is no reliable indicator if the test case has been hit */
118  rtems_test_assert(ctx->append_count > 0);
119  rtems_test_assert(ctx->no_append_count > 0);
120
121  rv = unlink(path);
122  rtems_test_assert(rv == 0);
123}
124
125static void Init(rtems_task_argument arg)
126{
127  TEST_BEGIN();
128  test(&test_instance);
129  TEST_END();
130  rtems_test_exit(0);
131}
132
133#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
134#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
135
136#define CONFIGURE_MICROSECONDS_PER_TICK 1000
137
138#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4
139
140#define CONFIGURE_MAXIMUM_TASKS 1
141#define CONFIGURE_MAXIMUM_TIMERS 1
142#define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1
143
144#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
145
146#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
147
148#define CONFIGURE_INIT
149
150#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.