]> granicus.if.org Git - esp-idf/commitdiff
tiny-test-fw: filter out invalid IDF ports
authorHe Yin Ling <heyinling@espressif.com>
Tue, 10 Jul 2018 16:00:40 +0000 (00:00 +0800)
committerHe Yin Ling <heyinling@espressif.com>
Tue, 10 Jul 2018 16:00:40 +0000 (00:00 +0800)
tools/tiny-test-fw/IDF/IDFDUT.py

index b5434d5fbab1de239ab1e056aa0241dd33f5c6f4..8f870fec8bcd273ce42c5db99ac4a649537a3ab6 100644 (file)
@@ -43,6 +43,9 @@ class IDFDUT(DUT.SerialDUT):
     """ IDF DUT, extends serial with ESPTool methods """
 
     CHIP_TYPE_PATTERN = re.compile(r"Detecting chip type[.:\s]+(.+)")
+    # /dev/ttyAMA0 port is listed in Raspberry Pi
+    # /dev/tty.Bluetooth-Incoming-Port port is listed in Mac
+    INVALID_PORT_PATTERN = re.compile(r"AMA|Bluetooth")
 
     def __init__(self, name, port, log_file, app, **kwargs):
         self.download_config, self.partition_table = app.process_app_info()
@@ -133,8 +136,14 @@ class IDFDUT(DUT.SerialDUT):
         ports = [x.device for x in list_ports.comports()]
         espport = os.getenv('ESPPORT')
         if not espport:
-            return ports
-            
+            # It's a little hard filter out invalid port with `serial.tools.list_ports.grep()`:
+            # The check condition in `grep` is: `if r.search(port) or r.search(desc) or r.search(hwid)`.
+            # This means we need to make all 3 conditions fail, to filter out the port.
+            # So some part of the filters will not be straight forward to users.
+            # And negative regular expression (`^((?!aa|bb|cc).)*$`) is not easy to understand.
+            # Filter out invalid port by our own will be much simpler.
+            return [x for x in ports if not cls.INVALID_PORT_PATTERN.search(x)]
+
         port_hint = espport.decode('utf8')
 
         # If $ESPPORT is a valid port, make it appear first in the list