@@ -56,7 +56,7 @@ def find_target_by_path(target_path):
56
56
57
57
with open (target_path ) as pin_names_file :
58
58
pin_names_file_content = pin_names_file .read ()
59
-
59
+
60
60
target_list_match = re .search (
61
61
"\/* MBED TARGET LIST: ([0-9A-Z_,* \n ]+)*\/" ,
62
62
pin_names_file_content
@@ -71,7 +71,7 @@ def find_target_by_path(target_path):
71
71
re .MULTILINE ,
72
72
)
73
73
)
74
-
74
+
75
75
if not target_list :
76
76
print ("WARNING: MBED TARGET LIST marker invalid or not found in file " + target_path )
77
77
print ("Target could not be determined. Only the generic test suite will run. You can manually specify additional suites." )
@@ -98,18 +98,18 @@ def find_target_by_path(target_path):
98
98
def find_target_by_name (target_name = "" ):
99
99
"""Find a target by name."""
100
100
mbed_os_root = pathlib .Path (__file__ ).absolute ().parents [3 ]
101
-
101
+
102
102
targets = dict ()
103
103
104
104
for f in mbed_os_root .joinpath ('targets' ).rglob ("PinNames.h" ):
105
105
with open (f ) as pin_names_file :
106
106
pin_names_file_content = pin_names_file .read ()
107
-
107
+
108
108
target_list_match = re .search (
109
109
"\/* MBED TARGET LIST: ([0-9A-Z_,* \n ]+)*\/" ,
110
110
pin_names_file_content
111
111
)
112
-
112
+
113
113
target_list = []
114
114
if target_list_match :
115
115
target_list = list (
@@ -127,7 +127,7 @@ def find_target_by_name(target_name=""):
127
127
else :
128
128
for target in target_list :
129
129
targets [target ] = f
130
-
130
+
131
131
return targets
132
132
133
133
@@ -150,12 +150,12 @@ def check_markers(test_mode=False):
150
150
for f in search_dir .rglob ("PinNames.h" ):
151
151
with open (f ) as pin_names_file :
152
152
pin_names_file_content = pin_names_file .read ()
153
-
153
+
154
154
target_list_match = re .search (
155
155
"\/* MBED TARGET LIST: ([0-9A-Z_,* \n ]+)*\/" ,
156
156
pin_names_file_content
157
157
)
158
-
158
+
159
159
marker_target_list = []
160
160
if target_list_match :
161
161
marker_target_list = list (
@@ -165,7 +165,7 @@ def check_markers(test_mode=False):
165
165
re .MULTILINE ,
166
166
)
167
167
)
168
-
168
+
169
169
if not marker_target_list :
170
170
print ("WARNING: MBED TARGET LIST marker invalid or not found in file " + str (f ))
171
171
errors .append ({ "file" : str (f ), "error" : "marker invalid or not found" })
@@ -181,7 +181,7 @@ def check_markers(test_mode=False):
181
181
if not target_is_valid :
182
182
print ("WARNING: MBED TARGET LIST in file " + str (f ) + " includes target '" + target + "' which doesn't exist in targets.json or is not public" )
183
183
errors .append ({ "file" : str (f ), "error" : "target not found" })
184
-
184
+
185
185
return errors
186
186
187
187
@@ -190,7 +190,7 @@ def check_duplicate_pinnames_files(test_mode=False):
190
190
mbed_os_root = pathlib .Path (__file__ ).absolute ().parents [3 ]
191
191
192
192
errors = []
193
-
193
+
194
194
file_hash_dict = dict ()
195
195
196
196
if test_mode :
@@ -202,20 +202,20 @@ def check_duplicate_pinnames_files(test_mode=False):
202
202
with open (f ) as pin_names_file :
203
203
pin_names_file_content = pin_names_file .read ()
204
204
file_hash_dict [str (f )] = hashlib .md5 (pin_names_file_content .encode ('utf-8' )).hexdigest ()
205
-
206
- rev_dict = {}
207
- for key , value in file_hash_dict .items ():
208
- rev_dict .setdefault (value , set ()).add (key )
209
- duplicates = [key for key , values in rev_dict .items ()
210
- if len (values ) > 1 ]
211
-
205
+
206
+ rev_dict = {}
207
+ for key , value in file_hash_dict .items ():
208
+ rev_dict .setdefault (value , set ()).add (key )
209
+ duplicates = [key for key , values in rev_dict .items ()
210
+ if len (values ) > 1 ]
211
+
212
212
for duplicate in duplicates :
213
213
print ("WARNING: Duplicate files" )
214
214
for file_path , file_hash in file_hash_dict .items ():
215
215
if file_hash == duplicate :
216
216
errors .append ({ "file" : file_path , "error" : "duplicate file" })
217
217
print ("\t " + file_path )
218
-
218
+
219
219
return errors
220
220
221
221
def check_duplicate_markers (test_mode = False ):
@@ -225,7 +225,7 @@ def check_duplicate_markers(test_mode=False):
225
225
errors = []
226
226
227
227
markers = dict ()
228
-
228
+
229
229
if test_mode :
230
230
search_dir = pathlib .Path (__file__ ).parent .joinpath ('test_files' ).absolute ()
231
231
else :
@@ -234,12 +234,12 @@ def check_duplicate_markers(test_mode=False):
234
234
for f in search_dir .rglob ("PinNames.h" ):
235
235
with open (f ) as pin_names_file :
236
236
pin_names_file_content = pin_names_file .read ()
237
-
237
+
238
238
target_list_match = re .search (
239
239
"\/* MBED TARGET LIST: ([0-9A-Z_,* \n ]+)*\/" ,
240
240
pin_names_file_content
241
241
)
242
-
242
+
243
243
marker_target_list = []
244
244
if target_list_match :
245
245
marker_target_list = list (
@@ -249,7 +249,7 @@ def check_duplicate_markers(test_mode=False):
249
249
re .MULTILINE ,
250
250
)
251
251
)
252
-
252
+
253
253
for target in marker_target_list :
254
254
if target in markers :
255
255
print ("WARNING: target duplicate in " + str (f ) + ", " + target + " first listed in " + markers [target ])
@@ -260,7 +260,7 @@ def check_duplicate_markers(test_mode=False):
260
260
return errors
261
261
262
262
263
- def target_has_arduino_form_factor (target_name ):
263
+ def target_has_form_factor (target_name , form_factor ):
264
264
"""Check if the target has the Arduino form factor."""
265
265
mbed_os_root = pathlib .Path (__file__ ).absolute ().parents [3 ]
266
266
@@ -272,7 +272,7 @@ def target_has_arduino_form_factor(target_name):
272
272
if target_name in target_data :
273
273
if "supported_form_factors" in target_data [target_name ]:
274
274
form_factors = target_data [target_name ]["supported_form_factors" ]
275
- if "ARDUINO_UNO" in form_factors :
275
+ if form_factor in form_factors :
276
276
return True
277
277
278
278
return False
@@ -440,6 +440,22 @@ def legacy_assignment_check(pin_name_content):
440
440
invalid_items .append ({"key" : key , "val" : val , "message" : message })
441
441
return invalid_items
442
442
443
+
444
+ def legacy_alias_check (pin_name_content ):
445
+ invalid_items = []
446
+ legacy_assignments = dict (
447
+ re .findall (
448
+ r"^\s*((?:SPI|I2C)_\w*)\s*=\s*([a-zA-Z0-9_]+)" ,
449
+ pin_name_content ,
450
+ re .MULTILINE ,
451
+ )
452
+ )
453
+ for key , val in legacy_assignments .items ():
454
+ message = "legacy assignment; SPI_xxx and I2C_xxx must be #define'd"
455
+ invalid_items .append ({"key" : key , "val" : val , "message" : message })
456
+ return invalid_items
457
+
458
+
443
459
def legacy_uart_check (pin_name_dict ):
444
460
invalid_items = []
445
461
if "CONSOLE_TX" not in pin_name_dict or "CONSOLE_RX" not in pin_name_dict :
@@ -448,6 +464,13 @@ def legacy_uart_check(pin_name_dict):
448
464
return invalid_items
449
465
450
466
467
+ def legacy_arduino_uno_check (arduino_form_factor ):
468
+ invalid_items = []
469
+ if arduino_form_factor == True :
470
+ message = "ARDUINO form factor is deprecated, should be replaced by ARDUINO_UNO"
471
+ invalid_items .append ({"key" : "" , "val" : "" , "message" : message })
472
+ return invalid_items
473
+
451
474
def print_summary (report ):
452
475
targets = set ([case ["platform_name" ] for case in report ])
453
476
@@ -610,13 +633,13 @@ def print_pretty_html_report(report):
610
633
output .append ("'>" )
611
634
output .append (case ["result" ])
612
635
output .append ("</td>" )
613
-
636
+
614
637
output .append ("<td style='color:" )
615
638
output .append (count_color )
616
639
output .append ("'>" )
617
640
output .append (str (len (case ["errors" ])))
618
641
output .append ("</td>" )
619
-
642
+
620
643
output .append ("<td>" )
621
644
output .extend (error_details )
622
645
output .append ("</td>" )
@@ -662,12 +685,24 @@ def has_passed_all_test_cases(report):
662
685
"case_function" : legacy_assignment_check ,
663
686
"case_input" : "content" ,
664
687
},
688
+ {
689
+ "suite_name" : "generic" ,
690
+ "case_name" : "alias" ,
691
+ "case_function" : legacy_alias_check ,
692
+ "case_input" : "content" ,
693
+ },
665
694
{
666
695
"suite_name" : "generic" ,
667
696
"case_name" : "uart" ,
668
697
"case_function" : legacy_uart_check ,
669
698
"case_input" : "content" ,
670
699
},
700
+ {
701
+ "suite_name" : "generic" ,
702
+ "case_name" : "arduino_formfactor" ,
703
+ "case_function" : legacy_arduino_uno_check ,
704
+ "case_input" : "arduino_form_factor" ,
705
+ },
671
706
{
672
707
"suite_name" : "arduino_uno" ,
673
708
"case_name" : "duplicate" ,
@@ -718,21 +753,27 @@ def validate_pin_names(args):
718
753
719
754
pin_name_dict = pin_name_to_dict (pin_name_content )
720
755
721
- arduino_support = target_has_arduino_form_factor (target )
756
+ arduino_uno_support = target_has_form_factor (target , "ARDUINO_UNO" )
757
+
758
+ arduino_support = target_has_form_factor (target , "ARDUINO" )
722
759
723
760
for case in test_cases :
724
761
if suites :
725
762
if case ["suite_name" ] not in suites :
726
763
continue
727
764
else :
728
- if not arduino_support and case ["suite_name" ] == "arduino_uno" :
765
+ if not arduino_uno_support and case ["suite_name" ] == "arduino_uno" :
729
766
continue
767
+ if not arduino_uno_support and not arduino_support and case ["case_name" ] == "arduino_formfactor" :
768
+ continue
769
+
730
770
731
771
if case ["case_input" ] == "dict" :
732
772
case_input = pin_name_dict
733
773
elif case ["case_input" ] == "content" :
734
774
case_input = pin_name_content
735
-
775
+ elif case ["case_input" ] == "arduino_form_factor" :
776
+ case_input = arduino_support
736
777
case_output = case ["case_function" ](case_input )
737
778
738
779
case_result = "FAILED" if case_output else "PASSED"
0 commit comments