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/qwifi.py | 52 +++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 32 deletions(-) (limited to 'test-cli/test/tests/qwifi.py') diff --git a/test-cli/test/tests/qwifi.py b/test-cli/test/tests/qwifi.py index d08149b..188e300 100644 --- a/test-cli/test/tests/qwifi.py +++ b/test-cli/test/tests/qwifi.py @@ -1,45 +1,33 @@ from test.helpers.syscmd import SysCommand import unittest -import subprocess class Qwifi(unittest.TestCase): - def __init__(self, testname, testfunc, signal): + def __init__(self, testname, testfunc, varlist): super(Qwifi, self).__init__(testfunc) - self.__signal = signal + if "signal" in varlist: + self.__signal = varlist["signal"] + else: + raise Exception('signal param inside Qwifi must be defined') self._testMethodDoc = testname - # WiFi SERVERIP fixed at the moment. - self._serverip = "192.168.5.1" def execute(self): - # First check connection with the wifi server using ping command - #str_cmd = "ping -c 1 {} > /dev/null".format(self._serverip) - #wifi_ping = SysCommand("wifi_ping", str_cmd) - #wifi_ping.execute() - #res = subprocess.call(['ping', '-c', '1', self._serverip]) - p = subprocess.Popen(['ping','-c','1',self._serverip,'-W','2'],stdout=subprocess.PIPE) - p.wait() - res=p.poll() - if res == 0: - str_cmd= "iw wlan0 link" - wifi_stats = SysCommand("wifi_stats", str_cmd) - if wifi_stats.execute() == 0: - w_stats = wifi_stats.getOutput().decode('ascii').splitlines() - #self._longMessage = str(self.__raw_out).replace("'", "") - if not w_stats[0] == "Not connected.": - signal_st = w_stats[5].split(" ")[1] - try: - int(signal_st) - if -1*int(signal_st) > int(self.__signal): - self.fail("failed: signal to server lower than expected") - except ValueError: - self.fail("failed: error output (Bad connection?)") - else: + str_cmd= "iw wlan0 link" + wifi_stats = SysCommand("wifi_stats", str_cmd) + if wifi_stats.execute() == 0: + w_stats = wifi_stats.getOutput().decode('ascii').splitlines() + #self._longMessage = str(self.__raw_out).replace("'", "") + if not w_stats[0] == "Not connected.": + signal_st = w_stats[5].split(" ")[1] + try: + int(signal_st) + if -1*int(signal_st) > int(self.__signal): + self.fail("failed: signal to server lower than expected") + except ValueError: self.fail("failed: error output (Bad connection?)") - #tx_brate = float(w_stats[6].split(" ")[2]) else: - self.fail("failed: couldn't execute iw command") + self.fail("failed: error output (Bad connection?)") + #tx_brate = float(w_stats[6].split(" ")[2]) else: - self.fail("failed: ping to server {}".format(self._serverip)) - + self.fail("failed: couldn't execute iw command") -- cgit v1.1 From a615dac03a9ea7897bf3947ba8d31278b2cea121 Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Thu, 5 Mar 2020 16:29:31 +0100 Subject: Modify tests. --- test-cli/test/tests/qwifi.py | 88 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 68 insertions(+), 20 deletions(-) (limited to 'test-cli/test/tests/qwifi.py') diff --git a/test-cli/test/tests/qwifi.py b/test-cli/test/tests/qwifi.py index 188e300..154dd52 100644 --- a/test-cli/test/tests/qwifi.py +++ b/test-cli/test/tests/qwifi.py @@ -1,33 +1,81 @@ -from test.helpers.syscmd import SysCommand import unittest +import sh +import re + class Qwifi(unittest.TestCase): + __sip = None + __numbytestx = None + __bind = None + __OKBW = None + __port = None + #varlist: sip, bind, OKBW, port def __init__(self, testname, testfunc, varlist): super(Qwifi, self).__init__(testfunc) - if "signal" in varlist: - self.__signal = varlist["signal"] + if "sip" in varlist: + self.__sip = varlist["sip"] + else: + raise Exception('sip param inside Qwifi have been be defined') + if "OKBW" in varlist: + self.__OKBW = varlist["OKBW"] + else: + raise Exception('OKBW param inside Qwifi must be defined') + if "port" in varlist: + self.__port = varlist["port"] else: - raise Exception('signal param inside Qwifi must be defined') + raise Exception('port param inside Qwifi must be defined') + if "bind" in varlist: + self.__bind = varlist["bind"] + else: + self.__bind = None + self.__numbytestx = "10M" self._testMethodDoc = testname def execute(self): - str_cmd= "iw wlan0 link" - wifi_stats = SysCommand("wifi_stats", str_cmd) - if wifi_stats.execute() == 0: - w_stats = wifi_stats.getOutput().decode('ascii').splitlines() - #self._longMessage = str(self.__raw_out).replace("'", "") - if not w_stats[0] == "Not connected.": - signal_st = w_stats[5].split(" ")[1] - try: - int(signal_st) - if -1*int(signal_st) > int(self.__signal): - self.fail("failed: signal to server lower than expected") - except ValueError: - self.fail("failed: error output (Bad connection?)") + # check if the board is connected to the router by wifi + p = sh.iw("wlan0", "link") + if p.exit_code == 0: + # get the first line of the output stream + out1 = p.stdout.decode('ascii').splitlines()[0] + if out1 != "Not connected.": + #check if the board has ip in the wlan0 interface + p = sh.ifconfig("wlan0") + if p.exit_code == 0: + result = re.search("inet addr:(?!127\.0{1,3}\.0{1,3}\.0{0,2}1$)((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)", + p.stdout) + if result: + # execute iperf command against the server + if self.__bind is None: + p = sh.iperf("-c", self.__sip, "-x", "CMSV", "-n", self.__numbytestx, "-f", "m", "-p", + self.__port) + else: + p = sh.iperf("-c", self.__sip, "-x", "CMSV", "-n", self.__numbytestx, "-f", "m", "-p", + self.__port, "-B", self.__bind) + # check if it was executed succesfully + if p.exit_code == 0: + if p.stdout == "": + self.fail("failed: error executing iperf command") + # analyze output string + # split by lines + lines = p.stdout.splitlines() + # get first line + dat = lines[1].decode('ascii') + # search for the BW value + a = re.search("\d+(\.\d)? Mbits/sec", dat) + b = a.group().split() + bwreal = b[0] + + # check if BW is in the expected range + self.failUnless(float(bwreal) > float(self.__OKBW) * 0.9, + "failed: speed is lower than spected. Speed(MB/s)" + str(bwreal)) + else: + self.fail("failed: could not complete iperf command") + else: + self.fail("failed: wlan0 interface doesn't have any ip address.") + else: + self.fail("failed: could not complete ifconfig command.") else: - self.fail("failed: error output (Bad connection?)") - #tx_brate = float(w_stats[6].split(" ")[2]) + self.fail("failed: wifi module is not connected to the router.") else: self.fail("failed: couldn't execute iw command") - -- 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/qwifi.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'test-cli/test/tests/qwifi.py') diff --git a/test-cli/test/tests/qwifi.py b/test-cli/test/tests/qwifi.py index 154dd52..2a5fa0c 100644 --- a/test-cli/test/tests/qwifi.py +++ b/test-cli/test/tests/qwifi.py @@ -9,14 +9,16 @@ class Qwifi(unittest.TestCase): __bind = None __OKBW = None __port = None + params = None - #varlist: sip, bind, OKBW, port + #varlist: serverip, bind, OKBW, port def __init__(self, testname, testfunc, varlist): + self.params = varlist super(Qwifi, self).__init__(testfunc) - if "sip" in varlist: - self.__sip = varlist["sip"] + if "serverip" in varlist: + self.__serverip = varlist["serverip"] else: - raise Exception('sip param inside Qwifi have been be defined') + raise Exception('serverip param inside Qwifi have been be defined') if "OKBW" in varlist: self.__OKBW = varlist["OKBW"] else: @@ -47,10 +49,10 @@ class Qwifi(unittest.TestCase): if result: # execute iperf command against the server if self.__bind is None: - p = sh.iperf("-c", self.__sip, "-x", "CMSV", "-n", self.__numbytestx, "-f", "m", "-p", + p = sh.iperf("-c", self.__serverip, "-x", "CMSV", "-n", self.__numbytestx, "-f", "m", "-p", self.__port) else: - p = sh.iperf("-c", self.__sip, "-x", "CMSV", "-n", self.__numbytestx, "-f", "m", "-p", + p = sh.iperf("-c", self.__serverip, "-x", "CMSV", "-n", self.__numbytestx, "-f", "m", "-p", self.__port, "-B", self.__bind) # check if it was executed succesfully if p.exit_code == 0: -- 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/qwifi.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'test-cli/test/tests/qwifi.py') diff --git a/test-cli/test/tests/qwifi.py b/test-cli/test/tests/qwifi.py index 2a5fa0c..8daf069 100644 --- a/test-cli/test/tests/qwifi.py +++ b/test-cli/test/tests/qwifi.py @@ -4,14 +4,14 @@ import re class Qwifi(unittest.TestCase): - __sip = None + __serverip = None __numbytestx = None __bind = None - __OKBW = None + __bwexpected = None __port = None params = None - #varlist: serverip, bind, OKBW, port + # varlist content: serverip, bwexpected, port, (optional)bind def __init__(self, testname, testfunc, varlist): self.params = varlist super(Qwifi, self).__init__(testfunc) @@ -19,8 +19,8 @@ class Qwifi(unittest.TestCase): self.__serverip = varlist["serverip"] else: raise Exception('serverip param inside Qwifi have been be defined') - if "OKBW" in varlist: - self.__OKBW = varlist["OKBW"] + if "bwexpected" in varlist: + self.__bwexpected = varlist["bwexpected"] else: raise Exception('OKBW param inside Qwifi must be defined') if "port" in varlist: @@ -41,11 +41,12 @@ class Qwifi(unittest.TestCase): # get the first line of the output stream out1 = p.stdout.decode('ascii').splitlines()[0] if out1 != "Not connected.": - #check if the board has ip in the wlan0 interface + # check if the board has ip in the wlan0 interface p = sh.ifconfig("wlan0") if p.exit_code == 0: - result = re.search("inet addr:(?!127\.0{1,3}\.0{1,3}\.0{0,2}1$)((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)", - p.stdout) + result = re.search( + 'inet addr:(?!127\.0{1,3}\.0{1,3}\.0{0,2}1$)((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)', + p.stdout.decode('ascii')) if result: # execute iperf command against the server if self.__bind is None: @@ -69,7 +70,7 @@ class Qwifi(unittest.TestCase): bwreal = b[0] # check if BW is in the expected range - self.failUnless(float(bwreal) > float(self.__OKBW) * 0.9, + self.failUnless(float(bwreal) > float(self.__bwexpected) * 0.9, "failed: speed is lower than spected. Speed(MB/s)" + str(bwreal)) else: self.fail("failed: could not complete iperf command") -- cgit v1.1 From f86887baef80509460da0bff8f48b2900a627282 Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Mon, 13 Apr 2020 09:49:51 +0200 Subject: Added new DB functions. Added Qrreader.py file. --- test-cli/test/tests/qwifi.py | 1 + 1 file changed, 1 insertion(+) (limited to 'test-cli/test/tests/qwifi.py') diff --git a/test-cli/test/tests/qwifi.py b/test-cli/test/tests/qwifi.py index 8daf069..b0b8d6b 100644 --- a/test-cli/test/tests/qwifi.py +++ b/test-cli/test/tests/qwifi.py @@ -44,6 +44,7 @@ class Qwifi(unittest.TestCase): # check if the board has ip in the wlan0 interface p = sh.ifconfig("wlan0") if p.exit_code == 0: + # check if wlan0 has an IP result = re.search( 'inet addr:(?!127\.0{1,3}\.0{1,3}\.0{0,2}1$)((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)', p.stdout.decode('ascii')) -- 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/qwifi.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'test-cli/test/tests/qwifi.py') diff --git a/test-cli/test/tests/qwifi.py b/test-cli/test/tests/qwifi.py index b0b8d6b..684cb34 100644 --- a/test-cli/test/tests/qwifi.py +++ b/test-cli/test/tests/qwifi.py @@ -6,12 +6,11 @@ import re class Qwifi(unittest.TestCase): __serverip = None __numbytestx = None - __bind = None __bwexpected = None __port = None params = None - # varlist content: serverip, bwexpected, port, (optional)bind + # varlist content: serverip, bwexpected, port def __init__(self, testname, testfunc, varlist): self.params = varlist super(Qwifi, self).__init__(testfunc) @@ -27,10 +26,6 @@ class Qwifi(unittest.TestCase): self.__port = varlist["port"] else: raise Exception('port param inside Qwifi must be defined') - if "bind" in varlist: - self.__bind = varlist["bind"] - else: - self.__bind = None self.__numbytestx = "10M" self._testMethodDoc = testname @@ -50,12 +45,12 @@ class Qwifi(unittest.TestCase): p.stdout.decode('ascii')) if result: # execute iperf command against the server - if self.__bind is None: - p = sh.iperf("-c", self.__serverip, "-x", "CMSV", "-n", self.__numbytestx, "-f", "m", "-p", - self.__port) - else: + try: p = sh.iperf("-c", self.__serverip, "-x", "CMSV", "-n", self.__numbytestx, "-f", "m", "-p", - self.__port, "-B", self.__bind) + self.__port, _timeout=20) + except sh.TimeoutException: + self.fail("failed: iperf timeout reached") + # check if it was executed succesfully if p.exit_code == 0: if p.stdout == "": -- 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/qwifi.py | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'test-cli/test/tests/qwifi.py') diff --git a/test-cli/test/tests/qwifi.py b/test-cli/test/tests/qwifi.py index 684cb34..0944dd7 100644 --- a/test-cli/test/tests/qwifi.py +++ b/test-cli/test/tests/qwifi.py @@ -1,6 +1,7 @@ import unittest import sh import re +import json class Qwifi(unittest.TestCase): @@ -9,6 +10,7 @@ class Qwifi(unittest.TestCase): __bwexpected = None __port = None params = None + __bwreal = None # varlist content: serverip, bwexpected, port def __init__(self, testname, testfunc, varlist): @@ -46,8 +48,8 @@ class Qwifi(unittest.TestCase): if result: # execute iperf command against the server try: - p = sh.iperf("-c", self.__serverip, "-x", "CMSV", "-n", self.__numbytestx, "-f", "m", "-p", - self.__port, _timeout=20) + p = sh.iperf3("-c", self.__serverip, "-n", self.__numbytestx, "-f", "m", "-p", self.__port, + "-J", _timeout=20) except sh.TimeoutException: self.fail("failed: iperf timeout reached") @@ -56,18 +58,15 @@ class Qwifi(unittest.TestCase): if p.stdout == "": self.fail("failed: error executing iperf command") # analyze output string - # split by lines - lines = p.stdout.splitlines() - # get first line - dat = lines[1].decode('ascii') - # search for the BW value - a = re.search("\d+(\.\d)? Mbits/sec", dat) - b = a.group().split() - bwreal = b[0] + data = json.loads(p.stdout.decode('ascii')) + self.__bwreal = float(data['end']['sum_received']['bits_per_second']) / 1024 / 1024 + # save result file + with open('/tmp/wifi-iperf.json', 'w') as outfile: + json.dump(data, outfile) # check if BW is in the expected range - self.failUnless(float(bwreal) > float(self.__bwexpected) * 0.9, - "failed: speed is lower than spected. Speed(MB/s)" + str(bwreal)) + self.failUnless(self.__bwreal > float(self.__bwexpected) * 0.9, + "failed: speed is lower than spected. Speed(Mbits/s)" + str(self.__bwreal)) else: self.fail("failed: could not complete iperf command") else: @@ -78,3 +77,14 @@ class Qwifi(unittest.TestCase): self.fail("failed: wifi module is not connected to the router.") else: self.fail("failed: couldn't execute iw command") + + def getresults(self): + # resultlist is a python list of python dictionaries + resultlist = [ + { + "desc": "iperf3 output", + "data": "/tmp/wifi-iperf.json", + "type": "file" + } + ] + return resultlist -- cgit v1.1 From 736ddcfe6dc3b5edbab6773f1c6687f6597fa7a3 Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Wed, 17 Jun 2020 10:50:02 +0200 Subject: SOPA0000: Beatified JSON files generated by tests which use iperf3. --- test-cli/test/tests/qwifi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test-cli/test/tests/qwifi.py') diff --git a/test-cli/test/tests/qwifi.py b/test-cli/test/tests/qwifi.py index 0944dd7..a5b66e9 100644 --- a/test-cli/test/tests/qwifi.py +++ b/test-cli/test/tests/qwifi.py @@ -62,7 +62,7 @@ class Qwifi(unittest.TestCase): self.__bwreal = float(data['end']['sum_received']['bits_per_second']) / 1024 / 1024 # save result file with open('/tmp/wifi-iperf.json', 'w') as outfile: - json.dump(data, outfile) + json.dump(data, outfile, indent=4) # check if BW is in the expected range self.failUnless(self.__bwreal > float(self.__bwexpected) * 0.9, -- 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/qwifi.py | 76 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 64 insertions(+), 12 deletions(-) (limited to 'test-cli/test/tests/qwifi.py') diff --git a/test-cli/test/tests/qwifi.py b/test-cli/test/tests/qwifi.py index a5b66e9..6f972d3 100644 --- a/test-cli/test/tests/qwifi.py +++ b/test-cli/test/tests/qwifi.py @@ -11,6 +11,7 @@ class Qwifi(unittest.TestCase): __port = None params = None __bwreal = None + __resultlist = None # resultlist is a python list of python dictionaries # varlist content: serverip, bwexpected, port def __init__(self, testname, testfunc, varlist): @@ -30,6 +31,7 @@ class Qwifi(unittest.TestCase): raise Exception('port param inside Qwifi must be defined') self.__numbytestx = "10M" self._testMethodDoc = testname + self.__resultlist = [] def execute(self): # check if the board is connected to the router by wifi @@ -63,28 +65,78 @@ class Qwifi(unittest.TestCase): # save result file with open('/tmp/wifi-iperf.json', 'w') as outfile: json.dump(data, outfile, indent=4) + self.__resultlist.append( + { + "desc": "iperf3 output", + "data": "/tmp/wifi-iperf.json", + "type": "file" + } + ) # check if BW is in the expected range - self.failUnless(self.__bwreal > float(self.__bwexpected) * 0.9, - "failed: speed is lower than spected. Speed(Mbits/s)" + str(self.__bwreal)) + if self.__bwreal < float(self.__bwexpected): + self.__resultlist.append( + { + "desc": "Test result", + "data": "FAILED: speed is lower than expected. Speed(Mbits/s): " + str(self.__bwreal), + "type": "string" + } + ) + self.fail("failed: speed is lower than expected. Speed(Mbits/s): " + str(self.__bwreal)) else: - self.fail("failed: could not complete iperf command") + self.__resultlist.append( + { + "desc": "Test result", + "data": "FAILED: could not complete iperf3 command", + "type": "string" + } + ) + self.fail("failed: could not complete iperf3 command") else: + self.__resultlist.append( + { + "desc": "Test result", + "data": "FAILED: wlan0 interface doesn't have any ip address", + "type": "string" + } + ) self.fail("failed: wlan0 interface doesn't have any ip address.") else: + self.__resultlist.append( + { + "desc": "Test result", + "data": "FAILED: could not complete ifconfig command", + "type": "string" + } + ) self.fail("failed: could not complete ifconfig command.") else: + self.__resultlist.append( + { + "desc": "Test result", + "data": "FAILED: wifi module is not connected to the router", + "type": "string" + } + ) self.fail("failed: wifi module is not connected to the router.") else: - self.fail("failed: couldn't execute iw command") + self.__resultlist.append( + { + "desc": "Test result", + "data": "FAILED: could not execute iw command", + "type": "string" + } + ) + self.fail("failed: could not execute iw command") - def getresults(self): - # resultlist is a python list of python dictionaries - resultlist = [ + # Test successful + self.__resultlist.append( { - "desc": "iperf3 output", - "data": "/tmp/wifi-iperf.json", - "type": "file" + "desc": "Test result", + "data": "OK", + "type": "string" } - ] - return resultlist + ) + + def getresults(self): + return self.__resultlist -- 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/qwifi.py | 63 ++++++-------------------------------------- 1 file changed, 8 insertions(+), 55 deletions(-) (limited to 'test-cli/test/tests/qwifi.py') diff --git a/test-cli/test/tests/qwifi.py b/test-cli/test/tests/qwifi.py index 6f972d3..eb1f0bf 100644 --- a/test-cli/test/tests/qwifi.py +++ b/test-cli/test/tests/qwifi.py @@ -63,80 +63,33 @@ class Qwifi(unittest.TestCase): data = json.loads(p.stdout.decode('ascii')) self.__bwreal = float(data['end']['sum_received']['bits_per_second']) / 1024 / 1024 # save result file - with open('/tmp/wifi-iperf.json', 'w') as outfile: + with open('/tmp/station/wifi-iperf3.json', 'w') as outfile: json.dump(data, outfile, indent=4) + outfile.close() self.__resultlist.append( { - "desc": "iperf3 output", - "data": "/tmp/wifi-iperf.json", - "type": "file" + "description": "iperf3 output", + "filepath": "/tmp/station/wifi-iperf3.json", + "mimetype": "application/json" } ) # check if BW is in the expected range if self.__bwreal < float(self.__bwexpected): - self.__resultlist.append( - { - "desc": "Test result", - "data": "FAILED: speed is lower than expected. Speed(Mbits/s): " + str(self.__bwreal), - "type": "string" - } - ) self.fail("failed: speed is lower than expected. Speed(Mbits/s): " + str(self.__bwreal)) else: - self.__resultlist.append( - { - "desc": "Test result", - "data": "FAILED: could not complete iperf3 command", - "type": "string" - } - ) self.fail("failed: could not complete iperf3 command") else: - self.__resultlist.append( - { - "desc": "Test result", - "data": "FAILED: wlan0 interface doesn't have any ip address", - "type": "string" - } - ) self.fail("failed: wlan0 interface doesn't have any ip address.") else: - self.__resultlist.append( - { - "desc": "Test result", - "data": "FAILED: could not complete ifconfig command", - "type": "string" - } - ) self.fail("failed: could not complete ifconfig command.") else: - self.__resultlist.append( - { - "desc": "Test result", - "data": "FAILED: wifi module is not connected to the router", - "type": "string" - } - ) self.fail("failed: wifi module is not connected to the router.") else: - self.__resultlist.append( - { - "desc": "Test result", - "data": "FAILED: could not execute iw command", - "type": "string" - } - ) self.fail("failed: could not execute iw command") - # 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 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/qwifi.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test-cli/test/tests/qwifi.py') diff --git a/test-cli/test/tests/qwifi.py b/test-cli/test/tests/qwifi.py index eb1f0bf..4522057 100644 --- a/test-cli/test/tests/qwifi.py +++ b/test-cli/test/tests/qwifi.py @@ -51,7 +51,7 @@ class Qwifi(unittest.TestCase): # execute iperf command against the server try: p = sh.iperf3("-c", self.__serverip, "-n", self.__numbytestx, "-f", "m", "-p", self.__port, - "-J", _timeout=20) + "-J", _timeout=30) except sh.TimeoutException: self.fail("failed: iperf timeout reached") @@ -63,13 +63,13 @@ class Qwifi(unittest.TestCase): data = json.loads(p.stdout.decode('ascii')) self.__bwreal = float(data['end']['sum_received']['bits_per_second']) / 1024 / 1024 # save result file - with open('/tmp/station/wifi-iperf3.json', 'w') as outfile: + with open('/mnt/station_ramdisk/wifi-iperf3.json', 'w') as outfile: json.dump(data, outfile, indent=4) outfile.close() self.__resultlist.append( { "description": "iperf3 output", - "filepath": "/tmp/station/wifi-iperf3.json", + "filepath": "/mnt/station_ramdisk/wifi-iperf3.json", "mimetype": "application/json" } ) -- cgit v1.1 From 47827e40f71696e04ad805296dedc44a03451db3 Mon Sep 17 00:00:00 2001 From: Hector Fernandez Date: Mon, 6 Jul 2020 17:51:09 +0200 Subject: In case iperf3 server is busy, clients wait and retry. --- test-cli/test/tests/qwifi.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'test-cli/test/tests/qwifi.py') diff --git a/test-cli/test/tests/qwifi.py b/test-cli/test/tests/qwifi.py index 4522057..3dd9e38 100644 --- a/test-cli/test/tests/qwifi.py +++ b/test-cli/test/tests/qwifi.py @@ -2,6 +2,7 @@ import unittest import sh import re import json +import time class Qwifi(unittest.TestCase): @@ -12,6 +13,7 @@ class Qwifi(unittest.TestCase): params = None __bwreal = None __resultlist = None # resultlist is a python list of python dictionaries + timebetweenattempts = 5 # varlist content: serverip, bwexpected, port def __init__(self, testname, testfunc, varlist): @@ -48,12 +50,17 @@ class Qwifi(unittest.TestCase): 'inet addr:(?!127\.0{1,3}\.0{1,3}\.0{0,2}1$)((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)', p.stdout.decode('ascii')) if result: - # execute iperf command against the server - try: - p = sh.iperf3("-c", self.__serverip, "-n", self.__numbytestx, "-f", "m", "-p", self.__port, - "-J", _timeout=30) - except sh.TimeoutException: - self.fail("failed: iperf timeout reached") + # execute iperf command against the server, but it implements attempts in case the server is busy + iperfdone = False + while not iperfdone: + try: + p = sh.iperf3("-c", self.__serverip, "-n", self.__numbytestx, "-f", "m", "-p", self.__port, + "-J", _timeout=20) + iperfdone = True + except sh.TimeoutException: + self.fail("failed: iperf timeout reached") + except sh.ErrorReturnCode: + time.sleep(self.timebetweenattempts) # check if it was executed succesfully if p.exit_code == 0: -- 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/qwifi.py | 143 +++++++++++++++++++++---------------------- 1 file changed, 70 insertions(+), 73 deletions(-) (limited to 'test-cli/test/tests/qwifi.py') diff --git a/test-cli/test/tests/qwifi.py b/test-cli/test/tests/qwifi.py index 3dd9e38..4695041 100644 --- a/test-cli/test/tests/qwifi.py +++ b/test-cli/test/tests/qwifi.py @@ -1,9 +1,11 @@ import unittest -import sh -import re -import json import time - +import uuid +import iperf3 +import netifaces +from test.helpers.iw import iwScan +from test.helpers.utils import save_json_to_disk +from test.helpers.utils import station2Port class Qwifi(unittest.TestCase): __serverip = None @@ -19,81 +21,76 @@ class Qwifi(unittest.TestCase): def __init__(self, testname, testfunc, varlist): self.params = varlist super(Qwifi, self).__init__(testfunc) - if "serverip" in varlist: - self.__serverip = varlist["serverip"] - else: - raise Exception('serverip param inside Qwifi have been be defined') - if "bwexpected" in varlist: - self.__bwexpected = varlist["bwexpected"] - else: - raise Exception('OKBW param inside Qwifi must be defined') - if "port" in varlist: - self.__port = varlist["port"] - else: - raise Exception('port param inside Qwifi must be defined') - self.__numbytestx = "10M" self._testMethodDoc = testname + self.__xmlObj = varlist["xml"] + self.__QwifiName = varlist.get('name', 'qwifi') + self.__loops = varlist.get('loops', self.__xmlObj.getKeyVal(self.__QwifiName, "loops", "1")) + self.__port = varlist.get('port', self.__xmlObj.getKeyVal(self.__QwifiName, "port", "5000")) + self.__bw = varlist.get('bwexpected', self.__xmlObj.getKeyVal(self.__QwifiName, "bwexpected", "5.0")) + self.__serverip = varlist.get('serverip', self.__xmlObj.getKeyVal(self.__QwifiName, "serverip", "localhost")) + self.__duration = varlist.get('duration', self.__xmlObj.getKeyVal(self.__QwifiName, "duration", "10")) + self.__interface = varlist.get('interface', self.__xmlObj.getKeyVal(self.__QwifiName, "interface", "wlan0")) + self.__toPath = varlist.get('to', self.__xmlObj.getKeyVal(self.__QwifiName, "to", "/mnt/station_ramdisk")) + self.__retriesCount = varlist.get('retries', self.__xmlObj.getKeyVal(self.__QwifiName, "retries", "5")) + self.__waitRetryTime = varlist.get('wait_retry', self.__xmlObj.getKeyVal(self.__QwifiName, "wait_retry", "10")) + self.__wifi_res_file = varlist.get('wifi_res_file', self.__xmlObj.getKeyVal(self.__QwifiName, "wifi_res_file", "wifi_test_{}.json")) + self.__wifi_st_file = varlist.get('wifi_st_file', self.__xmlObj.getKeyVal(self.__QwifiName, "wifi_st_file", "wifi_st_{}.json")) + self.__file_uuid = uuid.uuid4() + self.__wifi_res_file = self.__wifi_res_file.format(self.__file_uuid) + self.__wifi_st_file = self.__wifi_st_file.format(self.__file_uuid) self.__resultlist = [] - def execute(self): - # check if the board is connected to the router by wifi - p = sh.iw("wlan0", "link") - if p.exit_code == 0: - # get the first line of the output stream - out1 = p.stdout.decode('ascii').splitlines()[0] - if out1 != "Not connected.": - # check if the board has ip in the wlan0 interface - p = sh.ifconfig("wlan0") - if p.exit_code == 0: - # check if wlan0 has an IP - result = re.search( - 'inet addr:(?!127\.0{1,3}\.0{1,3}\.0{0,2}1$)((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)', - p.stdout.decode('ascii')) - if result: - # execute iperf command against the server, but it implements attempts in case the server is busy - iperfdone = False - while not iperfdone: - try: - p = sh.iperf3("-c", self.__serverip, "-n", self.__numbytestx, "-f", "m", "-p", self.__port, - "-J", _timeout=20) - iperfdone = True - except sh.TimeoutException: - self.fail("failed: iperf timeout reached") - except sh.ErrorReturnCode: - time.sleep(self.timebetweenattempts) - - # check if it was executed succesfully - if p.exit_code == 0: - if p.stdout == "": - self.fail("failed: error executing iperf command") - # analyze output string - data = json.loads(p.stdout.decode('ascii')) - self.__bwreal = float(data['end']['sum_received']['bits_per_second']) / 1024 / 1024 - # save result file - with open('/mnt/station_ramdisk/wifi-iperf3.json', 'w') as outfile: - json.dump(data, outfile, indent=4) - outfile.close() - self.__resultlist.append( - { - "description": "iperf3 output", - "filepath": "/mnt/station_ramdisk/wifi-iperf3.json", - "mimetype": "application/json" - } - ) + def checkInterface(self, reqInterface): + ifaces = netifaces.interfaces() + for t in ifaces: + if t == reqInterface: + return True + return False - # check if BW is in the expected range - if self.__bwreal < float(self.__bwexpected): - self.fail("failed: speed is lower than expected. Speed(Mbits/s): " + str(self.__bwreal)) - else: - self.fail("failed: could not complete iperf3 command") - else: - self.fail("failed: wlan0 interface doesn't have any ip address.") + def execute(self): + self.__resultlist = [] + stationList = {} + # check interfaces + if not self.checkInterface(self.__interface): + self.fail('Interface not found: {}'.format(self.__interface)) + # scan networks + scanner = iwScan(self.__interface) + if scanner.scan(): + stationList = scanner.getStations() + # check if we are connected + if not scanner.findConnected(): + self.fail('Not connected to test AP') + else: + strError = scanner.getLastError() + self.fail('qWifi scanner Execution error: {}'.format(strError)) + # Start Iperf + client = iperf3.Client() + client.duration = int(self.__duration) + client.server_hostname = self.__serverip + client.port = station2Port(self.__port) + count = int(self.__retriesCount) + while count > 0: + result = client.run() + if result.error == None: + if result.received_Mbps >= float(self.__bw) and result.sent_Mbps >= float(self.__bw): + save_json_to_disk(filePath='{}/{}'.format(self.__toPath, self.__wifi_st_file), + description='wifi scan', + mime='application/json', + json_data=stationList, + result=self.__resultlist) + save_json_to_disk(filePath='{}/{}'.format(self.__toPath, self.__wifi_res_file), + description='wifi {} iperf3'.format(self.__interface), + mime='application/json', + json_data=result.json, + result=self.__resultlist) + return else: - self.fail("failed: could not complete ifconfig command.") + self.fail('bw fail: rx:{} tx:{}'.format(result.received_Mbps, result.sent_Mbps)) else: - self.fail("failed: wifi module is not connected to the router.") - else: - self.fail("failed: could not execute iw command") + count = count - 1 + time.sleep(int(self.__waitRetryTime)) + + self.fail('qWifi (max tries) Execution error: {}'.format(result.error)) def getresults(self): return self.__resultlist -- cgit v1.1