Not working, fixing replay_learning.py

pull/2217/head
Gregor Kikelj 5 years ago
parent 7878673284
commit 9c8e911ed2
  1. 15
      .pre-commit-config.yaml
  2. 2
      selfdrive/locationd/test/ubloxd.py
  3. 8
      selfdrive/locationd/ubloxd_main.cc
  4. 3
      selfdrive/loggerd/tests/test_loggerd.py
  5. 33
      selfdrive/manager.py
  6. 3
      selfdrive/test/process_replay/process_replay.py
  7. 9
      selfdrive/test/process_replay/test_processes.py
  8. 46
      selfdrive/test/valgrind_testing.py
  9. 2
      tools/replay/unlogger.py

@ -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

@ -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():

@ -12,6 +12,7 @@
#include <math.h>
#include <ctime>
#include <chrono>
// #include <iostream>
#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"<<std::endl;
LOGW("starting ubloxd");
signal(SIGINT, (sighandler_t) set_do_exit);
signal(SIGTERM, (sighandler_t) set_do_exit);
@ -41,8 +43,9 @@ int ubloxd_main(poll_ubloxraw_msg_func poll_func, send_gps_event_func send_func)
subscriber->setTimeout(100);
PubMaster pm({"ubloxGnss", "gpsLocationExternal"});
// int t=0;
while (!do_exit) {
// std::cout<<"Got to here on round "<<t++<<std::endl;
Message * msg = subscriber->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<capnp::word>((msg->getSize() / sizeof(capnp::word)) + 1);
memcpy(amsg.begin(), msg->getData(), msg->getSize());
// std::cout<<"Message is :"<<std::endl;
// std::cout<<amsg.begin()<<std::endl;
capnp::FlatArrayMessageReader cmsg(amsg);
cereal::Event::Reader event = cmsg.getRoot<cereal::Event>();
auto ubloxRaw = event.getUbloxRaw();

@ -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()

@ -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()

@ -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']

@ -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:

@ -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()

@ -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):

Loading…
Cancel
Save