tests: add a simple test case for gpioset
authorBartosz Golaszewski <bartekgola@gmail.com>
Mon, 12 Jun 2017 19:38:04 +0000 (21:38 +0200)
committerBartosz Golaszewski <bartekgola@gmail.com>
Mon, 12 Jun 2017 19:38:04 +0000 (21:38 +0200)
Verify the 'exit' mode of gpioset.

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

index 49d7e2507cff7680605cf940ccf69c12e133fd17..2508465bb5bfa503d46be3e64de9fb560faa9c2b 100644 (file)
@@ -27,7 +27,8 @@ if WITH_TOOLS
 gpiod_test_SOURCES +=  tests-gpiodetect.c \
                        tests-gpiofind.c \
                        tests-gpioget.c \
-                       tests-gpioinfo.c
+                       tests-gpioinfo.c \
+                       tests-gpioset.c
 
 endif
 
diff --git a/tests/tests-gpioset.c b/tests/tests-gpioset.c
new file mode 100644 (file)
index 0000000..29f3e61
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Test cases for the gpioset 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 gpioset_set_lines_and_exit(void)
+{
+       unsigned int offsets[8];
+       int rv, values[8];
+
+       test_tool_run("gpioset", "gpiochip2",
+                     "0=0", "1=0", "2=1", "3=1",
+                     "4=1", "5=1", "6=0", "7=1", (char *)NULL);
+       test_tool_wait();
+
+       TEST_ASSERT(test_tool_exited());
+       TEST_ASSERT_RET_OK(test_tool_exit_status());
+       TEST_ASSERT_NULL(test_tool_stdout());
+       TEST_ASSERT_NULL(test_tool_stderr());
+
+       offsets[0] = 0;
+       offsets[1] = 1;
+       offsets[2] = 2;
+       offsets[3] = 3;
+       offsets[4] = 4;
+       offsets[5] = 5;
+       offsets[6] = 6;
+       offsets[7] = 7;
+
+       rv = gpiod_simple_get_value_multiple(TEST_CONSUMER, test_chip_name(2),
+                                            offsets, values, 8, false);
+       TEST_ASSERT_RET_OK(rv);
+
+       TEST_ASSERT_EQ(values[0], 0);
+       TEST_ASSERT_EQ(values[1], 0);
+       TEST_ASSERT_EQ(values[2], 1);
+       TEST_ASSERT_EQ(values[3], 1);
+       TEST_ASSERT_EQ(values[4], 1);
+       TEST_ASSERT_EQ(values[5], 1);
+       TEST_ASSERT_EQ(values[6], 0);
+       TEST_ASSERT_EQ(values[7], 1);
+}
+TEST_DEFINE(gpioset_set_lines_and_exit,
+           "tools: gpioset - set lines and exit",
+           0, { 8, 8, 8 });