From 9332c933fc05f42882640c9a4e35fab09854af84 Mon Sep 17 00:00:00 2001 From: Manel Caro Date: Sat, 9 Mar 2019 21:25:56 +0100 Subject: Board: Client Test Suite Initial Commit --- test-cli/test/tests/qi2c.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 test-cli/test/tests/qi2c.py (limited to 'test-cli/test/tests/qi2c.py') diff --git a/test-cli/test/tests/qi2c.py b/test-cli/test/tests/qi2c.py new file mode 100644 index 0000000..409005c --- /dev/null +++ b/test-cli/test/tests/qi2c.py @@ -0,0 +1,29 @@ +from test.helpers.syscmd import SysCommand +import unittest + +class Qi2c(unittest.TestCase): + + def __init__(self, testname, testfunc, busnum, register): + super(Qi2c, self).__init__(testfunc) + self.__busnum = busnum + self.__register = register.split("/") + self.__devices=[] + self._testMethodDoc = testname + + def execute(self): + str_cmd= "i2cdetect -a -y -r {}".format(self.__busnum) + i2c_command = SysCommand("i2cdetect", str_cmd) + if i2c_command.execute() == 0: + self.__raw_out = i2c_command.getOutput() + if self.__raw_out == "": + return -1 + lines=self.__raw_out.decode('ascii').splitlines() + for i in range(len(lines)): + if (lines[i].count('UU')): + if (lines[i].find("UU")): + self.__devices.append("0x{}{}".format((i - 1), hex(int((lines[i].find("UU") - 4) / 3)).split('x')[-1])) + for i in range(len(self.__register)): + if not(self.__register[i] in self.__devices): + self.fail("failed: device {} not found in bus i2c-{}".format(self.__register[i], self.__busnum)) + else: + self.fail("failed: could not complete i2cdedtect command") -- cgit v1.1