M test/harness/harness.py => test/harness/harness.py +14 -0
@@ 20,6 20,19 @@ class Harness:
self.port_name = port
self.connection = serial.CDCSerial(port)
+ @classmethod
+ def from_detect(cls):
+ '''
+ Try to instantiate from first detected device.
+ Do not use this method if you need >1 unique devices.
+ '''
+ found = serial.CDCSerial.find_Pures()
+ if found:
+ port = found[0]
+ return cls(found[0])
+ else:
+ raise TestError(Error.PORT_NOT_FOUND)
+
def get_connection(self):
return self.connection
@@ 71,3 84,4 @@ class Harness:
"body": body
})
return ret
+
M test/harness/interface/CDCSerial.py => test/harness/interface/CDCSerial.py +11 -3
@@ 28,14 28,14 @@ class CDCSerial:
try:
self.serial = serial.Serial(port_name, baudrate=115200, timeout=10)
self.serial.flushInput()
- log.info("port opened!")
+ log.info(f"opened port {port_name}!")
break
except (FileNotFoundError, serial.serialutil.SerialException) as err:
- log.error("can't open {}, retrying...".format(port_name))
+ log.error(f"can't open {port_name}, retrying...")
time.sleep(1)
self.timeout = self.timeout - 1
if self.timeout == 0:
- log.error("uart {} not found - probably OS did not boot".format(port_name))
+ log.error(f"uart {port_name} not found - probably OS did not boot")
raise TestError(Error.PORT_NOT_FOUND)
def __del__(self):
@@ 130,3 130,11 @@ class CDCSerial:
ret = self.write(self.__wrap_message(body))
return ret["body"]["isLocked"]
+
+ @staticmethod
+ def find_Pures() -> str:
+ '''
+ Return a list of paths (str) to any Mudita Pure phone found connected to the system
+ '''
+ import serial.tools.list_ports as list_ports
+ return [_.device for _ in list_ports.comports() if _.manufacturer == 'Mudita' and _.product == 'Mudita Pure']