Răsfoiți Sursa

Merge branch 'bugfix/ttfw_idf_port_detecting_hang' into 'master'

fix: running ttfw tests locally hang forever while detecting ports

See merge request espressif/esp-idf!13048
He Yin Ling 4 ani în urmă
părinte
comite
d1ab7fbd5a
1 a modificat fișierele cu 19 adăugiri și 1 ștergeri
  1. 19 1
      tools/ci/python_packages/ttfw_idf/IDFDUT.py

+ 19 - 1
tools/ci/python_packages/ttfw_idf/IDFDUT.py

@@ -369,9 +369,27 @@ class IDFDUT(DUT.SerialDUT):
         with open(output_file, 'wb') as f:
         with open(output_file, 'wb') as f:
             f.write(content)
             f.write(content)
 
 
+    @staticmethod
+    def _sort_usb_ports(ports):
+        """
+        Move the usb ports to the very beginning
+        :param ports: list of ports
+        :return: list of ports with usb ports at beginning
+        """
+        usb_ports = []
+        rest_ports = []
+        for port in ports:
+            if 'usb' in port.lower():
+                usb_ports.append(port)
+            else:
+                rest_ports.append(port)
+        return usb_ports + rest_ports
+
     @classmethod
     @classmethod
     def list_available_ports(cls):
     def list_available_ports(cls):
-        ports = [x.device for x in list_ports.comports()]
+        # It will return other kinds of ports as well, such as ttyS* ports.
+        # Give the usb ports higher priority
+        ports = cls._sort_usb_ports([x.device for x in list_ports.comports()])
         espport = os.getenv('ESPPORT')
         espport = os.getenv('ESPPORT')
         if not espport:
         if not espport:
             # It's a little hard filter out invalid port with `serial.tools.list_ports.grep()`:
             # It's a little hard filter out invalid port with `serial.tools.list_ports.grep()`: