Skip to contentSkip to conversation

package/python-rpi-gopi: really fix for gcc-10, plus runtime test (branch yem/fixes)

PATCH New Yann E. MORIN 3 participants 5 messages Aug 21, 2020 – Aug 23, 2020

lore
Share & tools
lore
#0 lore raw

cover package/python-rpi-gopi: really fix for gcc-10, plus runtime test (branch yem/fixes)

Hello All!

A previous patch was applied, that indeed made the gc-10 build succeed (because, -fno-common). However, that patch only looked at quiescing the build errors, and thus broke runtime, see #13166;

ImportError: /usr/lib/python3.8/site-packages/RPi/_GPIO.cpython-38-aarch64-linux-gnu.so: undefined symbol: high

To avoid this situation, add a (limited) runtime test.

Regards,
Yann E. MORIN.

The following changes since commit 09e5e3dbdd4eade0190bb2bd303115dbb4336f9b

package/igd2-for-linux: fix build with gcc 10 (2020-08-21 00:20:34 +0200)

are available in the git repository at:

https://git.busybox.net/~ymorin/git/buildroot

for you to fetch changes up to 748705989a4a29b9a0a1bc565d1adf83a8a70f45

support/tests: add runtime test for python-rpi-gpio (2020-08-21 18:29:42 +0200)

----------------------------------------------------------------
Yann E. MORIN (2):
package/python-rpi-gpio: fix gcc-10 compatibility patch support/tests: add runtime test for python-rpi-gpio

 .../0001-fix-build-with-gcc-10.x.patch             | 66 ++++++++++++++++------
 .../tests/package/sample_python_rpi_gpio.py        |  6 ++
 .../testing/tests/package/test_python_rpi_gpio.py  | 11 ++++
 3 files changed, 65 insertions(+), 18 deletions(-)
 create mode 100644 support/testing/tests/package/sample_python_rpi_gpio.py
 create mode 100644 support/testing/tests/package/test_python_rpi_gpio.py
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#1 lore raw

PATCH 1/2 package/python-rpi-gpio: fix gcc-10 compatibility patch

Although the patch makes the package build OK, it fails at runtime when the module is imported, because of missing symbols:

ImportError: /usr/lib/python3.8/site-packages/RPi/_GPIO.cpython-38-aarch64-linux-gnu.so: undefined symbol: high

Fix that by making sure the symbols are declared once, but only once.

Fixes #13166
Cc Michael Fischer <[email protected]>
Cc Asaf Kahlon <[email protected]>
Cc Yegor Yefremov <[email protected]>
Cc Ian Haylock <[email protected]>
---
 .../0001-fix-build-with-gcc-10.x.patch        | 66 ++++++++++++++-----
 1 file changed, 48 insertions(+), 18 deletions(-)
package/python-rpi-gpio/0001-fix-build-with-gcc-10.x.patch +48 -18
index 7c7b772894..95892f997f 100644
@@ -2,6 +2,19 @@ Description: This patch fixes the "multiple definition of" errors with gcc10
 
 Signed-off-by: Michael Fischer <[email protected]>
 
