summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2022-01-17 17:15:31 +1100
committerDamien George <damien@micropython.org>2022-01-17 17:35:04 +1100
commitc54717a78f8640cbf4ae6c824569df253ffb689c (patch)
tree5c65c60a3fa759f814297cca19c2c81cc19d3d2f
parent5df1d8be6c1c55292824c698761159dc29b384d6 (diff)
tests/run-multitests.py: Set HOST_IP so tests work between PC and board.
Signed-off-by: Damien George <damien@micropython.org>
-rwxr-xr-xtests/run-multitests.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/tests/run-multitests.py b/tests/run-multitests.py
index 20ef4a7aa..f55d52b6e 100755
--- a/tests/run-multitests.py
+++ b/tests/run-multitests.py
@@ -66,7 +66,7 @@ class multitest:
import network
ip = network.WLAN().ifconfig()[0]
except:
- ip = "127.0.0.1"
+ ip = HOST_IP
return ip
{}
@@ -87,6 +87,20 @@ IGNORE_OUTPUT_MATCHES = (
)
+def get_host_ip(_ip_cache=[]):
+ if not _ip_cache:
+ try:
+ import socket
+
+ s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+ s.connect(("8.8.8.8", 80))
+ _ip_cache.append(s.getsockname()[0])
+ s.close()
+ except:
+ _ip_cache.append("127.0.0.1")
+ return _ip_cache[0]
+
+
class PyInstance:
def __init__(self):
pass
@@ -274,6 +288,13 @@ def run_test_on_instances(test_file, num_instances, instances):
injected_globals = ""
output = [[] for _ in range(num_instances)]
+ # If the test calls get_network_ip() then inject HOST_IP so that devices can know
+ # the IP address of the host. Do this lazily to not require a TCP/IP connection
+ # on the host if it's not needed.
+ with open(test_file, "rb") as f:
+ if b"get_network_ip" in f.read():
+ injected_globals += "HOST_IP = '" + get_host_ip() + "'\n"
+
if cmd_args.trace_output:
print("TRACE {}:".format("|".join(str(i) for i in instances)))