From fbc58c4682bfb8305e5b71b32be5ba9b844aa0e3 Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Thu, 8 Jun 2017 13:06:13 +0200 Subject: [PATCH] tests: add a simple test case for gpiodetect Use the newly added API for subprocesses to test a simple use case of the gpiodetect tool. Signed-off-by: Bartosz Golaszewski --- tests/Makefile.am | 6 ++++++ tests/tests-gpiodetect.c | 46 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 tests/tests-gpiodetect.c diff --git a/tests/Makefile.am b/tests/Makefile.am index d327bc3..a07bce6 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 0000000..747fead --- /dev/null +++ b/tests/tests-gpiodetect.c @@ -0,0 +1,46 @@ +/* + * Test cases for the gpiodetect tool. + * + * Copyright (C) 2017 Bartosz Golaszewski + * + * 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 + +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 }); -- 2.30.2