Skip to contentSkip to conversation

support/testing/tests/package/test_python_paho_mqtt: new runtime test

PATCH Applied Marcus Hoffmann 2 participants 3 messages Aug 29, 2022 – Aug 31, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v2 2/2 support/testing/tests/package/test_python_paho_mqtt: new runtime test

---
 .../tests/package/sample_python_paho_mqtt.py  | 12 ++++++++
 .../tests/package/test_python_paho_mqtt.py    | 29 +++++++++++++++++++
 2 files changed, 41 insertions(+)
 create mode 100644 support/testing/tests/package/sample_python_paho_mqtt.py
 create mode 100644 support/testing/tests/package/test_python_paho_mqtt.py
support/testing/tests/package/sample_python_paho_mqtt.py new file +12 -0
new file mode 100644
index 0000000000..769ad6250f
@@ -0,0 +1,12 @@
+from paho.mqtt import publish, subscribe
+
+publish.single(
+        'buildroot/test',
+        payload="Hello, World!",
+        qos=2,
+        retain=True,
+        hostname="localhost",
+        port=1883)
+
+message = subscribe.simple('buildroot/test')
+print(message.payload.decode())
support/testing/tests/package/test_python_paho_mqtt.py new file +29 -0
new file mode 100644
index 0000000000..b1e2b8fb42
@@ -0,0 +1,29 @@
+from tests.package.test_python import TestPythonPackageBase
+import os
+import time
+
+
+class TestPythonPahoMQTT(TestPythonPackageBase):
+    __test__ = True
+    config = TestPythonPackageBase.config + \
+        """
+        BR2_PACKAGE_MOSQUITTO=y
+        BR2_PACKAGE_MOSQUITTO_BROKER=y
+        BR2_PACKAGE_PYTHON3=y
+        BR2_PACKAGE_PYTHON_PAHO_MQTT=y
+        """
+    sample_scripts = ["tests/package/sample_python_paho_mqtt.py"]
+
+    def test_run(self):
+        self.login()
+        self.check_sample_scripts_exist()
+        cmd = "mosquitto > /dev/null 2>&1 &"
+        _, exit_code = self.emulator.run(cmd, timeout=self.timeout)
+
+        # Give some time for mosquitto broker to start up
+        time.sleep(1)
+
+        cmd = "%s %s" % (self.interpreter, os.path.basename(self.sample_scripts[0]))
+        output, exit_code = self.emulator.run(cmd, timeout=self.timeout)
+        self.assertEqual(exit_code, 0)
+        self.assertEqual(output[0], "Hello, World!")
Signature · 6 lines
2.25.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw

Markus, All,

On 2022-08-29 19:18 +0200, Marcus Hoffmann spake thusly:

Quoted 3 lines

---

[--SNIP--]

support/testing/tests/package/test_python_paho_mqtt.py

Quoted 6 lines
support/testing/tests/package/test_python_paho_mqtt.py new file +0 -0
new file mode 100644
index 0000000000..b1e2b8fb42
@@ -0,0 +1,29 @@

[--SNIP--]

support/testing/tests/package/test_python_paho_mqtt.py line 21

Quoted 5 lines
support/testing/tests/package/test_python_paho_mqtt.py new file +5 -0
+    def test_run(self):
+        self.login()
+        self.check_sample_scripts_exist()
+        cmd = "mosquitto > /dev/null 2>&1 &"
+        _, exit_code = self.emulator.run(cmd, timeout=self.timeout)

No need to manually start it, it is already started with a startu script, as can be seen n the run log:

Starting mosquitto: OK

And indeed, manually running the qemu on the test image, and trying to launch mosquitto yields an error:

[...]
Starting network: OK
Starting mosquitto: OK

Welcome to Buildroot
buildroot login: root
# mosquitto
[...]
11: Opening ipv4 listen socket on port 1883.
11: Error: Address already in use
11: Opening ipv6 listen socket on port 1883.
11: Error: Address already in use

