Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ports/qemu/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ test_natmod: $(BUILD)/firmware.elf
$(eval DIRNAME=ports/$(notdir $(CURDIR)))
cd $(TOP)/tests && \
for natmod in btree deflate framebuf heapq random_basic re; do \
./run-natmodtests.py -p -d execpty:"$(QEMU_SYSTEM) $(QEMU_ARGS) -serial pty -kernel ../$(DIRNAME)/$<" $(RUN_TESTS_EXTRA) extmod/$$natmod*.py; \
./run-natmodtests.py -t execpty:"$(QEMU_SYSTEM) $(QEMU_ARGS) -serial pty -kernel ../$(DIRNAME)/$<" $(RUN_TESTS_EXTRA) extmod/$$natmod*.py; \
done

$(BUILD)/firmware.elf: $(LDSCRIPT) $(OBJ)
Expand Down
44 changes: 18 additions & 26 deletions tests/run-multitests.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,17 +238,8 @@ def wait_finished(self):


class PyInstancePyboard(PyInstance):
@staticmethod
def map_device_shortcut(device):
if device[0] == "a" and device[1:].isdigit():
return "/dev/ttyACM" + device[1:]
elif device[0] == "u" and device[1:].isdigit():
return "/dev/ttyUSB" + device[1:]
else:
return device

def __init__(self, device):
device = self.map_device_shortcut(device)
device = device
self.device = device
self.pyb = pyboard.Pyboard(device)
self.pyb.enter_raw_repl()
Expand Down Expand Up @@ -562,16 +553,24 @@ def main():

cmd_parser = argparse.ArgumentParser(
description="Run network tests for MicroPython",
epilog=(
run_tests_module.test_instance_epilog
+ "Each instance arg can optionally have custom env provided, eg. <cmd>,ENV=VAR,ENV=VAR...\n"
),
formatter_class=argparse.RawTextHelpFormatter,
)
cmd_parser.add_argument(
"-s", "--show-output", action="store_true", help="show test output after running"
)
cmd_parser.add_argument(
"-t", "--trace-output", action="store_true", help="trace test output while running"
"-c", "--trace-output", action="store_true", help="trace test output while running"
)
cmd_parser.add_argument(
"-i", "--instance", action="append", default=[], help="instance(s) to run the tests on"
"-t",
"--test-instance",
action="append",
default=[],
help="instance(s) to run the tests on",
)
cmd_parser.add_argument(
"-p",
Expand All @@ -586,14 +585,6 @@ def main():
default=run_tests_module.base_path("results"),
help="directory for test results",
)
cmd_parser.epilog = (
"Supported instance types:\r\n"
" -i pyb:<port> physical device (eg. pyboard) on provided repl port.\n"
" -i micropython unix micropython instance, path customised with MICROPY_MICROPYTHON env.\n"
" -i cpython desktop python3 instance, path customised with MICROPY_CPYTHON3 env.\n"
" -i exec:<path> custom program run on provided path.\n"
"Each instance arg can optionally have custom env provided, eg. <cmd>,ENV=VAR,ENV=VAR...\n"
)
cmd_parser.add_argument("files", nargs="+", help="input test files")
cmd_args = cmd_parser.parse_args()

Expand All @@ -606,22 +597,23 @@ def main():
instances_truth = [PyInstanceSubProcess([PYTHON_TRUTH]) for _ in range(max_instances)]

instances_test = []
for i in cmd_args.instance:
for i in cmd_args.test_instance:
# 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":
elif cmd == "unix":
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:") :]))
elif cmd == "webassembly" or cmd.startswith("execpty:"):
print("unsupported instance string: {}".format(cmd), file=sys.stderr)
sys.exit(2)
else:
print("unknown instance string: {}".format(cmd), file=sys.stderr)
sys.exit(1)
device = run_tests_module.convert_device_shortcut_to_real_device(cmd)
instances_test.append(PyInstancePyboard(device))

for _ in range(max_instances - len(instances_test)):
instances_test.append(PyInstanceSubProcess([MICROPYTHON]))
Expand Down
28 changes: 16 additions & 12 deletions tests/run-natmodtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@

run_tests_module = __import__("run-tests")

sys.path.append("../tools")
import pyboard

# Paths for host executables
CPYTHON3 = os.getenv("MICROPY_CPYTHON3", "python3")
MICROPYTHON = os.getenv("MICROPY_MICROPYTHON", "../ports/unix/build-coverage/micropython")
Expand Down Expand Up @@ -112,7 +109,7 @@ def run_script(self, script):
output = self.pyb.exec_(script)
output = output.replace(b"\r\n", b"\n")
return output, None
except pyboard.PyboardError as er:
except run_tests_module.pyboard.PyboardError as er:
return b"", er


Expand Down Expand Up @@ -227,14 +224,16 @@ def run_tests(target_truth, target, args, resolved_arch):

