aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>2023-09-19 11:31:41 +0200
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>2023-09-25 09:00:11 +0200
commitb91187b7cdaab1789695c668432907b3381e6ea5 (patch)
tree5367a95efac4e78bd12411323970659173a6f0ba
parentec76ea717bc2aa4f083c22928c76cbfe0bc38e83 (diff)
downloadlibgpiod-b91187b7cdaab1789695c668432907b3381e6ea5.tar.gz
bindings: cxx: tests: don't use the same chip from different threads
There are no thread-safety guarantees in libgpiod. Let's not reuse the chip object created in one thread to generate info events in another but create a second chip for that purpose instead. Reported-by: Erik Schilling <erik.schilling@linaro.org> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Reviewed-by: Erik Schilling <erik.schilling@linaro.org>
-rw-r--r--bindings/cxx/tests/tests-info-event.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/bindings/cxx/tests/tests-info-event.cpp b/bindings/cxx/tests/tests-info-event.cpp
index 249b1e81..21c0ef00 100644
--- a/bindings/cxx/tests/tests-info-event.cpp
+++ b/bindings/cxx/tests/tests-info-event.cpp
@@ -3,6 +3,7 @@
#include <catch2/catch.hpp>
#include <chrono>
+#include <filesystem>
#include <gpiod.hpp>
#include <sstream>
#include <thread>
@@ -17,11 +18,11 @@ using event_type = ::gpiod::info_event::event_type;
namespace {
-void request_reconfigure_release_line(::gpiod::chip& chip)
+void request_reconfigure_release_line(const ::std::filesystem::path& chip_path)
{
::std::this_thread::sleep_for(::std::chrono::milliseconds(10));
- auto request = chip
+ auto request = ::gpiod::chip(chip_path)
.prepare_request()
.add_line_settings(7, ::gpiod::line_settings())
.do_request();
@@ -48,7 +49,9 @@ TEST_CASE("Lines can be watched", "[info-event][chip]")
.set_num_lines(8)
.build();
- ::gpiod::chip chip(sim.dev_path());
+ const auto chip_path = sim.dev_path();
+
+ ::gpiod::chip chip(chip_path);
SECTION("watch_line_info() returns line info")
{
@@ -74,7 +77,7 @@ TEST_CASE("Lines can be watched", "[info-event][chip]")
REQUIRE(info.direction() == direction::INPUT);
- ::std::thread thread(request_reconfigure_release_line, ::std::ref(chip));
+ ::std::thread thread(request_reconfigure_release_line, ::std::ref(chip_path));
REQUIRE(chip.wait_info_event(::std::chrono::seconds(1)));
auto event = chip.read_info_event();