summaryrefslogtreecommitdiff
path: root/test-cli/test/tests/qeeprom.py
blob: cafbc7f64da55527491e04abb97fa808f9b423b5 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import sh
import unittest


class Qeeprom(unittest.TestCase):
    params = None
    __position = None
    __eeprompath = None
    __resultlist = None  # resultlist is a python list of python dictionaries

    # varlist: position,  eeprompath
    def __init__(self, testname, testfunc, varlist):
        self.params = varlist
        super(Qeeprom, self).__init__(testfunc)
        self._testMethodDoc = testname
        self.__resultlist = []
        if "position" in varlist:
            self.__position = varlist["position"]
        else:
            raise Exception('position 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):
        # generate some data
        data_tx = "isee_test"
        # write data into the eeprom
        p = sh.dd(sh.echo(data_tx), "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=" + str(len(data_tx)))
            if p.exit_code == 0:
                data_rx = p.stdout.decode('ascii')
                # compare both values
                if data_rx != data_tx:
                    # Both data are different
                    self.__resultlist.append(
                        {
                            "desc": "Test result",
                            "data": "FAILED: mismatch between written and received values.",
                            "type": "string"
                        }
                    )
                    self.fail("failed: mismatch between written and received values.")
            else:
                self.__resultlist.append(
                    {
                        "desc": "Test result",
                        "data": "FAILED: Unable to read from the EEPROM device.",
                        "type": "string"
                    }
                )
                self.fail("failed: Unable to read from the EEPROM device.")
        else:
            self.__resultlist.append(
                {
                    "desc": "Test result",
                    "data": "FAILED: Unable to write on the EEPROM device.",
                    "type": "string"
                }
            )
            self.fail("failed: Unable to write on the EEPROM device.")

        # Test successful
        self.__resultlist.append(
            {
                "desc": "Test result",
                "data": "OK",
                "type": "string"
            }
        )

    def getresults(self):
        return self.__resultlist