tests: add a test case for gpioget
authorBartosz Golaszewski <bartekgola@gmail.com>
Mon, 12 Jun 2017 17:58:21 +0000 (19:58 +0200)
committerBartosz Golaszewski <bartekgola@gmail.com>
Mon, 12 Jun 2017 18:28:19 +0000 (20:28 +0200)
Add a simple test case for gpioget: read all lines at their initial
state, change the values of some of them and re-read.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
tests/Makefile.am
tests/tests-gpioget.c [new file with mode: 0644]

index 26210e6912af9e35e921d03b4fdbbd4d6d7cbc67..49d7e2507cff7680605cf940ccf69c12e133fd17 100644 (file)
@@ -26,6 +26,7 @@ if WITH_TOOLS
 
 gpiod_test_SOURCES +=  tests-gpiodetect.c \
                        tests-gpiofind.c \
+                       tests-gpioget.c \
                        tests-gpioinfo.c
 
 endif
diff --git a/tests/tests-gpioget.c b/tests/tests-gpioget.c
new file mode 100644 (file)
index 0000000..cee17a0
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Test cases for the gpioget tool.
+ *
+ * Copyright (C) 2017 Bartosz Golaszewski <bartekgola@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2.1 of the GNU Lesser General Public License
+ * as published by the Free Software Foundation.
+ */
+
+#include "gpiod-test.h"
+
+static void gpioget_read_all_lines(void)
+{
+       unsigned int offsets[4];
+       int rv, values[4];
+
+       test_tool_run("gpioget", "gpiochip1",
+                     "0", "1", "2", "3", "4", "5", "6", "7", (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_NULL(test_tool_stderr());
+       TEST_ASSERT_STR_EQ(test_tool_stdout(), "0 0 0 0 0 0 0 0\n");
+
+       offsets[0] = 2;
+       offsets[1] = 3;
+       offsets[2] = 5;
+       offsets[3] = 7;
+
+       values[0] = values[1] = values[2] = values[3] = 1;
+
+       rv = gpiod_simple_set_value_multiple(TEST_CONSUMER, test_chip_name(1),
+                                            offsets, values, 4, false,
+                                            NULL, NULL);
+       TEST_ASSERT_RET_OK(rv);
+
+       test_tool_run("gpioget", "gpiochip1",
+                     "0", "1", "2", "3", "4", "5", "6", "7", (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_NULL(test_tool_stderr());
+       TEST_ASSERT_STR_EQ(test_tool_stdout(), "0 0 1 1 0 1 0 1\n");
+}
+TEST_DEFINE(gpioget_read_all_lines,
+           "tools: gpioget - read all lines",
+           0, { 8, 8, 8 });