Skip to content

Commit fe510ee

Browse files
committed
autotest: add ratchet for log message documentation
this should ensure that when a log message is added then it must be documented as well ... and hopefully we can reduce the length of these lists over time
1 parent 1cdb64b commit fe510ee

File tree

1 file changed

+126
-9
lines changed

1 file changed

+126
-9
lines changed

Tools/autotest/vehicle_test_suite.py

Lines changed: 126 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3087,6 +3087,109 @@ def all_log_format_ids(self):
30873087

30883088
return ids
30893089

3090+
def LoggerDocumentation_greylist(self):
3091+
'''returns a set of messages should should be documented but
3092+
are currently known as undocumented'''
3093+
return set([
3094+
"FENC", # fence
3095+
"FTN3", # gyrofft
3096+
"GEN", # generator
3097+
"IE24", # generator
3098+
"IEFC", # generator
3099+
"IREG", # INS something
3100+
"ISBD", # InertialSensor batch logging
3101+
"ISBH", # InertialSensor batch logging
3102+
"RELY", # relay
3103+
"RTCM", # GPS
3104+
"SBRE", # septentrio
3105+
3106+
"SAF1", # blimp-sim
3107+
"SAN1", # blimp-sim
3108+
"SAN2", # blimp-sim
3109+
"SBA1", # blimp-sim
3110+
"SBLM", # blimp-sim
3111+
"SCTL", # glider-sim
3112+
"SFA1", # blimp-sim
3113+
"SFAN", # blimp-sim
3114+
"SFN", # blimp-sim
3115+
"SFT", # blimp-sim
3116+
"SFV1", # blimp-sim
3117+
"SMGC", # blimp-sim
3118+
"SRT1", # blimp-sim
3119+
"SRT2", # blimp-sim
3120+
"SRT3", # blimp-sim
3121+
"SSAN", # blimp-sim
3122+
3123+
"GLT", # glider sim
3124+
"SL2", # glider-sim
3125+
"SLD", # glider-sim
3126+
3127+
"SMVZ", # Sim-Volz
3128+
3129+
"SORC", # Soaring
3130+
"VAR", # soaring
3131+
3132+
"TCLR", # tempcal
3133+
"TEMP", # temperature sensor library
3134+
3135+
"ARHS", # autorotation
3136+
"AROT", # autorotation
3137+
"ARSC", # autorotation
3138+
"ATDH", # heli autotune
3139+
"ATNH", # heli autotune
3140+
"ATSH", # heli autotune
3141+
"CC", # AC_CustomControl
3142+
"FWDT", # quadplane
3143+
"GMB1", # sologimbal
3144+
"GMB2", # sologimbal
3145+
"QBRK", # quadplane
3146+
"SURF", # surface-tracking
3147+
"ATUN", # Copter autotune
3148+
])
3149+
3150+
def LoggerDocumentation_whitelist(self):
3151+
'''returns a set of messages which we do not want to see
3152+
documentation for'''
3153+
3154+
# we allow for no docs for replay messages, as these are not for end-users. They are
3155+
# effectively binary blobs for replay
3156+
# Documenting these is still useful! -pb
3157+
REPLAY_MSGS = ['RFRH', 'RFRF', 'REV2', 'RSO2', 'RWA2', 'REV3', 'RSO3', 'RWA3', 'RMGI',
3158+
'REY3', 'RFRN', 'RISH', 'RISI', 'RISJ', 'RBRH', 'RBRI', 'RRNH', 'RRNI',
3159+
'RGPH', 'RGPI', 'RGPJ', 'RASH', 'RASI', 'RBCH', 'RBCI', 'RVOH', 'RMGH',
3160+
'ROFH', 'REPH', 'REVH', 'RWOH', 'RBOH', 'RSLL']
3161+
3162+
ret = set(REPLAY_MSGS)
3163+
3164+
# messages not expected to be on particular vehicles. Nothing
3165+
# needs fixing below this point, unless you can come up with a
3166+
# better way to avoid this list!
3167+
3168+
# We extract all message that need to be documented from the
3169+
# code, but we don't pay attention to which vehicles will use
3170+
# those messages. We *do* care about the documented messages
3171+
# for a vehicle as we follow the tree created by the
3172+
# documentation (eg. @Path:
3173+
# ../libraries/AP_LandingGear/AP_LandingGear.cpp).
3174+
vinfo_key = self.vehicleinfo_key()
3175+
if vinfo_key != 'ArduPlane':
3176+
ret.update([
3177+
"TECS", # only Plane has TECS
3178+
"TEC2", # only Plane has TECS
3179+
"TEC3", # only Plane has TECS
3180+
"SOAR", # only Planes can truly soar
3181+
"SORC", # soaring is pure magic
3182+
"QBRK", # quadplane
3183+
"FWDT", # quadplane
3184+
])
3185+
if vinfo_key == 'ArduCopter':
3186+
ret.update([
3187+
"CC", # only Copter has the CustomController
3188+
])
3189+
# end not-expected-to-be-fixed block
3190+
3191+
return ret
3192+
30903193
def LoggerDocumentation(self):
30913194
'''Test Onboard Logging Generation'''
30923195
xml_filepath = os.path.join(self.buildlogs_dirpath(), "LogMessages.xml")
@@ -3127,12 +3230,8 @@ def LoggerDocumentation(self):
31273230
objectify.enable_recursive_str()
31283231
tree = objectify.fromstring(xml)
31293232

