From 4318ab12bb2e95ffe63d5dd8457944bfa67c6bd6 Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Mon, 3 Jun 2019 18:18:38 +0200 Subject: [PATCH] tests: provide test_trigger_event() We use a separate thread to trigger line events for library test cases but if we're testing tools which are separate processes, we can generate the events from the main thread. Add a simple helper for that. Signed-off-by: Bartosz Golaszewski --- tests/gpiod-test.c | 14 ++++++++++++++ tests/gpiod-test.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/tests/gpiod-test.c b/tests/gpiod-test.c index e00f4bf..621d837 100644 --- a/tests/gpiod-test.c +++ b/tests/gpiod-test.c @@ -1014,6 +1014,20 @@ void test_set_event(unsigned int chip_index, event_unlock(); } +void test_trigger_event(unsigned int chip_index, unsigned int line_offset) +{ + int val, rv; + + val = gpio_mockup_get_value(globals.mockup, chip_index, line_offset); + if (val < 0) + die_perr("error reading GPIO value from debugfs"); + + rv = gpio_mockup_set_pull(globals.mockup, chip_index, + line_offset, val ? 0 : 1); + if (rv) + die_perr("error setting GPIO line pull over debugfs"); +} + bool test_regex_match(const char *str, const char *pattern) { char errbuf[128]; diff --git a/tests/gpiod-test.h b/tests/gpiod-test.h index c3ca0b1..1815c65 100644 --- a/tests/gpiod-test.h +++ b/tests/gpiod-test.h @@ -102,6 +102,8 @@ void test_debugfs_set_value(unsigned int chip_index, void test_set_event(unsigned int chip_index, unsigned int line_offset, unsigned int freq); +void test_trigger_event(unsigned int chip_index, unsigned int line_offset); + void test_tool_run(char *tool, ...); void test_tool_wait(void); const char *test_tool_stdout(void); -- 2.30.2