summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoel Sherrill <joel@rtems.org>2016-12-05 21:06:40 -0600
committerJoel Sherrill <joel@rtems.org>2017-01-11 09:45:32 -0600
commitef362818dff3e7dc437d90133424e9c9f0608a02 (patch)
treec6800ad8c9bcd8d9a894c48ea533c38d9eb3a962
parentposix: Fix alarm() in SMP configurations (diff)
downloadrtems-ef362818dff3e7dc437d90133424e9c9f0608a02.tar.bz2
Add support for posix_devctl()
-rw-r--r--cpukit/libcsupport/Makefile.am3
-rw-r--r--cpukit/libcsupport/src/posix_devctl.c72
-rw-r--r--cpukit/posix/src/sysconf.c2
-rw-r--r--testsuites/psxtests/Makefile.am3
-rw-r--r--testsuites/psxtests/configure.ac1
-rw-r--r--testsuites/psxtests/psxdevctl01/Makefile.am23
-rw-r--r--testsuites/psxtests/psxdevctl01/main.c50
-rw-r--r--testsuites/psxtests/psxdevctl01/psxdevctl01.doc23
-rw-r--r--testsuites/psxtests/psxdevctl01/psxdevctl01.scn4
-rw-r--r--testsuites/psxtests/psxdevctl01/test.c81
-rw-r--r--testsuites/psxtests/psxhdrs/Makefile.am3
-rw-r--r--testsuites/psxtests/psxhdrs/devctl/posix_devctl.c37
12 files changed, 301 insertions, 1 deletions
diff --git a/cpukit/libcsupport/Makefile.am b/cpukit/libcsupport/Makefile.am
index bf78fa0c65..559ad81446 100644
--- a/cpukit/libcsupport/Makefile.am
+++ b/cpukit/libcsupport/Makefile.am
@@ -138,7 +138,8 @@ libcsupport_a_SOURCES += src/printertask.c
libcsupport_a_SOURCES += $(LIBC_GLUE_C_FILES) $(PASSWORD_GROUP_C_FILES) \
$(TERMINAL_IDENTIFICATION_C_FILES) $(SYSTEM_CALL_C_FILES) \
$(DIRECTORY_SCAN_C_FILES) $(ID_C_FILES) src/envlock.c \
- $(TERMIOS_C_FILES) src/getpagesize.c src/getrusage.c
+ $(TERMIOS_C_FILES) src/getpagesize.c src/getrusage.c src/posix_devctl.c
+
libcsupport_a_SOURCES += src/flockfile.c src/funlockfile.c src/ftrylockfile.c
diff --git a/cpukit/libcsupport/src/posix_devctl.c b/cpukit/libcsupport/src/posix_devctl.c
new file mode 100644
index 0000000000..9b86e0e059
--- /dev/null
+++ b/cpukit/libcsupport/src/posix_devctl.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2016 Joel Sherrill <joel@rtems.org>. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define _POSIX_26_C_SOURCE
+
+#include <devctl.h>
+#include <sys/ioctl.h>
+#include <rtems/seterr.h>
+
+int posix_devctl(
+ int fd,
+ int dcmd,
+ void *restrict dev_data_ptr,
+ size_t nbyte,
+ int *restrict dev_info_ptr
+)
+{
+ /*
+ * The POSIX 1003.26 standard allows for library implementations
+ * that implement posix_devctl() using ioctl(). In this case,
+ * the extra parameters are largely ignored.
+ *
+ * The FACE Technical Standard requires only that FIONBIO
+ * be supported for sockets.
+ *
+ * This method appears to be rarely implemented and there are
+ * no known required use cases for this method beyond those
+ * from the FACE Technical Standard.
+ */
+
+ /*
+ * POSIX 1003.26 mentions that nbyte must be non-negative but this
+ * doesn't make sense because size_t is guaranteed to be unsigned.
+ */
+
+ /*
+ * Since this is implemented on top of ioctl(), the device information
+ * is not going to be passed down. Fill it in with zero so the behavior
+ * is defined.
+ */
+ if (dev_info_ptr != NULL) {
+ *dev_info_ptr = 0;
+ }
+
+ return ioctl(fd, dcmd, dev_data_ptr);
+}
diff --git a/cpukit/posix/src/sysconf.c b/cpukit/posix/src/sysconf.c
index 0e7b1e5305..c5f66f6f46 100644
--- a/cpukit/posix/src/sysconf.c
+++ b/cpukit/posix/src/sysconf.c
@@ -51,6 +51,8 @@ long sysconf(
return (long) rtems_configuration_get_maximum_processors();
case _SC_NPROCESSORS_ONLN:
return (long) rtems_get_processor_count();
+ case _SC_POSIX_26_VERSION:
+ return (long) _POSIX_26_VERSION;
#if defined(__sparc__)
case 515: /* Solaris _SC_STACK_PROT */
return 0;
diff --git a/testsuites/psxtests/Makefile.am b/testsuites/psxtests/Makefile.am
index 0ff5cb300e..40faa61a4f 100644
--- a/testsuites/psxtests/Makefile.am
+++ b/testsuites/psxtests/Makefile.am
@@ -27,6 +27,9 @@ _SUBDIRS += psxfile01 psxfile02 psxfilelock01 psxgetrusage01 psxid01 \
psximfs01 psximfs02 psxreaddir psxstat psxmount psx13 psxchroot01 \
psxpasswd01 psxpasswd02 psxpipe01 psxtimes01 psxfchx01
+## POSIX Devctl tests
+_SUBDIRS += psxdevctl01
+
## POSIX Keys are always available
_SUBDIRS += psxkey01 psxkey02 psxkey03 psxkey04 \
psxkey05 psxkey06 psxkey08 psxkey09 psxkey10
diff --git a/testsuites/psxtests/configure.ac b/testsuites/psxtests/configure.ac
index 29f9a192fa..6b12e4903a 100644
--- a/testsuites/psxtests/configure.ac
+++ b/testsuites/psxtests/configure.ac
@@ -147,6 +147,7 @@ psxconcurrency01/Makefile
psxcond01/Makefile
psxcond02/Makefile
psxconfig01/Makefile
+psxdevctl01/Makefile
psxeintr_join/Makefile
psxenosys/Makefile
psxfatal01/Makefile
diff --git a/testsuites/psxtests/psxdevctl01/Makefile.am b/testsuites/psxtests/psxdevctl01/Makefile.am
new file mode 100644
index 0000000000..3bc9bdc988
--- /dev/null
+++ b/testsuites/psxtests/psxdevctl01/Makefile.am
@@ -0,0 +1,23 @@
+
+rtems_tests_PROGRAMS = psxdevctl01
+psxdevctl01_SOURCES = main.c test.c ../include/pmacros.h
+
+dist_rtems_tests_DATA = psxdevctl01.scn
+
+include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg
+include $(top_srcdir)/../automake/compile.am
+include $(top_srcdir)/../automake/leaf.am
+
+
+AM_CPPFLAGS += -I$(top_srcdir)/include
+AM_CPPFLAGS += -I$(top_srcdir)/../support/include
+
+LINK_OBJS = $(psxdevctl01_OBJECTS)
+LINK_LIBS = $(psxdevctl01_LDLIBS)
+
+psxdevctl01$(EXEEXT): $(psxdevctl01_OBJECTS) \
+ $(psxdevctl01_DEPENDENCIES)
+ @rm -f psxdevctl01$(EXEEXT)
+ $(make-exe)
+
+include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/psxtests/psxdevctl01/main.c b/testsuites/psxtests/psxdevctl01/main.c
new file mode 100644
index 0000000000..2228551f1d
--- /dev/null
+++ b/testsuites/psxtests/psxdevctl01/main.c
@@ -0,0 +1,50 @@
+/**
+ * @file
+ *
+ * Test program wrapper for POSIX Devctl
+ */
+
+/*
+ * COPYRIGHT (c) 2016.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#define CONFIGURE_INIT
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <bsp.h>
+#include <pmacros.h>
+
+/* forward declarations to avoid warnings */
+rtems_task Init(rtems_task_argument ignored);
+void test_main(void);
+
+rtems_task Init(
+ rtems_task_argument ignored
+)
+{
+ test_main();
+ rtems_test_exit( 0 );
+}
+
+/* configuration information */
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
+
+#define CONFIGURE_MAXIMUM_TASKS 1
+
+#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_INIT
+
+#include <rtems/confdefs.h>
+/* end of file */
diff --git a/testsuites/psxtests/psxdevctl01/psxdevctl01.doc b/testsuites/psxtests/psxdevctl01/psxdevctl01.doc
new file mode 100644
index 0000000000..fee22d237d
--- /dev/null
+++ b/testsuites/psxtests/psxdevctl01/psxdevctl01.doc
@@ -0,0 +1,23 @@
+# COPYRIGHT (c) 2016.
+# On-Line Applications Research Corporation (OAR).
+#
+# The license and distribution terms for this file may be
+# found in the file LICENSE in this distribution or at
+# http://www.rtems.org/license/LICENSE.
+#
+
+This file describes the directives and concepts tested by this test set.
+
+test set name: psxdevctl01
+
+directives:
+
+ posix_devctl
+
+concepts:
+
++ Ensure that proper error values result when passing different combinations of
+ arguments to posix_devctl().
+
++ Ensure that a requestn is passed through the underlying ioctl() operation
+ to the console device driver and flagged as an error.
diff --git a/testsuites/psxtests/psxdevctl01/psxdevctl01.scn b/testsuites/psxtests/psxdevctl01/psxdevctl01.scn
new file mode 100644
index 0000000000..1df1d7e6e8
--- /dev/null
+++ b/testsuites/psxtests/psxdevctl01/psxdevctl01.scn
@@ -0,0 +1,4 @@
+*** BEGIN OF TEST PSXDEVCTL 1 ***
+posix_devctl() FIONBIO on stdin return dev_info -- EBADF
+posix_devctl() FIONBIO on stdin return dev_info -- EBADF
+*** END OF TEST PSXDEVCTL 1 ***
diff --git a/testsuites/psxtests/psxdevctl01/test.c b/testsuites/psxtests/psxdevctl01/test.c
new file mode 100644
index 0000000000..423e8c50b8
--- /dev/null
+++ b/testsuites/psxtests/psxdevctl01/test.c
@@ -0,0 +1,81 @@
+/**
+ * @file
+ *
+ * This test exercises the posix_devctl() method.
+ */
+
+/*
+ * COPYRIGHT (c) 2016.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define TESTS_USE_PRINTK
+#define _POSIX_26_C_SOURCE
+#include "tmacros.h"
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <stdlib.h>
+
+#include <devctl.h>
+
+#include <unistd.h>
+#include <fcntl.h>
+
+const char rtems_test_name[] = "PSXDEVCTL 1";
+
+/* forward declarations to avoid warnings */
+int test_main(void);
+
+/*
+ * main entry point to the test
+ */
+
+#if defined(__rtems__)
+int test_main(void)
+#else
+int main(
+ int argc,
+ char **argv
+)
+#endif
+{
+ int status;
+ int fd;
+ int dcmd;
+ int dev_data;
+ void *dev_data_ptr;
+ size_t nbyte;
+ int dev_info;
+
+ TEST_BEGIN();
+
+ puts( "posix_devctl() FIONBIO on stdin return dev_info -- EBADF" );
+ fd = 0;
+ dcmd = FIONBIO;
+ dev_data_ptr = &dev_data;
+ nbyte = sizeof(dev_data);
+ status = posix_devctl( fd, dcmd, dev_data_ptr, nbyte, &dev_info );
+ rtems_test_assert( status == -1 );
+ rtems_test_assert( errno == EBADF );
+ rtems_test_assert( dev_info == 0 );
+
+ puts( "posix_devctl() FIONBIO on stdin NULL dev_info -- EBADF" );
+ fd = 0;
+ dcmd = FIONBIO;
+ dev_data_ptr = NULL;
+ nbyte = 0;
+ status = posix_devctl( fd, dcmd, dev_data_ptr, nbyte, NULL );
+ rtems_test_assert( status == -1 );
+ rtems_test_assert( errno == EBADF );
+
+ TEST_END();
+ exit(0);
+}
diff --git a/testsuites/psxtests/psxhdrs/Makefile.am b/testsuites/psxtests/psxhdrs/Makefile.am
index 82fb315b19..e902500b9d 100644
--- a/testsuites/psxtests/psxhdrs/Makefile.am
+++ b/testsuites/psxtests/psxhdrs/Makefile.am
@@ -1,6 +1,9 @@
noinst_LIBRARIES = lib.a
lib_a_SOURCES =
+# methods in <devctl.h>
+lib_a_SOURCES += devctl/posix_devctl.c
+
# methods in <pthread.h>
lib_a_SOURCES += pthread/pthread_attr_destroy.c
lib_a_SOURCES += pthread/pthread_attr_getdetachstate.c
diff --git a/testsuites/psxtests/psxhdrs/devctl/posix_devctl.c b/testsuites/psxtests/psxhdrs/devctl/posix_devctl.c
new file mode 100644
index 0000000000..3a40c7869a
--- /dev/null
+++ b/testsuites/psxtests/psxhdrs/devctl/posix_devctl.c
@@ -0,0 +1,37 @@
+/*
+ * COPYRIGHT (c) 2016.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define _POSIX_26_C_SOURCE
+
+#include <devctl.h>
+
+int test( void );
+
+int test( void )
+{
+ int result;
+ int fd;
+ int dcmd;
+ void *dev_data_ptr;
+ size_t nbyte;
+ int dev_info;
+
+ fd = -1;
+ dcmd = 0;
+ dev_data_ptr = NULL;
+ nbyte = 0;
+
+ result = posix_devctl(fd, dcmd, dev_data_ptr, nbyte, &dev_info);
+
+ return result;
+}