summaryrefslogtreecommitdiff
path: root/test-cli/test/tests/qeeprom.py
blob: 2bab248fa2ecf6c3237782af57055b52181b5690 (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
from test.helpers.syscmd import SysCommand
import unittest
import uuid

class Qeeprom(unittest.TestCase):

    def __init__(self, testname, testfunc, varlist):
        super(Qeeprom, self).__init__(testfunc)
        self._testMethodDoc = testname

    def execute(self):
        str_cmd = "find /sys/ -iname 'eeprom'"
        eeprom_location = SysCommand("eeprom_location", str_cmd)
        if eeprom_location.execute() == 0:
            self.__raw_out = eeprom_location.getOutput()
            if self.__raw_out == "":
                self.fail("Unable to get EEPROM location. IS EEPROM CONNECTED?")
                return -1
            eeprom=self.__raw_out.decode('ascii')
            test_uuid = uuid.uuid4()
            str_cmd="echo '{}' > {}".format(str(test_uuid), eeprom)
            eeprom_write = SysCommand("eeprom_write", str_cmd)
            if eeprom_write.execute() == 0:
                self.__raw_out = eeprom_write.getOutput()
                if self.__raw_out == "":
                    self.fail("Unable to write on the EEPROM?")
                    return -1
                str_cmd = "head -2 {}".format(eeprom)
                eeprom_read = SysCommand("eeprom_read", str_cmd)
                if eeprom_read.execute() == 0:
                    self.__raw_out = eeprom_read.getOutput()
                    if self.__raw_out == "":
                        self.fail("Unable to read from the EEPROM?")
                        return -1
                    if(str(self.__raw_out).find(str(test_uuid)) == -1):
                        self.fail("failed: READ/WRITE mismatch")
        else:
            self.fail("failed: could not complete find eeprom command")