summaryrefslogtreecommitdiffstatshomepage
path: root/tests/run-multitests.py
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2020-06-05 15:41:40 +1000
committerDamien George <damien.p.george@gmail.com>2020-06-10 22:41:57 +1000
commit00c3e2156a7b5447966019ad46a1c9763f0890ee (patch)
tree37e451d9f7ed75e4345c9f757566f852a40106a4 /tests/run-multitests.py
parent3f77f2c60ca80ea9189f85193dbd746e9a6034a9 (diff)
downloadmicropython-00c3e2156a7b5447966019ad46a1c9763f0890ee.tar.gz
micropython-00c3e2156a7b5447966019ad46a1c9763f0890ee.zip
tests/run-multitests.py: Allow passing unique env vars to each instance.
For example, to run the BLE multitests entirely with the unix port: env MICROPY_MICROPYTHON=../ports/unix/micropython-dev ./run-multitests.py \ -i micropython,MICROPYBTUSB=01 \ -i micropython,MICROPYBTUSB=02:02 \ multi_bluetooth/ble_*.py
Diffstat (limited to 'tests/run-multitests.py')
-rwxr-xr-xtests/run-multitests.py41
1 files changed, 27 insertions, 14 deletions
diff --git a/tests/run-multitests.py b/tests/run-multitests.py
index 567e9b5ffa..7ab4e85c57 100755
--- a/tests/run-multitests.py
+++ b/tests/run-multitests.py
@@ -92,20 +92,25 @@ class PyInstance:
class PyInstanceSubProcess(PyInstance):
- def __init__(self, cmd):
- self.cmd = cmd
+ def __init__(self, argv, env=None):
+ self.argv = argv
+ self.env = {n: v for n, v in (i.split("=") for i in env)} if env else None
self.popen = None
self.finished = True
def __str__(self):
- return self.cmd[0].rsplit("/")[-1]
+ return self.argv[0].rsplit("/")[-1]
def run_script(self, script):
output = b""
err = None
try:
p = subprocess.run(
- self.cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, input=script
+ self.argv,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT,
+ input=script,
+ env=self.env,
)
output = p.stdout
except subprocess.CalledProcessError as er:
@@ -114,7 +119,11 @@ class PyInstanceSubProcess(PyInstance):
def start_script(self, script):
self.popen = subprocess.Popen(
- self.cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
+ self.argv,
+ stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT,
+ env=self.env,
)
self.popen.stdin.write(script)
self.popen.stdin.close()
@@ -404,16 +413,20 @@ def main():
instances_test = []
for i in cmd_args.instance:
- if i.startswith("exec:"):
- instances_test.append(PyInstanceSubProcess([i[len("exec:") :]]))
- elif i == "micropython":
- instances_test.append(PyInstanceSubProcess([MICROPYTHON]))
- elif i == "cpython":
- instances_test.append(PyInstanceSubProcess([CPYTHON3]))
- elif i.startswith("pyb:"):
- instances_test.append(PyInstancePyboard(i[len("pyb:") :]))
+ # Each instance arg is <cmd>,ENV=VAR,ENV=VAR...
+ i = i.split(",")
+ cmd = i[0]
+ env = i[1:]
+ if cmd.startswith("exec:"):
+ instances_test.append(PyInstanceSubProcess([cmd[len("exec:") :]], env))
+ elif cmd == "micropython":
+ instances_test.append(PyInstanceSubProcess([MICROPYTHON], env))
+ elif cmd == "cpython":
+ instances_test.append(PyInstanceSubProcess([CPYTHON3], env))
+ elif cmd.startswith("pyb:"):
+ instances_test.append(PyInstancePyboard(cmd[len("pyb:") :]))
else:
- print("unknown instance string: {}".format(i), file=sys.stderr)
+ print("unknown instance string: {}".format(cmd), file=sys.stderr)
sys.exit(1)
for _ in range(max_instances - len(instances_test)):