def test_process(cfg, lr, cmp_log_fn, ignore_fields=None, ignore_msgs=None): if ignore_fields is None: ignore_fields = [] if ignore_msgs is None: ignore_msgs = [] cmp_log_path = cmp_log_fn if os.path.exists(cmp_log_fn) else BASE_URL + os.path.basename(cmp_log_fn) cmp_log_msgs = list(LogReader(cmp_log_path)) log_msgs = replay_process(cfg, lr) # check to make sure openpilot is engaged in the route # TODO: update routes so enable check can run # failed enable check: honda bosch, hyundai, chrysler, and subaru if cfg.proc_name == "controlsd" and FULL_TEST and False: for msg in log_msgs: if msg.which() == "controlsState": if msg.controlsState.active: break else: segment = cmp_log_fn.split("/")[-1].split("_")[0] raise Exception("Route never enabled: %s" % segment) try: return compare_logs(cmp_log_msgs, log_msgs, ignore_fields+cfg.ignore, ignore_msgs, cfg.tolerance) except Exception as e: return str(e)
def test_process(cfg, lr, cmp_log_fn, ignore_fields=None, ignore_msgs=None): if ignore_fields is None: ignore_fields = [] if ignore_msgs is None: ignore_msgs = [] cmp_log_path = cmp_log_fn if os.path.exists( cmp_log_fn) else BASE_URL + os.path.basename(cmp_log_fn) cmp_log_msgs = list(LogReader(cmp_log_path)) log_msgs = replay_process(cfg, lr) # check to make sure openpilot is engaged in the route if cfg.proc_name == "controlsd": for msg in log_msgs: if msg.which() == "carParams": if msg.carParams.notCar: break if msg.which() == "controlsState": if msg.controlsState.active: break else: segment = cmp_log_fn.split("/")[-1].split("_")[0] raise Exception(f"Route never enabled: {segment}") try: return compare_logs(cmp_log_msgs, log_msgs, ignore_fields + cfg.ignore, ignore_msgs, cfg.tolerance) except Exception as e: return str(e)
def test_process(cfg, lr, ref_log_path, new_log_path, ignore_fields=None, ignore_msgs=None): if ignore_fields is None: ignore_fields = [] if ignore_msgs is None: ignore_msgs = [] ref_log_msgs = list(LogReader(ref_log_path)) log_msgs = replay_process(cfg, lr) # check to make sure openpilot is engaged in the route if cfg.proc_name == "controlsd": if not check_enabled(log_msgs): return f"Route did not enable at all or for long enough: {new_log_path}", log_msgs try: return compare_logs(ref_log_msgs, log_msgs, ignore_fields + cfg.ignore, ignore_msgs, cfg.tolerance, cfg.field_tolerances), log_msgs except Exception as e: return str(e), log_msgs
def test_process(cfg, lr, cmp_log_fn, ignore_fields=[], ignore_msgs=[]): if not os.path.isfile(cmp_log_fn): req = requests.get(BASE_URL + os.path.basename(cmp_log_fn)) assert req.status_code == 200, ("Failed to download %s" % cmp_log_fn) with tempfile.NamedTemporaryFile(suffix=".bz2") as f: f.write(req.content) f.flush() f.seek(0) cmp_log_msgs = list(LogReader(f.name)) else: cmp_log_msgs = list(LogReader(cmp_log_fn)) log_msgs = replay_process(cfg, lr) # check to make sure openpilot is engaged in the route # TODO: update routes so enable check can run # failed enable check: honda bosch, hyundai, chrysler, and subaru if cfg.proc_name == "controlsd" and FULL_TEST and False: for msg in log_msgs: if msg.which() == "controlsState": if msg.controlsState.active: break else: segment = cmp_log_fn.split("/")[-1].split("_")[0] raise Exception("Route never enabled: %s" % segment) return compare_logs(cmp_log_msgs, log_msgs, ignore_fields + cfg.ignore, ignore_msgs)
def test_process(cfg, lr, ref_log_path, ignore_fields=None, ignore_msgs=None): if ignore_fields is None: ignore_fields = [] if ignore_msgs is None: ignore_msgs = [] ref_log_msgs = list(LogReader(ref_log_path)) log_msgs = replay_process(cfg, lr) # check to make sure openpilot is engaged in the route if cfg.proc_name == "controlsd": if not check_enabled(log_msgs): raise Exception(f"Route never enabled: {ref_log_path}") try: return compare_logs(ref_log_msgs, log_msgs, ignore_fields + cfg.ignore, ignore_msgs, cfg.tolerance), log_msgs except Exception as e: return str(e), log_msgs
def test_process(cfg, lr, cmp_log_fn, ignore_fields=[], ignore_msgs=[]): if not os.path.isfile(cmp_log_fn): assert False, ("Failed to open %s" % cmp_log_fn) else: print("Opening file [%s]" % cmp_log_fn) cmp_log_msgs = list(LogReader(cmp_log_fn)) log_msgs = replay_process(cfg, lr) # check to make sure openpilot is engaged in the route # TODO: update routes so enable check can run # failed enable check: honda bosch, hyundai, chrysler, and subaru if cfg.proc_name == "controlsd" and FULL_TEST and False: for msg in log_msgs: if msg.which() == "controlsState": if msg.controlsState.active: break else: segment = cmp_log_fn.split("/")[-1].split("_")[0] raise Exception("Route never enabled: %s" % segment) return compare_logs(cmp_log_msgs, log_msgs, ignore_fields+cfg.ignore, ignore_msgs)
def test_process(cfg, lr, ref_log_fn, ignore_fields=None, ignore_msgs=None): if ignore_fields is None: ignore_fields = [] if ignore_msgs is None: ignore_msgs = [] ref_log_path = ref_log_fn if os.path.exists( ref_log_fn) else BASE_URL + os.path.basename(ref_log_fn) ref_log_msgs = list(LogReader(ref_log_path)) log_msgs = replay_process(cfg, lr) # check to make sure openpilot is engaged in the route if cfg.proc_name == "controlsd": if not check_enabled(log_msgs): segment = ref_log_fn.split("/")[-1].split("_")[0] raise Exception(f"Route never enabled: {segment}") try: return compare_logs(ref_log_msgs, log_msgs, ignore_fields + cfg.ignore, ignore_msgs, cfg.tolerance), log_msgs except Exception as e: return str(e), log_msgs
def test_process(dat, name): cfg = get_process_config(name) lr = convert_to_lr(dat) pr.TIMEOUT = 0.1 return pr.replay_process(cfg, lr, TOYOTA.COROLLA_TSS2)
no_upload = "--no-upload" in sys.argv process_replay_dir = os.path.dirname(os.path.abspath(__file__)) ref_commit_fn = os.path.join(process_replay_dir, "ref_commit") ref_commit = get_git_commit() with open(ref_commit_fn, "w") as f: f.write(ref_commit) for car_brand, segment in segments: rlog_fn = get_segment(segment) if rlog_fn is None: print("failed to get segment %s" % segment) sys.exit(1) lr = LogReader(rlog_fn) for cfg in CONFIGS: log_msgs = replay_process(cfg, lr) log_fn = os.path.join(process_replay_dir, "%s_%s_%s.bz2" % (segment, cfg.proc_name, ref_commit)) save_log(log_fn, log_msgs) if not no_upload: upload_file(log_fn, os.path.basename(log_fn)) os.remove(log_fn) os.remove(rlog_fn) print("done")
import argparse from selfdrive.test.process_replay.compare_logs import save_log from selfdrive.test.process_replay.process_replay import CONFIGS, replay_process from tools.lib.logreader import MultiLogIterator from tools.lib.route import Route if __name__ == "__main__": parser = argparse.ArgumentParser( description="Run process on route and create new logs", formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument("route", help="The route name to use") parser.add_argument("process", help="The process to run") args = parser.parse_args() cfg = [c for c in CONFIGS if c.proc_name == args.process][0] route = Route(args.route) lr = MultiLogIterator(route.log_paths()) inputs = list(lr) outputs = replay_process(cfg, inputs) # Remove message generated by the process under test and merge in the new messages produces = {o.which() for o in outputs} inputs = [i for i in inputs if i.which() not in produces] outputs = sorted(inputs + outputs, key=lambda x: x.logMonoTime) fn = f"{args.route}_{args.process}.bz2" save_log(fn, outputs)