tests: event: new test case
authorBartosz Golaszewski <bartekgola@gmail.com>
Mon, 12 Feb 2018 10:55:49 +0000 (11:55 +0100)
committerBartosz Golaszewski <bartekgola@gmail.com>
Mon, 12 Feb 2018 11:11:51 +0000 (12:11 +0100)
Verify that the active-low flag is respected when reading line values
from lines configured for events.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
tests/tests-event.c

index bf800b72ad32b62bf5e73f5bb3bb24556f44f2c3..45d5c4e747114127b20852f069c46aa422e117e7 100644 (file)
@@ -171,6 +171,44 @@ TEST_DEFINE(event_get_value,
            "events - mixing events and gpiod_line_get_value()",
            0, { 8 });
 
+static void event_get_value_active_low(void)
+{
+       TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL;
+       struct timespec ts = { 1, 0 };
+       struct gpiod_line_event ev;
+       struct gpiod_line *line;
+       int rv;
+
+       chip = gpiod_chip_open(test_chip_path(0));
+       TEST_ASSERT_NOT_NULL(chip);
+
+       line = gpiod_chip_get_line(chip, 7);
+       TEST_ASSERT_NOT_NULL(line);
+
+       rv = gpiod_line_request_falling_edge_events_flags(line, TEST_CONSUMER,
+                                       GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW);
+       TEST_ASSERT_RET_OK(rv);
+
+       rv = gpiod_line_get_value(line);
+       TEST_ASSERT_EQ(rv, 1);
+
+       test_set_event(0, 7, TEST_EVENT_FALLING, 100);
+
+       rv = gpiod_line_event_wait(line, &ts);
+       TEST_ASSERT_EQ(rv, 1);
+
+       rv = gpiod_line_event_read(line, &ev);
+       TEST_ASSERT_RET_OK(rv);
+
+       TEST_ASSERT_EQ(ev.event_type, GPIOD_LINE_EVENT_FALLING_EDGE);
+
+       rv = gpiod_line_get_value(line);
+       TEST_ASSERT_EQ(rv, 0);
+}
+TEST_DEFINE(event_get_value_active_low,
+           "events - mixing events and gpiod_line_get_value() (active-low flag)",
+           0, { 8 });
+
 static void event_wait_multiple(void)
 {
        TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL;