From 82ae2c8e4309272be1807a64a3bfe9541d855d01 Mon Sep 17 00:00:00 2001 From: Mike Kinney Date: Fri, 3 Dec 2021 09:50:48 -0800 Subject: [PATCH] added smoke tests on one device --- README.md | 13 ++- meshtastic/node.py | 3 + meshtastic/test/test_smoke1.py | 197 +++++++++++++++++++++++++++++++++ pytest.ini | 3 + 4 files changed, 211 insertions(+), 5 deletions(-) create mode 100644 meshtastic/test/test_smoke1.py diff --git a/README.md b/README.md index ccde356..9a5efbb 100644 --- a/README.md +++ b/README.md @@ -178,8 +178,11 @@ pip3 install . pytest ``` Possible options for testing: -* for more verbosity, add "-v" or even "-vv" like this: pytest -vv -* to run just unit tests: pytest -munit -* to run just integration tests: pytest -mint -* if you want to add another classification of tests, then look in pytest.ini -* if you want to see the unit test code coverage: pytest --cov=meshtastic +* For more verbosity, add "-v" or even "-vv" like this: pytest -vv +* To run just unit tests: pytest -munit +* To run just integration tests: pytest -mint +* To run a smoke test with only one device connected serially: pytest -msmoke1 + CAUTION: Running smoke1 will reset values on the device. +* To run a specific test: pytest -msmoke1 meshtastic/test/test_smoke1.py::test_smoke1_info +* To add another classification of tests, then look in pytest.ini +* To see the unit test code coverage: pytest --cov=meshtastic diff --git a/meshtastic/node.py b/meshtastic/node.py index acafce7..fed469b 100644 --- a/meshtastic/node.py +++ b/meshtastic/node.py @@ -259,6 +259,9 @@ class Node: channelSet = apponly_pb2.ChannelSet() channelSet.ParseFromString(decodedURL) + if len(channelSet.settings) == 0: + raise Exception("There were no settings.") + i = 0 for chs in channelSet.settings: ch = channel_pb2.Channel() diff --git a/meshtastic/test/test_smoke1.py b/meshtastic/test/test_smoke1.py new file mode 100644 index 0000000..289b4f8 --- /dev/null +++ b/meshtastic/test/test_smoke1.py @@ -0,0 +1,197 @@ +"""Meshtastic smoke tests with a single device""" +import re +import subprocess +import platform +import time + +# Do not like using hard coded sleeps, but it probably makes +# sense to pause for the radio at apprpriate times +import pytest + + +@pytest.mark.smoke1 +def test_smoke1_reboot(): + """Test reboot""" + return_value, out = subprocess.getstatusoutput('meshtastic --reboot') + assert return_value == 0 + # pause for the radio to reset (10 seconds for the pause, and a few more seconds to be back up) + time.sleep(18) + + +@pytest.mark.smoke1 +def test_smoke1_info(): + """Test --info""" + return_value, out = subprocess.getstatusoutput('meshtastic --info') + assert re.match(r'Connected to radio', out) + assert re.search(r'^Owner', out, re.MULTILINE) + assert re.search(r'^My info', out, re.MULTILINE) + assert re.search(r'^Nodes in mesh', out, re.MULTILINE) + assert re.search(r'^Preferences', out, re.MULTILINE) + assert re.search(r'^Channels', out, re.MULTILINE) + assert re.search(r'^ PRIMARY', out, re.MULTILINE) + assert re.search(r'^Primary channel URL', out, re.MULTILINE) + assert return_value == 0 + + +@pytest.mark.smoke1 +def test_smoke1_send_hello(): + """Test --sendtext hello""" + return_value, out = subprocess.getstatusoutput('meshtastic --sendtext hello') + assert re.match(r'Connected to radio', out) + assert re.search(r'^Sending text message hello to \^all', out, re.MULTILINE) + assert return_value == 0 + + +@pytest.mark.smoke1 +def test_smoke1_set_is_router_true(): + """Test --set is_router true""" + return_value, out = subprocess.getstatusoutput('meshtastic --set is_router true') + assert re.match(r'Connected to radio', out) + assert re.search(r'^Set is_router to true', out, re.MULTILINE) + assert return_value == 0 + # pause for the radio + time.sleep(1) + return_value, out = subprocess.getstatusoutput('meshtastic --get is_router') + assert re.search(r'^is_router: True', out, re.MULTILINE) + assert return_value == 0 + + +@pytest.mark.smoke1 +def test_smoke1_set_location_info(): + """Test --setlat, --setlon and --setalt """ + return_value, out = subprocess.getstatusoutput('meshtastic --setlat 32.7767 --setlon -96.7970 --setalt 1337') + assert re.match(r'Connected to radio', out) + assert re.search(r'^Fixing altitude', out, re.MULTILINE) + assert re.search(r'^Fixing latitude', out, re.MULTILINE) + assert re.search(r'^Fixing longitude', out, re.MULTILINE) + assert return_value == 0 + # pause for the radio + time.sleep(1) + return_value, out2 = subprocess.getstatusoutput('meshtastic --info') + assert re.search(r'1337', out2, re.MULTILINE) + assert re.search(r'32.7767', out2, re.MULTILINE) + assert re.search(r'-96.797', out2, re.MULTILINE) + assert return_value == 0 + + +@pytest.mark.smoke1 +def test_smoke1_set_is_router_false(): + """Test --set is_router false""" + return_value, out = subprocess.getstatusoutput('meshtastic --set is_router false') + assert re.match(r'Connected to radio', out) + assert re.search(r'^Set is_router to false', out, re.MULTILINE) + assert return_value == 0 + # pause for the radio + time.sleep(1) + return_value, out = subprocess.getstatusoutput('meshtastic --get is_router') + assert re.search(r'^is_router: False', out, re.MULTILINE) + assert return_value == 0 + + +@pytest.mark.smoke1 +def test_smoke1_set_owner(): + """Test --set-owner name""" + # make sure the owner is not Joe + return_value, out = subprocess.getstatusoutput('meshtastic --set-owner Bob') + assert re.match(r'Connected to radio', out) + assert re.search(r'^Setting device owner to Bob', out, re.MULTILINE) + assert return_value == 0 + # pause for the radio + time.sleep(1) + return_value, out = subprocess.getstatusoutput('meshtastic --info') + assert not re.search(r'Owner: Joe', out, re.MULTILINE) + assert return_value == 0 + # pause for the radio + time.sleep(1) + return_value, out = subprocess.getstatusoutput('meshtastic --set-owner Joe') + assert re.match(r'Connected to radio', out) + assert re.search(r'^Setting device owner to Joe', out, re.MULTILINE) + assert return_value == 0 + # pause for the radio + time.sleep(1) + return_value, out = subprocess.getstatusoutput('meshtastic --info') + assert re.search(r'Owner: Joe', out, re.MULTILINE) + assert return_value == 0 + + +@pytest.mark.smoke1 +def test_smoke1_ch_set_name(): + """Test --ch-set name""" + return_value, out = subprocess.getstatusoutput('meshtastic --info') + assert not re.search(r'MyChannel', out, re.MULTILINE) + assert return_value == 0 + # pause for the radio + time.sleep(1) + return_value, out = subprocess.getstatusoutput('meshtastic --ch-set name MyChannel') + assert re.match(r'Connected to radio', out) + assert re.search(r'^Set name to MyChannel', out, re.MULTILINE) + assert return_value == 0 + # pause for the radio + time.sleep(1) + return_value, out = subprocess.getstatusoutput('meshtastic --info') + assert re.search(r'MyChannel', out, re.MULTILINE) + assert return_value == 0 + + +@pytest.mark.smoke1 +def test_smoke1_ch_set_modem_config(): + """Test --ch-set modem_config""" + return_value, out = subprocess.getstatusoutput('meshtastic --info') + assert not re.search(r'Bw31_25Cr48Sf512', out, re.MULTILINE) + assert return_value == 0 + # pause for the radio + time.sleep(1) + return_value, out = subprocess.getstatusoutput('meshtastic --ch-set modem_config Bw31_25Cr48Sf512') + assert re.match(r'Connected to radio', out) + assert re.search(r'^Set modem_config to Bw31_25Cr48Sf512', out, re.MULTILINE) + assert return_value == 0 + # pause for the radio + time.sleep(1) + return_value, out = subprocess.getstatusoutput('meshtastic --info') + assert re.search(r'Bw31_25Cr48Sf512', out, re.MULTILINE) + assert return_value == 0 + + +@pytest.mark.smoke1 +def test_smoke1_seturl_default(): + """Test --seturl with default value""" + # set some channel value so we no longer have a default channel + return_value, out = subprocess.getstatusoutput('meshtastic --ch-set name foo') + assert return_value == 0 + # pause for the radio + time.sleep(1) + # ensure we no longer have a default primary channel + return_value, out = subprocess.getstatusoutput('meshtastic --info') + assert not re.search('CgUYAyIBAQ', out, re.MULTILINE) + assert return_value == 0 + url = "https://www.meshtastic.org/d/#CgUYAyIBAQ" + return_value, out = subprocess.getstatusoutput(f"meshtastic --seturl {url}") + assert re.match(r'Connected to radio', out) + assert return_value == 0 + # pause for the radio + time.sleep(1) + return_value, out = subprocess.getstatusoutput('meshtastic --info') + assert re.search('CgUYAyIBAQ', out, re.MULTILINE) + assert return_value == 0 + + +@pytest.mark.smoke1 +def test_smoke1_seturl_invalid_url(): + """Test --seturl with invalid url""" + # Note: This url is no longer a valid url. + url = "https://www.meshtastic.org/c/#GAMiENTxuzogKQdZ8Lz_q89Oab8qB0RlZmF1bHQ=" + return_value, out = subprocess.getstatusoutput(f"meshtastic --seturl {url}") + assert re.match(r'Connected to radio', out) + assert re.search('Aborting', out, re.MULTILINE) + + +@pytest.mark.smoke1 +def test_smoke1_factory_reset(): + """Test factory reset""" + return_value, out = subprocess.getstatusoutput('meshtastic --set factory_reset true') + assert re.match(r'Connected to radio', out) + assert re.search(r'^Set factory_reset to true', out, re.MULTILINE) + assert re.search(r'^Writing modified preferences to device', out, re.MULTILINE) + assert return_value == 0 + # NOTE: The radio may not be responsive after this, may need to do a manual reboot + # by pressing the button diff --git a/pytest.ini b/pytest.ini index 9c7d72e..54ebba1 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,5 +1,8 @@ [pytest] +addopts = -m "not smoke1" + markers = unit: marks tests as unit tests int: marks tests as integration tests + smoke1: runs smoke test on one device