aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBartosz Golaszewski <bgolaszewski@baylibre.com>2019-03-28 14:14:51 +0100
committerBartosz Golaszewski <bgolaszewski@baylibre.com>2019-04-23 11:49:12 +0200
commitfaaffc3abe4728200dbdb8e148e0c85b77464ce1 (patch)
treeacb435a3c80615ff7c037066915c7fd3163a5458
parent78f8694da13405495276b97b688fe8fcee74677f (diff)
downloadlibgpiod-faaffc3abe4728200dbdb8e148e0c85b77464ce1.tar.gz
tests: provide test_debugfs_get/set_value() helpers
Since linux v5.1 gpio-mockup simulates pull-up/down resistors for dummy lines. The current pull can be set using debugfs. Since we can no longer verify if the character device interface properly sets line values, the debugfs interface now also allows to read line values. This way we can verify if the ABI works correctly using different code paths. Provide functions for reading and setting values of mockup GPIO lines. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
-rw-r--r--tests/gpiod-test.c60
-rw-r--r--tests/gpiod-test.h5
2 files changed, 65 insertions, 0 deletions
diff --git a/tests/gpiod-test.c b/tests/gpiod-test.c
index 1f37985b..56ef770f 100644
--- a/tests/gpiod-test.c
+++ b/tests/gpiod-test.c
@@ -3,6 +3,7 @@
* This file is part of libgpiod.
*
* Copyright (C) 2017-2018 Bartosz Golaszewski <bartekgola@gmail.com>
+ * Copyright (C) 2019 Bartosz Golaszewski <bgolaszewski@baylibre.com>
*/
#include <ctype.h>
@@ -1113,6 +1114,65 @@ unsigned int test_chip_num(unsigned int index)
return globals.test_ctx.chips[index]->number;
}
+static int test_debugfs_open(unsigned int chip_index,
+ unsigned int line_offset, int flags)
+{
+ char *path;
+ int fd;
+
+ path = xappend(NULL, "/sys/kernel/debug/gpio-mockup/gpiochip%u/%u",
+ chip_index, line_offset);
+
+ fd = open(path, flags);
+ if (fd < 0)
+ die_perr("unable to open the debugfs line ('%s') attribute for reading",
+ path);
+
+ free(path);
+ return fd;
+}
+
+int test_debugfs_get_value(unsigned int chip_index, unsigned int line_offset)
+{
+ ssize_t rd;
+ char buf;
+ int fd;
+
+ fd = test_debugfs_open(chip_index, line_offset, O_RDONLY);
+
+ rd = read(fd, &buf, 1);
+ if (rd < 0)
+ die_perr("error reading the debugfs line attribute");
+ if (rd != 1)
+ die("unable to read the line value from debugfs");
+ if (buf != '0' && buf != '1')
+ die("invalid line value read from debugfs");
+
+ close(fd);
+ return buf == '0' ? 0 : 1;
+}
+
+void test_debugfs_set_value(unsigned int chip_index,
+ unsigned int line_offset, int val)
+{
+ char buf[2];
+ ssize_t wr;
+ int fd;
+
+ fd = test_debugfs_open(chip_index, line_offset, O_WRONLY);
+
+ buf[0] = val ? '1' : 0;
+ buf[1] = '\n';
+
+ wr = write(fd, &buf, sizeof(buf));
+ if (wr < 0)
+ die_perr("error writing to the debugfs line attribute");
+ if (wr != sizeof(buf))
+ die("unable to write the line value to debugfs");
+
+ close(fd);
+}
+
void _test_register(struct _test_case *test)
{
struct _test_case *tmp;
diff --git a/tests/gpiod-test.h b/tests/gpiod-test.h
index 040d993f..c3ca0b19 100644
--- a/tests/gpiod-test.h
+++ b/tests/gpiod-test.h
@@ -3,6 +3,7 @@
* This file is part of libgpiod.
*
* Copyright (C) 2017-2018 Bartosz Golaszewski <bartekgola@gmail.com>
+ * Copyright (C) 2019 Bartosz Golaszewski <bgolaszewski@baylibre.com>
*/
/* Testing framework - functions and definitions used by test cases. */
@@ -93,6 +94,10 @@ const char *test_chip_path(unsigned int index);
const char *test_chip_name(unsigned int index);
unsigned int test_chip_num(unsigned int index);
+int test_debugfs_get_value(unsigned int chip_index, unsigned int line_offset);
+void test_debugfs_set_value(unsigned int chip_index,
+ unsigned int line_offset, int val);
+
/* Last argument is the delay between line value switches in microseconds. */
void test_set_event(unsigned int chip_index,
unsigned int line_offset, unsigned int freq);