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/files/dtmf-13579.wav | Bin 17722 -> 0 bytes test-cli/test/files/usbtest/usbdatatest.bin | Bin 33554431 -> 0 bytes test-cli/test/files/usbtest/usbdatatest.md5 | 1 - test-cli/test/tests/qaudio.py | 6 +-- test-cli/test/tests/qusb.py | 64 +++++++++++++----------- test-cli/test/tests/qusbdual.py | 74 ++++++++++++++++++++++++++++ test-cli/test_main.py | 3 ++ 7 files changed, 115 insertions(+), 33 deletions(-) delete mode 100644 test-cli/test/files/dtmf-13579.wav delete mode 100644 test-cli/test/files/usbtest/usbdatatest.bin delete mode 100644 test-cli/test/files/usbtest/usbdatatest.md5 create mode 100644 test-cli/test/tests/qusbdual.py diff --git a/test-cli/test/files/dtmf-13579.wav b/test-cli/test/files/dtmf-13579.wav deleted file mode 100644 index c5b416a..0000000 Binary files a/test-cli/test/files/dtmf-13579.wav and /dev/null differ diff --git a/test-cli/test/files/usbtest/usbdatatest.bin b/test-cli/test/files/usbtest/usbdatatest.bin deleted file mode 100644 index 423eec3..0000000 Binary files a/test-cli/test/files/usbtest/usbdatatest.bin and /dev/null differ diff --git a/test-cli/test/files/usbtest/usbdatatest.md5 b/test-cli/test/files/usbtest/usbdatatest.md5 deleted file mode 100644 index 4358fb7..0000000 --- a/test-cli/test/files/usbtest/usbdatatest.md5 +++ /dev/null @@ -1 +0,0 @@ -6ef9717ac968b592803d0026f662a85e usbdatatest.bin diff --git a/test-cli/test/tests/qaudio.py b/test-cli/test/tests/qaudio.py index ef0cf53..acad4a9 100644 --- a/test-cli/test/tests/qaudio.py +++ b/test-cli/test/tests/qaudio.py @@ -2,7 +2,6 @@ import unittest import sh import wave import contextlib -import os def calc_audio_duration(fname): @@ -26,11 +25,10 @@ class Qaudio(unittest.TestCase): self.__resultlist = [] def execute(self): - test_abspath = os.path.dirname(os.path.abspath(__file__)) + "/../" # analize audio file - recordtime = calc_audio_duration(os.path.join(test_abspath, "files/dtmf-13579.wav")) + 0.15 + recordtime = calc_audio_duration("/var/lib/hwtest-files/dtmf-13579.wav") + 0.15 # play and record - p1 = sh.aplay(os.path.join(test_abspath, "files/dtmf-13579.wav"), _bg=True) + p1 = sh.aplay("/var/lib/hwtest-files/dtmf-13579.wav", _bg=True) p2 = sh.arecord("-r", 8000, "-d", recordtime, "/tmp/station/recorded.wav", _bg=True) p1.wait() p2.wait() 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 diff --git a/test-cli/test/tests/qusbdual.py b/test-cli/test/tests/qusbdual.py new file mode 100644 index 0000000..bb295b8 --- /dev/null +++ b/test-cli/test/tests/qusbdual.py @@ -0,0 +1,74 @@ +import sh +import unittest +import os.path + + +class Qusbdual(unittest.TestCase): + params = None + __resultlist = None # resultlist is a python list of python dictionaries + + def __init__(self, testname, testfunc, varlist): + self.params = varlist + super(Qusbdual, self).__init__(testfunc) + self._testMethodDoc = testname + if "repetitions" in varlist: + self.__repetitions = varlist["repetitions"] + else: + raise Exception('repetitions param inside Qusbdual must be defined') + self.__resultlist = [] + + def execute(self): + # check if file-as-filesystem exists + if not os.path.isfile('/var/lib/hwtest-files/mass-otg-test.img'): + self.fail("failed: Unable to find file-as-filesystem image.") + # generate mass storage gadget + p = sh.modprobe("g_mass_storage", "file=/var/lib/hwtest-files/mass-otg-test.img") + if p.exit_code != 0: + self.fail("failed: Unable to create a mass storage gadget.") + # find the mass storage device + try: + p = sh.grep(sh.lsblk("-So", "NAME,VENDOR"), "Linux") + except sh.ErrorReturnCode as e: + self.fail("failed: could not find any mass storage gadget") + device = p.stdout.decode().split(" ")[0] + # mount the mass storage gadget + sh.mkdir("-p", "/tmp/station/hdd_gadget") + p = sh.mount("-o", "ro", "/dev/" + device, "/tmp/station/hdd_gadget") + if p.exit_code != 0: + self.fail("failed: Unable to mount the mass storage gadget.") + # execute test + for i in range(self.__repetitions): + # copy files + try: + p = sh.cp("/tmp/station/hdd_gadget/usb-test.bin", "/tmp/station/hdd_gadget/usb-test.bin.md5", + "/tmp/stationnfs") + except sh.ErrorReturnCode as e: + sh.umount("/tmp/station/hdd_gadget") + sh.rmdir("/tmp/station/hdd_gadget") + self.fail("failed: Unable to copy files through USB.") + # Check md5 + try: + p = sh.md5sum("/tmp/stationnfs/usb-test.bin") + except sh.ErrorReturnCode as e: + sh.umount("/tmp/station/hdd_gadget") + sh.rmdir("/tmp/station/hdd_gadget") + self.fail("failed: Unable to calculate MD5 of the copied file.") + newmd5 = p.stdout.decode().split(" ")[0] + with open('/tmp/station/hdd_gadget/usb-test.bin.md5', 'r') as outfile: + oldmd5 = outfile.read() + outfile.close() + if newmd5 != oldmd5: + sh.umount("/tmp/station/hdd_gadget") + sh.rmdir("/tmp/station/hdd_gadget") + self.fail("failed: MD5 check failed.") + # delete copied files + sh.rm("-f", "/tmp/stationnfs/usb-test.bin", "/tmp/stationnfs/usb-test.bin.md5") + # Finish + sh.umount("/tmp/station/hdd_gadget") + sh.rmdir("/tmp/station/hdd_gadget") + + def getresults(self): + return self.__resultlist + + def gettextresult(self): + return "" diff --git a/test-cli/test_main.py b/test-cli/test_main.py index b32ad26..36d5fb1 100644 --- a/test-cli/test_main.py +++ b/test-cli/test_main.py @@ -86,6 +86,9 @@ def add_test(suite, testdefname, paramlist): elif testdefname == "AUDIO": suite.addTest(Qaudio(testdefname, "execute", paramlist)) return 0 + elif testdefname == "USBDUAL": + suite.addTest(Qaudio(testdefname, "execute", paramlist)) + return 0 elif testdefname == "DMESG": tests_manually_executed.append(Qdmesg(testdefname, "execute", paramlist)) return 0 -- cgit v1.1