Skip to content

Commit addbcb7

Browse files
jaenrig-ifxactions-user
authored andcommitted
tests/ports/psoc6/../network: Added randomized ssid to avoid conflicts.
Signed-off-by: enriquezgarc <[email protected]>
1 parent a7d4253 commit addbcb7

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

tests/ports/psoc6/board_only_hw/multi/network.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
raise SystemExit
88

99
channel_new = 1
10-
ssid_default = "mpy-psoc6-wlan"
1110

1211

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

1817
ap_if = network.WLAN(network.AP_IF)
1918
print("ap instance created")
20-
ap_if.config(channel=channel_new)
19+
20+
# Generate "random" SSID to avoid test conflicts
21+
time_stamp = time.time()
22+
ssid_new = "mpy-psoc6-" + str(time_stamp)
23+
multitest.globals(ssid_gen=ssid_new)
24+
ap_if.config(channel=channel_new, ssid=ssid_new)
2125

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

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

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

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

8187
# connect()
82-
sta_if.connect(ssid_default, "mpy_PSOC6_w3lc0me!")
88+
sta_if.connect(ssid_gen, "mpy_PSOC6_w3lc0me!")
8389
print("sta attempt connection to ap")
8490

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

102108
print("sta attempt connection to ap (with bssid)")
103-
sta_if.connect(ssid_default, "mpy_PSOC6_w3lc0me!", bssid=ap_mac)
109+
sta_if.connect(ssid_gen, "mpy_PSOC6_w3lc0me!", bssid=ap_mac)
104110

105111
print("sta is active: ", sta_if.active() == True)

tests/ports/psoc6/board_only_hw/multi/network_config.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import binascii, time
2+
import random
23

34
try:
45
import network
56
except ImportError:
67
print("SKIP")
78
raise SystemExit
89

9-
channel_new = 5
10-
ssid_new = "mpy-test-conf-wlan"
10+
channel_new = random.randint(1, 5)
1111
pass_new = "alicessecret"
1212
sec_new = network.WLAN.WPA2
1313

@@ -26,8 +26,14 @@ def instance0():
2626
# get config()
2727
ap_if.config(channel=channel_new)
2828
print("ap config get channel: ", ap_if.config("channel") == channel_new)
29+
30+
# Generate "random" SSID to avoid test conflicts
31+
time_stamp = time.time()
32+
ssid_new = "mpy-test-" + str(time_stamp)
33+
multitest.globals(ssid_gen=ssid_new)
2934
ap_if.config(ssid=ssid_new)
3035
print("ap config get ssid: ", ap_if.config("ssid") == ssid_new)
36+
3137
ap_if.config(security=sec_new, key=pass_new)
3238
print("ap config get security: ", ap_if.config("security") == sec_new)
3339
try:
@@ -67,7 +73,7 @@ def instance1():
6773
print("sta instance created")
6874

6975
# connect()
70-
sta_if.connect(ssid_new, pass_new)
76+
sta_if.connect(ssid_gen, pass_new)
7177
print("sta attempt connection to ap")
7278

7379
# active()
@@ -78,7 +84,7 @@ def instance1():
7884

7985
# config()
8086
print("sta assoc ap channel config: ", sta_if.config("channel") == channel_new)
81-
print("sta assoc ap ssid config: ", sta_if.config("ssid") == ssid_new)
87+
print("sta assoc ap ssid config: ", sta_if.config("ssid") == ssid_gen)
8288
print("sta assoc ap security config: ", sta_if.config("security") == sec_new)
8389

8490
try:

0 commit comments

Comments
 (0)