bindings: cxx: Use 'upstream' include path
PATCH 4/5 bindings: cxx: Fix compile errors
In reply to Alexander SteinThis fixes the following compile errors:
tests-event.cpp:152:3: error: cannot declare reference to 'class std::system_error&', which is not a typedef or a template type argument
152 | REQUIRE_THROWS_AS(line.event_get_fd(), ::std::system_error&);
--- bindings/cxx/tests/tests-chip.cpp | 8 ++++---- bindings/cxx/tests/tests-event.cpp | 4 ++-- bindings/cxx/tests/tests-line.cpp | 16 ++++++++-------- 3 files changed, 14 insertions(+), 14 deletions(-)
bindings/cxx/tests/tests-chip.cpp +4 -4
@@ -107,7 +107,7 @@ TEST_CASE("Uninitialized GPIO chip behaves correctly", "[chip]") SECTION("using uninitialized chip throws logic_error") { - REQUIRE_THROWS_AS(chip.name(), ::std::logic_error&); + REQUIRE_THROWS_AS(chip.name(), ::std::logic_error); } }
@@ -139,7 +139,7 @@ TEST_CASE("GPIO chip can be opened with the open() method with implicit lookup", TEST_CASE("Trying to open a nonexistent chip throws system_error", "[chip]") { - REQUIRE_THROWS_AS(::gpiod::chip("nonexistent-chip"), ::std::system_error&); + REQUIRE_THROWS_AS(::gpiod::chip("nonexistent-chip"), ::std::system_error); } TEST_CASE("Chip object can be reset", "[chip]")
@@ -244,12 +244,12 @@ TEST_CASE("Errors occurring when retrieving lines are correctly reported", "[chi SECTION("invalid offset (single line)") { - REQUIRE_THROWS_AS(chip.get_line(9), ::std::out_of_range&); + REQUIRE_THROWS_AS(chip.get_line(9), ::std::out_of_range); } SECTION("invalid offset (multiple lines)") { - REQUIRE_THROWS_AS(chip.get_lines({ 1, 19, 4, 7 }), ::std::out_of_range&); + REQUIRE_THROWS_AS(chip.get_lines({ 1, 19, 4, 7 }), ::std::out_of_range); } SECTION("line not found by name")
bindings/cxx/tests/tests-event.cpp +2 -2
@@ -149,7 +149,7 @@ TEST_CASE("It's possible to retrieve the event file descriptor", "[event][line]" SECTION("error if not requested") { - REQUIRE_THROWS_AS(line.event_get_fd(), ::std::system_error&); + REQUIRE_THROWS_AS(line.event_get_fd(), ::std::system_error); } SECTION("error if requested for values")
@@ -157,7 +157,7 @@ TEST_CASE("It's possible to retrieve the event file descriptor", "[event][line]" config.request_type = ::gpiod::line_request::DIRECTION_INPUT; line.request(config); - REQUIRE_THROWS_AS(line.event_get_fd(), ::std::system_error&); + REQUIRE_THROWS_AS(line.event_get_fd(), ::std::system_error); } }
bindings/cxx/tests/tests-line.cpp +8 -8
@@ -122,7 +122,7 @@ TEST_CASE("Line bulk object works correctly", "[line][bulk]") { auto lines = chip.get_all_lines(); - REQUIRE_THROWS_AS(lines.get(11), ::std::out_of_range&); + REQUIRE_THROWS_AS(lines.get(11), ::std::out_of_range); } }
@@ -242,7 +242,7 @@ TEST_CASE("Exported line can be released", "[line]") line.release(); REQUIRE_FALSE(line.is_requested()); - REQUIRE_THROWS_AS(line.get_value(), ::std::system_error&); + REQUIRE_THROWS_AS(line.get_value(), ::std::system_error); } TEST_CASE("Uninitialized GPIO line behaves correctly", "[line]")
@@ -256,7 +256,7 @@ TEST_CASE("Uninitialized GPIO line behaves correctly", "[line]") SECTION("using uninitialized line throws logic_error") { - REQUIRE_THROWS_AS(line.name(), ::std::logic_error&); + REQUIRE_THROWS_AS(line.name(), ::std::logic_error); } }
@@ -271,7 +271,7 @@ TEST_CASE("Uninitialized GPIO line_bulk behaves correctly", "[line][bulk]") SECTION("using uninitialized line_bulk throws logic_error") { - REQUIRE_THROWS_AS(bulk.get(0), ::std::logic_error&); + REQUIRE_THROWS_AS(bulk.get(0), ::std::logic_error); } }
@@ -289,7 +289,7 @@ TEST_CASE("Cannot request the same line twice", "[line]") auto line = chip.get_line(3); REQUIRE_NOTHROW(line.request(config)); - REQUIRE_THROWS_AS(line.request(config), ::std::system_error&); + REQUIRE_THROWS_AS(line.request(config), ::std::system_error); } SECTION("request the same line twice in line_bulk")
@@ -300,7 +300,7 @@ TEST_CASE("Cannot request the same line twice", "[line]") */ auto lines = chip.get_lines({ 2, 3, 4, 4 }); - REQUIRE_THROWS_AS(lines.request(config), ::std::system_error&); + REQUIRE_THROWS_AS(lines.request(config), ::std::system_error); } }
@@ -312,12 +312,12 @@ TEST_CASE("Cannot get/set values of unrequested lines", "[line]") SECTION("get value") { - REQUIRE_THROWS_AS(line.get_value(), ::std::system_error&); + REQUIRE_THROWS_AS(line.get_value(), ::std::system_error); } SECTION("set value") { - REQUIRE_THROWS_AS(line.set_value(1), ::std::system_error&); + REQUIRE_THROWS_AS(line.set_value(1), ::std::system_error); } }
Signature · 1 line
2.22.0
PATCH 3/5 bindings: cxx: Split out catch's main()
In reply to Alexander SteinCompiling the source using CATCH_CONFIG_MAIN to provide main() takes several seconds, so split it out from any library testing code, so it really needs to be built once only.
--- bindings/cxx/tests/Makefile.am | 3 ++- bindings/cxx/tests/gpiod-cxx-test-main.cpp | 2 ++ bindings/cxx/tests/gpiod-cxx-test.cpp | 2 -- 3 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 bindings/cxx/tests/gpiod-cxx-test-main.cpp
bindings/cxx/tests/Makefile.am +2 -1
@@ -15,7 +15,8 @@ AM_LDFLAGS += -pthread bin_PROGRAMS = gpiod-cxx-test -gpiod_cxx_test_SOURCES = gpiod-cxx-test.cpp \ +gpiod_cxx_test_SOURCES = gpiod-cxx-test-main.cpp \ + gpiod-cxx-test.cpp \ gpio-mockup.cpp \ gpio-mockup.hpp \ tests-chip.cpp \
bindings/cxx/tests/gpiod-cxx-test-main.cpp new file +2 -0
@@ -0,0 +1,2 @@ +#define CATCH_CONFIG_MAIN +#include <catch2/catch.hpp>
bindings/cxx/tests/gpiod-cxx-test.cpp +0 -2
@@ -5,8 +5,6 @@ * Copyright (C) 2019 Bartosz Golaszewski <[email protected]> */ -#define CATCH_CONFIG_MAIN -#include <catch2/catch.hpp> #include <linux/version.h> #include <sys/utsname.h> #include <system_error>
Signature · 1 line
2.22.0
PATCH 5/5 bindings: cxx: Workaround --success run
In reply to Alexander SteinIf run with --success, all expressions are evaluated and printed out. But REQUIRE_FALSE(chip) tries to iterate over the chip resulting in this backtrace:
#0 gpiod_chip_num_lines (chip=chip@entry=0x0) at ../../lib/core.c:235 #1 gpiod_line_iter_new (chip=0x0) at ../../lib/iter.c:140 #2 gpiod::(anonymous namespace)::make_line_iter (chip=0x0) at ../../../bindings/cxx/iter.cpp:29 #3 gpiod::line_iter::line_iter (this=0x7fffffffd690, owner=...) at ../../../bindings/cxx/iter.cpp:109 #4 Catch::rangeToString<gpiod::chip> (range=...) at /usr/include/catch2/catch.hpp:1959
[...]
Workaround by forcing catch2 to call gpiod::chip::operator bool().
---
This actually looks like a flaw in the binding itself that the gpiod::line_iter can't cope with an empty gpiod::chip.
bindings/cxx/tests/tests-chip.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
bindings/cxx/tests/tests-chip.cpp +3 -3
@@ -70,7 +70,7 @@ TEST_CASE("GPIO chip can be opened with the open() method in different modes", " mockup::probe_guard mockup_chips({ 8, 8, 8 }); ::gpiod::chip chip; - REQUIRE_FALSE(chip); + REQUIRE_FALSE(!!chip); SECTION("open by name") {
@@ -102,7 +102,7 @@ TEST_CASE("Uninitialized GPIO chip behaves correctly", "[chip]") SECTION("uninitialized chip is 'false'") { - REQUIRE_FALSE(chip); + REQUIRE_FALSE(!!chip); } SECTION("using uninitialized chip throws logic_error")
@@ -149,7 +149,7 @@ TEST_CASE("Chip object can be reset", "[chip]") ::gpiod::chip chip(mockup::instance().chip_name(0)); REQUIRE(chip); chip.reset(); - REQUIRE_FALSE(chip); + REQUIRE_FALSE(!!chip); } TEST_CASE("Chip info can be correctly retrieved", "[chip]")
Signature · 1 line
2.22.0
PATCH 2/5 bindings: cxx: Try using pkg-config to detect catch2
In reply to Alexander SteinIf there is no system wide package, try using a regular header as before.
--- bindings/cxx/tests/Makefile.am | 2 +- configure.ac | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-)
bindings/cxx/tests/Makefile.am +1 -1
@@ -8,7 +8,7 @@ AM_CPPFLAGS = -I$(top_srcdir)/bindings/cxx/ -I$(top_srcdir)/include AM_CPPFLAGS += -I$(top_srcdir)/tests/mockup/ -AM_CPPFLAGS += -Wall -Wextra -g -std=gnu++11 +AM_CPPFLAGS += -Wall -Wextra -g -std=gnu++11 $(CATCH2_CFLAGS) AM_LDFLAGS = -lgpiodcxx -L$(top_builddir)/bindings/cxx/ AM_LDFLAGS += -lgpiomockup -L$(top_builddir)/tests/mockup/ AM_LDFLAGS += -pthread
configure.ac +5 -3
@@ -164,9 +164,11 @@ then if test "x$with_tests" = xtrue then - AC_LANG_PUSH([C++]) - AC_CHECK_HEADERS([catch2/catch.hpp], [], [HEADER_NOT_FOUND_CXX([catch2/catch.hpp])]) - AC_LANG_POP([C++]) + PKG_CHECK_MODULES([CATCH2], [catch2],, [ + AC_LANG_PUSH([C++]) + AC_CHECK_HEADERS([catch2/catch.hpp], [], [HEADER_NOT_FOUND_CXX([catch2/catch.hpp])]) + AC_LANG_POP([C++]) + ]) fi fi
Signature · 1 line
2.22.0
PATCH 1/5 bindings: cxx: Use 'upstream' include path
According to https://github.com/catchorg/Catch2/issues/1202 the regular include is 'catch2/catch.hpp'
Also CMake and pkg-config provide include paths for this include name.
--- bindings/cxx/tests/gpiod-cxx-test.cpp | 2 +- bindings/cxx/tests/tests-chip.cpp | 2 +- bindings/cxx/tests/tests-event.cpp | 2 +- bindings/cxx/tests/tests-iter.cpp | 2 +- bindings/cxx/tests/tests-line.cpp | 2 +- configure.ac | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-)
bindings/cxx/tests/gpiod-cxx-test.cpp +1 -1
@@ -6,7 +6,7 @@ */ #define CATCH_CONFIG_MAIN -#include <catch.hpp> +#include <catch2/catch.hpp> #include <linux/version.h> #include <sys/utsname.h> #include <system_error>
bindings/cxx/tests/tests-chip.cpp +1 -1
@@ -5,7 +5,7 @@ * Copyright (C) 2019 Bartosz Golaszewski <[email protected]> */ -#include <catch.hpp> +#include <catch2/catch.hpp> #include <gpiod.hpp> #include "gpio-mockup.hpp"
bindings/cxx/tests/tests-event.cpp +1 -1
@@ -5,7 +5,7 @@ * Copyright (C) 2019 Bartosz Golaszewski <[email protected]> */ -#include <catch.hpp> +#include <catch2/catch.hpp> #include <gpiod.hpp> #include <map> #include <poll.h>
bindings/cxx/tests/tests-iter.cpp +1 -1
@@ -5,7 +5,7 @@ * Copyright (C) 2019 Bartosz Golaszewski <[email protected]> */ -#include <catch.hpp> +#include <catch2/catch.hpp> #include <gpiod.hpp> #include "gpio-mockup.hpp"
bindings/cxx/tests/tests-line.cpp +1 -1
@@ -5,7 +5,7 @@ * Copyright (C) 2019 Bartosz Golaszewski <[email protected]> */ -#include <catch.hpp> +#include <catch2/catch.hpp> #include <gpiod.hpp> #include "gpio-mockup.hpp"
configure.ac +1 -1
@@ -165,7 +165,7 @@ then if test "x$with_tests" = xtrue then AC_LANG_PUSH([C++]) - AC_CHECK_HEADERS([catch.hpp], [], [HEADER_NOT_FOUND_CXX([catch.hpp])]) + AC_CHECK_HEADERS([catch2/catch.hpp], [], [HEADER_NOT_FOUND_CXX([catch2/catch.hpp])]) AC_LANG_POP([C++]) fi fi
Signature · 1 line
2.22.0
Re: [libgpiod] [PATCH 4/5] bindings: cxx: Fix compile errors
In reply to Alexander Steinśr., 7 sie 2019 o 21:51 Alexander Stein <[email protected]> napisał(a):
Quoted 7 lines
This fixes the following compile errors:
tests-event.cpp:152:3: error: cannot declare reference to 'class std::system_error&', which is not a typedef or a template type argument
152 |REQUIRE_THROWS_AS(line.event_get_fd(), ::std::system_error&);
Hi Alexander, thanks for working on this!
I'm getting the following warning when I don't use the reference:
In file included from tests-line.cpp:8:
tests-line.cpp: In function ‘void ____C_A_T_C_H____T_E_S_T____24()’:
tests-line.cpp:254:45: warning: catching polymorphic type ‘class std::system_error’ by value [-Wcatch-value=]
REQUIRE_THROWS_AS(line.get_value(), ::std::system_error);
^~~~~~~~~~~~I'm also not getting any build errors with my current next or master branch. My gcc is:
gcc (Debian 8.3.0-6) 8.3.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Bart
Quoted 142 lines
Signed-off-by Alexander Stein <[email protected]>--- bindings/cxx/tests/tests-chip.cpp | 8 ++++---- bindings/cxx/tests/tests-event.cpp | 4 ++-- bindings/cxx/tests/tests-line.cpp | 16 ++++++++-------- 3 files changed, 14 insertions(+), 14 deletions(-)bindings/cxx/tests/tests-chip.cpp +4
-4@@ -107,7 +107,7 @@ TEST_CASE("Uninitialized GPIO chip behaves correctly", "[chip]") SECTION("using uninitialized chip throws logic_error") { - REQUIRE_THROWS_AS(chip.name(), ::std::logic_error&); + REQUIRE_THROWS_AS(chip.name(), ::std::logic_error); } }@@ -139,7 +139,7 @@ TEST_CASE("GPIO chip can be opened with the open() method with implicit lookup", TEST_CASE("Trying to open a nonexistent chip throws system_error", "[chip]") { - REQUIRE_THROWS_AS(::gpiod::chip("nonexistent-chip"), ::std::system_error&); + REQUIRE_THROWS_AS(::gpiod::chip("nonexistent-chip"), ::std::system_error); } TEST_CASE("Chip object can be reset", "[chip]")@@ -244,12 +244,12 @@ TEST_CASE("Errors occurring when retrieving lines are correctly reported", "[chi SECTION("invalid offset (single line)") { - REQUIRE_THROWS_AS(chip.get_line(9), ::std::out_of_range&); + REQUIRE_THROWS_AS(chip.get_line(9), ::std::out_of_range); } SECTION("invalid offset (multiple lines)") { - REQUIRE_THROWS_AS(chip.get_lines({ 1, 19, 4, 7 }), ::std::out_of_range&); + REQUIRE_THROWS_AS(chip.get_lines({ 1, 19, 4, 7 }), ::std::out_of_range); } SECTION("line not found by name")bindings/cxx/tests/tests-event.cpp +2
-2@@ -149,7 +149,7 @@ TEST_CASE("It's possible to retrieve the event file descriptor", "[event][line]" SECTION("error if not requested") { - REQUIRE_THROWS_AS(line.event_get_fd(), ::std::system_error&); + REQUIRE_THROWS_AS(line.event_get_fd(), ::std::system_error); } SECTION("error if requested for values")@@ -157,7 +157,7 @@ TEST_CASE("It's possible to retrieve the event file descriptor", "[event][line]" config.request_type = ::gpiod::line_request::DIRECTION_INPUT; line.request(config); - REQUIRE_THROWS_AS(line.event_get_fd(), ::std::system_error&); + REQUIRE_THROWS_AS(line.event_get_fd(), ::std::system_error); } }bindings/cxx/tests/tests-line.cpp +8
-9@@ -122,7 +122,7 @@ TEST_CASE("Line bulk object works correctly", "[line][bulk]") { auto lines = chip.get_all_lines(); - REQUIRE_THROWS_AS(lines.get(11), ::std::out_of_range&); + REQUIRE_THROWS_AS(lines.get(11), ::std::out_of_range); } }@@ -242,7 +242,7 @@ TEST_CASE("Exported line can be released", "[line]") line.release(); REQUIRE_FALSE(line.is_requested()); - REQUIRE_THROWS_AS(line.get_value(), ::std::system_error&); + REQUIRE_THROWS_AS(line.get_value(), ::std::system_error); } TEST_CASE("Uninitialized GPIO line behaves correctly", "[line]")@@ -256,7 +256,7 @@ TEST_CASE("Uninitialized GPIO line behaves correctly", "[line]") SECTION("using uninitialized line throws logic_error") { - REQUIRE_THROWS_AS(line.name(), ::std::logic_error&); + REQUIRE_THROWS_AS(line.name(), ::std::logic_error); } }@@ -271,7 +271,7 @@ TEST_CASE("Uninitialized GPIO line_bulk behaves correctly", "[line][bulk]") SECTION("using uninitialized line_bulk throws logic_error") { - REQUIRE_THROWS_AS(bulk.get(0), ::std::logic_error&); + REQUIRE_THROWS_AS(bulk.get(0), ::std::logic_error); } }@@ -289,7 +289,7 @@ TEST_CASE("Cannot request the same line twice", "[line]") auto line = chip.get_line(3); REQUIRE_NOTHROW(line.request(config)); - REQUIRE_THROWS_AS(line.request(config), ::std::system_error&); + REQUIRE_THROWS_AS(line.request(config), ::std::system_error); } SECTION("request the same line twice in line_bulk")@@ -300,7 +300,7 @@ TEST_CASE("Cannot request the same line twice", "[line]") */ auto lines = chip.get_lines({ 2, 3, 4, 4 }); - REQUIRE_THROWS_AS(lines.request(config), ::std::system_error&); + REQUIRE_THROWS_AS(lines.request(config), ::std::system_error); } }@@ -312,12 +312,12 @@ TEST_CASE("Cannot get/set values of unrequested lines", "[line]") SECTION("get value") { - REQUIRE_THROWS_AS(line.get_value(), ::std::system_error&); + REQUIRE_THROWS_AS(line.get_value(), ::std::system_error); } SECTION("set value") { - REQUIRE_THROWS_AS(line.set_value(1), ::std::system_error&); + REQUIRE_THROWS_AS(line.set_value(1), ::std::system_error); } } --2.22.0
Re: [libgpiod] [PATCH 5/5] bindings: cxx: Workaround --success run
In reply to Alexander Steinśr., 7 sie 2019 o 21:51 Alexander Stein <[email protected]> napisał(a):
Quoted 9 lines
If run with --success, all expressions are evaluated and printed out. But
REQUIRE_FALSE(chip)tries to iterate over the chip resulting in this backtrace:#0 gpiod_chip_num_lines (chip=chip@entry=0x0) at ../../lib/core.c:235 #1 gpiod_line_iter_new (chip=0x0) at ../../lib/iter.c:140 #2 gpiod::(anonymous namespace)::make_line_iter (chip=0x0) at ../../../bindings/cxx/iter.cpp:29 #3 gpiod::line_iter::line_iter (this=0x7fffffffd690, owner=...) at ../../../bindings/cxx/iter.cpp:109 #4 Catch::rangeToString<gpiod::chip> (range=...) at /usr/include/catch2/catch.hpp:1959
Quoted 9 lines
[...]
Workaround by forcing catch2 to call
gpiod::chip::operatorbool().Signed-off-by Alexander Stein <[email protected]>---
This actually looks like a flaw in the binding itself that thegpiod::line_itercan't cope with an emptygpiod::chip.
Do you want to submit a patch that fixes that? Otherwise I can fix it. I think that simply throwing an exception on empty chip is enough, right?
Bart
Quoted 37 lines
bindings/cxx/tests/tests-chip.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)bindings/cxx/tests/tests-chip.cpp +3
-4@@ -70,7 +70,7 @@ TEST_CASE("GPIO chip can be opened with the open() method in different modes", " mockup::probe_guard mockup_chips({ 8, 8, 8 }); ::gpiod::chip chip; - REQUIRE_FALSE(chip); + REQUIRE_FALSE(!!chip); SECTION("open by name") {@@ -102,7 +102,7 @@ TEST_CASE("Uninitialized GPIO chip behaves correctly", "[chip]") SECTION("uninitialized chip is 'false'") { - REQUIRE_FALSE(chip); + REQUIRE_FALSE(!!chip); } SECTION("using uninitialized chip throws logic_error")@@ -149,7 +149,7 @@ TEST_CASE("Chip object can be reset", "[chip]") ::gpiod::chip chip(mockup::instance().chip_name(0)); REQUIRE(chip); chip.reset(); - REQUIRE_FALSE(chip); + REQUIRE_FALSE(!!chip); } TEST_CASE("Chip info can be correctly retrieved", "[chip]") --2.22.0
Re: [libgpiod] [PATCH 4/5] bindings: cxx: Fix compile errors
In reply to Bartosz Golaszewskiczw., 8 sie 2019 o 17:25 Bartosz Golaszewski <[email protected]> napisał(a):
Quoted 24 lines
śr., 7 sie 2019 o 21:51 Alexander Stein <[email protected]> napisał(a):
Quoted 7 lines
This fixes the following compile errors:
tests-event.cpp:152:3: error: cannot declare reference to 'class std::system_error&', which is not a typedef or a template type argument
152 |REQUIRE_THROWS_AS(line.event_get_fd(), ::std::system_error&);Hi Alexander, thanks for working on this!
I'm getting the following warning when I don't use the reference:
In file included from tests-line.cpp:8:
tests-line.cpp: In function ‘void ____C_A_T_C_H____T_E_S_T____24()’:
tests-line.cpp:254:45: warning: catching polymorphic type ‘class std::system_error’ by value [-Wcatch-value=]REQUIRE_THROWS_AS(line.get_value(), ::std::system_error); ^~~~~~~~~~~~I'm also not getting any build errors with my current next or master branch. My gcc is:
Quoted 6 lines
gcc (Debian 8.3.0-6) 8.3.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.Bart
Nevermind that - I was using Debian's packaged version which happens to be quite old. The current version actually does fail to build. I'll test and pick up your patches tomorrow.
Bart
Quoted 143 lines
Quoted 143 lines
Signed-off-by Alexander Stein <[email protected]>--- bindings/cxx/tests/tests-chip.cpp | 8 ++++---- bindings/cxx/tests/tests-event.cpp | 4 ++-- bindings/cxx/tests/tests-line.cpp | 16 ++++++++-------- 3 files changed, 14 insertions(+), 14 deletions(-)bindings/cxx/tests/tests-chip.cpp +4
-4@@ -107,7 +107,7 @@ TEST_CASE("Uninitialized GPIO chip behaves correctly", "[chip]") SECTION("using uninitialized chip throws logic_error") { - REQUIRE_THROWS_AS(chip.name(), ::std::logic_error&); + REQUIRE_THROWS_AS(chip.name(), ::std::logic_error); } }@@ -139,7 +139,7 @@ TEST_CASE("GPIO chip can be opened with the open() method with implicit lookup", TEST_CASE("Trying to open a nonexistent chip throws system_error", "[chip]") { - REQUIRE_THROWS_AS(::gpiod::chip("nonexistent-chip"), ::std::system_error&); + REQUIRE_THROWS_AS(::gpiod::chip("nonexistent-chip"), ::std::system_error); } TEST_CASE("Chip object can be reset", "[chip]")@@ -244,12 +244,12 @@ TEST_CASE("Errors occurring when retrieving lines are correctly reported", "[chi SECTION("invalid offset (single line)") { - REQUIRE_THROWS_AS(chip.get_line(9), ::std::out_of_range&); + REQUIRE_THROWS_AS(chip.get_line(9), ::std::out_of_range); } SECTION("invalid offset (multiple lines)") { - REQUIRE_THROWS_AS(chip.get_lines({ 1, 19, 4, 7 }), ::std::out_of_range&); + REQUIRE_THROWS_AS(chip.get_lines({ 1, 19, 4, 7 }), ::std::out_of_range); } SECTION("line not found by name")bindings/cxx/tests/tests-event.cpp +2
-2@@ -149,7 +149,7 @@ TEST_CASE("It's possible to retrieve the event file descriptor", "[event][line]" SECTION("error if not requested") { - REQUIRE_THROWS_AS(line.event_get_fd(), ::std::system_error&); + REQUIRE_THROWS_AS(line.event_get_fd(), ::std::system_error); } SECTION("error if requested for values")@@ -157,7 +157,7 @@ TEST_CASE("It's possible to retrieve the event file descriptor", "[event][line]" config.request_type = ::gpiod::line_request::DIRECTION_INPUT; line.request(config); - REQUIRE_THROWS_AS(line.event_get_fd(), ::std::system_error&); + REQUIRE_THROWS_AS(line.event_get_fd(), ::std::system_error); } }bindings/cxx/tests/tests-line.cpp +8
-9@@ -122,7 +122,7 @@ TEST_CASE("Line bulk object works correctly", "[line][bulk]") { auto lines = chip.get_all_lines(); - REQUIRE_THROWS_AS(lines.get(11), ::std::out_of_range&); + REQUIRE_THROWS_AS(lines.get(11), ::std::out_of_range); } }@@ -242,7 +242,7 @@ TEST_CASE("Exported line can be released", "[line]") line.release(); REQUIRE_FALSE(line.is_requested()); - REQUIRE_THROWS_AS(line.get_value(), ::std::system_error&); + REQUIRE_THROWS_AS(line.get_value(), ::std::system_error); } TEST_CASE("Uninitialized GPIO line behaves correctly", "[line]")@@ -256,7 +256,7 @@ TEST_CASE("Uninitialized GPIO line behaves correctly", "[line]") SECTION("using uninitialized line throws logic_error") { - REQUIRE_THROWS_AS(line.name(), ::std::logic_error&); + REQUIRE_THROWS_AS(line.name(), ::std::logic_error); } }@@ -271,7 +271,7 @@ TEST_CASE("Uninitialized GPIO line_bulk behaves correctly", "[line][bulk]") SECTION("using uninitialized line_bulk throws logic_error") { - REQUIRE_THROWS_AS(bulk.get(0), ::std::logic_error&); + REQUIRE_THROWS_AS(bulk.get(0), ::std::logic_error); } }@@ -289,7 +289,7 @@ TEST_CASE("Cannot request the same line twice", "[line]") auto line = chip.get_line(3); REQUIRE_NOTHROW(line.request(config)); - REQUIRE_THROWS_AS(line.request(config), ::std::system_error&); + REQUIRE_THROWS_AS(line.request(config), ::std::system_error); } SECTION("request the same line twice in line_bulk")@@ -300,7 +300,7 @@ TEST_CASE("Cannot request the same line twice", "[line]") */ auto lines = chip.get_lines({ 2, 3, 4, 4 }); - REQUIRE_THROWS_AS(lines.request(config), ::std::system_error&); + REQUIRE_THROWS_AS(lines.request(config), ::std::system_error); } }@@ -312,12 +312,12 @@ TEST_CASE("Cannot get/set values of unrequested lines", "[line]") SECTION("get value") { - REQUIRE_THROWS_AS(line.get_value(), ::std::system_error&); + REQUIRE_THROWS_AS(line.get_value(), ::std::system_error); } SECTION("set value") { - REQUIRE_THROWS_AS(line.set_value(1), ::std::system_error&); + REQUIRE_THROWS_AS(line.set_value(1), ::std::system_error); } } --2.22.0
Re: [libgpiod] [PATCH 5/5] bindings: cxx: Workaround --success run
In reply to Bartosz GolaszewskiQuoted 21 lines · CEST Bartosz Golaszewski
śr., 7 sie 2019 o 21:51 Alexander Stein <[email protected]> napisał(a):
Quoted 9 lines
If run with --success, all expressions are evaluated and printed out. But
REQUIRE_FALSE(chip)tries to iterate over the chip resulting in this backtrace:#0 gpiod_chip_num_lines (chip=chip@entry=0x0) at ../../lib/core.c:235 #1 gpiod_line_iter_new (chip=0x0) at ../../lib/iter.c:140 #2 gpiod::(anonymous namespace)::make_line_iter (chip=0x0) at ../../../bindings/cxx/iter.cpp:29 #3 gpiod::line_iter::line_iter (this=0x7fffffffd690, owner=...) at ../../../bindings/cxx/iter.cpp:109 #4 Catch::rangeToString<gpiod::chip> (range=...) at /usr/include/catch2/catch.hpp:1959Quoted 9 lines
[...]
Workaround by forcing catch2 to call
gpiod::chip::operatorbool().Signed-off-by Alexander Stein <[email protected]>---
This actually looks like a flaw in the binding itself that thegpiod::line_itercan't cope with an emptygpiod::chip.
Quoted 3 lines
Do you want to submit a patch that fixes that? Otherwise I can fix it. I think that simply throwing an exception on empty chip is enough, right?
Reading that backtrace today, the actual problem is gpiod_chip_num_lines deferencing the nullptr.
There are 2 possibilities:
* if gpiod_chip is NULL in gpiod_line_iter_new(), return NULLL iter as well (which will raise an exception on line iter.cpp:31)
* return an iter with num_lines = 0
Can't rate the 2nd one if this will raise other problems.
Best regards,
Alexander
Re: [libgpiod] [PATCH 5/5] bindings: cxx: Workaround --success run
czw., 8 sie 2019 o 20:41 Alexander Stein <[email protected]> napisał(a):
Quoted 32 lines · CEST Bartosz Golaszewski
Quoted 21 lines
śr., 7 sie 2019 o 21:51 Alexander Stein <[email protected]> napisał(a):
Quoted 9 lines
If run with --success, all expressions are evaluated and printed out. But
REQUIRE_FALSE(chip)tries to iterate over the chip resulting in this backtrace:#0 gpiod_chip_num_lines (chip=chip@entry=0x0) at ../../lib/core.c:235 #1 gpiod_line_iter_new (chip=0x0) at ../../lib/iter.c:140 #2 gpiod::(anonymous namespace)::make_line_iter (chip=0x0) at ../../../bindings/cxx/iter.cpp:29 #3 gpiod::line_iter::line_iter (this=0x7fffffffd690, owner=...) at ../../../bindings/cxx/iter.cpp:109 #4 Catch::rangeToString<gpiod::chip> (range=...) at /usr/include/catch2/catch.hpp:1959Quoted 9 lines
[...]
Workaround by forcing catch2 to call
gpiod::chip::operatorbool().Signed-off-by Alexander Stein <[email protected]>---
This actually looks like a flaw in the binding itself that thegpiod::line_itercan't cope with an emptygpiod::chip.Quoted 3 lines
Do you want to submit a patch that fixes that? Otherwise I can fix it. I think that simply throwing an exception on empty chip is enough, right?
Reading that backtrace today, the actual problem is
gpiod_chip_num_linesdeferencing the nullptr.
There are 2 possibilities:
* ifgpiod_chipis NULL ingpiod_line_iter_new(), return NULLL iter as well (which will raise an exception on line iter.cpp:31)
* return an iter withnum_lines= 0
Quoted 7 lines
Can't rate the 2nd one if this will raise other problems.
Best regards,
Alexander
Hardening of argument validation in the core library (checking of NULL-pointers, etc.) has been on my TODO list for some time now. It seems I'll finally have to do it.
Thanks for the patches, all applied!
Bartosz