tests: gpioset: test case for the 'signal' mode
authorBartosz Golaszewski <bartekgola@gmail.com>
Tue, 13 Jun 2017 13:15:45 +0000 (15:15 +0200)
committerBartosz Golaszewski <bartekgola@gmail.com>
Tue, 13 Jun 2017 13:20:40 +0000 (15:20 +0200)
Run gpioset on a set of lines, give it a couple milliseconds to
execute, then send it SIGTERM and check that it exits correctly.

Repeat for SIGINT.

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

index 6636d33356eedded81d785f67100621ce3741846..89c1f50169242e51133b3cbdae9b1696904a2067 100644 (file)
@@ -10,6 +10,9 @@
 
 #include "gpiod-test.h"
 
+#include <signal.h>
+#include <unistd.h>
+
 static void gpioset_set_lines_and_exit(void)
 {
        unsigned int offsets[8];
@@ -126,3 +129,45 @@ static void gpioset_set_some_lines_and_wait_for_enter(void)
 TEST_DEFINE(gpioset_set_some_lines_and_wait_for_enter,
            "tools: gpioset - set some lines and wait for enter",
            0, { 8, 8, 8 });
+
+static void gpioset_set_some_lines_and_wait_for_signal(void)
+{
+       static const int signals[] = { SIGTERM, SIGINT };
+
+       unsigned int offsets[5], i;
+       int rv, values[5];
+
+       for (i = 0; i < TEST_ARRAY_SIZE(signals); i++) {
+               test_tool_run("gpioset", "--mode=signal", "gpiochip2",
+                             "1=0", "2=1", "5=0", "6=0", "7=1", (char *)NULL);
+               usleep(200000);
+               test_tool_signal(signals[i]);
+               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] = 1;
+               offsets[1] = 2;
+               offsets[2] = 5;
+               offsets[3] = 6;
+               offsets[4] = 7;
+
+               rv = gpiod_simple_get_value_multiple(TEST_CONSUMER,
+                                                    test_chip_name(2),
+                                                    offsets, values,
+                                                    5, false);
+               TEST_ASSERT_RET_OK(rv);
+
+               TEST_ASSERT_EQ(values[0], 0);
+               TEST_ASSERT_EQ(values[1], 1);
+               TEST_ASSERT_EQ(values[2], 0);
+               TEST_ASSERT_EQ(values[3], 0);
+               TEST_ASSERT_EQ(values[4], 1);
+       }
+}
+TEST_DEFINE(gpioset_set_some_lines_and_wait_for_signal,
+           "tools: gpioset - set some lines and wait for signal",
+           0, { 8, 8, 8 });