From: Bartosz Golaszewski Date: Wed, 22 Feb 2017 09:57:23 +0000 (+0100) Subject: tests: add a couple line test cases X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=bef994b3353ab44c493e5c369a2ee015016d22fd;p=qemu-gpiodev%2Flibgpiod.git tests: add a couple line test cases Add first test cases for GPIO lines. Signed-off-by: Bartosz Golaszewski --- diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am index 260b22e..3e216cc 100644 --- a/tests/unit/Makefile.am +++ b/tests/unit/Makefile.am @@ -13,4 +13,4 @@ DEPENDENCIES = libgpiod.la check_PROGRAMS = gpiod-unit -gpiod_unit_SOURCES = gpiod-unit.c tests-chip.c tests-iter.c +gpiod_unit_SOURCES = gpiod-unit.c tests-chip.c tests-iter.c tests-line.c diff --git a/tests/unit/tests-line.c b/tests/unit/tests-line.c new file mode 100644 index 0000000..ef0db62 --- /dev/null +++ b/tests/unit/tests-line.c @@ -0,0 +1,62 @@ +/* + * GPIO line test cases for libgpiod. + * + * 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-unit.h" + +static void line_request_output(void) +{ + GU_CLEANUP(gu_release_line) struct gpiod_line *line_0 = NULL; + GU_CLEANUP(gu_release_line) struct gpiod_line *line_1 = NULL; + GU_CLEANUP(gu_close_chip) struct gpiod_chip *chip = NULL; + int status; + + chip = gpiod_chip_open(gu_chip_path(0)); + GU_ASSERT_NOT_NULL(chip); + + line_0 = gpiod_chip_get_line(chip, 2); + line_1 = gpiod_chip_get_line(chip, 5); + GU_ASSERT_NOT_NULL(line_0); + GU_ASSERT_NOT_NULL(line_1); + + status = gpiod_line_request_output(line_0, "gpiod-unit", false, 0); + GU_ASSERT_RET_OK(status); + status = gpiod_line_request_output(line_1, "gpiod-unit", false, 1); + GU_ASSERT_RET_OK(status); + + GU_ASSERT_EQ(gpiod_line_get_value(line_0), 0); + GU_ASSERT_EQ(gpiod_line_get_value(line_1), 1); +} +GU_DEFINE_TEST(line_request_output, + "line_request_output()", + GU_LINES_UNNAMED, { 8 }); + +static void line_set_value(void) +{ + GU_CLEANUP(gu_release_line) struct gpiod_line *line = NULL; + GU_CLEANUP(gu_close_chip) struct gpiod_chip *chip = NULL; + int status; + + chip = gpiod_chip_open(gu_chip_path(0)); + GU_ASSERT_NOT_NULL(chip); + + line = gpiod_chip_get_line(chip, 2); + GU_ASSERT_NOT_NULL(line); + + status = gpiod_line_request_output(line, "gpiod-unit", false, 0); + GU_ASSERT_RET_OK(status); + + GU_ASSERT_RET_OK(gpiod_line_set_value(line, 1)); + GU_ASSERT_EQ(gpiod_line_get_value(line), 1); + GU_ASSERT_RET_OK(gpiod_line_set_value(line, 0)); + GU_ASSERT_EQ(gpiod_line_get_value(line), 0); +} +GU_DEFINE_TEST(line_set_value, + "line_set_value()", + GU_LINES_UNNAMED, { 8 });