blob: 44490bc9c10b7194244fdc30fda7cbb46813bd0f (
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
|
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")
|