diff mbox series

[1/3] bindings: cxx: tests: add tests for bulk events get_values

Message ID 20200617030639.27690-2-warthog618@gmail.com
State New
Headers show
Series [1/3] bindings: cxx: tests: add tests for bulk events get_values | expand

Commit Message

Kent Gibson June 17, 2020, 3:06 a.m. UTC
Add tests to verify the behaviour of get_values when applied to a bulk
of event lines.

Reported-by: Gerrit Wyen <ml@ionscale.com>
Signed-off-by: Kent Gibson <warthog618@gmail.com>

---

The reported behaviour is that only the first line value is returned correctly.
The tests verify that behaviour in v1.5.

 bindings/cxx/tests/tests-event.cpp | 36 +++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/bindings/cxx/tests/tests-event.cpp b/bindings/cxx/tests/tests-event.cpp
index 63b6cc5..6d1c069 100644
--- a/bindings/cxx/tests/tests-event.cpp
+++ b/bindings/cxx/tests/tests-event.cpp
@@ -193,7 +193,7 @@  TEST_CASE("Event file descriptors can be used for polling", "[event]")
 	}
 }
 
-TEST_CASE("It's possible to read values from lines requested for events", "[event][line]")
+TEST_CASE("It's possible to read a value from a line requested for events", "[event][line]")
 {
 	mockup::probe_guard mockup_chips({ 8 });
 	::gpiod::chip chip(mockup::instance().chip_name(0));
@@ -219,6 +219,40 @@  TEST_CASE("It's possible to read values from lines requested for events", "[even
 	}
 }
 
+TEST_CASE("It's possible to read values from lines requested for events", "[event][bulk]")
+{
+	mockup::probe_guard mockup_chips({ 8 });
+	::gpiod::chip chip(mockup::instance().chip_name(0));
+	auto lines = chip.get_lines({ 0, 1, 2, 3, 4 });
+	::gpiod::line_request config;
+
+	config.consumer = consumer.c_str();
+	config.request_type = ::gpiod::line_request::EVENT_BOTH_EDGES;
+
+	mockup::instance().chip_set_pull(0, 5, 1);
+
+	SECTION("active-high (default)")
+	{
+		lines.request(config);
+		REQUIRE(lines.get_values() == ::std::vector<int>({ 0, 0, 0, 0, 0 }));
+		mockup::instance().chip_set_pull(0, 1, 1);
+		mockup::instance().chip_set_pull(0, 3, 1);
+		mockup::instance().chip_set_pull(0, 4, 1);
+		REQUIRE(lines.get_values() == ::std::vector<int>({ 0, 1, 0, 1, 1 }));
+	}
+
+	SECTION("active-low")
+	{
+		config.flags = ::gpiod::line_request::FLAG_ACTIVE_LOW;
+		lines.request(config);
+		REQUIRE(lines.get_values() == ::std::vector<int>({ 1, 1, 1, 1, 1 }));
+		mockup::instance().chip_set_pull(0, 1, 1);
+		mockup::instance().chip_set_pull(0, 3, 1);
+		mockup::instance().chip_set_pull(0, 4, 1);
+		REQUIRE(lines.get_values() == ::std::vector<int>({ 1, 0, 1, 0, 0 }));
+	}
+}
+
 TEST_CASE("It's possible to read more than one line event", "[event][line]")
 {
 	mockup::probe_guard mockup_chips({ 8 });