From 09de774dcc1a5abc1c8f3a00fdb039aa3c522f52 Mon Sep 17 00:00:00 2001 From: Manel Caro Date: Wed, 4 Mar 2020 17:46:36 +0100 Subject: SOPA Initial Commit --- test-cli/test/tests/qusb.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'test-cli/test/tests/qusb.py') diff --git a/test-cli/test/tests/qusb.py b/test-cli/test/tests/qusb.py index 44490bc..0390143 100644 --- a/test-cli/test/tests/qusb.py +++ b/test-cli/test/tests/qusb.py @@ -3,17 +3,20 @@ import unittest class Qusb(unittest.TestCase): - def __init__(self, testname, testfunc, devLabel, numPorts): + def __init__(self, testname, testfunc, varlist): super(Qusb, self).__init__(testfunc) - self.__numPorts = numPorts + if "numPorts" in varlist: + self.__numPorts = varlist["numPorts"] + else: + raise Exception('numPorts param inside Qusb must be defined') self._testMethodDoc = testname - self.__devLabel = devLabel + if "devLabel" in varlist: + self.__devLabel = varlist["devLabel"] + else: + raise Exception('devLabel param inside Qusb must be defined') 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" @@ -57,4 +60,4 @@ class Qusb(unittest.TestCase): else: self.fail("failed: reference and real usb host devices number mismatch") else: - self.fail("failed: couldn't execute lsblk command") + self.fail("failed: couldn't execute lsblk command") \ No newline at end of file -- cgit v1.1 From 9f07a57d89a927aa9b172c1bf20c7ab563658c73 Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Fri, 6 Mar 2020 12:46:27 +0100 Subject: Fixed multiple errors. --- test-cli/test/tests/qusb.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'test-cli/test/tests/qusb.py') diff --git a/test-cli/test/tests/qusb.py b/test-cli/test/tests/qusb.py index 0390143..70265a5 100644 --- a/test-cli/test/tests/qusb.py +++ b/test-cli/test/tests/qusb.py @@ -1,9 +1,14 @@ from test.helpers.syscmd import SysCommand import unittest + class Qusb(unittest.TestCase): + __numPorts = None + __devLabel = None + params = None def __init__(self, testname, testfunc, varlist): + self.params = varlist super(Qusb, self).__init__(testfunc) if "numPorts" in varlist: self.__numPorts = varlist["numPorts"] @@ -14,27 +19,27 @@ class Qusb(unittest.TestCase): self.__devLabel = varlist["devLabel"] else: raise Exception('devLabel param inside Qusb must be defined') - if testname=="USBOTG": + if testname == "USBOTG": self.__usbFileName = "/this_is_an_usb_otg" self.__usbtext = "USBOTG" else: self.__usbFileName = "/this_is_an_usb_host" self.__usbtext = "USBHOST" - self.__numUsbFail=[] + self.__numUsbFail = [] def execute(self): - str_cmd= "lsblk -o LABEL" + 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=[] + host_list = [] for i in range(len(lines)): - if str(lines[i].decode('ascii'))==self.__devLabel: + if str(lines[i].decode('ascii')) == self.__devLabel: host_list.append(i) - if len(host_list)==int(self.__numPorts): + if len(host_list) == int(self.__numPorts): str_cmd = "lsblk -o MOUNTPOINT" lsblk_command = SysCommand("lsblk", str_cmd) if lsblk_command.execute() == 0: @@ -45,13 +50,14 @@ class Qusb(unittest.TestCase): else: lines = lsblk_command.getOutput().splitlines() for i in range(len(host_list)): - file_path=str(lines[host_list[i]].decode('ascii')) + self.__usbFileName + 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: + 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.fail( + "failed: could not read from usb {}".format(lines[host_list[i]].decode('ascii'))) self.__numUsbFail.append(host_list[i]) usb_file.close() else: @@ -60,4 +66,4 @@ class Qusb(unittest.TestCase): else: self.fail("failed: reference and real usb host devices number mismatch") else: - self.fail("failed: couldn't execute lsblk command") \ No newline at end of file + self.fail("failed: couldn't execute lsblk command") -- cgit v1.1 From c685367cbd6abf1c6ae442df759e39b25a907d3b Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Mon, 9 Mar 2020 12:39:50 +0100 Subject: Fixed several test procedures. --- test-cli/test/tests/qusb.py | 87 +++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 55 deletions(-) (limited to 'test-cli/test/tests/qusb.py') diff --git a/test-cli/test/tests/qusb.py b/test-cli/test/tests/qusb.py index 70265a5..7ecf31e 100644 --- a/test-cli/test/tests/qusb.py +++ b/test-cli/test/tests/qusb.py @@ -1,69 +1,46 @@ -from test.helpers.syscmd import SysCommand +import sh import unittest +import re +from test.helpers.changedir import changedir class Qusb(unittest.TestCase): - __numPorts = None - __devLabel = None params = None def __init__(self, testname, testfunc, varlist): self.params = varlist super(Qusb, self).__init__(testfunc) - if "numPorts" in varlist: - self.__numPorts = varlist["numPorts"] - else: - raise Exception('numPorts param inside Qusb must be defined') self._testMethodDoc = testname - if "devLabel" in varlist: - self.__devLabel = varlist["devLabel"] - else: - raise Exception('devLabel param inside Qusb must be defined') - if testname == "USBOTG": - self.__usbFileName = "/this_is_an_usb_otg" - self.__usbtext = "USBOTG" - 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") - + # Execute script usb.sh + p = sh.bash('test/helpers/usb.sh') + # Search in the stdout a pattern "/dev/sd + {letter} + {number} + q = re.search("/dev/sd\w\d", p.stdout.decode('ascii')) + # get the first device which matches the pattern + device = q.group(0) + # create a new folder where the pendrive is going to be mounted + sh.mkdir("-p", "/mnt/pendrive") + # mount the device + p = sh.mount(device, "/mnt/pendrive") + if p.exit_code == 0: + # copy files + p = sh.cp("/root/usbtest/usbdatatest.bin", "/root/usbtest/usbdatatest.md5", "/mnt/pendrive") + if p.exit_code == 0: + # check md5 + with changedir("/mnt/pendrive/"): + p = sh.md5sum("-c", "usbdatatest.md5") + q = re.search("OK", p.stdout.decode('ascii')) + # delete files + sh.rm("-f", "/mnt/pendrive/usbdatatest.bin", "/mnt/pendrive/usbdatatest.md5") + # umount + sh.umount("/mnt/pendrive") + # check result + if q is None: + self.fail("failed: wrong md5 result.") else: - self.fail("failed: reference and real usb host devices number mismatch") + # umount + sh.umount("/mnt/pendrive") + self.fail("failed: unable to copy files.") else: - self.fail("failed: couldn't execute lsblk command") + self.fail("failed: unable to mount the device.") -- cgit v1.1 From d38c92bfd7b6abe3a52b51b87b1a2949b857d9b4 Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Mon, 9 Mar 2020 19:16:08 +0100 Subject: Created function to flash the eeprom memory. --- test-cli/test/tests/qusb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test-cli/test/tests/qusb.py') diff --git a/test-cli/test/tests/qusb.py b/test-cli/test/tests/qusb.py index 7ecf31e..6a004f0 100644 --- a/test-cli/test/tests/qusb.py +++ b/test-cli/test/tests/qusb.py @@ -14,7 +14,7 @@ class Qusb(unittest.TestCase): def execute(self): # Execute script usb.sh - p = sh.bash('test/helpers/usb.sh') + p = sh.bash('test/scripts/usb.sh') # Search in the stdout a pattern "/dev/sd + {letter} + {number} q = re.search("/dev/sd\w\d", p.stdout.decode('ascii')) # get the first device which matches the pattern -- cgit v1.1 From 41ffba6a76a80a7ef4553cb8856393dd209d172e Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Tue, 10 Mar 2020 17:37:16 +0100 Subject: First release of the test. All the tests work correctly for SOPA0000. --- test-cli/test/tests/qusb.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'test-cli/test/tests/qusb.py') diff --git a/test-cli/test/tests/qusb.py b/test-cli/test/tests/qusb.py index 6a004f0..6c22c48 100644 --- a/test-cli/test/tests/qusb.py +++ b/test-cli/test/tests/qusb.py @@ -21,11 +21,19 @@ class Qusb(unittest.TestCase): device = q.group(0) # create a new folder where the pendrive is going to be mounted sh.mkdir("-p", "/mnt/pendrive") + # check if the device is mounted, and umount it + try: + p = sh.findmnt("-n", device) + if p.exit_code == 0: + sh.umount(device) + except sh.ErrorReturnCode_1: + # error = 1 means "no found" + pass # mount the device p = sh.mount(device, "/mnt/pendrive") if p.exit_code == 0: # copy files - p = sh.cp("/root/usbtest/usbdatatest.bin", "/root/usbtest/usbdatatest.md5", "/mnt/pendrive") + p = sh.cp("test/files/usbtest/usbdatatest.bin", "test/files/usbtest/usbdatatest.md5", "/mnt/pendrive") if p.exit_code == 0: # check md5 with changedir("/mnt/pendrive/"): -- cgit v1.1 From 6a680137694233008005415e22cf889b85baa292 Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Thu, 16 Apr 2020 17:09:19 +0200 Subject: First release --- test-cli/test/tests/qusb.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'test-cli/test/tests/qusb.py') diff --git a/test-cli/test/tests/qusb.py b/test-cli/test/tests/qusb.py index 6c22c48..4c177d9 100644 --- a/test-cli/test/tests/qusb.py +++ b/test-cli/test/tests/qusb.py @@ -1,6 +1,7 @@ import sh import unittest import re +import os from test.helpers.changedir import changedir @@ -14,7 +15,9 @@ class Qusb(unittest.TestCase): def execute(self): # Execute script usb.sh - p = sh.bash('test/scripts/usb.sh') + test_abspath = os.path.dirname(os.path.abspath(__file__)) + test_abspath = os.path.join(test_abspath, "..", "..") + p = sh.bash(os.path.join(test_abspath, 'test/scripts/usb.sh')) # Search in the stdout a pattern "/dev/sd + {letter} + {number} q = re.search("/dev/sd\w\d", p.stdout.decode('ascii')) # get the first device which matches the pattern @@ -33,7 +36,9 @@ class Qusb(unittest.TestCase): p = sh.mount(device, "/mnt/pendrive") if p.exit_code == 0: # copy files - p = sh.cp("test/files/usbtest/usbdatatest.bin", "test/files/usbtest/usbdatatest.md5", "/mnt/pendrive") + p = sh.cp(os.path.join(test_abspath, "test/files/usbtest/usbdatatest.bin"), + os.path.join(test_abspath, "test/files/usbtest/usbdatatest.md5"), + "/mnt/pendrive") if p.exit_code == 0: # check md5 with changedir("/mnt/pendrive/"): -- cgit v1.1 From 09b3bb38fc7305c9b47c29bc90ebc9c636827307 Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Wed, 17 Jun 2020 09:44:56 +0200 Subject: SOPA0000: Added support for saving results (strings or files) in the DB. It also saves a final DMESG file. --- test-cli/test/tests/qusb.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test-cli/test/tests/qusb.py') diff --git a/test-cli/test/tests/qusb.py b/test-cli/test/tests/qusb.py index 4c177d9..316cef5 100644 --- a/test-cli/test/tests/qusb.py +++ b/test-cli/test/tests/qusb.py @@ -57,3 +57,8 @@ class Qusb(unittest.TestCase): self.fail("failed: unable to copy files.") else: self.fail("failed: unable to mount the device.") + + def getresults(self): + # resultlist is a python list of python dictionaries + resultlist = [] + return resultlist -- cgit v1.1 From db3b1e45c47a1ef23c1ad67114a09cbec0976681 Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Thu, 25 Jun 2020 11:45:31 +0200 Subject: Solved bugs. Adapted to DB changes. --- test-cli/test/tests/qusb.py | 56 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 8 deletions(-) (limited to 'test-cli/test/tests/qusb.py') diff --git a/test-cli/test/tests/qusb.py b/test-cli/test/tests/qusb.py index 316cef5..d952afc 100644 --- a/test-cli/test/tests/qusb.py +++ b/test-cli/test/tests/qusb.py @@ -7,11 +7,13 @@ from test.helpers.changedir import changedir class Qusb(unittest.TestCase): params = None + __resultlist = None # resultlist is a python list of python dictionaries def __init__(self, testname, testfunc, varlist): self.params = varlist super(Qusb, self).__init__(testfunc) self._testMethodDoc = testname + self.__resultlist = [] def execute(self): # Execute script usb.sh @@ -19,9 +21,19 @@ class Qusb(unittest.TestCase): test_abspath = os.path.join(test_abspath, "..", "..") p = sh.bash(os.path.join(test_abspath, 'test/scripts/usb.sh')) # Search in the stdout a pattern "/dev/sd + {letter} + {number} - q = re.search("/dev/sd\w\d", p.stdout.decode('ascii')) + match = re.search("/dev/sd\w\d", p.stdout.decode('ascii')) # get the first device which matches the pattern - device = q.group(0) + if match: + device = match.group(0) + else: + self.__resultlist.append( + { + "desc": "Test result", + "data": "FAILED: No pendrive found", + "type": "string" + } + ) + self.fail("failed: No pendrive found.") # create a new folder where the pendrive is going to be mounted sh.mkdir("-p", "/mnt/pendrive") # check if the device is mounted, and umount it @@ -50,15 +62,43 @@ class Qusb(unittest.TestCase): sh.umount("/mnt/pendrive") # check result if q is None: - self.fail("failed: wrong md5 result.") + self.__resultlist.append( + { + "desc": "Test result", + "data": "FAILED: Wrong md5 result", + "type": "string" + } + ) + self.fail("failed: Wrong md5 result.") else: # umount sh.umount("/mnt/pendrive") - self.fail("failed: unable to copy files.") + self.__resultlist.append( + { + "desc": "Test result", + "data": "FAILED: Unable to copy files to the USB memory device", + "type": "string" + } + ) + self.fail("failed: Unable to copy files to the USB memory device.") else: - self.fail("failed: unable to mount the device.") + self.__resultlist.append( + { + "desc": "Test result", + "data": "FAILED: Unable to mount the USB memory device", + "type": "string" + } + ) + self.fail("failed: Unable to mount the USB memory device.") + + # Test successful + self.__resultlist.append( + { + "desc": "Test result", + "data": "OK", + "type": "string" + } + ) def getresults(self): - # resultlist is a python list of python dictionaries - resultlist = [] - return resultlist + return self.__resultlist -- cgit v1.1 From 9ac8a326412b04e4873b883c2f2a056ca0b22480 Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Thu, 25 Jun 2020 14:42:42 +0200 Subject: Modified USB test and the way it finds USB memory storages. --- test-cli/test/tests/qusb.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'test-cli/test/tests/qusb.py') diff --git a/test-cli/test/tests/qusb.py b/test-cli/test/tests/qusb.py index d952afc..32d99ef 100644 --- a/test-cli/test/tests/qusb.py +++ b/test-cli/test/tests/qusb.py @@ -2,6 +2,7 @@ import sh import unittest import re import os +from test.helpers.usb import USBDevices from test.helpers.changedir import changedir @@ -16,24 +17,20 @@ class Qusb(unittest.TestCase): self.__resultlist = [] def execute(self): - # Execute script usb.sh - test_abspath = os.path.dirname(os.path.abspath(__file__)) - test_abspath = os.path.join(test_abspath, "..", "..") - p = sh.bash(os.path.join(test_abspath, 'test/scripts/usb.sh')) - # Search in the stdout a pattern "/dev/sd + {letter} + {number} - match = re.search("/dev/sd\w\d", p.stdout.decode('ascii')) - # get the first device which matches the pattern - if match: - device = match.group(0) + # get usb device + dev_obj = USBDevices(self.params["xml"]) + if dev_obj.getMassStorage(): + device = dev_obj.getMassStorage()['disk'] + "1" else: self.__resultlist.append( { "desc": "Test result", - "data": "FAILED: No pendrive found", + "data": "FAILED: No USB memory found", "type": "string" } ) - self.fail("failed: No pendrive found.") + self.fail("failed: No USB memory found.") + # create a new folder where the pendrive is going to be mounted sh.mkdir("-p", "/mnt/pendrive") # check if the device is mounted, and umount it @@ -48,11 +45,12 @@ class Qusb(unittest.TestCase): p = sh.mount(device, "/mnt/pendrive") if p.exit_code == 0: # copy files - p = sh.cp(os.path.join(test_abspath, "test/files/usbtest/usbdatatest.bin"), - os.path.join(test_abspath, "test/files/usbtest/usbdatatest.md5"), + test_abspath = os.path.dirname(os.path.abspath(__file__)) + "/../" + p = sh.cp(os.path.join(test_abspath, "files/usbtest/usbdatatest.bin"), + os.path.join(test_abspath, "files/usbtest/usbdatatest.md5"), "/mnt/pendrive") if p.exit_code == 0: - # check md5 + # check with changedir("/mnt/pendrive/"): p = sh.md5sum("-c", "usbdatatest.md5") q = re.search("OK", p.stdout.decode('ascii')) -- cgit v1.1 From 34df86b37d6838b115e65e5f3a332344afeb86b8 Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Wed, 1 Jul 2020 10:45:34 +0200 Subject: Changes to adapt to new way to save results in DB. Created audio test. Added protections against unexpected status in DB. --- test-cli/test/tests/qusb.py | 40 +++------------------------------------- 1 file changed, 3 insertions(+), 37 deletions(-) (limited to 'test-cli/test/tests/qusb.py') diff --git a/test-cli/test/tests/qusb.py b/test-cli/test/tests/qusb.py index 32d99ef..9b0cad3 100644 --- a/test-cli/test/tests/qusb.py +++ b/test-cli/test/tests/qusb.py @@ -22,13 +22,6 @@ class Qusb(unittest.TestCase): if dev_obj.getMassStorage(): device = dev_obj.getMassStorage()['disk'] + "1" else: - self.__resultlist.append( - { - "desc": "Test result", - "data": "FAILED: No USB memory found", - "type": "string" - } - ) self.fail("failed: No USB memory found.") # create a new folder where the pendrive is going to be mounted @@ -60,43 +53,16 @@ class Qusb(unittest.TestCase): sh.umount("/mnt/pendrive") # check result if q is None: - self.__resultlist.append( - { - "desc": "Test result", - "data": "FAILED: Wrong md5 result", - "type": "string" - } - ) self.fail("failed: Wrong md5 result.") else: # umount sh.umount("/mnt/pendrive") - self.__resultlist.append( - { - "desc": "Test result", - "data": "FAILED: Unable to copy files to the USB memory device", - "type": "string" - } - ) self.fail("failed: Unable to copy files to the USB memory device.") else: - self.__resultlist.append( - { - "desc": "Test result", - "data": "FAILED: Unable to mount the USB memory device", - "type": "string" - } - ) self.fail("failed: Unable to mount the USB memory device.") - # Test successful - self.__resultlist.append( - { - "desc": "Test result", - "data": "OK", - "type": "string" - } - ) - def getresults(self): return self.__resultlist + + def gettextresult(self): + return "" -- cgit v1.1 From 5dcd213c28451ac210703dc5bf9bf538671a0682 Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Fri, 3 Jul 2020 13:55:45 +0200 Subject: Created new USB LOOP test. Moved all the test files to /var/lib/hwtest-files/ folder. --- test-cli/test/tests/qusb.py | 64 +++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 28 deletions(-) (limited to 'test-cli/test/tests/qusb.py') diff --git a/test-cli/test/tests/qusb.py b/test-cli/test/tests/qusb.py index 9b0cad3..df1248d 100644 --- a/test-cli/test/tests/qusb.py +++ b/test-cli/test/tests/qusb.py @@ -1,9 +1,6 @@ import sh import unittest -import re -import os from test.helpers.usb import USBDevices -from test.helpers.changedir import changedir class Qusb(unittest.TestCase): @@ -14,6 +11,10 @@ class Qusb(unittest.TestCase): self.params = varlist super(Qusb, self).__init__(testfunc) self._testMethodDoc = testname + if "repetitions" in varlist: + self.__repetitions = varlist["repetitions"] + else: + raise Exception('repetitions param inside Qusb must be defined') self.__resultlist = [] def execute(self): @@ -23,43 +24,50 @@ class Qusb(unittest.TestCase): device = dev_obj.getMassStorage()['disk'] + "1" else: self.fail("failed: No USB memory found.") - - # create a new folder where the pendrive is going to be mounted - sh.mkdir("-p", "/mnt/pendrive") # check if the device is mounted, and umount it try: p = sh.findmnt("-n", device) if p.exit_code == 0: sh.umount(device) - except sh.ErrorReturnCode_1: + except sh.ErrorReturnCode as e: # error = 1 means "no found" pass # mount the device + sh.mkdir("-p", "/mnt/pendrive") p = sh.mount(device, "/mnt/pendrive") - if p.exit_code == 0: + if p.exit_code != 0: + self.fail("failed: Unable to mount the USB memory device.") + # execute test + for i in range(self.__repetitions): # copy files - test_abspath = os.path.dirname(os.path.abspath(__file__)) + "/../" - p = sh.cp(os.path.join(test_abspath, "files/usbtest/usbdatatest.bin"), - os.path.join(test_abspath, "files/usbtest/usbdatatest.md5"), - "/mnt/pendrive") - if p.exit_code == 0: - # check - with changedir("/mnt/pendrive/"): - p = sh.md5sum("-c", "usbdatatest.md5") - q = re.search("OK", p.stdout.decode('ascii')) - # delete files - sh.rm("-f", "/mnt/pendrive/usbdatatest.bin", "/mnt/pendrive/usbdatatest.md5") - # umount - sh.umount("/mnt/pendrive") - # check result - if q is None: - self.fail("failed: Wrong md5 result.") - else: - # umount + try: + p = sh.cp("/var/lib/hwtest-files/usbdatatest.bin", + "/var/lib/hwtest-files/usbdatatest.bin.md5", + "/mnt/pendrive") + except sh.ErrorReturnCode as e: sh.umount("/mnt/pendrive") + sh.rmdir("/mnt/pendrive") self.fail("failed: Unable to copy files to the USB memory device.") - else: - self.fail("failed: Unable to mount the USB memory device.") + # check MD5 + try: + p = sh.md5sum("/mnt/pendrive/usbdatatest.bin") + except sh.ErrorReturnCode as e: + sh.umount("/mnt/pendrive") + sh.rmdir("/mnt/pendrive") + self.fail("failed: Unable to calculate MD5 of the copied file.") + newmd5 = p.stdout.decode().split(" ")[0] + with open('/mnt/pendrive/usbdatatest.bin.md5', 'r') as outfile: + oldmd5 = outfile.read() + outfile.close() + if newmd5 != oldmd5: + sh.umount("/mnt/pendrive") + sh.rmdir("/mnt/pendrive") + self.fail("failed: MD5 check failed.") + # delete copied files + sh.rm("-f", "/mnt/pendrive/usbdatatest.bin", "/mnt/pendrive/usbdatatest.bin.md5") + # Finish + sh.umount("/mnt/pendrive") + sh.rmdir("/mnt/pendrive") def getresults(self): return self.__resultlist -- cgit v1.1 From 0e8e3ecd4b9be71c41008b95950d089819622dff Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Mon, 6 Jul 2020 14:08:27 +0200 Subject: Corrected some errors in USB and USBDUAL tests. --- test-cli/test/tests/qusb.py | 50 ++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 16 deletions(-) (limited to 'test-cli/test/tests/qusb.py') diff --git a/test-cli/test/tests/qusb.py b/test-cli/test/tests/qusb.py index df1248d..b5d152e 100644 --- a/test-cli/test/tests/qusb.py +++ b/test-cli/test/tests/qusb.py @@ -1,6 +1,7 @@ import sh import unittest from test.helpers.usb import USBDevices +import os.path class Qusb(unittest.TestCase): @@ -33,41 +34,58 @@ class Qusb(unittest.TestCase): # error = 1 means "no found" pass # mount the device - sh.mkdir("-p", "/mnt/pendrive") - p = sh.mount(device, "/mnt/pendrive") + sh.mkdir("-p", "/tmp/station/pendrive") + p = sh.mount(device, "/tmp/station/pendrive") if p.exit_code != 0: self.fail("failed: Unable to mount the USB memory device.") # execute test - for i in range(self.__repetitions): + for i in range(int(self.__repetitions)): # copy files try: p = sh.cp("/var/lib/hwtest-files/usbdatatest.bin", "/var/lib/hwtest-files/usbdatatest.bin.md5", - "/mnt/pendrive") + "/tmp/station/pendrive") except sh.ErrorReturnCode as e: - sh.umount("/mnt/pendrive") - sh.rmdir("/mnt/pendrive") + try: + sh.umount("/tmp/station/pendrive") + except sh.ErrorReturnCode: + pass + sh.rmdir("/tmp/station/pendrive") self.fail("failed: Unable to copy files to the USB memory device.") + # check if the device is still mounted + if not os.path.ismount("/tmp/station/pendrive"): + sh.rm("/tmp/station/pendrive/*") + sh.rmdir("/tmp/station/pendrive") + self.fail("failed: USB device unmounted during/after copying files.") # check MD5 try: - p = sh.md5sum("/mnt/pendrive/usbdatatest.bin") + p = sh.md5sum("/tmp/station/pendrive/usbdatatest.bin") except sh.ErrorReturnCode as e: - sh.umount("/mnt/pendrive") - sh.rmdir("/mnt/pendrive") + try: + sh.umount("/tmp/station/pendrive") + except sh.ErrorReturnCode: + pass + sh.rmdir("/tmp/station/pendrive") self.fail("failed: Unable to calculate MD5 of the copied file.") newmd5 = p.stdout.decode().split(" ")[0] - with open('/mnt/pendrive/usbdatatest.bin.md5', 'r') as outfile: - oldmd5 = outfile.read() + with open('/tmp/station/pendrive/usbdatatest.bin.md5', 'r') as outfile: + oldmd5 = outfile.read().rstrip("\n") outfile.close() if newmd5 != oldmd5: - sh.umount("/mnt/pendrive") - sh.rmdir("/mnt/pendrive") + try: + sh.umount("/tmp/station/pendrive") + except sh.ErrorReturnCode: + pass + sh.rmdir("/tmp/station/pendrive") self.fail("failed: MD5 check failed.") # delete copied files - sh.rm("-f", "/mnt/pendrive/usbdatatest.bin", "/mnt/pendrive/usbdatatest.bin.md5") + sh.rm("-f", "/tmp/station/pendrive/usbdatatest.bin", "/tmp/station/pendrive/usbdatatest.bin.md5") # Finish - sh.umount("/mnt/pendrive") - sh.rmdir("/mnt/pendrive") + try: + sh.umount("/tmp/station/pendrive") + except sh.ErrorReturnCode: + pass + sh.rmdir("/tmp/station/pendrive") def getresults(self): return self.__resultlist -- cgit v1.1 From 1d51a80b57cc8c80c78d67c85290503997060e9e Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Mon, 6 Jul 2020 17:22:17 +0200 Subject: Modified paths of ram and nfs temporary folders. --- test-cli/test/tests/qusb.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'test-cli/test/tests/qusb.py') diff --git a/test-cli/test/tests/qusb.py b/test-cli/test/tests/qusb.py index b5d152e..6302012 100644 --- a/test-cli/test/tests/qusb.py +++ b/test-cli/test/tests/qusb.py @@ -34,8 +34,8 @@ class Qusb(unittest.TestCase): # error = 1 means "no found" pass # mount the device - sh.mkdir("-p", "/tmp/station/pendrive") - p = sh.mount(device, "/tmp/station/pendrive") + sh.mkdir("-p", "/mnt/station_ramdisk/pendrive") + p = sh.mount(device, "/mnt/station_ramdisk/pendrive") if p.exit_code != 0: self.fail("failed: Unable to mount the USB memory device.") # execute test @@ -44,48 +44,48 @@ class Qusb(unittest.TestCase): try: p = sh.cp("/var/lib/hwtest-files/usbdatatest.bin", "/var/lib/hwtest-files/usbdatatest.bin.md5", - "/tmp/station/pendrive") + "/mnt/station_ramdisk/pendrive") except sh.ErrorReturnCode as e: try: - sh.umount("/tmp/station/pendrive") + sh.umount("/mnt/station_ramdisk/pendrive") except sh.ErrorReturnCode: pass - sh.rmdir("/tmp/station/pendrive") + sh.rmdir("/mnt/station_ramdisk/pendrive") self.fail("failed: Unable to copy files to the USB memory device.") # check if the device is still mounted - if not os.path.ismount("/tmp/station/pendrive"): - sh.rm("/tmp/station/pendrive/*") - sh.rmdir("/tmp/station/pendrive") + if not os.path.ismount("/mnt/station_ramdisk/pendrive"): + sh.rm("/mnt/station_ramdisk/pendrive/*") + sh.rmdir("/mnt/station_ramdisk/pendrive") self.fail("failed: USB device unmounted during/after copying files.") # check MD5 try: - p = sh.md5sum("/tmp/station/pendrive/usbdatatest.bin") + p = sh.md5sum("/mnt/station_ramdisk/pendrive/usbdatatest.bin") except sh.ErrorReturnCode as e: try: - sh.umount("/tmp/station/pendrive") + sh.umount("/mnt/station_ramdisk/pendrive") except sh.ErrorReturnCode: pass - sh.rmdir("/tmp/station/pendrive") + sh.rmdir("/mnt/station_ramdisk/pendrive") self.fail("failed: Unable to calculate MD5 of the copied file.") newmd5 = p.stdout.decode().split(" ")[0] - with open('/tmp/station/pendrive/usbdatatest.bin.md5', 'r') as outfile: + with open('/mnt/station_ramdisk/pendrive/usbdatatest.bin.md5', 'r') as outfile: oldmd5 = outfile.read().rstrip("\n") outfile.close() if newmd5 != oldmd5: try: - sh.umount("/tmp/station/pendrive") + sh.umount("/mnt/station_ramdisk/pendrive") except sh.ErrorReturnCode: pass - sh.rmdir("/tmp/station/pendrive") + sh.rmdir("/mnt/station_ramdisk/pendrive") self.fail("failed: MD5 check failed.") # delete copied files - sh.rm("-f", "/tmp/station/pendrive/usbdatatest.bin", "/tmp/station/pendrive/usbdatatest.bin.md5") + sh.rm("-f", "/mnt/station_ramdisk/pendrive/usbdatatest.bin", "/mnt/station_ramdisk/pendrive/usbdatatest.bin.md5") # Finish try: - sh.umount("/tmp/station/pendrive") + sh.umount("/mnt/station_ramdisk/pendrive") except sh.ErrorReturnCode: pass - sh.rmdir("/tmp/station/pendrive") + sh.rmdir("/mnt/station_ramdisk/pendrive") def getresults(self): return self.__resultlist -- cgit v1.1 From d46bce422fd03cd57d1ba336361da17d6efb48db Mon Sep 17 00:00:00 2001 From: Manel Caro Date: Fri, 31 Jul 2020 02:07:37 +0200 Subject: TEST restructure --- test-cli/test/tests/qusb.py | 143 ++++++++++++++++++++++---------------------- 1 file changed, 71 insertions(+), 72 deletions(-) (limited to 'test-cli/test/tests/qusb.py') diff --git a/test-cli/test/tests/qusb.py b/test-cli/test/tests/qusb.py index 6302012..3182685 100644 --- a/test-cli/test/tests/qusb.py +++ b/test-cli/test/tests/qusb.py @@ -1,91 +1,90 @@ -import sh +import shutil import unittest -from test.helpers.usb import USBDevices import os.path +import os +import sh +from test.helpers.md5 import md5_file class Qusb(unittest.TestCase): params = None __resultlist = None # resultlist is a python list of python dictionaries + __QusbName = None def __init__(self, testname, testfunc, varlist): self.params = varlist super(Qusb, self).__init__(testfunc) self._testMethodDoc = testname - if "repetitions" in varlist: - self.__repetitions = varlist["repetitions"] - else: - raise Exception('repetitions param inside Qusb must be defined') + self.__xmlObj = varlist["xml"] + + self.__QusbName = varlist.get('name', 'qusb') + self.__loops = varlist.get('loops', self.__xmlObj.getKeyVal(self.__QusbName, "loops", "3")) + self.__filepath_from = varlist.get('path', self.__xmlObj.getKeyVal(self.__QusbName, "path", "/root/hwtest-files")) + self.__file_source = varlist.get('file', self.__xmlObj.getKeyVal(self.__QusbName, "file", "usb-test.bin")) + self.__file_md5 = varlist.get('file_md5', self.__xmlObj.getKeyVal(self.__QusbName, "file_md5", "usb-test.bin.md5")) + self.__path_to = varlist.get('pathto', self.__xmlObj.getKeyVal(self.__QusbName, "pathto", "/mnt/test/disk2")) + self.__check_mounted = varlist.get('check_mounted', self.__xmlObj.getKeyVal(self.__QusbName, "check_mounted", "")) + self.__resultlist = [] - def execute(self): - # get usb device - dev_obj = USBDevices(self.params["xml"]) - if dev_obj.getMassStorage(): - device = dev_obj.getMassStorage()['disk'] + "1" - else: - self.fail("failed: No USB memory found.") - # check if the device is mounted, and umount it - try: - p = sh.findmnt("-n", device) - if p.exit_code == 0: - sh.umount(device) - except sh.ErrorReturnCode as e: - # error = 1 means "no found" - pass - # mount the device - sh.mkdir("-p", "/mnt/station_ramdisk/pendrive") - p = sh.mount(device, "/mnt/station_ramdisk/pendrive") - if p.exit_code != 0: - self.fail("failed: Unable to mount the USB memory device.") - # execute test - for i in range(int(self.__repetitions)): - # copy files + def removefileIfExist(self, fname): + if os.path.exists(fname): try: - p = sh.cp("/var/lib/hwtest-files/usbdatatest.bin", - "/var/lib/hwtest-files/usbdatatest.bin.md5", - "/mnt/station_ramdisk/pendrive") - except sh.ErrorReturnCode as e: - try: - sh.umount("/mnt/station_ramdisk/pendrive") - except sh.ErrorReturnCode: - pass - sh.rmdir("/mnt/station_ramdisk/pendrive") - self.fail("failed: Unable to copy files to the USB memory device.") - # check if the device is still mounted - if not os.path.ismount("/mnt/station_ramdisk/pendrive"): - sh.rm("/mnt/station_ramdisk/pendrive/*") - sh.rmdir("/mnt/station_ramdisk/pendrive") - self.fail("failed: USB device unmounted during/after copying files.") - # check MD5 - try: - p = sh.md5sum("/mnt/station_ramdisk/pendrive/usbdatatest.bin") - except sh.ErrorReturnCode as e: - try: - sh.umount("/mnt/station_ramdisk/pendrive") - except sh.ErrorReturnCode: - pass - sh.rmdir("/mnt/station_ramdisk/pendrive") - self.fail("failed: Unable to calculate MD5 of the copied file.") - newmd5 = p.stdout.decode().split(" ")[0] - with open('/mnt/station_ramdisk/pendrive/usbdatatest.bin.md5', 'r') as outfile: - oldmd5 = outfile.read().rstrip("\n") - outfile.close() - if newmd5 != oldmd5: - try: - sh.umount("/mnt/station_ramdisk/pendrive") - except sh.ErrorReturnCode: - pass - sh.rmdir("/mnt/station_ramdisk/pendrive") - self.fail("failed: MD5 check failed.") - # delete copied files - sh.rm("-f", "/mnt/station_ramdisk/pendrive/usbdatatest.bin", "/mnt/station_ramdisk/pendrive/usbdatatest.bin.md5") - # Finish + os.remove(fname) + except OSError as error: + return False, str(error) + return True, '' + + def checkfiles(self): + if not os.path.isfile('{}/{}'.format(self.__filepath_from, self.__file_source)): + return False, 'File test binary Not found {}/{}'.format(self.__filepath_from, self.__file_source) + if not os.path.isfile('{}/{}'.format(self.__filepath_from, self.__file_md5)): + return False, 'File test binary md5 Not found {}/{}'.format(self.__filepath_from, self.__file_md5) + if self.__check_mounted != '': + if not os.path.ismount('{}'.format(self.__check_mounted)): + return False, 'Required mounted failed: {}'.format(self.__path_to) + r, s = self.removefileIfExist('{}/{}'.format(self.__path_to, self.__file_source)) + if not r: + return r, s + return True, '' + + def getTestFile_md5(self, fname): + t = '' + with open('{}'.format(fname), 'r') as outfile: + t = outfile.read().rstrip("\n") + outfile.close() + return t + + def ExecuteTranfer(self): try: - sh.umount("/mnt/station_ramdisk/pendrive") - except sh.ErrorReturnCode: - pass - sh.rmdir("/mnt/station_ramdisk/pendrive") + originalMD5 = self.getTestFile_md5('{}/{}'.format(self.__filepath_from, self.__file_md5)) + if originalMD5 == '': + self.fail('MD5 file {}/{} Not contain any md5'.format(self.__filepath_from, self.__file_md5)) + # shutil.copy2('{}/{}'.format(self.__filepath_from, self.__file_source), '{}'.format(self.__path_to)) + sh.cp('{}/{}'.format(self.__filepath_from, self.__file_source), '{}'.format(self.__path_to)) + sh.sync() + md5val = md5_file('{}/{}'.format(self.__path_to, self.__file_source)) + self.removefileIfExist('{}/{}'.format(self.__path_to, self.__file_source)) + if originalMD5 != md5val: + return False, 'md5 check failed {}<>{}'.format(originalMD5, md5val) + except OSError as why: + return False,'Error: {} tranfer failed'.format(why.errno) + except Exception as details: + return False, 'USB Exception: {} tranfer failed'.format(details) + return True, '' + + def execute(self): + v, m = self.checkfiles() + if not v: + self.fail(m) + countLoops = int(self.__loops) + while countLoops > 0: + res, msg = self.ExecuteTranfer() + if not res: + res, msg = self.ExecuteTranfer() + if not res: + self.fail(msg) + countLoops = countLoops - 1 def getresults(self): return self.__resultlist -- cgit v1.1 From d4071b6579312b2fb265e379031f588354d35f3a Mon Sep 17 00:00:00 2001 From: Manel Caro Date: Fri, 2 Oct 2020 14:12:09 +0200 Subject: solve usb error bug with quotes message --- test-cli/test/tests/qusb.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test-cli/test/tests/qusb.py') diff --git a/test-cli/test/tests/qusb.py b/test-cli/test/tests/qusb.py index 3182685..4f76d0c 100644 --- a/test-cli/test/tests/qusb.py +++ b/test-cli/test/tests/qusb.py @@ -69,6 +69,8 @@ class Qusb(unittest.TestCase): return False, 'md5 check failed {}<>{}'.format(originalMD5, md5val) except OSError as why: return False,'Error: {} tranfer failed'.format(why.errno) + except sh.ErrorReturnCode as shError: + return False, 'USB Exception: tranfer failed' except Exception as details: return False, 'USB Exception: {} tranfer failed'.format(details) return True, '' -- cgit v1.1