From 58f665583e8023f1245910e953eafff05121e782 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Tue, 3 Apr 2012 16:15:34 +0200 Subject: networking: socket to/from file descriptor o Move rtems_bsdnet_fdToSocket() and rtems_bsdnet_makeFdForSocket() to "cpukit/libnetworking/rtems/rtems_syscall.c". o The rtems_bsdnet_makeFdForSocket() function is now static. o Check in rtems_bsdnet_fdToSocket() function that the file descriptor uses the socket handlers, otherwise an error status will be returned and errno set to ENOTSOCK. o New test libtests/syscall01. --- testsuites/libtests/syscall01/init.c | 115 +++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 testsuites/libtests/syscall01/init.c (limited to 'testsuites/libtests/syscall01/init.c') diff --git a/testsuites/libtests/syscall01/init.c b/testsuites/libtests/syscall01/init.c new file mode 100644 index 0000000000..b438a9306c --- /dev/null +++ b/testsuites/libtests/syscall01/init.c @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2012 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Obere Lagerstr. 30 + * 82178 Puchheim + * Germany + * + * + * 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 +#include +#include +#include +#include + +#include +#include + +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 = open(open_driver_path, O_RDWR); + rtems_test_assert(fd >= 0); + + n = send(fd, buf, sizeof(buf), 0); + rtems_test_assert(n == -1); + rtems_test_assert(errno == ENOTSOCK); + + 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); +} + +static void Init(rtems_task_argument arg) +{ + int rv; + + puts("\n\n*** TEST SYSCALL 1 ***"); + + rv = rtems_bsdnet_initialize_network(); + rtems_test_assert(rv == 0); + + test(); + + puts("*** END OF TEST SYSCALL 1 ***"); + + 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_RTEMS_INIT_TASKS_TABLE + +#define CONFIGURE_INIT + +#include -- cgit v1.2.3