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 | #include "tmacros.h" |
---|
20 | |
---|
21 | #include <sys/socket.h> |
---|
22 | #include <sys/stat.h> |
---|
23 | #include <errno.h> |
---|
24 | #include <fcntl.h> |
---|
25 | #include <unistd.h> |
---|
26 | |
---|
27 | #include <rtems/libio.h> |
---|
28 | #include <rtems/rtems_bsdnet.h> |
---|
29 | |
---|
30 | const char rtems_test_name[] = "SYSCALL 1"; |
---|
31 | |
---|
32 | /* forward declarations to avoid warnings */ |
---|
33 | static rtems_task Init(rtems_task_argument argument); |
---|
34 | |
---|
35 | static const char open_driver_path [] = "/dev/open_driver"; |
---|
36 | |
---|
37 | struct rtems_bsdnet_config rtems_bsdnet_config; |
---|
38 | |
---|
39 | static void test(void) |
---|
40 | { |
---|
41 | int rv; |
---|
42 | char buf [1]; |
---|
43 | ssize_t n; |
---|
44 | int fd; |
---|
45 | |
---|
46 | fd = open(open_driver_path, O_RDWR); |
---|
47 | rtems_test_assert(fd >= 0); |
---|
48 | |
---|
49 | errno = 0; |
---|
50 | n = send(fd, buf, sizeof(buf), 0); |
---|
51 | rtems_test_assert(n == -1); |
---|
52 | rtems_test_assert(errno == ENOTSOCK); |
---|
53 | |
---|
54 | errno = 0; |
---|
55 | n = recv(fd, buf, sizeof(buf), 0); |
---|
56 | rtems_test_assert(n == -1); |
---|
57 | rtems_test_assert(errno == ENOTSOCK); |
---|
58 | |
---|
59 | rv = close(fd); |
---|
60 | rtems_test_assert(rv == 0); |
---|
61 | |
---|
62 | fd = socket(PF_INET, SOCK_DGRAM, 0); |
---|
63 | rtems_test_assert(fd >= 0); |
---|
64 | |
---|
65 | errno = 0; |
---|
66 | rv = fsync(fd); |
---|
67 | rtems_test_assert(rv == -1); |
---|
68 | rtems_test_assert(errno == EINVAL); |
---|
69 | |
---|
70 | errno = 0; |
---|
71 | rv = fdatasync(fd); |
---|
72 | rtems_test_assert(rv == -1); |
---|
73 | rtems_test_assert(errno == EINVAL); |
---|
74 | |
---|
75 | rv = close(fd); |
---|
76 | rtems_test_assert(rv == 0); |
---|
77 | } |
---|
78 | |
---|
79 | static void Init(rtems_task_argument arg) |
---|
80 | { |
---|
81 | int rv; |
---|
82 | |
---|
83 | TEST_BEGIN(); |
---|
84 | |
---|
85 | rv = rtems_bsdnet_initialize_network(); |
---|
86 | rtems_test_assert(rv == 0); |
---|
87 | |
---|
88 | test(); |
---|
89 | |
---|
90 | TEST_END(); |
---|
91 | |
---|
92 | rtems_test_exit(0); |
---|
93 | } |
---|
94 | |
---|
95 | static rtems_device_driver open_driver_initialize( |
---|
96 | rtems_device_major_number major, |
---|
97 | rtems_device_minor_number minor, |
---|
98 | void *arg |
---|
99 | ) |
---|
100 | { |
---|
101 | rtems_status_code sc = rtems_io_register_name(open_driver_path, major, 0); |
---|
102 | rtems_test_assert(sc == RTEMS_SUCCESSFUL); |
---|
103 | |
---|
104 | return RTEMS_SUCCESSFUL; |
---|
105 | } |
---|
106 | |
---|
107 | static rtems_device_driver open_driver_open( |
---|
108 | rtems_device_major_number major, |
---|
109 | rtems_device_minor_number minor, |
---|
110 | void *arg |
---|
111 | ) |
---|
112 | { |
---|
113 | rtems_libio_open_close_args_t *oc = arg; |
---|
114 | |
---|
115 | oc->iop->data0 = 1; |
---|
116 | oc->iop->data1 = (void *) 1; |
---|
117 | |
---|
118 | return RTEMS_SUCCESSFUL; |
---|
119 | } |
---|
120 | |
---|
121 | #define OPEN_DRIVER { \ |
---|
122 | .initialization_entry = open_driver_initialize, \ |
---|
123 | .open_entry = open_driver_open \ |
---|
124 | } |
---|
125 | |
---|
126 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
127 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
128 | #define CONFIGURE_APPLICATION_EXTRA_DRIVERS OPEN_DRIVER |
---|
129 | |
---|
130 | #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM |
---|
131 | |
---|
132 | #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4 |
---|
133 | |
---|
134 | #define CONFIGURE_MAXIMUM_TASKS 2 |
---|
135 | |
---|
136 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
137 | |
---|
138 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
139 | |
---|
140 | #define CONFIGURE_INIT |
---|
141 | |
---|
142 | #include <rtems/confdefs.h> |
---|