Module: xenomai-3 Branch: wip/gpio Commit: 898532ac4952edc99093c530002483e8a7fa9e27 URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=898532ac4952edc99093c530002483e8a7fa9e27
Author: Philippe Gerum <r...@xenomai.org> Date: Wed Jun 1 15:59:27 2016 +0200 testsuite/gpiotest: add GPIO test suite --- testsuite/Makefile.am | 2 + testsuite/gpiotest/Makefile.am | 19 ++++ testsuite/gpiotest/gpiotest.c | 188 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 209 insertions(+) diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am index e83e6cb..c345472 100644 --- a/testsuite/Makefile.am +++ b/testsuite/Makefile.am @@ -4,12 +4,14 @@ SUBDIRS = latency smokey if XENO_COBALT SUBDIRS += \ clocktest \ + gpiotest \ switchtest \ xeno-test endif DIST_SUBDIRS = \ clocktest \ + gpiotest \ latency \ smokey \ switchtest \ diff --git a/testsuite/gpiotest/Makefile.am b/testsuite/gpiotest/Makefile.am new file mode 100644 index 0000000..b01427b --- /dev/null +++ b/testsuite/gpiotest/Makefile.am @@ -0,0 +1,19 @@ +testdir = @XENO_TEST_DIR@ + +CCLD = $(top_srcdir)/scripts/wrap-link.sh $(CC) + +test_PROGRAMS = gpiotest + +gpiotest_SOURCES = gpiotest.c + +gpiotest_CPPFLAGS = \ + $(XENO_USER_CFLAGS) \ + -I$(top_srcdir)/include + +gpiotest_LDFLAGS = @XENO_AUTOINIT_LDFLAGS@ $(XENO_POSIX_WRAPPERS) + +gpiotest_LDADD = \ + ../../lib/smokey/libsmokey.la \ + ../../lib/@XENO_CORE_LIB@ \ + @XENO_USER_LDADD@ \ + -lpthread -lrt diff --git a/testsuite/gpiotest/gpiotest.c b/testsuite/gpiotest/gpiotest.c new file mode 100644 index 0000000..838f498 --- /dev/null +++ b/testsuite/gpiotest/gpiotest.c @@ -0,0 +1,188 @@ +/* + * Copyright (C) 2016 Philippe Gerum <r...@xenomai.org>. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ +#include <stdio.h> +#include <error.h> +#include <errno.h> +#include <stdlib.h> +#include <unistd.h> +#include <fcntl.h> +#include <smokey/smokey.h> +#include <rtdm/gpio.h> + +smokey_test_plugin(interrupt, + SMOKEY_ARGLIST( + SMOKEY_STRING(device), + ), + "Wait for interrupts from a GPIO pin.\n" + "\tdevice=<device-path>." +); + +smokey_test_plugin(read_value, + SMOKEY_ARGLIST( + SMOKEY_STRING(device), + ), + "Read GPIO value.\n" + "\tdevice=<device-path>." +); + +smokey_test_plugin(write_value, + SMOKEY_ARGLIST( + SMOKEY_STRING(device), + ), + "Write GPIO value.\n" + "\tdevice=<device-path>." +); + +static int run_interrupt(struct smokey_test *t, int argc, char *const argv[]) +{ + const char *device = NULL; + int fd, ret; + fd_set set; + + smokey_parse_args(t, argc, argv); + + if (!SMOKEY_ARG_ISSET(interrupt, device)) { + warning("missing device= specification"); + return -EINVAL; + } + + device = SMOKEY_ARG_STRING(interrupt, device); + fd = open(device, O_RDWR); + if (fd < 0) { + ret = -errno; + warning("cannot open device %s [%s]", + device, symerror(ret)); + return ret; + } + + ret = ioctl(fd, GPIO_RTIOC_IRQEN); + if (ret) { + ret = -errno; + warning("GPIO_RTIOC_IRQEN failed on %s [%s]", + device, symerror(ret)); + return ret; + } + + FD_ZERO(&set); + FD_SET(fd, &set); + + for (;;) { + ret = select(fd + 1, &set, NULL, NULL, NULL); + if (ret < 0) { + ret = -errno; + warning("failed listening to %s [%s]", + device, symerror(ret)); + } + printf("kick %d!\n", ret); + } + + close(fd); + + return 0; +} + +static int run_read_value(struct smokey_test *t, int argc, char *const argv[]) +{ + const char *device = NULL; + int fd, ret, value = -1; + + smokey_parse_args(t, argc, argv); + + if (!SMOKEY_ARG_ISSET(read_value, device)) { + warning("missing device= specification"); + return -EINVAL; + } + + device = SMOKEY_ARG_STRING(read_value, device); + fd = open(device, O_RDONLY); + if (fd < 0) { + ret = -errno; + warning("cannot open device %s [%s]", + device, symerror(ret)); + return ret; + } + + ret = read(fd, &value, sizeof(value)); + close(fd); + + if (!__Tassert(ret == sizeof(value))) + return -EINVAL; + + smokey_trace("value=%d", value); + + return 0; +} + +static int run_write_value(struct smokey_test *t, int argc, char *const argv[]) +{ + const char *device = NULL; + int fd, ret, value; + + smokey_parse_args(t, argc, argv); + + if (!SMOKEY_ARG_ISSET(write_value, device)) { + warning("missing device= specification"); + return -EINVAL; + } + + device = SMOKEY_ARG_STRING(write_value, device); + fd = open(device, O_WRONLY); + if (fd < 0) { + ret = -errno; + warning("cannot open device %s [%s]", + device, symerror(ret)); + return ret; + } + + ret = write(fd, &value, sizeof(value)); + close(fd); + + if (!__Tassert(ret == sizeof(value))) + return -EINVAL; + + return 0; +} + +int main(int argc, char *const argv[]) +{ + struct smokey_test *t; + int ret, fails = 0; + + if (pvlist_empty(&smokey_test_list)) + return 0; + + for_each_smokey_test(t) { + ret = t->run(t, argc, argv); + if (ret) { + if (ret == -ENOSYS) { + smokey_note("%s skipped (no kernel support)", + t->name); + continue; + } + fails++; + if (smokey_keep_going) + continue; + if (smokey_verbose_mode) + error(1, -ret, "test %s failed", t->name); + return 1; + } + smokey_note("%s OK", t->name); + } + + return fails != 0; +} _______________________________________________ Xenomai-git mailing list Xenomai-git@xenomai.org https://xenomai.org/mailman/listinfo/xenomai-git