summaryrefslogtreecommitdiff
path: root/test-cli/test/tests/qserial.py
diff options
context:
space:
mode:
Diffstat (limited to 'test-cli/test/tests/qserial.py')
-rw-r--r--test-cli/test/tests/qserial.py22
1 files changed, 14 insertions, 8 deletions
diff --git a/test-cli/test/tests/qserial.py b/test-cli/test/tests/qserial.py
index d798578..67e3af1 100644
--- a/test-cli/test/tests/qserial.py
+++ b/test-cli/test/tests/qserial.py
@@ -6,7 +6,10 @@ import time
class Qserial(unittest.TestCase):
params = None
+ __port = None
+ __baudrate = None
+ #varlist: port, baudrate
def __init__(self, testname, testfunc, varlist):
self.params = varlist
super(Qserial, self).__init__(testfunc)
@@ -14,28 +17,31 @@ class Qserial(unittest.TestCase):
self.__port = varlist["port"]
else:
raise Exception('port param inside Qserial must be defined')
- self.__serial = serial.Serial(self.__port, timeout=1)
+
if "baudrate" in varlist:
self.__baudrate = varlist["baudrate"]
else:
raise Exception('baudrate param inside Qserial must be defined')
self._testMethodDoc = testname
+ # open serial connection
+ self.__serial = serial.Serial(self.__port, self.__baudrate, timeout=1)
+ self.__serial.flushInput()
+ self.__serial.flushOutput()
+
def __del__(self):
self.__serial.close()
def execute(self):
- self.__serial.flushInput()
- self.__serial.flushOutput()
- #generate a random uuid
+ # generate a random uuid
test_uuid = str(uuid.uuid4()).encode()
- #send the uuid through serial port
+ # send the uuid through serial port
self.__serial.write(test_uuid)
time.sleep(0.05) # there might be a small delay
if self.__serial.inWaiting() == 0:
- self.fail("failed: PORT {} wait timeout exceded, wrong communication?".format(self.__port))
+ self.fail("failed: port {} wait timeout exceded".format(self.__port))
else:
# check if what it was sent is equal to what has been received
- if (self.__serial.readline() != test_uuid):
- self.fail("failed: PORT {} write/read mismatch".format(self.__port))
+ if self.__serial.readline() != test_uuid:
+ self.fail("failed: port {} write/read mismatch".format(self.__port))