tests: add a simple test case for gpiodetect
authorBartosz Golaszewski <bartekgola@gmail.com>
Thu, 8 Jun 2017 11:06:13 +0000 (13:06 +0200)
committerBartosz Golaszewski <bartekgola@gmail.com>
Thu, 8 Jun 2017 11:06:13 +0000 (13:06 +0200)
Use the newly added API for subprocesses to test a simple use case
of the gpiodetect tool.

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

index d327bc365c22fbff0f4926c9d33f07c9d1ca7b41..a07bce643768d40ced71b36e3506283837832ff6 100644 (file)
@@ -22,6 +22,12 @@ gpiod_test_SOURCES = gpiod-test.c \
                        tests-misc.c \
                        tests-simple-api.c
 
+if WITH_TOOLS
+
+gpiod_test_SOURCES +=  tests-gpiodetect.c
+
+endif
+
 check: check-am
        @echo " ********************************************************"
        @echo " * Tests have been built as tests/gpio-test.            *"
diff --git a/tests/tests-gpiodetect.c b/tests/tests-gpiodetect.c
new file mode 100644 (file)
index 0000000..747fead
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Test cases for the gpiodetect 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"
+
+#include <stdio.h>
+
+static void gpiodetect_good(void)
+{
+       TEST_CLEANUP(test_free_str) char *pattern0 = NULL;
+       TEST_CLEANUP(test_free_str) char *pattern1 = NULL;
+       TEST_CLEANUP(test_free_str) char *pattern2 = NULL;
+       int ret0, ret1, ret2;
+
+       ret0 = asprintf(&pattern0,
+                       "%s [gpio-mockup-A] (4 lines)", test_chip_name(0));
+       ret1 = asprintf(&pattern1,
+                       "%s [gpio-mockup-B] (8 lines)", test_chip_name(1));
+       ret2 = asprintf(&pattern2,
+                       "%s [gpio-mockup-C] (16 lines)", test_chip_name(2));
+
+       TEST_ASSERT(ret0 > 0);
+       TEST_ASSERT(ret1 > 0);
+       TEST_ASSERT(ret2 > 0);
+
+       test_gpiotool_run("gpiodetect", (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(), pattern0);
+       TEST_ASSERT_STR_CONTAINS(test_tool_stdout(), pattern1);
+       TEST_ASSERT_STR_CONTAINS(test_tool_stdout(), pattern2);
+       TEST_ASSERT_NULL(test_tool_stderr());
+}
+TEST_DEFINE(gpiodetect_good,
+           "tools: gpiodetect - good",
+           0, { 4, 8, 16 });