2020-11-05 19:25:17 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
'''
|
|
|
|
check that replay produced identical results
|
|
|
|
'''
|
|
|
|
|
2020-11-08 06:28:53 -04:00
|
|
|
from __future__ import print_function
|
2020-11-05 19:25:17 -04:00
|
|
|
|
2021-10-18 03:50:12 -03:00
|
|
|
def check_log(logfile, progress=print, ekf2_only=False, ekf3_only=False, verbose=False, accuracy=0.0):
|
2020-11-05 19:25:17 -04:00
|
|
|
'''check replay log for matching output'''
|
2020-11-08 20:30:00 -04:00
|
|
|
from pymavlink import mavutil
|
2020-11-08 06:28:53 -04:00
|
|
|
progress("Processing log %s" % logfile)
|
2020-11-08 20:30:00 -04:00
|
|
|
failure = 0
|
|
|
|
errors = 0
|
2020-11-05 19:25:17 -04:00
|
|
|
count = 0
|
2020-11-05 20:04:58 -04:00
|
|
|
base_count = 0
|
2020-11-05 19:25:17 -04:00
|
|
|
counts = {}
|
2020-11-05 20:04:58 -04:00
|
|
|
base_counts = {}
|
2020-11-05 19:25:17 -04:00
|
|
|
|
2020-11-08 06:28:53 -04:00
|
|
|
mlog = mavutil.mavlink_connection(logfile)
|
2020-11-05 19:25:17 -04:00
|
|
|
|
2020-11-15 17:48:38 -04:00
|
|
|
ek2_list = ['NKF1','NKF2','NKF3','NKF4','NKF5','NKF0','NKQ', 'NKY0', 'NKY1']
|
|
|
|
ek3_list = ['XKF1','XKF2','XKF3','XKF4','XKF0','XKFS','XKQ','XKFD','XKV1','XKV2','XKY0','XKY1']
|
2020-11-05 19:25:17 -04:00
|
|
|
|
2020-11-08 06:28:53 -04:00
|
|
|
if ekf2_only:
|
2020-11-05 19:25:17 -04:00
|
|
|
mlist = ek2_list
|
2020-11-08 06:28:53 -04:00
|
|
|
elif ekf3_only:
|
2020-11-05 19:25:17 -04:00
|
|
|
mlist = ek3_list
|
|
|
|
else:
|
|
|
|
mlist = ek2_list + ek3_list
|
|
|
|
|
|
|
|
base = {}
|
|
|
|
for m in mlist:
|
|
|
|
base[m] = {}
|
|
|
|
|
|
|
|
while True:
|
|
|
|
m = mlog.recv_match(type=mlist)
|
|
|
|
if m is None:
|
|
|
|
break
|
|
|
|
if not hasattr(m,'C'):
|
|
|
|
continue
|
|
|
|
mtype = m.get_type()
|
2020-11-05 20:04:58 -04:00
|
|
|
if not mtype in counts:
|
|
|
|
counts[mtype] = 0
|
|
|
|
base_counts[mtype] = 0
|
2020-11-05 19:25:17 -04:00
|
|
|
core = m.C
|
|
|
|
if core < 100:
|
|
|
|
base[mtype][core] = m
|
2020-11-05 20:04:58 -04:00
|
|
|
base_count += 1
|
|
|
|
base_counts[mtype] += 1
|
2020-11-05 19:25:17 -04:00
|
|
|
continue
|
|
|
|
mb = base[mtype][core-100]
|
|
|
|
count += 1
|
|
|
|
counts[mtype] += 1
|
|
|
|
mismatch = False
|
|
|
|
for f in m._fieldnames:
|
|
|
|
if f == 'C':
|
|
|
|
continue
|
|
|
|
v1 = getattr(m,f)
|
|
|
|
v2 = getattr(mb,f)
|
2021-07-14 19:17:48 -03:00
|
|
|
ok = v1 == v2
|
2021-10-18 03:50:12 -03:00
|
|
|
if not ok and accuracy > 0:
|
2021-07-14 19:17:48 -03:00
|
|
|
avg = (v1+v2)*0.5
|
2021-10-18 03:50:12 -03:00
|
|
|
margin = accuracy*0.01*avg
|
2021-07-14 19:17:48 -03:00
|
|
|
if abs(v1-v2) <= abs(margin):
|
|
|
|
ok = True
|
|
|
|
if not ok:
|
2020-11-05 19:25:17 -04:00
|
|
|
mismatch = True
|
|
|
|
errors += 1
|
2020-11-08 06:28:53 -04:00
|
|
|
progress("Mismatch in field %s.%s: %s %s" % (mtype, f, str(v1), str(v2)))
|
2020-11-05 19:25:17 -04:00
|
|
|
if mismatch:
|
2020-11-08 06:28:53 -04:00
|
|
|
progress(mb)
|
|
|
|
progress(m)
|
|
|
|
progress("Processed %u/%u messages, %u errors" % (count, base_count, errors))
|
|
|
|
if verbose:
|
2020-11-05 20:04:58 -04:00
|
|
|
for mtype in counts.keys():
|
2020-11-08 06:28:53 -04:00
|
|
|
progress("%s %u/%u %d" % (mtype, counts[mtype], base_counts[mtype], base_counts[mtype]-counts[mtype]))
|
2020-11-16 23:16:12 -04:00
|
|
|
if count == 0 or abs(count - base_count) > 100:
|
2020-11-05 20:04:58 -04:00
|
|
|
failure += 1
|
2020-11-08 06:28:53 -04:00
|
|
|
if failure != 0 or errors != 0:
|
|
|
|
return False
|
|
|
|
return True
|
2020-11-05 19:25:17 -04:00
|
|
|
|
2020-11-08 06:28:53 -04:00
|
|
|
if __name__ == '__main__':
|
2020-11-08 20:30:00 -04:00
|
|
|
import sys
|
|
|
|
from argparse import ArgumentParser
|
|
|
|
parser = ArgumentParser(description=__doc__)
|
|
|
|
parser.add_argument("--ekf2-only", action='store_true', help="only check EKF2")
|
|
|
|
parser.add_argument("--ekf3-only", action='store_true', help="only check EKF3")
|
|
|
|
parser.add_argument("--verbose", action='store_true', help="verbose output")
|
2021-07-14 19:17:48 -03:00
|
|
|
parser.add_argument("--accuracy", type=float, default=0.0, help="accuracy percentage for match")
|
2020-11-08 20:30:00 -04:00
|
|
|
parser.add_argument("logs", metavar="LOG", nargs="+")
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
failed = False
|
2020-11-08 06:28:53 -04:00
|
|
|
for filename in args.logs:
|
2021-10-18 03:50:12 -03:00
|
|
|
if not check_log(filename, print, args.ekf2_only, args.ekf3_only, args.verbose, accuracy=args.accuracy):
|
2020-11-08 20:30:00 -04:00
|
|
|
failed = True
|
2020-11-05 20:04:58 -04:00
|
|
|
|
2020-11-08 20:30:00 -04:00
|
|
|
if failed:
|
|
|
|
print("FAILED")
|
2020-11-08 06:28:53 -04:00
|
|
|
sys.exit(1)
|
|
|
|
print("Passed")
|
|
|
|
sys.exit(0)
|