summaryrefslogtreecommitdiff
path: root/test-cli/test/tests/qmmcflash.py
blob: 0f5a0c1f542e6f660ce0e77add24cc1a7120d597 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import unittest
import scanf
from scanf import scanf
from sh import mmc
from sh import ErrorReturnCode
from test.helpers.utils import save_file_to_disk
from test.helpers.utils import sys_read

class Qmmcflash(unittest.TestCase):
    params = None

    def __init__(self, testname, testfunc, varlist):
        self.params = varlist
        super(Qmmcflash, self).__init__(testfunc)
        self._testMethodDoc = testname
        self.__xmlObj = varlist["xml"]

        self.__QeMMCName = varlist.get('name', 'qemmc')
        self.__emmcDevice = varlist.get('device', self.__xmlObj.getKeyVal(self.__QeMMCName, "device", "mmcblk0"))
        self.__toPath = varlist.get('to', self.__xmlObj.getKeyVal(self.__QeMMCName, "to", "/mnt/station_ramdisk"))
        self.__mmc_res_file = varlist.get('emmc_res_file', self.__xmlObj.getKeyVal(self.__QeMMCName, "emmc_res_file", "emmc_status.txt"))
        self.__mmcPort = varlist.get('mmc_port', self.__xmlObj.getKeyVal(self.__QeMMCName, "mmc_port", "0"))
        self.__mmcID = varlist.get('mmc_id', self.__xmlObj.getKeyVal(self.__QeMMCName, "mmc_id", "0001"))

        self.__resultlist = []

    def execute(self):
        try:
            dataOut = mmc('extcsd', 'read', '/dev/{}'.format(self.__emmcDevice))
            save_file_to_disk(filePath='{}/{}'.format(self.__toPath, self.__mmc_res_file),
                              description='eMMC health test',
                              mime='text/plain',
                              data=dataOut.stdout.decode('utf-8'),
                              result=self.__resultlist)
            sysDevice = "/sys/bus/mmc/drivers/mmcblk/mmc{}:{}".format(self.__mmcPort, self.__mmcID)
            r, data = sys_read("{}/life_time".format(sysDevice))
            if not r:
                self.fail("emmc: life_time not found")
            res = scanf("0x%d 0x%d", data)
            if res[0] > 3 or res[1] > 3:
                self.fail("emmc: review {} life_time > 3".format(sysDevice))
            r, data = sys_read("{}/pre_eol_info".format(sysDevice))
            if not r:
                self.fail("emmc: pre_eol_info not found")
            res = scanf("0x%d", data)
            if res[0] != 1:
                self.fail("emmc: review {} pre_eol_info != 1".format(sysDevice))
        except ErrorReturnCode as Error:
            self.fail("emmc: failed {} ".format(Error.exit_code))

    def getresults(self):
        return self.__resultlist

    def gettextresult(self):
        return ""