From: Bartosz Golaszewski Date: Tue, 19 Sep 2023 09:31:41 +0000 (+0200) Subject: bindings: cxx: tests: don't use the same chip from different threads X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=b91187b7cdaab1789695c668432907b3381e6ea5;p=qemu-gpiodev%2Flibgpiod.git 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 Signed-off-by: Bartosz Golaszewski Reviewed-by: Erik Schilling --- diff --git a/bindings/cxx/tests/tests-info-event.cpp b/bindings/cxx/tests/tests-info-event.cpp index 249b1e8..21c0ef0 100644 --- a/bindings/cxx/tests/tests-info-event.cpp +++ b/bindings/cxx/tests/tests-info-event.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -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();