From 602f5bc61c260b11e8b61dcba68f4e898a54ee4f Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Mon, 29 Jul 2024 15:48:45 +1000 Subject: [PATCH] autotest: correct applet-testing scripts to use contexts for scripts means we don't leave the script lying around in case of test failure --- Tools/autotest/arduplane.py | 6 ++---- Tools/autotest/quadplane.py | 29 +++++----------------------- Tools/autotest/vehicle_test_suite.py | 4 ++-- 3 files changed, 9 insertions(+), 30 deletions(-) diff --git a/Tools/autotest/arduplane.py b/Tools/autotest/arduplane.py index 2af157ab9c..e734d4f83c 100644 --- a/Tools/autotest/arduplane.py +++ b/Tools/autotest/arduplane.py @@ -5077,8 +5077,8 @@ class AutoTestPlane(vehicle_test_suite.TestSuite): wipe=True) self.context_push() - self.install_applet_script(applet_script) - self.install_applet_script(airshow, install_name=trick72) + self.install_applet_script_context(applet_script) + self.install_applet_script_context(airshow, install_name=trick72) self.context_collect('STATUSTEXT') self.reboot_sitl() @@ -5124,8 +5124,6 @@ class AutoTestPlane(vehicle_test_suite.TestSuite): self.progress("Finished trick, max error=%.1fm" % highest_error) self.disarm_vehicle(force=True) - self.remove_installed_script(applet_script) - self.remove_installed_script(trick72) messages = self.context_collection('STATUSTEXT') self.context_pop() self.reboot_sitl() diff --git a/Tools/autotest/quadplane.py b/Tools/autotest/quadplane.py index 6b5730eba7..1395e245c2 100644 --- a/Tools/autotest/quadplane.py +++ b/Tools/autotest/quadplane.py @@ -1308,9 +1308,7 @@ class AutoTestQuadPlane(vehicle_test_suite.TestSuite): def VTOLQuicktune(self): '''VTOL Quicktune''' - applet_script = "VTOL-quicktune.lua" - - self.install_applet_script(applet_script) + self.install_applet_script_context("VTOL-quicktune.lua") self.set_parameters({ "SCR_ENABLE": 1, @@ -1320,7 +1318,6 @@ class AutoTestQuadPlane(vehicle_test_suite.TestSuite): self.reboot_sitl() - self.context_push() self.context_collect('STATUSTEXT') self.set_parameters({ "QUIK_ENABLE" : 1, @@ -1352,16 +1349,11 @@ class AutoTestQuadPlane(vehicle_test_suite.TestSuite): self.change_mode("QLAND") self.wait_disarmed(timeout=120) - self.set_parameter("QUIK_ENABLE", 0) - self.context_pop() - self.remove_installed_script(applet_script) - self.reboot_sitl() def PrecisionLanding(self): '''VTOL precision landing''' - applet_script = "plane_precland.lua" - self.install_applet_script(applet_script) + self.install_applet_script_context("plane_precland.lua") here = self.mav.location() target = self.offset_location_ne(here, 20, 0) @@ -1385,13 +1377,13 @@ class AutoTestQuadPlane(vehicle_test_suite.TestSuite): self.reboot_sitl() - self.context_push() - self.context_collect('STATUSTEXT') self.set_parameters({ "PLND_ALT_CUTOFF" : 5, "SIM_SPEEDUP" : 10, }) + self.context_collect('STATUSTEXT') + self.scripting_restart() self.wait_text("PLND: Loaded", check_context=True) @@ -1412,15 +1404,9 @@ class AutoTestQuadPlane(vehicle_test_suite.TestSuite): if error > 2: raise NotAchievedException("too far from target %.1fm" % error) - self.context_pop() - self.remove_installed_script(applet_script) - self.reboot_sitl() - def ShipLanding(self): '''ship landing test''' - applet_script = "plane_ship_landing.lua" - - self.install_applet_script(applet_script) + self.install_applet_script_context("plane_ship_landing.lua") self.set_parameters({ "SCR_ENABLE": 1, @@ -1438,7 +1424,6 @@ class AutoTestQuadPlane(vehicle_test_suite.TestSuite): self.reboot_sitl(check_position=False) - self.context_push() self.context_collect('STATUSTEXT') self.set_parameters({ "SHIP_ENABLE" : 1, @@ -1467,10 +1452,6 @@ class AutoTestQuadPlane(vehicle_test_suite.TestSuite): # with the deck self.wait_groundspeed(4.8, 5.2) - self.context_pop() - self.remove_installed_script(applet_script) - self.reboot_sitl(check_position=False) - def RCDisableAirspeedUse(self): '''check disabling airspeed using RC switch''' self.set_parameter("RC9_OPTION", 106) diff --git a/Tools/autotest/vehicle_test_suite.py b/Tools/autotest/vehicle_test_suite.py index 4e43d048bb..7d2d6055ba 100644 --- a/Tools/autotest/vehicle_test_suite.py +++ b/Tools/autotest/vehicle_test_suite.py @@ -4831,10 +4831,10 @@ class TestSuite(ABC): self.install_mavlink_module() self.context_get().installed_modules.append("mavlink") - def install_applet_script_context(self, scriptname): + def install_applet_script_context(self, scriptname, **kwargs): '''installs an applet script which will be removed when the context goes away''' - self.install_applet_script(scriptname) + self.install_applet_script(scriptname, **kwargs) self.context_get().installed_scripts.append(scriptname) def rootdir(self):