[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'
 | 
					      - name: 'Copy assets and unit data, reboot and wait for flipper'
 | 
				
			||||||
        id: copy
 | 
					        id: copy
 | 
				
			||||||
        if: steps.format_ext.outcome == 'success'
 | 
					        if: steps.format_ext.outcome == 'success'
 | 
				
			||||||
        timeout-minutes: 5
 | 
					        timeout-minutes: 7
 | 
				
			||||||
        run: |
 | 
					        run: |
 | 
				
			||||||
          source scripts/toolchain/fbtenv.sh
 | 
					          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/resources /ext
 | 
				
			||||||
          python3 scripts/storage.py -p ${{steps.device.outputs.flipper}} -f send assets/unit_tests /ext/unit_tests
 | 
					          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
 | 
					          python3 scripts/power.py -p ${{steps.device.outputs.flipper}} reboot
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,8 @@
 | 
				
			|||||||
#!/usr/bin/env python3
 | 
					#!/usr/bin/env python3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import time
 | 
				
			||||||
 | 
					from typing import Optional
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from flipper.app import App
 | 
					from flipper.app import App
 | 
				
			||||||
from flipper.storage import FlipperStorage
 | 
					from flipper.storage import FlipperStorage
 | 
				
			||||||
from flipper.utils.cdc import resolve_port
 | 
					from flipper.utils.cdc import resolve_port
 | 
				
			||||||
@ -27,8 +30,20 @@ class Main(App):
 | 
				
			|||||||
        )
 | 
					        )
 | 
				
			||||||
        self.parser_reboot2dfu.set_defaults(func=self.reboot2dfu)
 | 
					        self.parser_reboot2dfu.set_defaults(func=self.reboot2dfu)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _get_flipper(self):
 | 
					    def _get_flipper(self, retry_count: Optional[int] = 1):
 | 
				
			||||||
        if not (port := resolve_port(self.logger, self.args.port)):
 | 
					        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
 | 
					            return None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        flipper = FlipperStorage(port)
 | 
					        flipper = FlipperStorage(port)
 | 
				
			||||||
@ -36,28 +51,28 @@ class Main(App):
 | 
				
			|||||||
        return flipper
 | 
					        return flipper
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def power_off(self):
 | 
					    def power_off(self):
 | 
				
			||||||
        if not (flipper := self._get_flipper()):
 | 
					        if not (flipper := self._get_flipper(retry_count=10)):
 | 
				
			||||||
            return 1
 | 
					            return 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.logger.debug("Powering off")
 | 
					        self.logger.info("Powering off")
 | 
				
			||||||
        flipper.send("power off" + "\r")
 | 
					        flipper.send("power off" + "\r")
 | 
				
			||||||
        flipper.stop()
 | 
					        flipper.stop()
 | 
				
			||||||
        return 0
 | 
					        return 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def reboot(self):
 | 
					    def reboot(self):
 | 
				
			||||||
        if not (flipper := self._get_flipper()):
 | 
					        if not (flipper := self._get_flipper(retry_count=10)):
 | 
				
			||||||
            return 1
 | 
					            return 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.logger.debug("Rebooting")
 | 
					        self.logger.info("Rebooting")
 | 
				
			||||||
        flipper.send("power reboot" + "\r")
 | 
					        flipper.send("power reboot" + "\r")
 | 
				
			||||||
        flipper.stop()
 | 
					        flipper.stop()
 | 
				
			||||||
        return 0
 | 
					        return 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def reboot2dfu(self):
 | 
					    def reboot2dfu(self):
 | 
				
			||||||
        if not (flipper := self._get_flipper()):
 | 
					        if not (flipper := self._get_flipper(retry_count=10)):
 | 
				
			||||||
            return 1
 | 
					            return 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.logger.debug("Rebooting to DFU")
 | 
					        self.logger.info("Rebooting to DFU")
 | 
				
			||||||
        flipper.send("power reboot2dfu" + "\r")
 | 
					        flipper.send("power reboot2dfu" + "\r")
 | 
				
			||||||
        flipper.stop()
 | 
					        flipper.stop()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -22,14 +22,14 @@ def flp_serial_by_name(flp_name):
 | 
				
			|||||||
    if os.path.exists(flp_serial):
 | 
					    if os.path.exists(flp_serial):
 | 
				
			||||||
        return flp_serial
 | 
					        return flp_serial
 | 
				
			||||||
    else:
 | 
					    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):
 | 
					        if os.path.exists(flp_name):
 | 
				
			||||||
            return flp_name
 | 
					            return flp_name
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            return ""
 | 
					            return ""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
UPDATE_TIMEOUT = 60 * 4  # 4 minutes
 | 
					UPDATE_TIMEOUT = 30 * 4  # 4 minutes
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def main():
 | 
					def main():
 | 
				
			||||||
@ -50,7 +50,7 @@ def main():
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    if flipper == "":
 | 
					    if flipper == "":
 | 
				
			||||||
        logging.error("Flipper not found!")
 | 
					        logging.error("Flipper not found!")
 | 
				
			||||||
        sys.exit(1)
 | 
					        exit(1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    logging.info(f"Found Flipper at {flipper}")
 | 
					    logging.info(f"Found Flipper at {flipper}")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -20,14 +20,12 @@ def main():
 | 
				
			|||||||
        logging.error("Flipper not found!")
 | 
					        logging.error("Flipper not found!")
 | 
				
			||||||
        sys.exit(1)
 | 
					        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}")
 | 
					        logging.info(f"Found Flipper at {flp_serial}")
 | 
				
			||||||
        flipper.baudrate = 230400
 | 
					        flipper.baudrate = 230400
 | 
				
			||||||
        flipper.flushOutput()
 | 
					        flipper.flushOutput()
 | 
				
			||||||
        flipper.flushInput()
 | 
					        flipper.flushInput()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        flipper.timeout = 300
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        flipper.read_until(b">: ").decode("utf-8")
 | 
					        flipper.read_until(b">: ").decode("utf-8")
 | 
				
			||||||
        flipper.write(b"unit_tests\r")
 | 
					        flipper.write(b"unit_tests\r")
 | 
				
			||||||
        data = flipper.read_until(b">: ").decode("utf-8")
 | 
					        data = flipper.read_until(b">: ").decode("utf-8")
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user