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/.idea/workspace.xml | 54 +++++++++++++-------------------------- test-cli/test/helpers/qrreader.py | 40 ++++++++++++++--------------- test-cli/test/tests/qdmesg.py | 3 +-- test-cli/test/tests/qusb.py | 50 ++++++++++++++++++++++++------------ test-cli/test/tests/qusbdual.py | 7 ++++- test-cli/test_main.py | 6 ++--- 6 files changed, 81 insertions(+), 79 deletions(-) diff --git a/test-cli/.idea/workspace.xml b/test-cli/.idea/workspace.xml index 887bf9b..edde041 100644 --- a/test-cli/.idea/workspace.xml +++ b/test-cli/.idea/workspace.xml @@ -2,39 +2,11 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - + - + + + + - + - - - + + + @@ -116,6 +91,9 @@ + + @@ -125,6 +103,10 @@ + + + + diff --git a/test-cli/test/helpers/qrreader.py b/test-cli/test/helpers/qrreader.py index 908c9db..744db54 100644 --- a/test-cli/test/helpers/qrreader.py +++ b/test-cli/test/helpers/qrreader.py @@ -13,18 +13,17 @@ qrdevice_list = [ "SM SM-2D PRODUCT HID KBW" ] - -qrkey_list = { 'KEY_0':'0', - 'KEY_1':'1', - 'KEY_2':'2', - 'KEY_3':'3', - 'KEY_4':'4', - 'KEY_5':'5', - 'KEY_6':'6', - 'KEY_7':'7', - 'KEY_8':'8', - 'KEY_9':'9' - } +qrkey_list = {'KEY_0': '0', + 'KEY_1': '1', + 'KEY_2': '2', + 'KEY_3': '3', + 'KEY_4': '4', + 'KEY_5': '5', + 'KEY_6': '6', + 'KEY_7': '7', + 'KEY_8': '8', + 'KEY_9': '9' + } class QRReader: @@ -41,13 +40,13 @@ class QRReader: for device in devices: if device.name in qrdevice_list: self.__myReader['NAME'] = device.name - #print(self.__myReader['NAME']) + # print(self.__myReader['NAME']) self.__myReader['PATH'] = device.path - #print(self.__myReader['PATH']) + # print(self.__myReader['PATH']) self.__myReader['PHYS'] = device.phys - #print(self.__myReader['PHYS']) + # print(self.__myReader['PHYS']) - def IsQR (self): + def IsQR(self): return 'NAME' in self.__myReader def getQRNumber(self): @@ -84,7 +83,7 @@ class QRReader: return True return False - def wait_event (self, timeout): + def wait_event(self, timeout): selector.register(self.__dev, selectors.EVENT_READ) while True: events = selector.select(timeout); @@ -114,8 +113,7 @@ class QRReader: return r return False - -#qr = QRReader() -#if qr.openQR(): +# qr = QRReader() +# if qr.openQR(): # print(qr.readQRasync(2)) -#qr.closeQR() +# qr.closeQR() diff --git a/test-cli/test/tests/qdmesg.py b/test-cli/test/tests/qdmesg.py index 45dd4eb..8117deb 100644 --- a/test-cli/test/tests/qdmesg.py +++ b/test-cli/test/tests/qdmesg.py @@ -2,6 +2,7 @@ import sh import os.path from os import path + class Qdmesg: params = None __resultlist = None # resultlist is a python list of python dictionaries @@ -17,11 +18,9 @@ class Qdmesg: self.pgObj.run_test(self.params["testidctl"], self.params["testid"]) # delete previous file if path.exists("/tmp/station/dmesg.txt"): - print("dmesg remove") os.remove("/tmp/station/dmesg.txt") # generate file p = sh.dmesg("--color=never", _out="/tmp/station/dmesg.txt") - print("Exit code: {}".format(p.exit_code)) if p.exit_code == 0: # save result # with open('/tmp/station/dmesg.txt', 'w') as outfile: 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 diff --git a/test-cli/test/tests/qusbdual.py b/test-cli/test/tests/qusbdual.py index bb295b8..ad95b84 100644 --- a/test-cli/test/tests/qusbdual.py +++ b/test-cli/test/tests/qusbdual.py @@ -37,7 +37,7 @@ class Qusbdual(unittest.TestCase): if p.exit_code != 0: self.fail("failed: Unable to mount the mass storage gadget.") # execute test - for i in range(self.__repetitions): + for i in range(int(self.__repetitions)): # copy files try: p = sh.cp("/tmp/station/hdd_gadget/usb-test.bin", "/tmp/station/hdd_gadget/usb-test.bin.md5", @@ -46,6 +46,11 @@ class Qusbdual(unittest.TestCase): sh.umount("/tmp/station/hdd_gadget") sh.rmdir("/tmp/station/hdd_gadget") self.fail("failed: Unable to copy files through USB.") + # check if the device is still mounted + if not os.path.ismount("/tmp/station/hdd_gadget"): + sh.rm("/tmp/station/hdd_gadget/*") + sh.rmdir("/tmp/station/hdd_gadget") + self.fail("failed: USB device unmounted during/after copying files.") # Check md5 try: p = sh.md5sum("/tmp/stationnfs/usb-test.bin") diff --git a/test-cli/test_main.py b/test-cli/test_main.py index 36d5fb1..a8eff91 100644 --- a/test-cli/test_main.py +++ b/test-cli/test_main.py @@ -174,7 +174,7 @@ def main(): runner1 = SimpleTestRunner(psdbObj) testresult = runner1.run(suite1) - #Execute manually tests + # Execute manually tests for test in tests_manually_executed: test.execute() @@ -232,7 +232,7 @@ def main(): # get barcode using the scanner, only if autotest is disabled autotest = psdbObj.get_setup_variable("AUTOTEST_" + globalVar.station) - if autotest == "True": + if int(autotest) == 1: psdbObj.set_factorycode(globalVar.g_uuid, "1234567890") # fake factory code else: qrreceived = False @@ -268,7 +268,7 @@ def main(): # reset board if AUTOTEST is enabled autotest = psdbObj.get_setup_variable("AUTOTEST_" + globalVar.station) - if autotest == "True": + if int(autotest) == 1: os.system('reboot') -- cgit v1.1