summaryrefslogtreecommitdiffstats
path: root/testsuites/libtests/syscall01/init.c
blob: 990d5e134c3c6690a0ba1251829eec1b82636c19 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
 * Copyright (c) 2012 embedded brains GmbH.  All rights reserved.
 *
 *  embedded brains GmbH
 *  Obere Lagerstr. 30
 *  82178 Puchheim
 *  Germany
 *  <rtems@embedded-brains.de>
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rtems.com/license/LICENSE.
 */

#ifdef HAVE_CONFIG_H
  #include "config.h"
#endif

#include "tmacros.h"

#include <sys/socket.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>

#include <rtems/libio.h>
#include <rtems/rtems_bsdnet.h>

const char rtems_test_name[] = "SYSCALL 1";

/* forward declarations to avoid warnings */
static rtems_task Init(rtems_task_argument argument);

static const char open_driver_path [] = "/dev/open_driver";

struct rtems_bsdnet_config rtems_bsdnet_config;

static void test(void)
{
  int rv;
  char buf [1];
  ssize_t n;
  int fd;

  fd = open(open_driver_path, O_RDWR);
  rtems_test_assert(fd >= 0);

  errno = 0;
  n = send(fd, buf, sizeof(buf), 0);
  rtems_test_assert(n == -1);
  rtems_test_assert(errno == ENOTSOCK);

  errno = 0;
  n = recv(fd, buf, sizeof(buf), 0);
  rtems_test_assert(n == -1);
  rtems_test_assert(errno == ENOTSOCK);

  rv = close(fd);
  rtems_test_assert(rv == 0);

  fd = socket(PF_INET, SOCK_DGRAM, 0);
  rtems_test_assert(fd >= 0);

  errno = 0;
  rv = fsync(fd);
  rtems_test_assert(rv == -1);
  rtems_test_assert(errno == EINVAL);

  errno = 0;
  rv = fdatasync(fd);
  rtems_test_assert(rv == -1);
  rtems_test_assert(errno == EINVAL);

  rv = close(fd);
  rtems_test_assert(rv == 0);
}

static void Init(rtems_task_argument arg)
{
  int rv;

  TEST_BEGIN();

  rv = rtems_bsdnet_initialize_network();
  rtems_test_assert(rv == 0);

  test();

  TEST_END();

  rtems_test_exit(0);
}

static rtems_device_driver open_driver_initialize(
  rtems_device_major_number major,
  rtems_device_minor_number minor,
  void *arg
)
{
  rtems_status_code sc = rtems_io_register_name(open_driver_path, major, 0);
  rtems_test_assert(sc == RTEMS_SUCCESSFUL);

  return RTEMS_SUCCESSFUL;
}

static rtems_device_driver open_driver_open(
  rtems_device_major_number major,
  rtems_device_minor_number minor,
  void *arg
)
{
  rtems_libio_open_close_args_t *oc = arg;

  oc->iop->data0 = 1;
  oc->iop->data1 = (void *) 1;

  return RTEMS_SUCCESSFUL;
}

#define OPEN_DRIVER { \
  .initialization_entry = open_driver_initialize, \
  .open_entry = open_driver_open \
}

#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_APPLICATION_EXTRA_DRIVERS OPEN_DRIVER

#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM

#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4

#define CONFIGURE_MAXIMUM_TASKS 2

#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION

#define CONFIGURE_RTEMS_INIT_TASKS_TABLE

#define CONFIGURE_INIT

#include <rtems/confdefs.h>