Skip to content

Commit

Permalink
tests/ports/psoc6/../network: Added randomized ssid to avoid conflicts.
Browse files Browse the repository at this point in the history
Signed-off-by: enriquezgarc <enriquezgarcia.external@infineon.com>
  • Loading branch information
jaenrig-ifx committed Oct 15, 2024
1 parent 56d2e77 commit 66c9963
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
20 changes: 13 additions & 7 deletions tests/ports/psoc6/board_only_hw/multi/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
raise SystemExit

channel_new = 1
ssid_default = "mpy-psoc6-wlan"


# Access Point
Expand All @@ -17,7 +16,12 @@ def instance0():

ap_if = network.WLAN(network.AP_IF)
print("ap instance created")
ap_if.config(channel=channel_new)

# Generate "random" SSID to avoid test conflicts
time_stamp = time.time()
ssid_new = "mpy-psoc6-" + str(time_stamp)
multitest.globals(ssid_gen=ssid_new)
ap_if.config(channel=channel_new, ssid=ssid_new)

# active()
print("ap initially not active: ", ap_if.active() == False)
Expand Down Expand Up @@ -62,11 +66,13 @@ def instance1():

# scan()
wlan_nets = sta_if.scan()
test_ap_net = [net for net in wlan_nets if net[0] == b"mpy-psoc6-wlan"]
# The returned ssid is a bytes object
bytes_ssid = bytes(ssid_gen, "utf-8")
test_ap_net = [net for net in wlan_nets if net[0] == bytes_ssid]
print("sta scan finds ap wlan: ", test_ap_net != [])

wlan_ssid_filter = sta_if.scan(ssid="mpy-psoc6-wlan")
test_ap_net = [net for net in wlan_ssid_filter if net[0] == b"mpy-psoc6-wlan"]
wlan_ssid_filter = sta_if.scan(ssid=ssid_gen)
test_ap_net = [net for net in wlan_ssid_filter if net[0] == bytes_ssid]
print("sta scan finds ap wlan (ssid filter): ", test_ap_net != [])

# print('ap_mac: ', binascii.hexlify(ap_mac, ':'))
Expand All @@ -79,7 +85,7 @@ def instance1():
print("sta is not (yet) connected: ", sta_if.isconnected() == False)

# connect()
sta_if.connect(ssid_default, "mpy_PSOC6_w3lc0me!")
sta_if.connect(ssid_gen, "mpy_PSOC6_w3lc0me!")
print("sta attempt connection to ap")

# active()
Expand All @@ -100,6 +106,6 @@ def instance1():
print("sta is disconnected: ", sta_if.active() == False)

print("sta attempt connection to ap (with bssid)")
sta_if.connect(ssid_default, "mpy_PSOC6_w3lc0me!", bssid=ap_mac)
sta_if.connect(ssid_gen, "mpy_PSOC6_w3lc0me!", bssid=ap_mac)

print("sta is active: ", sta_if.active() == True)
14 changes: 10 additions & 4 deletions tests/ports/psoc6/board_only_hw/multi/network_config.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import binascii, time
import random

try:
import network
except ImportError:
print("SKIP")
raise SystemExit

channel_new = 5
ssid_new = "mpy-test-conf-wlan"
channel_new = random.randint(1, 5)
pass_new = "alicessecret"
sec_new = network.WLAN.WPA2

Expand All @@ -26,8 +26,14 @@ def instance0():
# get config()
ap_if.config(channel=channel_new)
print("ap config get channel: ", ap_if.config("channel") == channel_new)

# Generate "random" SSID to avoid test conflicts
time_stamp = time.time()
ssid_new = "mpy-test-" + str(time_stamp)
multitest.globals(ssid_gen=ssid_new)
ap_if.config(ssid=ssid_new)
print("ap config get ssid: ", ap_if.config("ssid") == ssid_new)

ap_if.config(security=sec_new, key=pass_new)
print("ap config get security: ", ap_if.config("security") == sec_new)
try:
Expand Down Expand Up @@ -67,7 +73,7 @@ def instance1():
print("sta instance created")

# connect()
sta_if.connect(ssid_new, pass_new)
sta_if.connect(ssid_gen, pass_new)
print("sta attempt connection to ap")

# active()
Expand All @@ -78,7 +84,7 @@ def instance1():

# config()
print("sta assoc ap channel config: ", sta_if.config("channel") == channel_new)
print("sta assoc ap ssid config: ", sta_if.config("ssid") == ssid_new)
print("sta assoc ap ssid config: ", sta_if.config("ssid") == ssid_gen)
print("sta assoc ap security config: ", sta_if.config("security") == sec_new)

try:
Expand Down

0 comments on commit 66c9963

Please sign in to comment.