[PATCH] tests: Add an option to use random ssids for remote tests

Jonathan Afek jonathan at wizery.com
Tue Jul 19 13:49:59 PDT 2016


More than one instance of a remote test can be executed
in a signle room. This option will make the different
instances use different ssids.

Signed-off-by: Jonathan Afek <jonathanx.afek at intel.com>
---
 tests/hwsim/hostapd.py        | 7 ++++++-
 tests/hwsim/wpasupplicant.py  | 8 ++++++--
 tests/remote/hwsim_wrapper.py | 4 ++++
 tests/remote/rutils.py        | 8 ++++++++
 4 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/tests/hwsim/hostapd.py b/tests/hwsim/hostapd.py
index 51ad02e..65126a0 100644
--- a/tests/hwsim/hostapd.py
+++ b/tests/hwsim/hostapd.py
@@ -406,7 +406,12 @@ def add_ap(apdev, params, wait_enabled=True, no_enable=False, timeout=30):
                    "acct_server_addr", "osu_server_uri" ]
         for field in fields:
             if field in params:
-                hapd.set(field, params[field])
+                if hostname is not None and field in ["ssid", "ssid2"]:
+                    import rutils
+                    prefix = rutils.RandomSsid.ssid_prefix
+                    hapd.set(field, prefix + params[field])
+                else:
+                    hapd.set(field, params[field])
         for f,v in params.items():
             if f in fields:
                 continue
diff --git a/tests/hwsim/wpasupplicant.py b/tests/hwsim/wpasupplicant.py
index d50a4c8..bb03ab1 100644
--- a/tests/hwsim/wpasupplicant.py
+++ b/tests/hwsim/wpasupplicant.py
@@ -982,10 +982,14 @@ class WpaSupplicant:
     def connect(self, ssid=None, ssid2=None, **kwargs):
         logger.info("Connect STA " + self.ifname + " to AP")
         id = self.add_network()
+        prefix = ""
+        if self.hostname is not None:
+            import rutils
+            prefix = rutils.RandomSsid.ssid_prefix
         if ssid:
-            self.set_network_quoted(id, "ssid", ssid)
+            self.set_network_quoted(id, "ssid", prefix + ssid)
         elif ssid2:
-            self.set_network(id, "ssid", ssid2)
+            self.set_network(id, "ssid", prefix + ssid2)
 
         quoted = [ "psk", "identity", "anonymous_identity", "password",
                    "ca_cert", "client_cert", "private_key",
diff --git a/tests/remote/hwsim_wrapper.py b/tests/remote/hwsim_wrapper.py
index d2598ab..8b28300 100644
--- a/tests/remote/hwsim_wrapper.py
+++ b/tests/remote/hwsim_wrapper.py
@@ -31,6 +31,10 @@ def run_hwsim_test(devices, setup_params, refs, duts, monitors, hwsim_test):
             dut_host = rutils.get_host(devices, dut)
             dut_hosts.append(dut_host)
 
+        # setup random ssid
+        if "random_ssid" in setup_params and setup_params["random_ssid"]:
+            rutils.RandomSsid.set_random_ssid_prefix()
+
         # setup log dir
         local_log_dir = setup_params['local_log_dir']
 
diff --git a/tests/remote/rutils.py b/tests/remote/rutils.py
index 879fadc..fb0d32e 100644
--- a/tests/remote/rutils.py
+++ b/tests/remote/rutils.py
@@ -9,6 +9,14 @@ import time
 from remotehost import Host
 import hostapd
 import config
+import random
+
+class RandomSsid(object):
+    ssid_prefix = ""
+    @classmethod
+    def set_random_ssid_prefix(cls):
+        chars = '0123456789abcdef'
+        cls.ssid_prefix = ''.join(random.choice(chars) for _ in range(4))
 
 class TestSkip(Exception):
     def __init__(self, reason):
-- 
2.9.1




More information about the Hostap mailing list