From 9c8e911ed2c7bed7aa161f6924a76a07213a482c Mon Sep 17 00:00:00 2001 From: Gregor Kikelj Date: Tue, 29 Sep 2020 11:45:26 +0200 Subject: [PATCH] Not working, fixing replay_learning.py --- .pre-commit-config.yaml | 15 +----- selfdrive/locationd/test/ubloxd.py | 2 +- selfdrive/locationd/ubloxd_main.cc | 8 +++- selfdrive/loggerd/tests/test_loggerd.py | 3 +- selfdrive/manager.py | 33 ++++++++++--- .../test/process_replay/process_replay.py | 3 +- .../test/process_replay/test_processes.py | 9 ++-- selfdrive/test/valgrind_testing.py | 46 ++++++++++++++++--- tools/replay/unlogger.py | 2 +- 9 files changed, 84 insertions(+), 37 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1cd805de4a..faa0b4bbcf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -31,17 +31,4 @@ repos: language: system types: [python] exclude: '^(pyextra)|(external)|(cereal)|(rednose)|(panda)|(laika)|(laika_repo)|(rednose_repo)/' -- repo: local - hooks: - - id: cppcheck - name: cppcheck - entry: cppcheck - language: system - types: [c++] - exclude: '^(phonelibs)|(external)|(cereal)|(opendbc)|(panda)|(tools)|(selfdrive/modeld/thneed/debug)|(selfdrive/modeld/test)|(selfdrive/camerad/test)/|(installer)' - args: - - --error-exitcode=1 - - --language=c++ - - --quiet - - --force - - -j8 + diff --git a/selfdrive/locationd/test/ubloxd.py b/selfdrive/locationd/test/ubloxd.py index 314c80237f..1f4c6af8a7 100755 --- a/selfdrive/locationd/test/ubloxd.py +++ b/selfdrive/locationd/test/ubloxd.py @@ -272,7 +272,7 @@ def handle_msg(dev, msg, nav_frame_buffer): except ublox.UBloxError as e: print(e) - #if dev is not None and dev.dev is not None: + # if dev is not None and dev.dev is not None: # dev.close() def main(): diff --git a/selfdrive/locationd/ubloxd_main.cc b/selfdrive/locationd/ubloxd_main.cc index ad895f8d3e..65885605d5 100644 --- a/selfdrive/locationd/ubloxd_main.cc +++ b/selfdrive/locationd/ubloxd_main.cc @@ -12,6 +12,7 @@ #include #include #include +// #include #include "messaging.hpp" #include "common/util.h" @@ -29,6 +30,7 @@ void set_do_exit(int sig) { using namespace ublox; int ubloxd_main(poll_ubloxraw_msg_func poll_func, send_gps_event_func send_func) { + // std::cout<<"Runnning ublox_main"<setTimeout(100); PubMaster pm({"ubloxGnss", "gpsLocationExternal"}); - + // int t=0; while (!do_exit) { + // std::cout<<"Got to here on round "<receive(); if (!msg){ if (errno == EINTR) { @@ -53,7 +56,8 @@ int ubloxd_main(poll_ubloxraw_msg_func poll_func, send_gps_event_func send_func) auto amsg = kj::heapArray((msg->getSize() / sizeof(capnp::word)) + 1); memcpy(amsg.begin(), msg->getData(), msg->getSize()); - + // std::cout<<"Message is :"<(); auto ubloxRaw = event.getUbloxRaw(); diff --git a/selfdrive/loggerd/tests/test_loggerd.py b/selfdrive/loggerd/tests/test_loggerd.py index a6ce23a533..714350425d 100755 --- a/selfdrive/loggerd/tests/test_loggerd.py +++ b/selfdrive/loggerd/tests/test_loggerd.py @@ -40,7 +40,8 @@ class TestLoggerd(unittest.TestCase): @classmethod def setUpClass(cls): if not (EON or TICI): - raise unittest.SkipTest + pass + # raise unittest.SkipTest def setUp(self): self._clear_logs() diff --git a/selfdrive/manager.py b/selfdrive/manager.py index 898297d64c..d5d2a1b3b1 100755 --- a/selfdrive/manager.py +++ b/selfdrive/manager.py @@ -22,6 +22,7 @@ os.environ['BASEDIR'] = BASEDIR TOTAL_SCONS_NODES = 1005 prebuilt = os.path.exists(os.path.join(BASEDIR, 'prebuilt')) +VALGRIND = os.getenv("VALGRIND") is not None # Create folders needed for msgq try: os.mkdir("/dev/shm") @@ -169,14 +170,14 @@ managed_processes = { "plannerd": "selfdrive.controls.plannerd", "radard": "selfdrive.controls.radard", "dmonitoringd": "selfdrive.monitoring.dmonitoringd", - "ubloxd": ("selfdrive/locationd", ["./ubloxd"]), - "loggerd": ("selfdrive/loggerd", ["./loggerd"]), + "ubloxd": ("selfdrive/locationd", ["./ubloxd"]), # 0 + "loggerd": ("selfdrive/loggerd", ["./loggerd"]), # 1 "logmessaged": "selfdrive.logmessaged", "locationd": "selfdrive.locationd.locationd", "tombstoned": "selfdrive.tombstoned", "logcatd": ("selfdrive/logcatd", ["./logcatd"]), "proclogd": ("selfdrive/proclogd", ["./proclogd"]), - "boardd": ("selfdrive/boardd", ["./boardd"]), # not used directly + "boardd": ("selfdrive/boardd", ["./boardd"]), "pandad": "selfdrive.pandad", "ui": ("selfdrive/ui", ["./ui"]), "calibrationd": "selfdrive.locationd.calibrationd", @@ -291,6 +292,18 @@ def nativelauncher(pargs, cwd): os.chmod(pargs[0], 0o700) os.execvp(pargs[0], pargs) +def valgrindlauncher(pargs, cwd): + # exec the process + os.chdir(cwd) + + # Run valgrind on a process + command = "valgrind --leak-check=full " + pargs[0] + output = os.popen(command) + while True: + s = output.read() + if s == "": + break + # print(s) def start_managed_process(name): if name in running or name not in managed_processes: @@ -302,9 +315,17 @@ def start_managed_process(name): else: pdir, pargs = proc cwd = os.path.join(BASEDIR, pdir) - cloudlog.info("starting process %s" % name) - running[name] = Process(name=name, target=nativelauncher, args=(pargs, cwd)) - running[name].start() + if VALGRIND: + print("\nVALGRIND" * 5) + print(pargs) + print(cwd) + running[name] = Process(name=name, target=valgrindlauncher, args=(pargs, cwd)) + else: + cloudlog.info("starting process %s" % name) + print(pargs) + print(cwd) + running[name] = Process(name=name, target=nativelauncher, args=(pargs, cwd)) + running[name].start() def start_daemon_process(name): params = Params() diff --git a/selfdrive/test/process_replay/process_replay.py b/selfdrive/test/process_replay/process_replay.py index 3b05b3871f..0d7ebb6cbd 100755 --- a/selfdrive/test/process_replay/process_replay.py +++ b/selfdrive/test/process_replay/process_replay.py @@ -201,7 +201,7 @@ def calibration_rcv_callback(msg, CP, cfg, fsm): # calibrationd publishes 1 calibrationData every 5 cameraOdometry packets. # should_recv always true to increment frame recv_socks = [] - frame = fsm.frame + 1 # incrementing hasn't happened yet in SubMaster + frame = fsm.frame + 1 # incrementing hasn't happened yet in SubMaster if frame == 0 or (msg.which() == 'cameraOdometry' and (frame % 5) == 0): recv_socks = ["liveCalibration"] return recv_socks, fsm.frame == 0 or msg.which() == 'cameraOdometry' @@ -288,6 +288,7 @@ CONFIGS = [ ] def replay_process(cfg, lr): + print("Running replay on inputs " + str(cfg) + " " + str(lr)) sub_sockets = [s for _, sub in cfg.pub_sub.items() for s in sub] pub_sockets = [s for s in cfg.pub_sub.keys() if s != 'can'] diff --git a/selfdrive/test/process_replay/test_processes.py b/selfdrive/test/process_replay/test_processes.py index 650c39bc6c..a87ba97e14 100755 --- a/selfdrive/test/process_replay/test_processes.py +++ b/selfdrive/test/process_replay/test_processes.py @@ -18,13 +18,13 @@ segments = [ ("GM", "7cc2a8365b4dd8a9|2018-12-02--12-10-44--2"), # GM.ACADIA ("CHRYSLER", "b6849f5cf2c926b1|2020-02-28--07-29-48--13"), # CHRYSLER.PACIFICA ("HYUNDAI", "5b7c365c50084530|2020-04-15--16-13-24--3"), # HYUNDAI.SONATA - #("CHRYSLER", "b6e1317e1bfbefa6|2020-03-04--13-11-40"), # CHRYSLER.JEEP_CHEROKEE + # ("CHRYSLER", "b6e1317e1bfbefa6|2020-03-04--13-11-40"), # CHRYSLER.JEEP_CHEROKEE ("SUBARU", "7873afaf022d36e2|2019-07-03--18-46-44--0"), # SUBARU.IMPREZA ("VOLKSWAGEN", "76b83eb0245de90e|2020-03-05--19-16-05--3"), # VW.GOLF ("NISSAN", "fbbfa6af821552b9|2020-03-03--08-09-43--0"), # NISSAN.XTRAIL # Enable when port is tested and dascamOnly is no longer set - #("MAZDA", "32a319f057902bb3|2020-04-27--15-18-58--2"), # MAZDA.CX5 + # ("MAZDA", "32a319f057902bb3|2020-04-27--15-18-58--2"), # MAZDA.CX5 ] # ford doesn't need to be tested until a full port is done @@ -105,6 +105,7 @@ def format_diff(results, ref_commit): return diff1, diff2, failed if __name__ == "__main__": + # os.environ["VALGRIND"] = "1" parser = argparse.ArgumentParser(description="Regression test to identify changes in a process's output") @@ -140,9 +141,8 @@ if __name__ == "__main__": tested_cars = set(c.lower() for c, _ in segments) untested = (set(interface_names) - set(excluded_interfaces)) - tested_cars assert len(untested) == 0, "Cars missing routes: %s" % (str(untested)) - results: Any = {} - for car_brand, segment in segments: + for car_brand, segment in segments: # Runs all tests, can focus on inside of the loop :) if (cars_whitelisted and car_brand.upper() not in args.whitelist_cars) or \ (not cars_whitelisted and car_brand.upper() in args.blacklist_cars): continue @@ -152,6 +152,7 @@ if __name__ == "__main__": results[segment] = {} rlog_fn = get_segment(segment) + print(rlog_fn) lr = LogReader(rlog_fn) for cfg in CONFIGS: diff --git a/selfdrive/test/valgrind_testing.py b/selfdrive/test/valgrind_testing.py index ecce82fd2e..03b8434544 100644 --- a/selfdrive/test/valgrind_testing.py +++ b/selfdrive/test/valgrind_testing.py @@ -1,15 +1,45 @@ import os import time -import subprocess +from multiprocessing import Process +import cereal.messaging as messaging +import random + +def valgrindlauncher(arg, cwd): + os.chdir(cwd) + + # Run valgrind on a process + command = "valgrind " + arg + print(command) + output = os.popen(command) + while True: + s = output.read() + if s == "": + break + print(s) def test_ubloxd(): - # unlogger_command = '~/openpilot/tools/replay/unlogger.py "202fc0c905c39dd8|2020-09-09--10-50-37"' - subprocess.Popen(["python", "~/openpilot/tools/replay/unlogger.py", "202fc0c905c39dd8|2020-09-09--10-50-37"]) + running = Process(name="ublox", target=valgrindlauncher, args=("./ubloxd & sleep 10; kill $!", "../locationd")) + running.start() + +def random_carstate(): + fields = ["vEgo", "aEgo", "gas", "steeringAngle"] + msg = messaging.new_message("carState") + cs = msg.carState + for f in fields: + setattr(cs, f, random.random() * 10) + return msg + +def send_gps(): + pub_sock = messaging.pub_sock("ubloxRaw") + time.sleep(3) - time.sleep(5) + msg = random_carstate() + pub_sock.send(msg.to_bytes()) - output = os.popen("valgrind --leak-check=full ~/openpilot/selfdrive/locationd/ubloxd & sleep 10; kill $!") - print("\n\n\n\n") +# python test_loggerd in tests kind of works, with VALGRIND=1 in ENV +def test_loggerd(): + output = os.popen("valgrind --leak-check=full ~/openpilot/selfdrive/loggerd/loggerd & sleep 30; kill $!") + print(2 * "\n") while True: s = output.read() if s == "": @@ -19,4 +49,6 @@ def test_ubloxd(): if __name__ == "__main__": - test_ubloxd() + # pm = messaging.PubMaster(['ubloxRaw']) + send_gps() + # test_ubloxd() diff --git a/tools/replay/unlogger.py b/tools/replay/unlogger.py index 2cef80b770..583c7f0aa6 100755 --- a/tools/replay/unlogger.py +++ b/tools/replay/unlogger.py @@ -90,7 +90,7 @@ class UnloggerWorker(object): # this assumes the encodeIdx always comes before the frame self._frame_id_lookup[ msg.encodeIdx.frameId] = msg.encodeIdx.segmentNum, msg.encodeIdx.segmentId - #print "encode", msg.encodeIdx.frameId, len(self._readahead), route_time + # print "encode", msg.encodeIdx.frameId, len(self._readahead), route_time self._readahead.appendleft((typ, msg, route_time, cookie)) def _send_logs(self, data_socket):