autotest: add support for testing mavlink in lua

This commit is contained in:
bugobliterator 2023-04-05 17:09:51 +10:00 committed by Andrew Tridgell
parent e79af89df3
commit dc8deec351
2 changed files with 38 additions and 7 deletions

View File

@ -37,6 +37,7 @@ from pymavlink import mavwp, mavutil, DFReader
from pymavlink import mavextra
from pymavlink.rotmat import Vector3
from pymavlink import quaternion
from pymavlink.generator import mavgen
from pysim import util, vehicleinfo
@ -4237,6 +4238,12 @@ class AutoTest(ABC):
self.install_test_modules()
self.context_get().installed_modules.append("test")
def install_mavlink_module_context(self):
'''installs mavlink module which will be removed when the context goes
away'''
self.install_mavlink_module()
self.context_get().installed_modules.append("mavlink")
def install_applet_script_context(self, scriptname):
'''installs an applet script which will be removed when the context goes
away'''
@ -7667,6 +7674,13 @@ Also, ignores heartbeats not from our target system'''
self.progress("Copying (%s) to (%s)" % (source, dest))
shutil.copytree(source, dest)
def install_mavlink_module(self):
dest = os.path.join("scripts", "modules", "mavlink")
ardupilotmega_xml = os.path.join(self.rootdir(), "modules", "mavlink",
"message_definitions", "v1.0", "ardupilotmega.xml")
mavgen.mavgen(mavgen.Opts(output=dest, wire_protocol='2.0', language='Lua'), [ardupilotmega_xml])
self.progress("Installed mavlink module")
def install_example_script(self, scriptname):
source = self.script_example_source_path(scriptname)
self.install_script(source, scriptname)

View File

@ -5221,15 +5221,19 @@ Brakes have negligible effect (with=%0.2fm without=%0.2fm delta=%0.2fm)
self.context_push()
test_scripts = ["scripting_test.lua", "math.lua", "strings.lua"]
success_text = ["Internal tests passed", "Math tests passed", "String tests passed"]
test_scripts = ["scripting_test.lua", "math.lua", "strings.lua", "mavlink_test.lua"]
success_text = ["Internal tests passed", "Math tests passed", "String tests passed", "Received heartbeat from"]
named_value_float_types = ["test"]
messages = []
named_value_float = []
def my_message_hook(mav, message):
if message.get_type() != 'STATUSTEXT':
return
messages.append(message)
if message.get_type() == 'STATUSTEXT':
messages.append(message)
# also sniff for named value float messages
if message.get_type() == 'NAMED_VALUE_FLOAT':
named_value_float.append(message)
self.install_message_hook_context(my_message_hook)
self.set_parameters({
@ -5238,6 +5242,7 @@ Brakes have negligible effect (with=%0.2fm without=%0.2fm delta=%0.2fm)
"SCR_VM_I_COUNT": 1000000,
})
self.install_test_modules_context()
self.install_mavlink_module_context()
for script in test_scripts:
self.install_test_script_context(script)
self.reboot_sitl()
@ -5255,9 +5260,21 @@ Brakes have negligible effect (with=%0.2fm without=%0.2fm delta=%0.2fm)
if text in m.text:
script_success = True
success = script_success and success
self.progress("Success")
if not success:
raise NotAchievedException("Scripting internal test failed")
raise NotAchievedException("Failed to receive STATUS_TEXT")
else:
self.progress("Success STATUS_TEXT")
for type in named_value_float_types:
script_success = False
for m in named_value_float:
if type == m.name:
script_success = True
success = script_success and success
if not success:
raise NotAchievedException("Failed to receive NAMED_VALUE_FLOAT")
else:
self.progress("Success NAMED_VALUE_FLOAT")
def test_scripting_hello_world(self):
self.start_subtest("Scripting hello world")