summaryrefslogtreecommitdiff
path: root/test-cli/test/tests/qnand.py
blob: 6de1eaf8e15595de0a972062a744f26697f0c05a (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
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 ""