diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 2e6336c07..794dce37f 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -45,9 +45,10 @@ jobs: - name: 'Copy assets and unit data, reboot and wait for flipper' id: copy if: steps.format_ext.outcome == 'success' - timeout-minutes: 5 + timeout-minutes: 7 run: | source scripts/toolchain/fbtenv.sh + python3 scripts/testing/await_flipper.py ${{steps.device.outputs.flipper}} python3 scripts/storage.py -p ${{steps.device.outputs.flipper}} -f send assets/resources /ext python3 scripts/storage.py -p ${{steps.device.outputs.flipper}} -f send assets/unit_tests /ext/unit_tests python3 scripts/power.py -p ${{steps.device.outputs.flipper}} reboot diff --git a/scripts/power.py b/scripts/power.py index 45a130c59..50bb2d4f7 100755 --- a/scripts/power.py +++ b/scripts/power.py @@ -1,5 +1,8 @@ #!/usr/bin/env python3 +import time +from typing import Optional + from flipper.app import App from flipper.storage import FlipperStorage from flipper.utils.cdc import resolve_port @@ -27,8 +30,20 @@ class Main(App): ) self.parser_reboot2dfu.set_defaults(func=self.reboot2dfu) - def _get_flipper(self): - if not (port := resolve_port(self.logger, self.args.port)): + def _get_flipper(self, retry_count: Optional[int] = 1): + port = None + self.logger.info(f"Attempting to find flipper with {retry_count} attempts.") + + for i in range(retry_count): + time.sleep(1) + self.logger.info(f"Attempting to find flipper #{i}.") + + if port := resolve_port(self.logger, self.args.port): + self.logger.info(f"Found flipper at {port}") + break + + if not port: + self.logger.info(f"Failed to find flipper") return None flipper = FlipperStorage(port) @@ -36,28 +51,28 @@ class Main(App): return flipper def power_off(self): - if not (flipper := self._get_flipper()): + if not (flipper := self._get_flipper(retry_count=10)): return 1 - self.logger.debug("Powering off") + self.logger.info("Powering off") flipper.send("power off" + "\r") flipper.stop() return 0 def reboot(self): - if not (flipper := self._get_flipper()): + if not (flipper := self._get_flipper(retry_count=10)): return 1 - self.logger.debug("Rebooting") + self.logger.info("Rebooting") flipper.send("power reboot" + "\r") flipper.stop() return 0 def reboot2dfu(self): - if not (flipper := self._get_flipper()): + if not (flipper := self._get_flipper(retry_count=10)): return 1 - self.logger.debug("Rebooting to DFU") + self.logger.info("Rebooting to DFU") flipper.send("power reboot2dfu" + "\r") flipper.stop() diff --git a/scripts/testing/await_flipper.py b/scripts/testing/await_flipper.py index ea07d6be7..f8dffeb66 100755 --- a/scripts/testing/await_flipper.py +++ b/scripts/testing/await_flipper.py @@ -22,14 +22,14 @@ def flp_serial_by_name(flp_name): if os.path.exists(flp_serial): return flp_serial else: - logging.info(f"Couldn't find {logging.info} on this attempt.") + logging.info(f"Couldn't find {flp_name} on this attempt.") if os.path.exists(flp_name): return flp_name else: return "" -UPDATE_TIMEOUT = 60 * 4 # 4 minutes +UPDATE_TIMEOUT = 30 * 4 # 4 minutes def main(): @@ -50,7 +50,7 @@ def main(): if flipper == "": logging.error("Flipper not found!") - sys.exit(1) + exit(1) logging.info(f"Found Flipper at {flipper}") diff --git a/scripts/testing/units.py b/scripts/testing/units.py index fd8e29a73..db302e9da 100755 --- a/scripts/testing/units.py +++ b/scripts/testing/units.py @@ -20,14 +20,12 @@ def main(): logging.error("Flipper not found!") sys.exit(1) - with serial.Serial(flp_serial, timeout=10) as flipper: + with serial.Serial(flp_serial, timeout=150) as flipper: logging.info(f"Found Flipper at {flp_serial}") flipper.baudrate = 230400 flipper.flushOutput() flipper.flushInput() - flipper.timeout = 300 - flipper.read_until(b">: ").decode("utf-8") flipper.write(b"unit_tests\r") data = flipper.read_until(b">: ").decode("utf-8")