So I dropped, that.

support/testing/tests/package/test_python_paho_mqtt.py line 24

Quoted 2 lines
support/testing/tests/package/test_python_paho_mqtt.py new file +2 -0
+        # Give some time for mosquitto broker to start up
+        time.sleep(1)

And thus, that too.

support/testing/tests/package/test_python_paho_mqtt.py line 27

Quoted 2 lines
support/testing/tests/package/test_python_paho_mqtt.py new file +2 -0
+        cmd = "%s %s" % (self.interpreter, os.path.basename(self.sample_scripts[0]))
+        output, exit_code = self.emulator.run(cmd, timeout=self.timeout)

The test class does not provide its own timeout, so it inherits the one from its base classs, which defines it as -1, which means no timeout, as is the default for emulator.run(), so I also dropped it.

Applied to master with the above changes, thanks.

Regards,
Yann E. MORIN.

Quoted 9 lines
support/testing/tests/package/test_python_paho_mqtt.py new file +2 -0
+        self.assertEqual(exit_code, 0)
+        self.assertEqual(output[0], "Hello, World!")
Signature · 6 lines
2.25.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Signature · 10 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.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#2 lore raw

Marcus, All,

On 2022-08-31 21:42 +0200, Yann E. MORIN spake thusly:

Quoted 1 line

Markus, All,

Sorry for the typo, Marcus, sorry.. :-/

Regards,
Yann E. MORIN.

Quoted 79 lines

On 2022-08-29 19:18 +0200, Marcus Hoffmann spake thusly:

Quoted 3 lines

---

[--SNIP--]

support/testing/tests/package/test_python_paho_mqtt.py

Quoted 6 lines
support/testing/tests/package/test_python_paho_mqtt.py new file +0 -0
new file mode 100644
index 0000000000..b1e2b8fb42
@@ -0,0 +1,29 @@

[--SNIP--]

support/testing/tests/package/test_python_paho_mqtt.py line 21

Quoted 5 lines
support/testing/tests/package/test_python_paho_mqtt.py new file +5 -0
+    def test_run(self):
+        self.login()
+        self.check_sample_scripts_exist()
+        cmd = "mosquitto > /dev/null 2>&1 &"
+        _, exit_code = self.emulator.run(cmd, timeout=self.timeout)

No need to manually start it, it is already started with a startu script, as can be seen n the run log:

Starting mosquitto: OK

And indeed, manually running the qemu on the test image, and trying to launch mosquitto yields an error:

[...]
Starting network: OK
Starting mosquitto: OK

Welcome to Buildroot
buildroot login: root
# mosquitto
[...]
11: Opening ipv4 listen socket on port 1883.
11: Error: Address already in use
11: Opening ipv6 listen socket on port 1883.
11: Error: Address already in use

So I dropped, that.

support/testing/tests/package/test_python_paho_mqtt.py line 24

Quoted 2 lines
support/testing/tests/package/test_python_paho_mqtt.py new file +2 -0
+        # Give some time for mosquitto broker to start up
+        time.sleep(1)

And thus, that too.

support/testing/tests/package/test_python_paho_mqtt.py line 27

Quoted 2 lines
support/testing/tests/package/test_python_paho_mqtt.py new file +2 -0
+        cmd = "%s %s" % (self.interpreter, os.path.basename(self.sample_scripts[0]))
+        output, exit_code = self.emulator.run(cmd, timeout=self.timeout)

The test class does not provide its own timeout, so it inherits the one from its base classs, which defines it as -1, which means no timeout, as is the default for emulator.run(), so I also dropped it.

Applied to master with the above changes, thanks.

Regards,
Yann E. MORIN.

Quoted 9 lines
support/testing/tests/package/test_python_paho_mqtt.py new file +2 -0
+        self.assertEqual(exit_code, 0)
+        self.assertEqual(output[0], "Hello, World!")
Signature · 6 lines
2.25.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Signature · 10 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.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Signature · 10 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.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot