From patchwork Tue Apr 7 11:15:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1267372 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=busybox.net (client-ip=140.211.166.138; helo=whitealder.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.a=rsa-sha256 header.s=google header.b=O70b+R1k; dkim-atps=neutral Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48xPx05wZTz9sSq for ; Tue, 7 Apr 2020 21:16:20 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 43BC387B4B; Tue, 7 Apr 2020 11:16:19 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id hz54A5YTgPeE; Tue, 7 Apr 2020 11:16:16 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by whitealder.osuosl.org (Postfix) with ESMTP id D392787A33; Tue, 7 Apr 2020 11:16:16 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by ash.osuosl.org (Postfix) with ESMTP id E39111BF844 for ; Tue, 7 Apr 2020 11:16:15 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id E089A86946 for ; Tue, 7 Apr 2020 11:16:15 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vGQLF0gnOL6b for ; Tue, 7 Apr 2020 11:16:14 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by fraxinus.osuosl.org (Postfix) with ESMTPS id 840C58693B for ; Tue, 7 Apr 2020 11:16:14 +0000 (UTC) Received: by mail-pj1-f41.google.com with SMTP id z3so615724pjr.4 for ; Tue, 07 Apr 2020 04:16:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DY4gm/2gckIRThfc01K7LpoTCXd7W3t+Gf9gufa5/Jo=; b=O70b+R1kBmvr0GRfWUwhQ7MqELahx60JwqVvoWoHoKb7m2RGLjIfUvKtoc5YmyOXrm h9yZOkzRsGEZpqHCeJiypGlPvV9g3C6jB05XE9gGNrOvdFjjbKqS5UDJNZPSj2KsK1Sk a1DwX/5OUQSYSUomKRd956nzbNXTx4VM9DXu8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DY4gm/2gckIRThfc01K7LpoTCXd7W3t+Gf9gufa5/Jo=; b=lN8hYAAeoGX3v5S9HOjKLnJAWG7Q8vxy/jKcxsXbIe/V1UxqbvB6xZBhoZ7ZNQBtYU q3qBvqKI2mAexK51CMhTOAw+2vbP+Nz+iUCN82VYqyOlQCuP979QGcieDD/RE8pb1IUk 1pFOaXbJ4Ftqpaet9UA5i89zwSDZC4RAcPwFrtdj+OeATx+TlLEHjyLbbUzd+DBbxo3U l4A3kzPWr6qA7x9bQkGvkxp+6Lb7n6G8VuVBdX5OIXHujmAQrEYzlfW0yg0L3f/7oCxg Wz3BReKmUuEaZjWg42DQfx0+KQbmD0/gl4T5rbiX5DAd/PreqLm9/jMO38lrExH/PMpG 2gIg== X-Gm-Message-State: AGi0PuZtUZ/s8J19mXFzTaHp8I6OoYVNycLUgMYU0qmA1MboK/IduLZs ddHrzCdrW2jBZ/3S5VYGGzAoCIhMZlE= X-Google-Smtp-Source: APiQypI9Mreaxu+g2Dq7W1PdQ+2TN3qM5/bhy/Q0+bhfSXgVMPLGQo3Up3SribS16QOxLZfTqNXAQg== X-Received: by 2002:a17:90a:2a06:: with SMTP id i6mr1915292pjd.99.1586258173594; Tue, 07 Apr 2020 04:16:13 -0700 (PDT) Received: from localhost.localdomain ([2405:201:c809:c7d5:79b0:3a91:34a5:abd7]) by smtp.gmail.com with ESMTPSA id e187sm13788802pfe.50.2020.04.07.04.16.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 04:16:12 -0700 (PDT) From: Jagan Teki To: buildroot@buildroot.org Date: Tue, 7 Apr 2020 16:45:14 +0530 Message-Id: <20200407111515.21131-5-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200407111515.21131-1-jagan@amarulasolutions.com> References: <20200407111515.21131-1-jagan@amarulasolutions.com> Subject: [Buildroot] [PATCH v8 4/5] support/testing: add python-pybind11 test X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Esben Haabendal , Jagan Teki , Suniel Mahesh , linux-amarula@amarulasolutions.com, "Yann E . MORIN" , Adam Duskett , Angelo Compagnucci MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" From: Adam Duskett This test is a simple integration test of the python-pybind11 package. It consists of the following: - The python-pybind11-addition-example package compiles a simple cpp file which adds two given numbers together and returns the results and installs the compiled file to /root/ This example is from the following URL: https://pybind11.readthedocs.io/en/stable/basics.html - The python-pybind11-addition-example package installs the sample_python_pybind11.py file which imports the above-compiled file and adds 1 and 2 together to /root/ - Execute the sample_python_pybind11.py in an emulator with the expected output of 3 and an exit code of 0. Signed-off-by: Adam Duskett [jagan: rebase, fix trailing whitespace, new line warninings] Signed-off-by: Jagan Teki --- Changes for v8 - new patch .gitlab-ci.yml | 2 + DEVELOPERS | 2 + .../br2-external/python-pybind11/Config.in | 1 + .../python-pybind11/external.desc | 1 + .../br2-external/python-pybind11/external.mk | 1 + .../Config.in | 5 ++ .../pybind11_addition_example.cpp | 9 +++ .../python-pybind11-addition-example.mk | 39 ++++++++++ .../sample_python_pybind11.py | 4 + .../tests/package/test_python_pybind11.py | 76 +++++++++++++++++++ 10 files changed, 140 insertions(+) create mode 100644 support/testing/tests/package/br2-external/python-pybind11/Config.in create mode 100644 support/testing/tests/package/br2-external/python-pybind11/external.desc create mode 100644 support/testing/tests/package/br2-external/python-pybind11/external.mk create mode 100644 support/testing/tests/package/br2-external/python-pybind11/package/python-pybind11-addition-example/Config.in create mode 100644 support/testing/tests/package/br2-external/python-pybind11/package/python-pybind11-addition-example/pybind11_addition_example.cpp create mode 100644 support/testing/tests/package/br2-external/python-pybind11/package/python-pybind11-addition-example/python-pybind11-addition-example.mk create mode 100644 support/testing/tests/package/br2-external/python-pybind11/package/python-pybind11-addition-example/sample_python_pybind11.py create mode 100644 support/testing/tests/package/test_python_pybind11.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d9519c3812..ce524337cb 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -471,6 +471,8 @@ tests.package.test_python_passlib.TestPythonPy2Passlib: { extends: .runtime_test tests.package.test_python_passlib.TestPythonPy3Passlib: { extends: .runtime_test } tests.package.test_python_pexpect.TestPythonPy2Pexpect: { extends: .runtime_test } tests.package.test_python_pexpect.TestPythonPy3Pexpect: { extends: .runtime_test } +tests.package.test_python_pybind11.TestPythonPy2Pybind11: { extends: .runtime_test } +tests.package.test_python_pybind11.TestPythonPy3Pybind11: { extends: .runtime_test } tests.package.test_python_pynacl.TestPythonPy2Pynacl: { extends: .runtime_test } tests.package.test_python_pynacl.TestPythonPy3Pynacl: { extends: .runtime_test } tests.package.test_python_pyyaml.TestPythonPy2Pyyaml: { extends: .runtime_test } diff --git a/DEVELOPERS b/DEVELOPERS index 308a59b264..f06d54a662 100644 --- a/DEVELOPERS +++ b/DEVELOPERS @@ -85,6 +85,8 @@ F: package/sngrep/ F: package/spidermonkey/ F: package/systemd/ F: support/testing/tests/package/test_python_gobject.py +F: support/testing/tests/package/br2-external/python-pybind11/ +F: support/testing/tests/package/test_python_pybind11.py N: Adam Heinrich F: package/jack1/ diff --git a/support/testing/tests/package/br2-external/python-pybind11/Config.in b/support/testing/tests/package/br2-external/python-pybind11/Config.in new file mode 100644 index 0000000000..27b502313b --- /dev/null +++ b/support/testing/tests/package/br2-external/python-pybind11/Config.in @@ -0,0 +1 @@ +source "$BR2_EXTERNAL_PYTHON_PYBIND11_PATH/package/python-pybind11-addition-example/Config.in" diff --git a/support/testing/tests/package/br2-external/python-pybind11/external.desc b/support/testing/tests/package/br2-external/python-pybind11/external.desc new file mode 100644 index 0000000000..04a636053a --- /dev/null +++ b/support/testing/tests/package/br2-external/python-pybind11/external.desc @@ -0,0 +1 @@ +name: PYTHON_PYBIND11 diff --git a/support/testing/tests/package/br2-external/python-pybind11/external.mk b/support/testing/tests/package/br2-external/python-pybind11/external.mk new file mode 100644 index 0000000000..db34e5f54d --- /dev/null +++ b/support/testing/tests/package/br2-external/python-pybind11/external.mk @@ -0,0 +1 @@ +include $(sort $(wildcard $(BR2_EXTERNAL_PYTHON_PYBIND11_PATH)/package/*/*.mk)) diff --git a/support/testing/tests/package/br2-external/python-pybind11/package/python-pybind11-addition-example/Config.in b/support/testing/tests/package/br2-external/python-pybind11/package/python-pybind11-addition-example/Config.in new file mode 100644 index 0000000000..7860559a13 --- /dev/null +++ b/support/testing/tests/package/br2-external/python-pybind11/package/python-pybind11-addition-example/Config.in @@ -0,0 +1,5 @@ +config BR2_PACKAGE_PYTHON_PYBIND11_ADDITION_EXAMPLE + bool "python-pybind11 addition example" + depends on BR2_PACKAGE_PYTHON_PYBIND11 + help + Simple class for testing python-pybind11 diff --git a/support/testing/tests/package/br2-external/python-pybind11/package/python-pybind11-addition-example/pybind11_addition_example.cpp b/support/testing/tests/package/br2-external/python-pybind11/package/python-pybind11-addition-example/pybind11_addition_example.cpp new file mode 100644 index 0000000000..61b3fce051 --- /dev/null +++ b/support/testing/tests/package/br2-external/python-pybind11/package/python-pybind11-addition-example/pybind11_addition_example.cpp @@ -0,0 +1,9 @@ +#include + +int add(int i, int j) { + return i + j; +} + +PYBIND11_MODULE(pybind11_addition_example, m) { + m.def("add", &add, "A function which adds two numbers"); +} diff --git a/support/testing/tests/package/br2-external/python-pybind11/package/python-pybind11-addition-example/python-pybind11-addition-example.mk b/support/testing/tests/package/br2-external/python-pybind11/package/python-pybind11-addition-example/python-pybind11-addition-example.mk new file mode 100644 index 0000000000..f620424fca --- /dev/null +++ b/support/testing/tests/package/br2-external/python-pybind11/package/python-pybind11-addition-example/python-pybind11-addition-example.mk @@ -0,0 +1,39 @@ +################################################################################ +# +# python-pybind11_addition_example +# +################################################################################ + +PYTHON_PYBIND11_ADDITION_EXAMPLE_DEPENDENCIES = python-pybind11 + +ifeq ($(BR2_PACKAGE_PYTHON),y) +PYTHON_PYBIND11_ADDITION_EXAMPLE_INCLUDES=`$(STAGING_DIR)/usr/bin/python2-config --includes` +PYTHON_PYBIND11_ADDITION_EXAMPLE_SUFFIX=`$(STAGING_DIR)/usr/bin/python2-config --extension-suffix` +else +PYTHON_PYBIND11_ADDITION_EXAMPLE_INCLUDES=`$(STAGING_DIR)/usr/bin/python3-config --includes` +PYTHON_PYBIND11_ADDITION_EXAMPLE_SUFFIX=`$(STAGING_DIR)/usr/bin/python3-config --extension-suffix` +endif +PYTHON_PYBIND11_ADDITION_EXAMPLE_OUTPUT=pybind11_addition_example$(PYTHON_PYBIND11_ADDITION_EXAMPLE_SUFFIX) + +define PYTHON_PYBIND11_ADDITION_EXAMPLE_BUILD_CMDS + $(INSTALL) -D $(PYTHON_PYBIND11_ADDITION_EXAMPLE_PKGDIR)/pybind11_addition_example.cpp \ + $(@D)/pybind11_addition_example.cpp + + $(INSTALL) -D $(PYTHON_PYBIND11_ADDITION_EXAMPLE_PKGDIR)/sample_python_pybind11.py \ + $(@D)/sample_python_pybind11.py + + cd $(@D); \ + $(TARGET_CXX) -std=c++11 -fPIC -shared \ + $(PYTHON_PYBIND11_ADDITION_EXAMPLE_INCLUDES) pybind11_addition_example.cpp \ + -o $(PYTHON_PYBIND11_ADDITION_EXAMPLE_OUTPUT) +endef + +define PYTHON_PYBIND11_ADDITION_EXAMPLE_INSTALL_TARGET_CMDS + $(INSTALL) -D -m 755 $(@D)/$(PYTHON_PYBIND11_ADDITION_EXAMPLE_OUTPUT) \ + $(TARGET_DIR)/root/$(PYTHON_PYBIND11_ADDITION_EXAMPLE_OUTPUT) + + $(INSTALL) -D -m 755 $(@D)/sample_python_pybind11.py \ + $(TARGET_DIR)/root/sample_python_pybind11.py +endef + +$(eval $(generic-package)) diff --git a/support/testing/tests/package/br2-external/python-pybind11/package/python-pybind11-addition-example/sample_python_pybind11.py b/support/testing/tests/package/br2-external/python-pybind11/package/python-pybind11-addition-example/sample_python_pybind11.py new file mode 100644 index 0000000000..29196481e1 --- /dev/null +++ b/support/testing/tests/package/br2-external/python-pybind11/package/python-pybind11-addition-example/sample_python_pybind11.py @@ -0,0 +1,4 @@ +#!/usr/bin/env python +import pybind11_addition_example + +print(pybind11_addition_example.add(1, 2)) diff --git a/support/testing/tests/package/test_python_pybind11.py b/support/testing/tests/package/test_python_pybind11.py new file mode 100644 index 0000000000..12bd77807e --- /dev/null +++ b/support/testing/tests/package/test_python_pybind11.py @@ -0,0 +1,76 @@ +import os +import infra.basetest + +class TestPythonPy2Pybind11(infra.basetest.BRTest): + br2_external = [infra.filepath("tests/package/br2-external/python-pybind11")] + config = \ + """ + BR2_aarch64=y + BR2_TOOLCHAIN_EXTERNAL=y + BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0" + BR2_LINUX_KERNEL=y + BR2_LINUX_KERNEL_CUSTOM_VERSION=y + BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="4.19.86" + BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y + BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/aarch64-virt/linux.config" + BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y + BR2_TARGET_ROOTFS_CPIO=y + BR2_TARGET_ROOTFS_CPIO_GZIP=y + BR2_PACKAGE_PYTHON=y + BR2_PACKAGE_PYTHON_PYBIND11=y + BR2_PACKAGE_PYTHON_PYBIND11_ADDITION_EXAMPLE=y + """ + + def login(self): + img = os.path.join(self.builddir, "images", "rootfs.cpio.gz") + kern = os.path.join(self.builddir, "images", "Image") + self.emulator.boot(arch="aarch64", + kernel=kern, + kernel_cmdline=["console=ttyAMA0"], + options=["-M", "virt", "-cpu", "cortex-a57", "-m", "512M", "-initrd", img]) + self.emulator.login() + + def test_run(self): + self.login() + cmd = "python sample_python_pybind11.py" + output, exit_code = self.emulator.run(cmd, 120) + print(output) + self.assertEqual(exit_code, 0) + self.assertEqual(output, ["3"]) + +class TestPythonPy3Pybind11(infra.basetest.BRTest): + br2_external = [infra.filepath("tests/package/br2-external/python-pybind11")] + config = \ + """ + BR2_aarch64=y + BR2_TOOLCHAIN_EXTERNAL=y + BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0" + BR2_LINUX_KERNEL=y + BR2_LINUX_KERNEL_CUSTOM_VERSION=y + BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="4.19.86" + BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y + BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/aarch64-virt/linux.config" + BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y + BR2_TARGET_ROOTFS_CPIO=y + BR2_TARGET_ROOTFS_CPIO_GZIP=y + BR2_PACKAGE_PYTHON3=y + BR2_PACKAGE_PYTHON_PYBIND11=y + BR2_PACKAGE_PYTHON_PYBIND11_ADDITION_EXAMPLE=y + """ + + def login(self): + img = os.path.join(self.builddir, "images", "rootfs.cpio.gz") + kern = os.path.join(self.builddir, "images", "Image") + self.emulator.boot(arch="aarch64", + kernel=kern, + kernel_cmdline=["console=ttyAMA0"], + options=["-M", "virt", "-cpu", "cortex-a57", "-m", "512M", "-initrd", img]) + self.emulator.login() + + def test_run(self): + self.login() + cmd = "python3 sample_python_pybind11.py" + output, exit_code = self.emulator.run(cmd, 120) + print(output) + self.assertEqual(exit_code, 0) + self.assertEqual(output, ["3"])