3130-
# we allow for no docs for replay messages, as these are not for end-users. They are
3131-
# effectively binary blobs for replay
3132-
REPLAY_MSGS = ['RFRH', 'RFRF', 'REV2', 'RSO2', 'RWA2', 'REV3', 'RSO3', 'RWA3', 'RMGI',
3133-
'REY3', 'RFRN', 'RISH', 'RISI', 'RISJ', 'RBRH', 'RBRI', 'RRNH', 'RRNI',
3134-
'RGPH', 'RGPI', 'RGPJ', 'RASH', 'RASI', 'RBCH', 'RBCI', 'RVOH', 'RMGH',
3135-
'ROFH', 'REPH', 'REVH', 'RWOH', 'RBOH', 'RSLL']
3233+
whitelist = self.LoggerDocumentation_whitelist()
3234+
greylist = self.LoggerDocumentation_greylist()
31363235

31373236
docco_ids = {}
31383237
for thing in tree.logformat:
@@ -3142,7 +3241,7 @@ def LoggerDocumentation(self):
31423241
"labels": [],
31433242
}
31443243
if getattr(thing.fields, 'field', None) is None:
3145-
if name in REPLAY_MSGS:
3244+
if name in whitelist:
31463245
continue
31473246
raise NotAchievedException("no doc fields for %s" % name)
31483247
for field in thing.fields.field:
@@ -3155,10 +3254,18 @@ def LoggerDocumentation(self):
31553254
# self.progress("Code ids: (%s)" % str(sorted(code_ids.keys())))
31563255
# self.progress("Docco ids: (%s)" % str(sorted(docco_ids.keys())))
31573256

3257+
undocumented = set()
3258+
overdocumented = set()
31583259
for name in sorted(code_ids.keys()):
31593260
if name not in docco_ids:
3160-
self.progress("Undocumented message: %s" % str(name))
3261+
if name in greylist:
3262+
self.progress(f"{name} should be documented but isn't")
3263+
continue
3264+
if name not in whitelist:
3265+
undocumented.add(name)
31613266
continue
3267+
if name in whitelist:
3268+
overdocumented.add(name)
31623269
seen_labels = {}
31633270
for label in code_ids[name]["labels"].split(","):
31643271
if label in seen_labels:
@@ -3168,9 +3275,19 @@ def LoggerDocumentation(self):
31683275
if label not in docco_ids[name]["labels"]:
31693276
raise NotAchievedException("%s.%s not in documented fields (have (%s))" %
31703277
(name, label, ",".join(docco_ids[name]["labels"])))
3278+
3279+
if len(undocumented):
3280+
for name in sorted(undocumented):
3281+
self.progress(f"Undocumented message: {name}")
3282+
raise NotAchievedException("Undocumented messages found")
3283+
if len(overdocumented):
3284+
for name in sorted(overdocumented):
3285+
self.progress(f"Message documented when it shouldn't be: {name}")
3286+
raise NotAchievedException("Overdocumented messages found")
3287+
31713288
missing = []
31723289
for name in sorted(docco_ids):
3173-
if name not in code_ids and name not in REPLAY_MSGS:
3290+
if name not in code_ids and name not in whitelist:
31743291
missing.append(name)
31753292
continue
31763293
for label in docco_ids[name]["labels"]:

0 commit comments

Comments
 (0)