@@ -91,7 +91,7 @@ def open(self, path, mode):
91
91
92
92
# Tests to skip on specific targets.
93
93
# These are tests that are difficult to detect that they should not be run on the given target.
94
- target_tests_to_skip = {
94
+ platform_tests_to_skip = {
95
95
"esp8266" : (
96
96
"micropython/viper_args.py" , # too large
97
97
"micropython/viper_binop_arith.py" , # too large
@@ -197,6 +197,53 @@ def convert_regex_escapes(line):
197
197
return bytes ("" .join (cs ), "utf8" )
198
198
199
199
200
+ def get_test_instance (test_instance , baudrate , user , password ):
201
+ if test_instance .startswith ("port:" ):
202
+ _ , port = test_instance .split (":" , 1 )
203
+ elif test_instance == "micropython" :
204
+ return None
205
+ elif test_instance == "webassembly" :
206
+ return PyboardNodeRunner ()
207
+ elif test_instance .startswith ("a" ) and test_instance [1 :].isdigit ():
208
+ port = "/dev/ttyACM" + test_instance [1 :]
209
+ elif test_instance .startswith ("u" ) and test_instance [1 :].isdigit ():
210
+ port = "/dev/ttyUSB" + test_instance [1 :]
211
+ elif test_instance .startswith ("c" ) and test_instance [1 :].isdigit ():
212
+ port = "COM" + test_instance [1 :]
213
+ else :
214
+ # Assume it's a device path.
215
+ port = test_instance
216
+
217
+ global pyboard
218
+ sys .path .append (base_path ("../tools" ))
219
+ import pyboard
220
+
221
+ pyb = pyboard .Pyboard (port , baudrate , user , password )
222
+ pyboard .Pyboard .run_script_on_remote_target = run_script_on_remote_target
223
+ pyb .enter_raw_repl ()
224
+ return pyb
225
+
226
+
227
+ def detect_test_platform (pyb , args ):
228
+ # Run a script to detect various bits of information about the target test instance.
229
+ output = run_feature_check (pyb , args , "target_info.py" )
230
+ if output .endswith (b"CRASH" ):
231
+ raise ValueError ("cannot detect platform: {}" .format (output ))
232
+ platform , arch = str (output , "ascii" ).strip ().split ()
233
+ if arch == "None" :
234
+ arch = None
235
+
236
+ args .platform = platform
237
+ args .arch = arch
238
+ if arch and not args .mpy_cross_flags :
239
+ args .mpy_cross_flags = "-march=" + arch
240
+
241
+ print ("platform={}" .format (platform ), end = "" )
242
+ if arch :
243
+ print (" arch={}" .format (arch ), end = "" )
244
+ print ()
245
+
246
+
200
247
def prepare_script_for_target (args , * , script_filename = None , script_text = None , force_plain = False ):
201
248
if force_plain or (not args .via_mpy and args .emit == "bytecode" ):
202
249
if script_filename is not None :
@@ -706,18 +753,18 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1):
706
753
skip_tests .add ("extmod/ssl_poll.py" )
707
754
708
755
# Skip thread mutation tests on targets that don't have the GIL.
709
- if args .target in ("rp2" , "unix" ):
756
+ if args .platform in ("darwin" , " rp2" , "unix" , "win32 " ):
710
757
for t in tests :
711
758
if t .startswith ("thread/mutate_" ):
712
759
skip_tests .add (t )
713
760
714
761
# Some tests shouldn't be run on pyboard
715
- if args .target != " unix" :
762
+ if args .platform not in ( "darwin" , " unix", "win32" ) :
716
763
skip_tests .add ("basics/exception_chain.py" ) # warning is not printed
717
764
skip_tests .add ("micropython/meminfo.py" ) # output is very different to PC output
718
765
719
- # Skip target -specific tests.
720
- skip_tests .update (target_tests_to_skip .get (args .target , ()))
766
+ # Skip platform -specific tests.
767
+ skip_tests .update (platform_tests_to_skip .get (args .platform , ()))
721
768
722
769
# Some tests are known to fail on 64-bit machines
723
770
if pyb is None and platform .architecture ()[0 ] == "64bit" :
@@ -936,13 +983,28 @@ def main():
936
983
specified test files. If test files nor directories are specified, the script
937
984
expects to be ran in the tests directory (where this file is located) and the
938
985
builtin tests suitable for the target platform are ran.
986
+
939
987
When running tests, run-tests.py compares the MicroPython output of the test with the output
940
988
produced by running the test through CPython unless a <test>.exp file is found, in which
941
989
case it is used as comparison.
990
+
942
991
If a test fails, run-tests.py produces a pair of <test>.out and <test>.exp files in the result
943
992
directory with the MicroPython output and the expectations, respectively.
944
993
""" ,
945
994
epilog = """\
995
+ The -t option accepts the following for the test instance:
996
+ - micropython - use the unix port of MicroPython, specified by the
997
+ MICROPY_MICROPYTHON environment variable
998
+ - webassembly - use the webassembly port of MicroPython, specified by the
999
+ MICROPY_MICROPYTHON_MJS environment variable
1000
+ - a<n> - use /dev/ttyACM<n>
1001
+ - u<n> - use /dev/ttyUSB<n>
1002
+ - c<n> - use COM<n>
1003
+ - exec:<command> - execute a command and attach to its stdin/stdout
1004
+ - execpty:<command> - execute a command and attach to the printed /dev/pts/<n> device
1005
+ - <a>.<b>.<c>.<d> - connect to the given IPv4 address
1006
+ - anything else specifies a serial port
1007
+
946
1008
Options -i and -e can be multiple and processed in the order given. Regex
947
1009
"search" (vs "match") operation is used. An action (include/exclude) of
948
1010
the last matching regex is used:
@@ -951,11 +1013,8 @@ def main():
951
1013
run-tests.py -e async -i async_foo - include all, exclude async, yet still include async_foo
952
1014
""" ,
953
1015
)
954
- cmd_parser .add_argument ("--target" , default = "unix" , help = "the target platform" )
955
1016
cmd_parser .add_argument (
956
- "--device" ,
957
- default = "/dev/ttyACM0" ,
958
- help = "the serial device or the IP address of the pyboard" ,
1017
+ "-t" , "--test-instance" , default = "micropython" , help = "the MicroPython instance to test"
959
1018
)
960
1019
cmd_parser .add_argument (
961
1020
"-b" , "--baudrate" , default = 115200 , help = "the baud rate of the serial device"
@@ -1039,43 +1098,11 @@ def main():
1039
1098
1040
1099
sys .exit (0 )
1041
1100
1042
- LOCAL_TARGETS = (
1043
- "unix" ,
1044
- "webassembly" ,
1045
- )
1046
- EXTERNAL_TARGETS = (
1047
- "pyboard" ,
1048
- "wipy" ,
1049
- "esp8266" ,
1050
- "esp32" ,
1051
- "minimal" ,
1052
- "nrf" ,
1053
- "qemu" ,
1054
- "renesas-ra" ,
1055
- "rp2" ,
1056
- "zephyr" ,
1057
- )
1058
- if args .target in LOCAL_TARGETS :
1059
- pyb = None
1060
- if args .target == "webassembly" :
1061
- pyb = PyboardNodeRunner ()
1062
- elif args .target in EXTERNAL_TARGETS :
1063
- global pyboard
1064
- sys .path .append (base_path ("../tools" ))
1065
- import pyboard
1066
-
1067
- pyb = pyboard .Pyboard (args .device , args .baudrate , args .user , args .password )
1068
- pyboard .Pyboard .run_script_on_remote_target = run_script_on_remote_target
1069
- pyb .enter_raw_repl ()
1070
- else :
1071
- raise ValueError ("target must be one of %s" % ", " .join (LOCAL_TARGETS + EXTERNAL_TARGETS ))
1101
+ # Get the test instance to run on.
1102
+ pyb = get_test_instance (args .test_instance , args .baudrate , args .user , args .password )
1072
1103
1073
- # Automatically detect the native architecture for mpy-cross if not given.
1074
- if not args .mpy_cross_flags :
1075
- output = run_feature_check (pyb , args , "target_info.py" )
1076
- arch = str (output , "ascii" ).strip ()
1077
- if arch != "None" :
1078
- args .mpy_cross_flags = "-march=" + arch
1104
+ # Automatically detect the platform.
1105
+ detect_test_platform (pyb , args )
1079
1106
1080
1107
if args .run_failures and (any (args .files ) or args .test_dirs is not None ):
1081
1108
raise ValueError (
@@ -1091,7 +1118,7 @@ def main():
1091
1118
tests = []
1092
1119
elif len (args .files ) == 0 :
1093
1120
test_extensions = ("*.py" ,)
1094
- if args .target == "webassembly" :
1121
+ if args .platform == "webassembly" :
1095
1122
test_extensions += ("*.js" , "*.mjs" )
1096
1123
1097
1124
if args .test_dirs is None :
@@ -1101,23 +1128,23 @@ def main():
1101
1128
"misc" ,
1102
1129
"extmod" ,
1103
1130
)
1104
- if args .target == "pyboard" :
1131
+ if args .platform == "pyboard" :
1105
1132
# run pyboard tests
1106
1133
test_dirs += ("float" , "stress" , "inlineasm" , "ports/stm32" )
1107
- elif args .target in ("renesas-ra" ):
1134
+ elif args .platform in ("renesas-ra" ):
1108
1135
test_dirs += ("float" , "inlineasm" , "ports/renesas-ra" )
1109
- elif args .target == "rp2" :
1136
+ elif args .platform == "rp2" :
1110
1137
test_dirs += ("float" , "stress" , "thread" , "ports/rp2" )
1111
1138
if "arm" in args .mpy_cross_flags :
1112
1139
test_dirs += ("inlineasm" ,)
1113
- elif args .target == "esp32" :
1140
+ elif args .platform == "esp32" :
1114
1141
test_dirs += ("float" , "stress" , "thread" )
1115
- elif args .target in ("esp8266" , "minimal" , "nrf" ):
1142
+ elif args .platform in ("esp8266" , "minimal" , "nrf" ):
1116
1143
test_dirs += ("float" ,)
1117
- elif args .target == "wipy" :
1144
+ elif args .platform == "wipy" :
1118
1145
# run WiPy tests
1119
1146
test_dirs += ("ports/cc3200" ,)
1120
- elif args .target == "unix" :
1147
+ elif args .platform == "unix" :
1121
1148
# run PC tests
1122
1149
test_dirs += (
1123
1150
"float" ,
@@ -1128,13 +1155,13 @@ def main():
1128
1155
"cmdline" ,
1129
1156
"ports/unix" ,
1130
1157
)
1131
- elif args .target == "qemu" :
1158
+ elif args .platform == "qemu" :
1132
1159
test_dirs += (
1133
1160
"float" ,
1134
1161
"inlineasm" ,
1135
1162
"ports/qemu" ,
1136
1163
)
1137
- elif args .target == "webassembly" :
1164
+ elif args .platform == "webassembly" :
1138
1165
test_dirs += ("float" , "ports/webassembly" )
1139
1166
else :
1140
1167
# run tests from these directories
0 commit comments