from test.helpers.syscmd import SysCommand import unittest import uuid class Qeeprom(unittest.TestCase): def __init__(self, testname, testfunc): super(Qeeprom, self).__init__(testfunc) self._testMethodDoc = testname 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") else: self.fail("failed: could not complete find eeprom command")