import unittest import sh import uuid from test.helpers.utils import save_file_to_disk class Qnand(unittest.TestCase): params = None __device = "10M" __resultlist = None # resultlist is a python list of python dictionaries # varlist: device def __init__(self, testname, testfunc, varlist): self.params = varlist super(Qnand, self).__init__(testfunc) self._testMethodDoc = testname self.__xmlObj = varlist["xml"] self.__QNandName = varlist.get('name', 'qnand') self.__device = varlist.get('device', self.__xmlObj.getKeyVal(self.__QNandName, "device", "/dev/mtd0")) self.__nand_res_file = varlist.get('nand_res_file', self.__xmlObj.getKeyVal(self.__QNandName, "nand_res_file", "nand_test_{}.txt")) self.__toPath = varlist.get('to', self.__xmlObj.getKeyVal(self.__QNandName, "to", "/mnt/station_ramdisk")) self.__file_uuid = uuid.uuid4() self.__nand_res_file = self.__nand_res_file.format(self.__file_uuid) nandtestPath = self.__xmlObj.getKeyVal("qnand", "nandtestPath", '/root/hwtest-files/nandtest"') if nandtestPath == '': self.myNandTest = sh.nandtest else: self.myNandTest = sh.Command(nandtestPath) self.__resultlist = [] def execute(self): try: res = self.myNandTest("-m", self.__device) save_file_to_disk(filePath='{}/{}'.format(self.__toPath, self.__nand_res_file), description='nand {} test'.format(self.__device), mime='text/plain', data=res.stdout.decode('utf-8'), result=self.__resultlist) except sh.ErrorReturnCode_1 as e: self.fail("nandtest failed: {}".format(e.ErrorReturnCode.stdout)) def getresults(self): return self.__resultlist def gettextresult(self): return ""