[Buildroot] [git commit] support/testing: add runtime test for easydbus

Julien Olivain via buildroot <[email protected]>
Newsgroups net.busybox.buildroot
Message-ID <[email protected]>
commit: https://gitlab.com/buildroot.org/buildroot/-/commit/4456d899d0481efe7e7994090d0b709dbba47f39
branch: https://gitlab.com/buildroot.org/buildroot/-/tree/master

Test an actual D-Bus round-trip using easydbus:
 - obtain a name on the system bus
 - subscribe to a signal on a chosen object/interface
 - emit signal with a string payload
 - run the easydbus mainloop
 - verify the handler received the expected payload

This covers both the default Lua interpreter (Lua 5.4) and LuaJIT
(Lua 5.1 ABI).

Signed-off-by: Marcin Niestroj <[email protected]>
[Julien:
 - move test files into a rootfs-overlay
 - move common BR2_PACKAGE_{,EASY}DBUS configs to EasyDBusBase
 - make stricter check of script output
 - add DEVELOPERS entry for rootfs-overlay files
]
Signed-off-by: Julien Olivain <[email protected]>
---
 DEVELOPERS                                         |  2 +
 support/testing/tests/package/test_easydbus.py     | 44 ++++++++++++++++++++++
 .../etc/dbus-1/system.d/easydbus.SampleTest.conf   |  8 ++++
 .../rootfs-overlay/root/easydbus-sample.lua        | 22 +++++++++++
 4 files changed, 76 insertions(+)

diff --git a/DEVELOPERS b/DEVELOPERS
index 353f4a2ccf..c462d41d75 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -2290,6 +2290,8 @@ F:	support/testing/tests/package/sample_python_dbus_fast.py
 F:	support/testing/tests/package/sample_python_dbus_next.py
 F:	support/testing/tests/package/sample_python_pytest.py
 F:	support/testing/tests/package/sample_python_pytest_asyncio.py
+F:	support/testing/tests/package/test_easydbus.py
+F:	support/testing/tests/package/test_easydbus/
 F:	support/testing/tests/package/test_netdata.py
 F:	support/testing/tests/package/test_python_dbus_next.py
 F:	support/testing/tests/package/test_python_pytest.py
diff --git a/support/testing/tests/package/test_easydbus.py b/support/testing/tests/package/test_easydbus.py
new file mode 100644
index 0000000000..b628214eb7
--- /dev/null
+++ b/support/testing/tests/package/test_easydbus.py
@@ -0,0 +1,44 @@
+import infra.basetest
+
+from tests.package.test_lua import TestLuaBase
+
+
+class EasyDBusBase(TestLuaBase):
+    rootfs_overlay = \
+        infra.filepath("tests/package/test_easydbus/rootfs-overlay")
+    config = TestLuaBase.config + \
+        f"""
+        BR2_PACKAGE_DBUS=y
+        BR2_PACKAGE_EASYDBUS=y
+        BR2_ROOTFS_OVERLAY="{rootfs_overlay}"
+        """
+
+    def signal_round_trip(self):
+        cmd = "lua /root/easydbus-sample.lua"
+        output, exit_code = self.emulator.run(cmd)
+        self.assertEqual(exit_code, 0)
+        self.assertEqual(output[0], "OK")
+
+
+class TestLuaEasyDBus(EasyDBusBase):
+    config = EasyDBusBase.config + \
+        """
+        BR2_PACKAGE_LUA=y
+        """
+
+    def test_run(self):
+        self.login()
+        self.module_test("easydbus")
+        self.signal_round_trip()
+
+
+class TestLuajitEasyDBus(EasyDBusBase):
+    config = EasyDBusBase.config + \
+        """
+        BR2_PACKAGE_LUAJIT=y
+        """
+
+    def test_run(self):
+        self.login()
+        self.module_test("easydbus")
+        self.signal_round_trip()
diff --git a/support/testing/tests/package/test_easydbus/rootfs-overlay/etc/dbus-1/system.d/easydbus.SampleTest.conf b/support/testing/tests/package/test_easydbus/rootfs-overlay/etc/dbus-1/system.d/easydbus.SampleTest.conf
new file mode 100644
index 0000000000..0daaa9ff43
--- /dev/null
+++ b/support/testing/tests/package/test_easydbus/rootfs-overlay/etc/dbus-1/system.d/easydbus.SampleTest.conf
@@ -0,0 +1,8 @@
+<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
+<busconfig>
+  <policy user="root">
+    <allow own="easydbus.SampleTest"/>
+    <allow send_destination="easydbus.SampleTest"/>
+  </policy>
+</busconfig>
diff --git a/support/testing/tests/package/test_easydbus/rootfs-overlay/root/easydbus-sample.lua b/support/testing/tests/package/test_easydbus/rootfs-overlay/root/easydbus-sample.lua
new file mode 100644
index 0000000000..e7afd210ba
--- /dev/null
+++ b/support/testing/tests/package/test_easydbus/rootfs-overlay/root/easydbus-sample.lua
@@ -0,0 +1,22 @@
+local dbus = require 'easydbus'
+
+local bus = assert(dbus.system())
+local service_name = 'easydbus.SampleTest'
+local object_path = '/easydbus/sample'
+local interface_name = 'easydbus.SampleTest'
+local signal_name = 'Pinged'
+
+local owner_id = assert(bus:own_name(service_name))
+
+local payload
+bus:subscribe(nil, object_path, interface_name, signal_name,
+              function(arg) payload = arg; dbus.mainloop_quit() end)
+assert(bus:emit(nil, object_path, interface_name, signal_name,
+                's', 'hello'))
+dbus.mainloop()
+
+bus:unown_name(owner_id)
+
+assert(payload == 'hello',
+       'unexpected payload: ' .. tostring(payload))
+print('OK')
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.