Files
micropython/ports/webassembly/Makefile
Damien George 8978102f35 tests/run-tests.py: Change --target/--device options to --test-instance.
Previously to this commit, running the test suite on a bare-metal board
required specifying the target (really platform) and device, eg:

    $ ./run-tests.py --target pyboard --device /dev/ttyACM1

That's quite a lot to type, and you also need to know what the target
platform is, when a lot of the time you either don't care or it doesn't
matter.

This commit makes it easier to run the tests by replacing both of these
options with a single `--test-instance` (`-t` for short) option.  That
option specifies the executable/port/device to test.  Then the target
platform is automatically detected.

The `--test-instance` can be passed:
- "unix" (the default) to use the unix version of MicroPython
- "webassembly" to test the webassembly port
- anything else is considered a port/device to pass to Pyboard

There are also some shortcuts to specify a port/device, following
`mpremote`:
- a<n> is short for /dev/ttyACM<n>
- u<n> is short for /dev/ttyUSB<n>
- c<n> is short for COM<n>

For example:

    $ ./run-tests.py -t a1

Note that the default test instance is "unix" and so this commit does not
change the standard way to run tests on the unix port, by just doing
`./run-tests.py`.

As part of this change, the platform (and it's native architecture if it
supports importing native .mpy files) is show at the start of the test run.

Signed-off-by: Damien George <damien@micropython.org>
2024-11-04 12:47:47 +11:00

160 lines
3.9 KiB
Makefile

################################################################################
# Initial setup of Makefile environment.
# Select the variant to build for:
ifdef VARIANT_DIR
# Custom variant path - remove trailing slash and get the final component of
# the path as the variant name.
VARIANT ?= $(notdir $(VARIANT_DIR:/=))
else
# If not given on the command line, then default to standard.
VARIANT ?= standard
VARIANT_DIR ?= variants/$(VARIANT)
endif
ifeq ($(wildcard $(VARIANT_DIR)/.),)
$(error Invalid VARIANT specified: $(VARIANT_DIR))
endif
# If the build directory is not given, make it reflect the variant name.
BUILD ?= build-$(VARIANT)
include ../../py/mkenv.mk
include $(VARIANT_DIR)/mpconfigvariant.mk
# Use the default frozen manifest, variants may override this.
FROZEN_MANIFEST ?= variants/manifest.py
# Qstr definitions (must come before including py.mk).
QSTR_DEFS = qstrdefsport.h
# Include py core make definitions.
include $(TOP)/py/py.mk
include $(TOP)/extmod/extmod.mk
################################################################################
# Project specific settings and compiler/linker flags.
CC = emcc
LD = emcc
NODE ?= node
TERSER ?= npx terser
INC += -I.
INC += -I$(TOP)
INC += -I$(BUILD)
INC += -I$(VARIANT_DIR)
CFLAGS += -std=c99 -Wall -Werror -Wdouble-promotion -Wfloat-conversion
CFLAGS += -Os -DNDEBUG
CFLAGS += $(INC)
EXPORTED_FUNCTIONS_EXTRA += ,\
_mp_js_do_exec,\
_mp_js_do_exec_async,\
_mp_js_do_import,\
_mp_js_register_js_module,\
_proxy_c_free_obj,\
_proxy_c_init,\
_proxy_c_to_js_call,\
_proxy_c_to_js_delete_attr,\
_proxy_c_to_js_dir,\
_proxy_c_to_js_get_array,\
_proxy_c_to_js_get_dict,\
_proxy_c_to_js_get_iter,\
_proxy_c_to_js_get_type,\
_proxy_c_to_js_has_attr,\
_proxy_c_to_js_iternext,\
_proxy_c_to_js_lookup_attr,\
_proxy_c_to_js_resume,\
_proxy_c_to_js_store_attr,\
_proxy_convert_mp_to_js_obj_cside
EXPORTED_RUNTIME_METHODS_EXTRA += ,\
PATH,\
PATH_FS,\
UTF8ToString,\
getValue,\
lengthBytesUTF8,\
setValue,\
stringToUTF8
JSFLAGS += -s EXPORTED_FUNCTIONS="\
_free,\
_malloc,\
_mp_js_init,\
_mp_js_repl_init,\
_mp_js_repl_process_char,\
_mp_hal_get_interrupt_char,\
_mp_sched_keyboard_interrupt$(EXPORTED_FUNCTIONS_EXTRA)"
JSFLAGS += -s EXPORTED_RUNTIME_METHODS="\
ccall,\
cwrap,\
FS$(EXPORTED_RUNTIME_METHODS_EXTRA)"
JSFLAGS += --js-library library.js
JSFLAGS += -s SUPPORT_LONGJMP=emscripten
JSFLAGS += -s MODULARIZE -s EXPORT_NAME=_createMicroPythonModule
################################################################################
# Source files and libraries.
SRC_SHARED = $(addprefix shared/,\
runtime/interrupt_char.c \
runtime/stdout_helpers.c \
runtime/pyexec.c \
readline/readline.c \
timeutils/timeutils.c \
)
SRC_C += \
lexer_dedent.c \
main.c \
modjs.c \
modjsffi.c \
mphalport.c \
objjsproxy.c \
proxy_c.c \
# List of sources for qstr extraction.
SRC_QSTR += $(SRC_C) $(SRC_SHARED)
SRC_JS += \
api.js \
objpyproxy.js \
proxy_js.js \
OBJ += $(PY_O)
OBJ += $(addprefix $(BUILD)/, $(SRC_SHARED:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
################################################################################
# Main targets.
.PHONY: all repl min test test_min
all: $(BUILD)/micropython.mjs
$(BUILD)/micropython.mjs: $(OBJ) library.js $(SRC_JS)
$(ECHO) "LINK $@"
$(Q)emcc $(LDFLAGS) -o $@ $(OBJ) $(JSFLAGS)
$(Q)cat $(SRC_JS) >> $@
$(BUILD)/micropython.min.mjs: $(BUILD)/micropython.mjs
$(TERSER) $< --compress --module -o $@
repl: $(BUILD)/micropython.mjs
$(NODE) $<
min: $(BUILD)/micropython.min.mjs
test: $(BUILD)/micropython.mjs $(TOP)/tests/run-tests.py
cd $(TOP)/tests && MICROPY_MICROPYTHON_MJS=../ports/webassembly/$< ./run-tests.py -t webassembly
test_min: $(BUILD)/micropython.min.mjs $(TOP)/tests/run-tests.py
cd $(TOP)/tests && MICROPY_MICROPYTHON_MJS=../ports/webassembly/$< ./run-tests.py -t webassembly
################################################################################
# Remaining make rules.
include $(TOP)/py/mkrules.mk