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.py62
1 files changed, 34 insertions, 28 deletions
diff --git a/test-cli/test/tests/qeeprom.py b/test-cli/test/tests/qeeprom.py
index 2bab248..5bb0755 100644
--- a/test-cli/test/tests/qeeprom.py
+++ b/test-cli/test/tests/qeeprom.py
@@ -1,38 +1,44 @@
-from test.helpers.syscmd import SysCommand
+import sh
import unittest
-import uuid
+
class Qeeprom(unittest.TestCase):
+ __position = None
+ __uuid = None
+ __eeprompath = None
+
+ # varlist: position, uuid, eeprompath
def __init__(self, testname, testfunc, varlist):
super(Qeeprom, self).__init__(testfunc)
self._testMethodDoc = testname
+ if "position" in varlist:
+ self.__position = varlist["position"]
+ else:
+ raise Exception('position param inside Qeeprom must be defined')
+ if "uuid" in varlist:
+ self.__uuid = varlist["uuid"]
+ else:
+ raise Exception('uuid 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 execute(self):
- str_cmd = "find /sys/ -iname 'eeprom'"
- eeprom_location = SysCommand("eeprom_location", str_cmd)
- if eeprom_location.execute() == 0:
- self.__raw_out = eeprom_location.getOutput()
- if self.__raw_out == "":
- self.fail("Unable to get EEPROM location. IS EEPROM CONNECTED?")
- return -1
- eeprom=self.__raw_out.decode('ascii')
- test_uuid = uuid.uuid4()
- str_cmd="echo '{}' > {}".format(str(test_uuid), eeprom)
- eeprom_write = SysCommand("eeprom_write", str_cmd)
- if eeprom_write.execute() == 0:
- self.__raw_out = eeprom_write.getOutput()
- if self.__raw_out == "":
- self.fail("Unable to write on the EEPROM?")
- return -1
- str_cmd = "head -2 {}".format(eeprom)
- eeprom_read = SysCommand("eeprom_read", str_cmd)
- if eeprom_read.execute() == 0:
- self.__raw_out = eeprom_read.getOutput()
- if self.__raw_out == "":
- self.fail("Unable to read from the EEPROM?")
- return -1
- if(str(self.__raw_out).find(str(test_uuid)) == -1):
- self.fail("failed: READ/WRITE mismatch")
+ # write data into the eeprom
+ p = sh.dd(sh.echo(self._uuid), "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=" + len(self.__uuid))
+ if p.exit_code == 0:
+ uuid_rx = p.stdout.decode('ascii')
+ # compare both values
+ if (uuid_rx != self.__uuid):
+ self.fail("failed: mismatch between written and received values.")
+
+ else:
+ self.fail("failed: Unable to read from the EEPROM device.")
else:
- self.fail("failed: could not complete find eeprom command")
+ self.fail("failed: Unable to write on the EEPROM device.")
+