+diff -purN python-rpi-gpio.org/source/common.c python-rpi-gpio/source/common.c
+--- python-rpi-gpio.org/source/common.c	2019-07-21 14:41:22.000000000 +0200
++++ python-rpi-gpio/source/common.c	2020-08-07 09:31:33.948575964 +0200
+@@ -28,6 +28,9 @@
+ const int pin_to_gpio_rev1[41] = {-1, -1, -1, 0, -1, 1, -1, 4, 14, -1, 15, 17, 18, 21, -1, 22, 23, -1, 24, 10, -1, 9, 25, 11, 8, -1, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
+ const int pin_to_gpio_rev2[41] = {-1, -1, -1, 2, -1, 3, -1, 4, 14, -1, 15, 17, 18, 27, -1, 22, 23, -1, 24, 10, -1, 9, 25, 11, 8, -1, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
+ const int pin_to_gpio_rev3[41] = {-1, -1, -1, 2, -1, 3, -1, 4, 14, -1, 15, 17, 18, 27, -1, 22, 23, -1, 24, 10, -1, 9, 25, 11, 8, -1, 7, -1, -1, 5, -1, 6, 12, 13, -1, 19, 16, 26, 20, -1, 21 };
++const int (*pin_to_gpio)[41];
++int gpio_direction[54];
++rpi_info rpiinfo;
+ int setup_error = 0;
+ int module_setup = 0;
+ 
 diff -purN python-rpi-gpio.org/source/common.h python-rpi-gpio/source/common.h
 --- python-rpi-gpio.org/source/common.h	2019-07-21 14:41:22.000000000 +0200
 +++ python-rpi-gpio/source/common.h	2020-08-07 09:31:33.948575964 +0200
@@ -29,10 +42,21 @@ diff -purN python-rpi-gpio.org/source/common.h python-rpi-gpio/source/common.h
 +extern int module_setup;
  int check_gpio_priv(void);
  int get_gpio_number(int channel, unsigned int *gpio);
+diff -purN python-rpi-gpio.org/source/constants.c python-rpi-gpio/source/constants.c
+--- python-rpi-gpio.org/source/constants.c	2019-07-21 14:41:22.000000000 +0200
++++ python-rpi-gpio/source/constants.c	2020-08-07 09:32:15.522196618 +0200
+@@ -21,6 +21,7 @@
+ */
+ 
+ #include "Python.h"
++#define CONSTANTS_C
+ #include "constants.h"
+ #include "common.h"
+ #include "c_gpio.h"
 diff -purN python-rpi-gpio.org/source/constants.h python-rpi-gpio/source/constants.h
 --- python-rpi-gpio.org/source/constants.h	2019-07-21 14:41:22.000000000 +0200
 +++ python-rpi-gpio/source/constants.h	2020-08-07 09:32:15.522196618 +0200
-@@ -23,22 +23,22 @@ SOFTWARE.
+@@ -23,22 +23,28 @@ SOFTWARE.
  #define PY_PUD_CONST_OFFSET 20
  #define PY_EVENT_CONST_OFFSET 30
  
@@ -53,23 +77,29 @@ diff -purN python-rpi-gpio.org/source/constants.h python-rpi-gpio/source/constan
 -PyObject *rising_edge;
 -PyObject *falling_edge;
 -PyObject *both_edge;
-+extern PyObject *high;
-+extern PyObject *low;
-+extern PyObject *input;
-+extern PyObject *output;
-+extern PyObject *pwm;
-+extern PyObject *serial;
-+extern PyObject *i2c;
-+extern PyObject *spi;
-+extern PyObject *unknown;
-+extern PyObject *board;
-+extern PyObject *bcm;
-+extern PyObject *pud_off;
-+extern PyObject *pud_up;
-+extern PyObject *pud_down;
-+extern PyObject *rising_edge;
-+extern PyObject *falling_edge;
-+extern PyObject *both_edge;
++#ifdef CONSTANTS_C
++#define MAYBE_EXTERN
++#else
++#define MAYBE_EXTERN extern
++#endif
++
++MAYBE_EXTERN PyObject *high;
++MAYBE_EXTERN PyObject *low;
++MAYBE_EXTERN PyObject *input;
++MAYBE_EXTERN PyObject *output;
++MAYBE_EXTERN PyObject *pwm;
++MAYBE_EXTERN PyObject *serial;
++MAYBE_EXTERN PyObject *i2c;
++MAYBE_EXTERN PyObject *spi;
++MAYBE_EXTERN PyObject *unknown;
++MAYBE_EXTERN PyObject *board;
++MAYBE_EXTERN PyObject *bcm;
++MAYBE_EXTERN PyObject *pud_off;
++MAYBE_EXTERN PyObject *pud_up;
++MAYBE_EXTERN PyObject *pud_down;
++MAYBE_EXTERN PyObject *rising_edge;
++MAYBE_EXTERN PyObject *falling_edge;
++MAYBE_EXTERN PyObject *both_edge;
  
  void define_constants(PyObject *module);
 diff -purN python-rpi-gpio.org/source/event_gpio.c python-rpi-gpio/source/event_gpio.c
Signature · 1 line
2.20.1
#2 lore raw

PATCH 1/2 package/python-rpi-gpio: fix gcc-10 compatibility patch

Hi Yann,

Thanks for the fix.

Quoted 4 lines · Yann E. MORIN

Although the patch makes the package build OK, it fails at runtime when the module is imported, because of missing symbols:

Quoted 8 lines

ImportError: /usr/lib/python3.8/site-packages/RPi/_GPIO.cpython-38-aarch64-linux-gnu.so: undefined symbol: high

Fix that by making sure the symbols are declared once, but only once.

Fixes #13166

Best,
Christian

#3 lore raw

PATCH 2/2 support/tests: add runtime test for python-rpi-gpio

In reply to Yann E. MORIN

Modeled after similar python packages.

However, this one is picky, and throws an exception when it detects that it is not running on a Raspberry Pi. So we just catch that exception and check this is what we expect.

Cc Christian Stewart <[email protected]>
Cc Michael Fischer <[email protected]>
Cc Asaf Kahlon <[email protected]>
Cc Yegor Yefremov <[email protected]>
Cc Ian Haylock <[email protected]>
---
 .../testing/tests/package/sample_python_rpi_gpio.py   |  6 ++++++
 support/testing/tests/package/test_python_rpi_gpio.py | 11 +++++++++++
 2 files changed, 17 insertions(+)
 create mode 100644 support/testing/tests/package/sample_python_rpi_gpio.py
 create mode 100644 support/testing/tests/package/test_python_rpi_gpio.py
support/testing/tests/package/sample_python_rpi_gpio.py new file +6 -0
new file mode 100644
index 0000000000..5f0d884e07
@@ -0,0 +1,6 @@
+try:
+    import RPi.GPIO  # noqa
+except RuntimeError as e:
+    assert(str(e) == 'This module can only be run on a Raspberry Pi!')
+else:
+    raise RuntimeError('Import succeeded when it should not have!')
support/testing/tests/package/test_python_rpi_gpio.py new file +11 -0
new file mode 100644
index 0000000000..c938ea39bb
@@ -0,0 +1,11 @@
+from tests.package.test_python import TestPythonPackageBase
+
+
+class TestPythonPy3RpiGpio(TestPythonPackageBase):
+    __test__ = True
+    config = TestPythonPackageBase.config + \
+        """
+        BR2_PACKAGE_PYTHON3=y
+        BR2_PACKAGE_PYTHON_RPI_GPIO=y
+        """
+    sample_scripts = ["tests/package/sample_python_rpi_gpio.py"]
Signature · 1 line
2.20.1
#4 lore raw

cover package/python-rpi-gopi: really fix for gcc-10, plus runtime test (branch yem/fixes)

In reply to Yann E. MORIN
Quoted 3 lines · On Fri, 21 Aug 2020 18:35:28 +0200 "Yann E. MORIN" <[email protected]>…

Yann E. MORIN (2):
package/python-rpi-gpio: fix gcc-10 compatibility patch support/tests: add runtime test for python-rpi-gpio

Both applied to master, thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com