summaryrefslogtreecommitdiff
path: root/test-cli/test/tests/qeeprom.py
diff options
context:
space:
mode:
Diffstat (limited to 'test-cli/test/tests/qeeprom.py')
-rw-r--r--test-cli/test/tests/qeeprom.py77
1 files changed, 48 insertions, 29 deletions
diff --git a/test-cli/test/tests/qeeprom.py b/test-cli/test/tests/qeeprom.py
index 7fc9fcd..7900381 100644
--- a/test-cli/test/tests/qeeprom.py
+++ b/test-cli/test/tests/qeeprom.py
@@ -1,46 +1,65 @@
-import sh
import unittest
-
+import os
class Qeeprom(unittest.TestCase):
params = None
- __position = None
- __eeprompath = None
__resultlist = None # resultlist is a python list of python dictionaries
+ __QEepromName = None
+ __i2cBus = None
+ __device = None
# varlist: position, eeprompath
def __init__(self, testname, testfunc, varlist):
self.params = varlist
super(Qeeprom, self).__init__(testfunc)
self._testMethodDoc = testname
+ self.__xmlObj = varlist["xml"]
+ self.__QEepromName = varlist.get('name', 'qeeprom')
+ self.__i2cAddress = varlist.get('i2c_address', self.__xmlObj.getKeyVal(self.__QEepromName, "i2c_address", "0050"))
+ self.__i2cBus = varlist.get('i2c_bus', self.__xmlObj.getKeyVal(self.__QEepromName, "i2c_bus", "0"))
+ self.__device = '/sys/bus/i2c/devices/{}-{}/eeprom'.format(self.__i2cBus, self.__i2cAddress)
+
self.__resultlist = []
- if "position" in varlist:
- self.__position = varlist["position"]
- else:
- raise Exception('position param inside Qeeprom must be defined')
- if "eeprompath" in varlist:
- self.__eeprompath = varlist["eeprompath"]
- else:
- raise Exception('eeprompath param inside Qeeprom must be defined')
+
+ def __check_device(self):
+ if os.path.isfile(self.__device):
+ return True
+ return False
+
+ def __eeprom_write(self, data):
+ try:
+ f = open(self.__device, "wb")
+ f.write(data)
+ f.close()
+ except IOError as Error:
+ return False, '{}'.format(Error.errno)
+ return True, ''
+
+ def __eeprom_read(self, size):
+ try:
+ f = open(self.__device, "rb")
+ data = f.read(size)
+ f.close()
+ except IOError as Error:
+ return False, '{}'.format(Error.errno)
+ return True, data
+
def execute(self):
- # generate some data
- data_tx = "isee_test"
- # write data into the eeprom
- p = sh.dd(sh.echo(data_tx), "of=" + self.__eeprompath, "bs=1", "seek=" + self.__position)
- if p.exit_code == 0:
- # read data from the eeprom
- p = sh.dd("if=" + self.__eeprompath, "bs=1", "skip=" + self.__position, "count=" + str(len(data_tx)))
- if p.exit_code == 0:
- data_rx = p.stdout.decode('ascii')
- # compare both values
- if data_rx != data_tx:
- # Both data are different
- self.fail("failed: mismatch between written and received values.")
- else:
- self.fail("failed: Unable to read from the EEPROM device.")
- else:
- self.fail("failed: Unable to write on the EEPROM device.")
+ if not self.__check_device():
+ self.fail("cannot open device {}".format(self.__device))
+
+ data = bytes('AbcDeFgHijK098521', 'utf-8')
+
+ v, w = self.__eeprom_write(data)
+ if not v:
+ self.fail("eeprom: {} write test failed".format(w))
+ v, r = self.__eeprom_read(len(data))
+ if not v:
+ self.fail("eeprom: {} read test failed".format(r))
+ if r != data:
+ self.fail("mismatch between write and read bytes")
+
def getresults(self):
return self.__resultlist