tests: new test case for gpioinfo
authorBartosz Golaszewski <bartekgola@gmail.com>
Fri, 9 Jun 2017 15:27:58 +0000 (17:27 +0200)
committerBartosz Golaszewski <bartekgola@gmail.com>
Fri, 9 Jun 2017 15:27:58 +0000 (17:27 +0200)
Check if we correctly report exported lines.

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

index 0aca1305572c0cdc9aada91f5e559d06d2b103c1..3837653daad2d2d9b29ce7857f86c755b6466a91 100644 (file)
@@ -10,7 +10,9 @@
 
 #include "gpiod-test.h"
 
-static void gpioinfo_good(void)
+#include <stdio.h>
+
+static void gpioinfo_simple(void)
 {
        test_gpiotool_run("gpioinfo", (char *)NULL);
        test_tool_wait();
@@ -25,6 +27,42 @@ static void gpioinfo_good(void)
        TEST_ASSERT_REGEX_MATCH(test_tool_stdout(),
                                "\\s+line\\s+7:\\s+unnamed\\s+unused\\s+output\\s+active-high");
 }
-TEST_DEFINE(gpioinfo_good,
-           "tools: gpioinfo - good",
+TEST_DEFINE(gpioinfo_simple,
+           "tools: gpioinfo - simple",
+           0, { 4, 8 });
+
+static void gpioinfo_one_exported(void)
+{
+       TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip = NULL;
+       struct gpiod_line *line;
+       char *ptrn;
+       int rv;
+
+       rv = asprintf(&ptrn,
+                     "\\s+line\\s+7:\\s+unnamed\\s+\\\"%s\\\"\\s+input\\s+active-low",
+                     TEST_CONSUMER);
+
+       chip = gpiod_chip_open(test_chip_path(1));
+       TEST_ASSERT_NOT_NULL(chip);
+
+       line = gpiod_chip_get_line(chip, 7);
+       TEST_ASSERT_NOT_NULL(line);
+
+       rv = gpiod_line_request_input(line, TEST_CONSUMER, true);
+       TEST_ASSERT_RET_OK(rv);
+
+       test_gpiotool_run("gpioinfo", (char *)NULL);
+       test_tool_wait();
+
+       TEST_ASSERT(test_tool_exited());
+       TEST_ASSERT_RET_OK(test_tool_exit_status());
+       TEST_ASSERT_NOT_NULL(test_tool_stdout());
+       TEST_ASSERT_STR_CONTAINS(test_tool_stdout(), "gpiochip0 - 4 lines:");
+       TEST_ASSERT_STR_CONTAINS(test_tool_stdout(), "gpiochip1 - 8 lines:");
+       TEST_ASSERT_REGEX_MATCH(test_tool_stdout(),
+                               "\\s+line\\s+0:\\s+unnamed\\s+unused\\s+output\\s+active-high");
+       TEST_ASSERT_REGEX_MATCH(test_tool_stdout(), ptrn);
+}
+TEST_DEFINE(gpioinfo_one_exported,
+           "tools: gpioinfo - one exported",
            0, { 4, 8 });