summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessandro Gatti <a.gatti@frob.it>2025-04-09 21:58:19 +0200
committerDamien George <damien@micropython.org>2025-06-04 22:35:39 +1000
commit9ef7322a5d11937e061b85da12900eeee62e9891 (patch)
treea64c48aefb5f72a14560b347b36558b2011951d6
parentbf2005de9e3d9e75a26a6bb98e82be8511266604 (diff)
tests/run-natmodtests.py: Allow injected code customisation.
This commit introduces a mechanism to customise the code that is injected to the board when performing a native module import. A new argument, "-b"/"--begin", is added so regular Python code can be inserted in the injected fragment between the module file creation and the effective module import. This is needed for running natmod tests on ESP8266 as that board does not have enough memory to fit certain modules unless additional configuration is performed. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
-rwxr-xr-xtests/run-natmodtests.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/run-natmodtests.py b/tests/run-natmodtests.py
index b858989da..073e0b053 100755
--- a/tests/run-natmodtests.py
+++ b/tests/run-natmodtests.py
@@ -73,6 +73,7 @@ class __FS:
return __File()
vfs.mount(__FS(), '/__remote')
sys.path.insert(0, '/__remote')
+{import_prelude}
sys.modules['{}'] = __import__('__injected')
"""
@@ -133,6 +134,13 @@ def detect_architecture(target):
def run_tests(target_truth, target, args, stats, resolved_arch):
+ global injected_import_hook_code
+
+ prelude = ""
+ if args.begin:
+ prelude = args.begin.read()
+ injected_import_hook_code = injected_import_hook_code.replace("{import_prelude}", prelude)
+
for test_file in args.files:
# Find supported test
test_file_basename = os.path.basename(test_file)
@@ -212,6 +220,13 @@ def main():
cmd_parser.add_argument(
"-a", "--arch", choices=AVAILABLE_ARCHS, help="override native architecture of the target"
)
+ cmd_parser.add_argument(
+ "-b",
+ "--begin",
+ type=argparse.FileType("rt"),
+ default=None,
+ help="prologue python file to execute before module import",
+ )
cmd_parser.add_argument("files", nargs="*", help="input test files")
args = cmd_parser.parse_args()