def main():
cmd_parser = argparse.ArgumentParser(
description="Run dynamic-native-module tests under MicroPython"
)
cmd_parser.add_argument(
"-p", "--pyboard", action="store_true", help="run tests via pyboard.py"
description="Run dynamic-native-module tests under MicroPython",
epilog=run_tests_module.test_instance_epilog,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
cmd_parser.add_argument(
"-d", "--device", default="/dev/ttyACM0", help="the device for pyboard.py"
"-t", "--test-instance", default="unix", help="the MicroPython instance to test"
)
cmd_parser.add_argument("--baudrate", default=115200, help="baud rate of the serial device")
cmd_parser.add_argument("--user", default="micro", help="telnet login username")
cmd_parser.add_argument("--password", default="python", help="telnet login password")
cmd_parser.add_argument(
"-a", "--arch", choices=AVAILABLE_ARCHS, help="override native architecture of the target"
)
Expand All @@ -256,10 +255,15 @@ def main():

target_truth = TargetSubprocess([CPYTHON3])

if args.pyboard:
target = TargetPyboard(pyboard.Pyboard(args.device))
else:
target = run_tests_module.get_test_instance(
args.test_instance, args.baudrate, args.user, args.password
)
if target is None:
# Use the unix port of MicroPython.
target = TargetSubprocess([MICROPYTHON])
else:
# Use a remote target.
target = TargetPyboard(target)

if hasattr(args, "arch") and args.arch is not None:
target_arch = args.arch
Expand Down
36 changes: 18 additions & 18 deletions tests/run-perfbench.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@

run_tests_module = __import__("run-tests")

sys.path.append("../tools")
import pyboard

prepare_script_for_target = run_tests_module.prepare_script_for_target

# Paths for host executables
Expand Down Expand Up @@ -47,12 +44,12 @@ def run_script_on_target(target, script):
output = b""
err = None

if isinstance(target, pyboard.Pyboard):
if hasattr(target, "enter_raw_repl"):
# Run via pyboard interface
try:
target.enter_raw_repl()
output = target.exec_(script)
except pyboard.PyboardError as er:
except run_tests_module.pyboard.PyboardError as er:
err = er
else:
# Run local executable
Expand Down Expand Up @@ -125,7 +122,7 @@ def run_benchmarks(args, target, param_n, param_m, n_average, test_list):
f.write(test_script)

# Process script through mpy-cross if needed
if isinstance(target, pyboard.Pyboard) or args.via_mpy:
if hasattr(target, "enter_raw_repl") or args.via_mpy:
crash, test_script_target = prepare_script_for_target(args, script_text=test_script)
if crash:
test_results.append((test_file, "fail", "preparation"))
Expand Down Expand Up @@ -253,17 +250,17 @@ def compute_diff(file1, file2, diff_score):
def main():
cmd_parser = argparse.ArgumentParser(description="Run benchmarks for MicroPython")
cmd_parser.add_argument(
"-t", "--diff-time", action="store_true", help="diff time outputs from a previous run"
"-m", "--diff-time", action="store_true", help="diff time outputs from a previous run"
)
cmd_parser.add_argument(
"-s", "--diff-score", action="store_true", help="diff score outputs from a previous run"
)
cmd_parser.add_argument(
"-p", "--pyboard", action="store_true", help="run tests via pyboard.py"
)
cmd_parser.add_argument(
"-d", "--device", default="/dev/ttyACM0", help="the device for pyboard.py"
"-t", "--test-instance", default="unix", help="the MicroPython instance to test"
)
cmd_parser.add_argument("--baudrate", default=115200, help="baud rate of the serial device")
cmd_parser.add_argument("--user", default="micro", help="telnet login username")
cmd_parser.add_argument("--password", default="python", help="telnet login password")
cmd_parser.add_argument("-a", "--average", default="8", help="averaging number")
cmd_parser.add_argument(
"--emit", default="bytecode", help="MicroPython emitter to use (bytecode or native)"
Expand Down Expand Up @@ -295,15 +292,18 @@ def main():
M = int(args.M[0])
n_average = int(args.average)

if args.pyboard:
if not args.mpy_cross_flags:
args.mpy_cross_flags = "-march=armv7m"
target = pyboard.Pyboard(args.device)
target.enter_raw_repl()
else:
target = run_tests_module.get_test_instance(
args.test_instance, args.baudrate, args.user, args.password
)
if target is None:
# Use the unix port of MicroPython.
target = [MICROPYTHON, "-X", "emit=" + args.emit]
if args.heapsize is not None:
target.extend(["-X", "heapsize=" + args.heapsize])
else:
# Use a remote target.
if not args.mpy_cross_flags:
args.mpy_cross_flags = "-march=armv7m"

if len(args.files) == 0:
tests_skip = ("benchrun.py",)
Expand All @@ -324,7 +324,7 @@ def main():
test_results = run_benchmarks(args, target, N, M, n_average, tests)
res = run_tests_module.create_test_report(args, test_results)

if isinstance(target, pyboard.Pyboard):
if hasattr(target, "exit_raw_repl"):
target.exit_raw_repl()
target.close()

Expand Down
19 changes: 12 additions & 7 deletions tests/run-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,22 +246,27 @@ def platform_to_port(platform):
return platform_to_port_map.get(platform, platform)


def convert_device_shortcut_to_real_device(device):
if device.startswith("a") and device[1:].isdigit():
return "/dev/ttyACM" + device[1:]
elif device.startswith("u") and device[1:].isdigit():
return "/dev/ttyUSB" + device[1:]
elif device.startswith("c") and device[1:].isdigit():
return "COM" + device[1:]
else:
return device


def get_test_instance(test_instance, baudrate, user, password):
if test_instance.startswith("port:"):
_, port = test_instance.split(":", 1)
elif test_instance == "unix":
return None
elif test_instance == "webassembly":
return PyboardNodeRunner()
elif test_instance.startswith("a") and test_instance[1:].isdigit():
port = "/dev/ttyACM" + test_instance[1:]
elif test_instance.startswith("u") and test_instance[1:].isdigit():
port = "/dev/ttyUSB" + test_instance[1:]
elif test_instance.startswith("c") and test_instance[1:].isdigit():
port = "COM" + test_instance[1:]
else:
# Assume it's a device path.
port = test_instance
port = convert_device_shortcut_to_real_device(test_instance)

global pyboard
sys.path.append(base_path("../tools"))
Expand Down
Loading