diff --git a/Tools/autotest/arducopter.py b/Tools/autotest/arducopter.py index f202f121b7..65af43f7d2 100644 --- a/Tools/autotest/arducopter.py +++ b/Tools/autotest/arducopter.py @@ -107,6 +107,8 @@ class AutoTestCopter(AutoTest): self.progress("WAITING FOR PARAMETERS") self.mavproxy.expect('Received [0-9]+ parameters') + self.get_mavlink_connection_going() + self.apply_defaultfile_parameters() util.expect_setup_callback(self.mavproxy, self.expect_callback) @@ -116,8 +118,6 @@ class AutoTestCopter(AutoTest): self.progress("Started simulator") - self.get_mavlink_connection_going() - self.hasInit = True self.progress("Ready to start testing!") diff --git a/Tools/autotest/ardusub.py b/Tools/autotest/ardusub.py index 968088a0d0..0eb862c003 100644 --- a/Tools/autotest/ardusub.py +++ b/Tools/autotest/ardusub.py @@ -153,6 +153,15 @@ class AutoTestSub(AutoTest): if ex is not None: raise ex + def reboot_sitl(self): + """Reboot SITL instance and wait it to reconnect.""" + self.mavproxy.send("reboot\n") + self.mavproxy.expect("Initialising APM") + # empty mav to avoid getting old timestamps: + while self.mav.recv_match(blocking=False): + pass + self.initialise_after_reboot_sitl() + def autotest(self): """Autotest ArduSub in SITL.""" self.check_test_syntax(test_file=os.path.realpath(__file__)) diff --git a/Tools/autotest/common.py b/Tools/autotest/common.py index 396371de84..fa67b214d3 100644 --- a/Tools/autotest/common.py +++ b/Tools/autotest/common.py @@ -198,22 +198,33 @@ class AutoTest(ABC): def reboot_sitl(self): """Reboot SITL instance and wait it to reconnect.""" + old_bootcount= self.get_parameter('STAT_BOOTCNT') self.mavproxy.send("reboot\n") - self.mavproxy.expect("Initialising APM") - # empty mav to avoid getting old timestamps: - if self.mav is not None: - while self.mav.recv_match(blocking=False): + tstart = self.get_sim_time() + while True: + if self.get_sim_time() - tstart > 10: + raise AutoTestTimeoutException("Did not detect reboot") + try: + if self.get_parameter('STAT_BOOTCNT', timeout=1) != old_bootcount: + break + except NotAchievedException: pass + + # empty mav to avoid getting old timestamps: + while self.mav.recv_match(blocking=False): + pass + + self.initialise_after_reboot_sitl() + + def initialise_after_reboot_sitl(self): + # after reboot stream-rates may be zero. Prompt MAVProxy to # send a rate-change message by changing away from our normal # stream rates and back again: - if self.mav is not None: - tstart = self.get_sim_time() + tstart = self.get_sim_time() while True: self.mavproxy.send("set streamrate %u\n" % (self.sitl_streamrate()+1)) - if self.mav is None: - break if self.get_sim_time() - tstart > 10: raise AutoTestTimeoutException("SYSTEM_TIME not received")