bindings: cxx: tests: add tests for bias flags
authorKent Gibson <warthog618@gmail.com>
Sun, 1 Dec 2019 03:23:51 +0000 (11:23 +0800)
committerBartosz Golaszewski <bgolaszewski@baylibre.com>
Mon, 9 Dec 2019 16:47:04 +0000 (17:47 +0100)
Extend test coverage over the bias flags in requests and the bias setting
returned by line.bias().

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
bindings/cxx/tests/gpiod-cxx-test.cpp
bindings/cxx/tests/tests-line.cpp

index 11c895ed2bbdb7211e593836e65211c785a26979..fbff8acd26e7a0584632bac1e87c9ef20282f424 100644 (file)
@@ -54,6 +54,6 @@ public:
        kernel_checker& operator=(kernel_checker&& other) = delete;
 };
 
-kernel_checker require_kernel(5, 2, 11);
+kernel_checker require_kernel(5, 5, 0);
 
 } /* namespace */
index fedaa05bcf56eb3477e653fd62b431d396f7b8bc..9a0b4885db6b19aeee99c761c52d42ec827ce6b3 100644 (file)
@@ -52,6 +52,9 @@ TEST_CASE("Line information can be correctly retrieved", "[line]")
                REQUIRE(line.consumer().empty());
                REQUIRE_FALSE(line.is_requested());
                REQUIRE_FALSE(line.is_used());
+               REQUIRE_FALSE(line.is_open_drain());
+               REQUIRE_FALSE(line.is_open_source());
+               REQUIRE(line.bias() == ::gpiod::line::BIAS_AS_IS);
        }
 
        SECTION("exported line")
@@ -68,6 +71,9 @@ TEST_CASE("Line information can be correctly retrieved", "[line]")
                REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_HIGH);
                REQUIRE(line.is_requested());
                REQUIRE(line.is_used());
+               REQUIRE_FALSE(line.is_open_drain());
+               REQUIRE_FALSE(line.is_open_source());
+               REQUIRE(line.bias() == ::gpiod::line::BIAS_AS_IS);
        }
 
        SECTION("exported line with flags")
@@ -88,6 +94,87 @@ TEST_CASE("Line information can be correctly retrieved", "[line]")
                REQUIRE(line.is_used());
                REQUIRE(line.is_open_drain());
                REQUIRE_FALSE(line.is_open_source());
+               REQUIRE(line.bias() == ::gpiod::line::BIAS_AS_IS);
+       }
+
+       SECTION("exported open source line")
+       {
+               ::gpiod::line_request config;
+
+               config.consumer = consumer.c_str();
+               config.request_type = ::gpiod::line_request::DIRECTION_OUTPUT;
+               config.flags = ::gpiod::line_request::FLAG_OPEN_SOURCE;
+               line.request(config);
+
+               REQUIRE(line.offset() == 4);
+               REQUIRE(line.name() == "gpio-mockup-A-4");
+               REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT);
+               REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_HIGH);
+               REQUIRE(line.is_requested());
+               REQUIRE(line.is_used());
+               REQUIRE_FALSE(line.is_open_drain());
+               REQUIRE(line.is_open_source());
+               REQUIRE(line.bias() == ::gpiod::line::BIAS_AS_IS);
+       }
+
+       SECTION("exported bias disable line")
+       {
+               ::gpiod::line_request config;
+
+               config.consumer = consumer.c_str();
+               config.request_type = ::gpiod::line_request::DIRECTION_OUTPUT;
+               config.flags = ::gpiod::line_request::FLAG_BIAS_DISABLE;
+               line.request(config);
+
+               REQUIRE(line.offset() == 4);
+               REQUIRE(line.name() == "gpio-mockup-A-4");
+               REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT);
+               REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_HIGH);
+               REQUIRE(line.is_requested());
+               REQUIRE(line.is_used());
+               REQUIRE_FALSE(line.is_open_drain());
+               REQUIRE_FALSE(line.is_open_source());
+               REQUIRE(line.bias() == ::gpiod::line::BIAS_DISABLE);
+       }
+
+       SECTION("exported pull-down line")
+       {
+               ::gpiod::line_request config;
+
+               config.consumer = consumer.c_str();
+               config.request_type = ::gpiod::line_request::DIRECTION_OUTPUT;
+               config.flags = ::gpiod::line_request::FLAG_BIAS_PULL_DOWN;
+               line.request(config);
+
+               REQUIRE(line.offset() == 4);
+               REQUIRE(line.name() == "gpio-mockup-A-4");
+               REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT);
+               REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_HIGH);
+               REQUIRE(line.is_requested());
+               REQUIRE(line.is_used());
+               REQUIRE_FALSE(line.is_open_drain());
+               REQUIRE_FALSE(line.is_open_source());
+               REQUIRE(line.bias() == ::gpiod::line::BIAS_PULL_DOWN);
+       }
+
+       SECTION("exported pull-up line")
+       {
+               ::gpiod::line_request config;
+
+               config.consumer = consumer.c_str();
+               config.request_type = ::gpiod::line_request::DIRECTION_OUTPUT;
+               config.flags = ::gpiod::line_request::FLAG_BIAS_PULL_UP;
+               line.request(config);
+
+               REQUIRE(line.offset() == 4);
+               REQUIRE(line.name() == "gpio-mockup-A-4");
+               REQUIRE(line.direction() == ::gpiod::line::DIRECTION_OUTPUT);
+               REQUIRE(line.active_state() == ::gpiod::line::ACTIVE_HIGH);
+               REQUIRE(line.is_requested());
+               REQUIRE(line.is_used());
+               REQUIRE_FALSE(line.is_open_drain());
+               REQUIRE_FALSE(line.is_open_source());
+               REQUIRE(line.bias() == ::gpiod::line::BIAS_PULL_UP);
        }
 
        SECTION("update line info")