import sh import unittest 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): # 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: Unable to write on the EEPROM device.")