tests: add a test case for using misc line flags together
authorBartosz Golaszewski <bgolaszewski@baylibre.com>
Tue, 6 Aug 2019 09:52:31 +0000 (11:52 +0200)
committerBartosz Golaszewski <bgolaszewski@baylibre.com>
Tue, 6 Aug 2019 14:44:34 +0000 (16:44 +0200)
This adds a test case that verifies that the ACTIVE_LOW flag works
correctly when used together with OPEN_SOURCE and OPEN_DRAIN flags.

Note: a bug has been discovered in the kernel that makes the LINEINFO
ioctl() incorrectly report the direction of lines requested with
open-drain or open-source flags as 'input' if the underlying hardware
doesn't support these config options. A patch fixing it has been sent
and once it's released, the FIXME's added by this patch will be
removed.

While at it: extend the previous misc flags test with additional checks
of the reported direction, but disable the one that fails due to the
bug mentioned above.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
tests/tests-line.c

index db8dc03379cd9d94e898f8df8ae189ba0bb20b44..7458992781194594810f7bf137ca39d67730ee1e 100644 (file)
@@ -462,6 +462,8 @@ GPIOD_TEST_CASE(misc_flags, 0, { 8 })
        g_assert_true(gpiod_line_is_used(line));
        g_assert_true(gpiod_line_is_open_drain(line));
        g_assert_false(gpiod_line_is_open_source(line));
+       g_assert_cmpint(gpiod_line_direction(line), ==,
+                       GPIOD_LINE_DIRECTION_OUTPUT);
 
        gpiod_line_release(line);
 
@@ -473,6 +475,71 @@ GPIOD_TEST_CASE(misc_flags, 0, { 8 })
        g_assert_true(gpiod_line_is_used(line));
        g_assert_false(gpiod_line_is_open_drain(line));
        g_assert_true(gpiod_line_is_open_source(line));
+       /*
+        * FIXME Enable the line below once the open-source/drain issue is
+        * fixed in the kernel.
+        */
+/*
+       g_assert_cmpint(gpiod_line_direction(line), ==,
+                       GPIOD_LINE_DIRECTION_OUTPUT);
+*/
+}
+
+GPIOD_TEST_CASE(misc_flags_work_together, 0, { 8 })
+{
+       g_autoptr(gpiod_chip_struct) chip = NULL;
+       struct gpiod_line_request_config config;
+       struct gpiod_line *line;
+       gint ret;
+
+       chip = gpiod_chip_open(gpiod_test_chip_path(0));
+       g_assert_nonnull(chip);
+       gpiod_test_return_if_failed();
+
+       line = gpiod_chip_get_line(chip, 2);
+       g_assert_nonnull(line);
+       gpiod_test_return_if_failed();
+
+       /*
+        * Verify that open drain/source flags work together
+        * with active_low.
+        */
+
+       config.request_type = GPIOD_LINE_REQUEST_DIRECTION_OUTPUT;
+       config.consumer = GPIOD_TEST_CONSUMER;
+       config.flags = GPIOD_LINE_REQUEST_FLAG_OPEN_DRAIN |
+                      GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW;
+
+       ret = gpiod_line_request(line, &config, 0);
+       g_assert_cmpint(ret, ==, 0);
+
+       g_assert_true(gpiod_line_is_used(line));
+       g_assert_true(gpiod_line_is_open_drain(line));
+       g_assert_false(gpiod_line_is_open_source(line));
+       g_assert_cmpint(gpiod_line_active_state(line), ==,
+                       GPIOD_LINE_ACTIVE_STATE_LOW);
+       /*
+        * FIXME Enable the line below once the open-source/drain issue is
+        * fixed in the kernel.
+        */
+/*
+       g_assert_cmpint(gpiod_line_direction(line), ==,
+                       GPIOD_LINE_DIRECTION_OUTPUT);
+*/
+
+       gpiod_line_release(line);
+
+       config.flags = GPIOD_LINE_REQUEST_FLAG_OPEN_SOURCE |
+                      GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW;
+
+       ret = gpiod_line_request(line, &config, 0);
+       g_assert_cmpint(ret, ==, 0);
+
+       g_assert_true(gpiod_line_is_used(line));
+       g_assert_false(gpiod_line_is_open_drain(line));
+       g_assert_true(gpiod_line_is_open_source(line));
+       g_assert_cmpint(gpiod_line_active_state(line), ==,
+                       GPIOD_LINE_ACTIVE_STATE_LOW);
 }
 
 GPIOD_TEST_CASE(open_source_open_drain_input_mode, 0, { 8 })