Proc replay: field tolerance unused (#29479)

field tolerance unused
pull/29478/head
Harald Schäfer 2 years ago committed by GitHub
parent 3861fca940
commit 1dea20e574
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      selfdrive/test/process_replay/compare_logs.py
  2. 1
      selfdrive/test/process_replay/process_replay.py
  3. 2
      selfdrive/test/process_replay/test_processes.py

@ -39,25 +39,12 @@ def remove_ignored_fields(msg, ignore):
return msg return msg
def get_field_tolerance(diff_field, field_tolerances): def compare_logs(log1, log2, ignore_fields=None, ignore_msgs=None, tolerance=None,):
diff_field_str = diff_field[0]
for s in diff_field[1:]:
# loop until number in field
if not isinstance(s, str):
break
diff_field_str += '.'+s
if diff_field_str in field_tolerances:
return field_tolerances[diff_field_str]
def compare_logs(log1, log2, ignore_fields=None, ignore_msgs=None, tolerance=None, field_tolerances=None):
if ignore_fields is None: if ignore_fields is None:
ignore_fields = [] ignore_fields = []
if ignore_msgs is None: if ignore_msgs is None:
ignore_msgs = [] ignore_msgs = []
if field_tolerances is None: tolerance = EPSILON if tolerance is None else tolerance
field_tolerances = {}
default_tolerance = EPSILON if tolerance is None else tolerance
log1, log2 = ( log1, log2 = (
[m for m in log if m.which() not in ignore_msgs] [m for m in log if m.which() not in ignore_msgs]
@ -88,13 +75,10 @@ def compare_logs(log1, log2, ignore_fields=None, ignore_msgs=None, tolerance=Non
def outside_tolerance(diff): def outside_tolerance(diff):
try: try:
if diff[0] == "change": if diff[0] == "change":
field_tolerance = default_tolerance
if (tol := get_field_tolerance(diff[1], field_tolerances)) is not None:
field_tolerance = tol
a, b = diff[2] a, b = diff[2]
finite = math.isfinite(a) and math.isfinite(b) finite = math.isfinite(a) and math.isfinite(b)
if finite and isinstance(a, numbers.Number) and isinstance(b, numbers.Number): if finite and isinstance(a, numbers.Number) and isinstance(b, numbers.Number):
return abs(a - b) > max(field_tolerance, field_tolerance * max(abs(a), abs(b))) return abs(a - b) > max(tolerance, tolerance * max(abs(a), abs(b)))
except TypeError: except TypeError:
pass pass
return True return True

@ -123,7 +123,6 @@ class ProcessConfig:
should_recv_callback: Optional[Callable] = None should_recv_callback: Optional[Callable] = None
tolerance: Optional[float] = None tolerance: Optional[float] = None
processing_time: float = 0.001 processing_time: float = 0.001
field_tolerances: Dict[str, float] = field(default_factory=dict)
timeout: int = 30 timeout: int = 30
simulation: bool = True simulation: bool = True
main_pub: Optional[str] = None main_pub: Optional[str] = None

@ -110,7 +110,7 @@ def test_process(cfg, lr, segment, ref_log_path, new_log_path, ignore_fields=Non
return f"Route did not enable at all or for long enough: {new_log_path}", log_msgs return f"Route did not enable at all or for long enough: {new_log_path}", log_msgs
try: try:
return compare_logs(ref_log_msgs, log_msgs, ignore_fields + cfg.ignore, ignore_msgs, cfg.tolerance, cfg.field_tolerances), log_msgs return compare_logs(ref_log_msgs, log_msgs, ignore_fields + cfg.ignore, ignore_msgs, cfg.tolerance), log_msgs
except Exception as e: except Exception as e:
return str(e), log_msgs return str(e), log_msgs

Loading…
Cancel
Save