summaryrefslogtreecommitdiff
path: root/test-cli/test/tests/qusb.py
diff options
context:
space:
mode:
authorManel Caro <mcaro@iseebcn.com>2019-03-09 21:25:56 +0100
committerManel Caro <mcaro@iseebcn.com>2019-03-09 21:25:56 +0100
commit9332c933fc05f42882640c9a4e35fab09854af84 (patch)
tree2b9b00b5a411b27f9705603c0d93b8925afd4677 /test-cli/test/tests/qusb.py
downloadboard-9332c933fc05f42882640c9a4e35fab09854af84.zip
board-9332c933fc05f42882640c9a4e35fab09854af84.tar.gz
board-9332c933fc05f42882640c9a4e35fab09854af84.tar.bz2
Board: Client Test Suite Initial Commit
Diffstat (limited to 'test-cli/test/tests/qusb.py')
-rw-r--r--test-cli/test/tests/qusb.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/test-cli/test/tests/qusb.py b/test-cli/test/tests/qusb.py
new file mode 100644
index 0000000..44490bc
--- /dev/null
+++ b/test-cli/test/tests/qusb.py
@@ -0,0 +1,60 @@
+from test.helpers.syscmd import SysCommand
+import unittest
+
+class Qusb(unittest.TestCase):
+
+ def __init__(self, testname, testfunc, devLabel, numPorts):
+ super(Qusb, self).__init__(testfunc)
+ self.__numPorts = numPorts
+ self._testMethodDoc = testname
+ self.__devLabel = devLabel
+ if testname=="USBOTG":
+ self.__usbFileName = "/this_is_an_usb_otg"
+ self.__usbtext = "USBOTG"
+ elif testname=="SATA":
+ self.__usbFileName = "/this_is_a_sata"
+ self.__usbtext = "SATA"
+ else:
+ self.__usbFileName = "/this_is_an_usb_host"
+ self.__usbtext = "USBHOST"
+ self.__numUsbFail=[]
+
+ def execute(self):
+ str_cmd= "lsblk -o LABEL"
+ lsblk_command = SysCommand("lsblk", str_cmd)
+ if lsblk_command.execute() == 0:
+ self.__raw_out = lsblk_command.getOutput()
+ if self.__raw_out == "":
+ return -1
+ lines = lsblk_command.getOutput().splitlines()
+ host_list=[]
+ for i in range(len(lines)):
+ if str(lines[i].decode('ascii'))==self.__devLabel:
+ host_list.append(i)
+ if len(host_list)==int(self.__numPorts):
+ str_cmd = "lsblk -o MOUNTPOINT"
+ lsblk_command = SysCommand("lsblk", str_cmd)
+ if lsblk_command.execute() == 0:
+ self.__raw_out = lsblk_command.getOutput()
+ if self.__raw_out == "":
+ print("failed: no command output")
+ self.fail("failed: no command output")
+ else:
+ lines = lsblk_command.getOutput().splitlines()
+ for i in range(len(host_list)):
+ file_path=str(lines[host_list[i]].decode('ascii')) + self.__usbFileName
+ usb_file = open(file_path, 'r')
+ read=usb_file.read()
+ if read.find(self.__usbtext)!=-1:
+ print(file_path + " --> OK!")
+ else:
+ self.fail("failed: could not read from usb {}".format(lines[host_list[i]].decode('ascii')))
+ self.__numUsbFail.append(host_list[i])
+ usb_file.close()
+ else:
+ self.fail("failed: couldn't execute lsblk command")
+
+ else:
+ self.fail("failed: reference and real usb host devices number mismatch")
+ else:
+ self.fail("failed: couldn't execute lsblk command")