mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-12-26 23:05:05 +03:00
[FL-3421] Unit bench: multiple attempts to find flipper (#2960)
* Unit bench: added retry count for finding flipper for reboot/reboot2dfu and power off scripts. Changed returns to sys.exit() since scripts are being used standalone * fixed typo in await flipper and changed debug level to info for searching flipper in power.py * reversed return operator instead of sys.exit, changed app.py exit behavior * test run to see if exit(1) fails the run * reversed test changes, fixed flipper name and increased await flipper timeout * await after flash increase * increased serial timeout * increased serial timeout, apparently it is for entire run Co-authored-by: doomwastaken <k.volkov@flipperdevices.com> Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
parent
15f92f765d
commit
4ade0fc76d
3
.github/workflows/unit_tests.yml
vendored
3
.github/workflows/unit_tests.yml
vendored
@ -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
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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}")
|
||||
|
||||
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user