tests/run-multitests.py: Set HOST_IP so tests work between PC and board.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George 2022-01-17 17:15:31 +11:00
parent 5df1d8be6c
commit c54717a78f
1 changed files with 22 additions and 1 deletions

View File

@ -66,7 +66,7 @@ class multitest:
import network import network
ip = network.WLAN().ifconfig()[0] ip = network.WLAN().ifconfig()[0]
except: except:
ip = "127.0.0.1" ip = HOST_IP
return 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: class PyInstance:
def __init__(self): def __init__(self):
pass pass
@ -274,6 +288,13 @@ def run_test_on_instances(test_file, num_instances, instances):
injected_globals = "" injected_globals = ""
output = [[] for _ in range(num_instances)] 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: if cmd_args.trace_output:
print("TRACE {}:".format("|".join(str(i) for i in instances))) print("TRACE {}:".format("|".join(str(i) for i in instances)))