From dd9b0231c696607c14a8c10adeeb4d047c5ff782 Mon Sep 17 00:00:00 2001 From: Justin Newberry Date: Tue, 29 Aug 2023 10:06:32 -0700 Subject: [PATCH 01/13] Tests: test_caching reduce global state (#29681) --- tools/lib/tests/__init__.py | 12 ++++++++++++ tools/lib/tests/test_caching.py | 10 ++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/tools/lib/tests/__init__.py b/tools/lib/tests/__init__.py index e69de29bb2..32219c6ce9 100644 --- a/tools/lib/tests/__init__.py +++ b/tools/lib/tests/__init__.py @@ -0,0 +1,12 @@ +import tempfile + +from unittest import mock + +def temporary_cache_dir(func): + def wrapper(*args, **kwargs): + with tempfile.TemporaryDirectory() as temp_dir: + cache_dir_patch = mock.patch("openpilot.tools.lib.url_file.CACHE_DIR", temp_dir) + cache_dir_patch.start() + func(*args, **kwargs) + cache_dir_patch.stop() + return wrapper \ No newline at end of file diff --git a/tools/lib/tests/test_caching.py b/tools/lib/tests/test_caching.py index 1e44b96489..0cb7d66d54 100644 --- a/tools/lib/tests/test_caching.py +++ b/tools/lib/tests/test_caching.py @@ -1,18 +1,14 @@ #!/usr/bin/env python3 import os -import shutil import unittest - -os.environ["COMMA_CACHE"] = "/tmp/__test_cache__" -from openpilot.tools.lib.url_file import URLFile, CACHE_DIR +from openpilot.tools.lib.url_file import URLFile +from tools.lib.tests import temporary_cache_dir class TestFileDownload(unittest.TestCase): def compare_loads(self, url, start=0, length=None): """Compares range between cached and non cached version""" - shutil.rmtree(CACHE_DIR) - file_cached = URLFile(url, cache=True) file_downloaded = URLFile(url, cache=False) @@ -35,6 +31,7 @@ class TestFileDownload(unittest.TestCase): self.assertEqual(file_cached.get_length(), file_downloaded.get_length()) self.assertEqual(response_cached, response_downloaded) + @temporary_cache_dir def test_small_file(self): # Make sure we don't force cache os.environ["FILEREADER_CACHE"] = "0" @@ -55,6 +52,7 @@ class TestFileDownload(unittest.TestCase): for i in range(length // 100): self.compare_loads(small_file_url, 100 * i, 100) + @temporary_cache_dir def test_large_file(self): large_file_url = "https://commadataci.blob.core.windows.net/openpilotci/0375fdf7b1ce594d/2019-06-13--08-32-25/3/qlog.bz2" # Load the end 100 bytes of both files From 7fbb7254fa13e0f219a1d8cd2d32c71388e93eb0 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Tue, 29 Aug 2023 13:51:50 -0400 Subject: [PATCH 02/13] Carcontroller: consolidate can sends method imports (#29695) * Carcontroller: consolidate can sends method imports * fix * ruff --- selfdrive/car/chrysler/carcontroller.py | 11 +++++----- selfdrive/car/ford/carcontroller.py | 27 ++++++++++++------------- selfdrive/car/toyota/carcontroller.py | 22 +++++++++----------- 3 files changed, 29 insertions(+), 31 deletions(-) diff --git a/selfdrive/car/chrysler/carcontroller.py b/selfdrive/car/chrysler/carcontroller.py index a568f927b8..050eb41b1a 100644 --- a/selfdrive/car/chrysler/carcontroller.py +++ b/selfdrive/car/chrysler/carcontroller.py @@ -1,7 +1,7 @@ from opendbc.can.packer import CANPacker from openpilot.common.realtime import DT_CTRL from openpilot.selfdrive.car import apply_meas_steer_torque_limits -from openpilot.selfdrive.car.chrysler.chryslercan import create_lkas_hud, create_lkas_command, create_cruise_buttons +from openpilot.selfdrive.car.chrysler import chryslercan from openpilot.selfdrive.car.chrysler.values import RAM_CARS, CarControllerParams, ChryslerFlags @@ -31,17 +31,18 @@ class CarController: # ACC cancellation if CC.cruiseControl.cancel: self.last_button_frame = self.frame - can_sends.append(create_cruise_buttons(self.packer, CS.button_counter + 1, das_bus, cancel=True)) + can_sends.append(chryslercan.create_cruise_buttons(self.packer, CS.button_counter + 1, das_bus, cancel=True)) # ACC resume from standstill elif CC.cruiseControl.resume: self.last_button_frame = self.frame - can_sends.append(create_cruise_buttons(self.packer, CS.button_counter + 1, das_bus, resume=True)) + can_sends.append(chryslercan.create_cruise_buttons(self.packer, CS.button_counter + 1, das_bus, resume=True)) # HUD alerts if self.frame % 25 == 0: if CS.lkas_car_model != -1: - can_sends.append(create_lkas_hud(self.packer, self.CP, lkas_active, CC.hudControl.visualAlert, self.hud_count, CS.lkas_car_model, CS.auto_high_beam)) + can_sends.append(chryslercan.create_lkas_hud(self.packer, self.CP, lkas_active, CC.hudControl.visualAlert, + self.hud_count, CS.lkas_car_model, CS.auto_high_beam)) self.hud_count += 1 # steering @@ -72,7 +73,7 @@ class CarController: apply_steer = 0 self.apply_steer_last = apply_steer - can_sends.append(create_lkas_command(self.packer, self.CP, int(apply_steer), lkas_control_bit)) + can_sends.append(chryslercan.create_lkas_command(self.packer, self.CP, int(apply_steer), lkas_control_bit)) self.frame += 1 diff --git a/selfdrive/car/ford/carcontroller.py b/selfdrive/car/ford/carcontroller.py index 86008c6352..fe9ee404a4 100644 --- a/selfdrive/car/ford/carcontroller.py +++ b/selfdrive/car/ford/carcontroller.py @@ -2,8 +2,7 @@ from cereal import car from openpilot.common.numpy_fast import clip from opendbc.can.packer import CANPacker from openpilot.selfdrive.car import apply_std_steer_angle_limits -from openpilot.selfdrive.car.ford.fordcan import CanBus, create_acc_msg, create_acc_ui_msg, create_button_msg, \ - create_lat_ctl_msg, create_lat_ctl2_msg, create_lka_msg, create_lkas_ui_msg +from openpilot.selfdrive.car.ford import fordcan from openpilot.selfdrive.car.ford.values import CANFD_CAR, CarControllerParams LongCtrlState = car.CarControl.Actuators.LongControlState @@ -27,7 +26,7 @@ class CarController: self.CP = CP self.VM = VM self.packer = CANPacker(dbc_name) - self.CAN = CanBus(CP) + self.CAN = fordcan.CanBus(CP) self.frame = 0 self.apply_curvature_last = 0 @@ -47,15 +46,15 @@ class CarController: ### acc buttons ### if CC.cruiseControl.cancel: - can_sends.append(create_button_msg(self.packer, self.CAN.camera, CS.buttons_stock_values, cancel=True)) - can_sends.append(create_button_msg(self.packer, self.CAN.main, CS.buttons_stock_values, cancel=True)) + can_sends.append(fordcan.create_button_msg(self.packer, self.CAN.camera, CS.buttons_stock_values, cancel=True)) + can_sends.append(fordcan.create_button_msg(self.packer, self.CAN.main, CS.buttons_stock_values, cancel=True)) elif CC.cruiseControl.resume and (self.frame % CarControllerParams.BUTTONS_STEP) == 0: - can_sends.append(create_button_msg(self.packer, self.CAN.camera, CS.buttons_stock_values, resume=True)) - can_sends.append(create_button_msg(self.packer, self.CAN.main, CS.buttons_stock_values, resume=True)) + can_sends.append(fordcan.create_button_msg(self.packer, self.CAN.camera, CS.buttons_stock_values, resume=True)) + can_sends.append(fordcan.create_button_msg(self.packer, self.CAN.main, CS.buttons_stock_values, resume=True)) # if stock lane centering isn't off, send a button press to toggle it off # the stock system checks for steering pressed, and eventually disengages cruise control elif CS.acc_tja_status_stock_values["Tja_D_Stat"] != 0 and (self.frame % CarControllerParams.ACC_UI_STEP) == 0: - can_sends.append(create_button_msg(self.packer, self.CAN.camera, CS.buttons_stock_values, tja_toggle=True)) + can_sends.append(fordcan.create_button_msg(self.packer, self.CAN.camera, CS.buttons_stock_values, tja_toggle=True)) ### lateral control ### # send steer msg at 20Hz @@ -73,13 +72,13 @@ class CarController: # TODO: extended mode mode = 1 if CC.latActive else 0 counter = (self.frame // CarControllerParams.STEER_STEP) % 0xF - can_sends.append(create_lat_ctl2_msg(self.packer, self.CAN, mode, 0., 0., -apply_curvature, 0., counter)) + can_sends.append(fordcan.create_lat_ctl2_msg(self.packer, self.CAN, mode, 0., 0., -apply_curvature, 0., counter)) else: - can_sends.append(create_lat_ctl_msg(self.packer, self.CAN, CC.latActive, 0., 0., -apply_curvature, 0.)) + can_sends.append(fordcan.create_lat_ctl_msg(self.packer, self.CAN, CC.latActive, 0., 0., -apply_curvature, 0.)) # send lka msg at 33Hz if (self.frame % CarControllerParams.LKA_STEP) == 0: - can_sends.append(create_lka_msg(self.packer, self.CAN)) + can_sends.append(fordcan.create_lka_msg(self.packer, self.CAN)) ### longitudinal control ### # send acc msg at 50Hz @@ -91,16 +90,16 @@ class CarController: gas = CarControllerParams.INACTIVE_GAS stopping = CC.actuators.longControlState == LongCtrlState.stopping - can_sends.append(create_acc_msg(self.packer, self.CAN, CC.longActive, gas, accel, stopping)) + can_sends.append(fordcan.create_acc_msg(self.packer, self.CAN, CC.longActive, gas, accel, stopping)) ### ui ### send_ui = (self.main_on_last != main_on) or (self.lkas_enabled_last != CC.latActive) or (self.steer_alert_last != steer_alert) # send lkas ui msg at 1Hz or if ui state changes if (self.frame % CarControllerParams.LKAS_UI_STEP) == 0 or send_ui: - can_sends.append(create_lkas_ui_msg(self.packer, self.CAN, main_on, CC.latActive, steer_alert, hud_control, CS.lkas_status_stock_values)) + can_sends.append(fordcan.create_lkas_ui_msg(self.packer, self.CAN, main_on, CC.latActive, steer_alert, hud_control, CS.lkas_status_stock_values)) # send acc ui msg at 5Hz or if ui state changes if (self.frame % CarControllerParams.ACC_UI_STEP) == 0 or send_ui: - can_sends.append(create_acc_ui_msg(self.packer, self.CAN, self.CP, main_on, CC.latActive, + can_sends.append(fordcan.create_acc_ui_msg(self.packer, self.CAN, self.CP, main_on, CC.latActive, fcw_alert, CS.out.cruiseState.standstill, hud_control, CS.acc_tja_status_stock_values)) diff --git a/selfdrive/car/toyota/carcontroller.py b/selfdrive/car/toyota/carcontroller.py index 01896f1421..2a02a57d86 100644 --- a/selfdrive/car/toyota/carcontroller.py +++ b/selfdrive/car/toyota/carcontroller.py @@ -2,9 +2,7 @@ from cereal import car from openpilot.common.numpy_fast import clip, interp from openpilot.selfdrive.car import apply_meas_steer_torque_limits, apply_std_steer_angle_limits, common_fault_avoidance, \ create_gas_interceptor_command, make_can_msg -from openpilot.selfdrive.car.toyota.toyotacan import create_steer_command, create_ui_command, \ - create_accel_command, create_acc_cancel_command, \ - create_fcw_command, create_lta_steer_command +from openpilot.selfdrive.car.toyota import toyotacan from openpilot.selfdrive.car.toyota.values import CAR, STATIC_DSU_MSGS, NO_STOP_TIMER_CAR, TSS2_CAR, \ MIN_ACC_SPEED, PEDAL_TRANSITION, CarControllerParams, ToyotaFlags, \ UNSUPPORTED_DSU_CAR @@ -85,13 +83,13 @@ class CarController: # toyota can trace shows this message at 42Hz, with counter adding alternatively 1 and 2; # sending it at 100Hz seem to allow a higher rate limit, as the rate limit seems imposed # on consecutive messages - can_sends.append(create_steer_command(self.packer, apply_steer, apply_steer_req)) + can_sends.append(toyotacan.create_steer_command(self.packer, apply_steer, apply_steer_req)) if self.frame % 2 == 0 and self.CP.carFingerprint in TSS2_CAR: lta_active = lat_active and self.CP.steerControlType == SteerControlType.angle full_torque_condition = (abs(CS.out.steeringTorqueEps) < self.params.STEER_MAX and abs(CS.out.steeringTorque) < MAX_DRIVER_TORQUE_ALLOWANCE) setme_x64 = 100 if lta_active and full_torque_condition else 0 - can_sends.append(create_lta_steer_command(self.packer, self.last_angle, lta_active, self.frame // 2, setme_x64)) + can_sends.append(toyotacan.create_lta_steer_command(self.packer, self.last_angle, lta_active, self.frame // 2, setme_x64)) # *** gas and brake *** if self.CP.enableGasInterceptor and CC.longActive: @@ -135,12 +133,12 @@ class CarController: # Lexus IS uses a different cancellation message if pcm_cancel_cmd and self.CP.carFingerprint in UNSUPPORTED_DSU_CAR: - can_sends.append(create_acc_cancel_command(self.packer)) + can_sends.append(toyotacan.create_acc_cancel_command(self.packer)) elif self.CP.openpilotLongitudinalControl: - can_sends.append(create_accel_command(self.packer, pcm_accel_cmd, pcm_cancel_cmd, self.standstill_req, lead, CS.acc_type, fcw_alert)) + can_sends.append(toyotacan.create_accel_command(self.packer, pcm_accel_cmd, pcm_cancel_cmd, self.standstill_req, lead, CS.acc_type, fcw_alert)) self.accel = pcm_accel_cmd else: - can_sends.append(create_accel_command(self.packer, 0, pcm_cancel_cmd, False, lead, CS.acc_type, False)) + can_sends.append(toyotacan.create_accel_command(self.packer, 0, pcm_cancel_cmd, False, lead, CS.acc_type, False)) if self.frame % 2 == 0 and self.CP.enableGasInterceptor and self.CP.openpilotLongitudinalControl: # send exactly zero if gas cmd is zero. Interceptor will send the max between read value and gas cmd. @@ -163,12 +161,12 @@ class CarController: send_ui = True if self.frame % 20 == 0 or send_ui: - can_sends.append(create_ui_command(self.packer, steer_alert, pcm_cancel_cmd, hud_control.leftLaneVisible, - hud_control.rightLaneVisible, hud_control.leftLaneDepart, - hud_control.rightLaneDepart, CC.enabled, CS.lkas_hud)) + can_sends.append(toyotacan.create_ui_command(self.packer, steer_alert, pcm_cancel_cmd, hud_control.leftLaneVisible, + hud_control.rightLaneVisible, hud_control.leftLaneDepart, + hud_control.rightLaneDepart, CC.enabled, CS.lkas_hud)) if (self.frame % 100 == 0 or send_ui) and (self.CP.enableDsu or self.CP.flags & ToyotaFlags.DISABLE_RADAR.value): - can_sends.append(create_fcw_command(self.packer, fcw_alert)) + can_sends.append(toyotacan.create_fcw_command(self.packer, fcw_alert)) # *** static msgs *** for addr, cars, bus, fr_step, vl in STATIC_DSU_MSGS: From 5f0729791ab6bdb22b3e971f0153a88441f8831a Mon Sep 17 00:00:00 2001 From: Justin Newberry Date: Tue, 29 Aug 2023 10:53:21 -0700 Subject: [PATCH 03/13] Parser: assert no duplicate message checks (#29696) * assert no duplicate checks * bump * remove duplicates * are both messages present? * guess we need this extra check * this makes it more clear * bump opendbc * fix preglobal --- opendbc | 2 +- selfdrive/car/hyundai/carstate.py | 6 +++++- selfdrive/car/subaru/carstate.py | 1 - selfdrive/car/subaru/subarucan.py | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/opendbc b/opendbc index 814763889d..034ca989bd 160000 --- a/opendbc +++ b/opendbc @@ -1 +1 @@ -Subproject commit 814763889df3d1f19112a9628dfb4d1f17c0c533 +Subproject commit 034ca989bd19e1dc2f6f5be903c037bc1aca750a diff --git a/selfdrive/car/hyundai/carstate.py b/selfdrive/car/hyundai/carstate.py index ee35bf6663..7a3c59e8d3 100644 --- a/selfdrive/car/hyundai/carstate.py +++ b/selfdrive/car/hyundai/carstate.py @@ -305,7 +305,6 @@ class CarState(CarStateBase): def get_can_parser_canfd(self, CP): messages = [ (self.gear_msg_canfd, 100), - (self.cruise_btns_msg_canfd, 50), (self.accelerator_msg_canfd, 100), ("WHEEL_SPEEDS", 100), ("STEERING_SENSORS", 100), @@ -316,6 +315,11 @@ class CarState(CarStateBase): ("DOORS_SEATBELTS", 4), ] + if not (CP.flags & HyundaiFlags.CANFD_ALT_BUTTONS): + messages += [ + ("CRUISE_BUTTONS", 50) + ] + if CP.enableBsm: messages += [ ("BLINDSPOTS_REAR_CORNERS", 20), diff --git a/selfdrive/car/subaru/carstate.py b/selfdrive/car/subaru/carstate.py index 027f317a09..c8a6dfe1e6 100644 --- a/selfdrive/car/subaru/carstate.py +++ b/selfdrive/car/subaru/carstate.py @@ -150,7 +150,6 @@ class CarState(CarStateBase): ("CruiseControl", 50), ("Wheel_Speeds", 50), ("Dash_State2", 1), - ("Dashlights", 10), ] return messages diff --git a/selfdrive/car/subaru/subarucan.py b/selfdrive/car/subaru/subarucan.py index 79ff3c8c56..0f297d9635 100644 --- a/selfdrive/car/subaru/subarucan.py +++ b/selfdrive/car/subaru/subarucan.py @@ -261,7 +261,7 @@ def create_preglobal_es_distance(packer, cruise_button, es_distance_msg): "Signal1", "Car_Follow", "Signal2", - "Brake_On", + "Cruise_Brake_Active", "Distance_Swap", "Standstill", "Signal3", From d37d179b5da8c30a3b8d74ba13396f2b27324121 Mon Sep 17 00:00:00 2001 From: Saber <81108166+Saber422@users.noreply.github.com> Date: Wed, 30 Aug 2023 02:58:29 +0800 Subject: [PATCH 04/13] VW MQB: Add FW for 2016 Skoda Superb (#29701) --- selfdrive/car/volkswagen/values.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/selfdrive/car/volkswagen/values.py b/selfdrive/car/volkswagen/values.py index 3ffc09a43d..36cb5ef534 100755 --- a/selfdrive/car/volkswagen/values.py +++ b/selfdrive/car/volkswagen/values.py @@ -1315,6 +1315,7 @@ FW_VERSIONS = { }, CAR.SKODA_SUPERB_MK3: { (Ecu.engine, 0x7e0, None): [ + b'\xf1\x8704E906027BT\xf1\x899042', b'\xf1\x8704L906026ET\xf1\x891343', b'\xf1\x8704L906026FP\xf1\x891196', b'\xf1\x8704L906026KB\xf1\x894071', @@ -1327,6 +1328,7 @@ FW_VERSIONS = { ], (Ecu.transmission, 0x7e1, None): [ b'\xf1\x870CW300042H \xf1\x891601', + b'\xf1\x870CW300049Q \xf1\x890906', b'\xf1\x870D9300011T \xf1\x894801', b'\xf1\x870D9300012 \xf1\x894940', b'\xf1\x870D9300013A \xf1\x894905', @@ -1350,6 +1352,7 @@ FW_VERSIONS = { ], (Ecu.eps, 0x712, None): [ b'\xf1\x875Q0909143K \xf1\x892033\xf1\x820514UZ070203', + b'\xf1\x875Q0909143M \xf1\x892041\xf1\x820522UZ050303', b'\xf1\x875Q0909143M \xf1\x892041\xf1\x820522UZ070303', b'\xf1\x875Q0909143P \xf1\x892051\xf1\x820526UZ070505', b'\xf1\x875Q0910143B \xf1\x892201\xf1\x82\00563UZ060700', From 2d4f5ac8eaa0a960d47ea34c9f404a755224d790 Mon Sep 17 00:00:00 2001 From: eFini Date: Wed, 30 Aug 2023 03:00:24 +0800 Subject: [PATCH 05/13] ui/map: fix icon naming (#29699) --- ...n_right.png => direction_notification_right.png} | Bin ...t.png => direction_notification_sharp_right.png} | Bin 2 files changed, 0 insertions(+), 0 deletions(-) rename selfdrive/assets/navigation/{direction_notificaiton_right.png => direction_notification_right.png} (100%) rename selfdrive/assets/navigation/{direction_notificaiton_sharp_right.png => direction_notification_sharp_right.png} (100%) diff --git a/selfdrive/assets/navigation/direction_notificaiton_right.png b/selfdrive/assets/navigation/direction_notification_right.png similarity index 100% rename from selfdrive/assets/navigation/direction_notificaiton_right.png rename to selfdrive/assets/navigation/direction_notification_right.png diff --git a/selfdrive/assets/navigation/direction_notificaiton_sharp_right.png b/selfdrive/assets/navigation/direction_notification_sharp_right.png similarity index 100% rename from selfdrive/assets/navigation/direction_notificaiton_sharp_right.png rename to selfdrive/assets/navigation/direction_notification_sharp_right.png From 5dc7028f91079dfa07347a4d24ff56b72c24bd20 Mon Sep 17 00:00:00 2001 From: Justin Newberry Date: Tue, 29 Aug 2023 13:36:26 -0700 Subject: [PATCH 06/13] Tests: logmessaged reduce global state (#29680) * reduce global state * use a decorator here too * use that one * use base imports * ipchandler in setup * move to common dir * move to helpers * wip * fix the decorator --- selfdrive/test/helpers.py | 19 +++++++++++++++++++ system/swaglog.py | 7 ++++++- system/tests/test_logmessaged.py | 23 ++++++++++++++--------- tools/lib/tests/__init__.py | 12 ------------ tools/lib/tests/test_caching.py | 6 +++--- 5 files changed, 42 insertions(+), 25 deletions(-) diff --git a/selfdrive/test/helpers.py b/selfdrive/test/helpers.py index f5ba67b407..3f4e4e1661 100644 --- a/selfdrive/test/helpers.py +++ b/selfdrive/test/helpers.py @@ -1,5 +1,8 @@ import os import time +import tempfile + +from unittest import mock from functools import wraps import cereal.messaging as messaging @@ -67,3 +70,19 @@ def with_processes(processes, init_time=0, ignore_stopped=None): return wrap return wrapper + + +def temporary_mock_dir(mock_path): + def wrapper(func): + @wraps(func) + def wrap(*args, **kwargs): + with tempfile.TemporaryDirectory() as temp_dir: + cache_dir_patch = mock.patch(mock_path, temp_dir) + cache_dir_patch.start() + func(*args, **kwargs, temp_dir=temp_dir) + cache_dir_patch.stop() + return wrap + return wrapper + +temporary_cache_dir = temporary_mock_dir("openpilot.tools.lib.url_file.CACHE_DIR") +temporary_swaglog_dir = temporary_mock_dir("openpilot.system.swaglog.SWAGLOG_DIR") \ No newline at end of file diff --git a/system/swaglog.py b/system/swaglog.py index 5fe1c2f27f..3d45ad9826 100644 --- a/system/swaglog.py +++ b/system/swaglog.py @@ -77,6 +77,9 @@ class UnixDomainSocketHandler(logging.Handler): self.sock = None def __del__(self): + self.close() + + def close(self): if self.sock is not None: self.sock.close() if self.zctx is not None: @@ -129,6 +132,8 @@ elif print_level == 'info': elif print_level == 'warning': outhandler.setLevel(logging.WARNING) +ipchandler = UnixDomainSocketHandler(SwagFormatter(log)) + log.addHandler(outhandler) # logs are sent through IPC before writing to disk to prevent disk I/O blocking -log.addHandler(UnixDomainSocketHandler(SwagFormatter(log))) +log.addHandler(ipchandler) diff --git a/system/tests/test_logmessaged.py b/system/tests/test_logmessaged.py index 955272d403..330f151368 100755 --- a/system/tests/test_logmessaged.py +++ b/system/tests/test_logmessaged.py @@ -1,21 +1,22 @@ #!/usr/bin/env python3 import glob import os -import shutil import time import unittest import cereal.messaging as messaging from openpilot.selfdrive.manager.process_config import managed_processes -from openpilot.system.swaglog import cloudlog, SWAGLOG_DIR +from openpilot.system.swaglog import cloudlog, ipchandler +from selfdrive.test.helpers import temporary_swaglog_dir class TestLogmessaged(unittest.TestCase): + def _setup(self, temp_dir): + # clear the IPC buffer in case some other tests used cloudlog and filled it + ipchandler.close() + ipchandler.connect() - def setUp(self): - if os.path.exists(SWAGLOG_DIR): - shutil.rmtree(SWAGLOG_DIR) - + self.temp_dir = temp_dir managed_processes['logmessaged'].start() self.sock = messaging.sub_sock("logMessage", timeout=1000, conflate=False) self.error_sock = messaging.sub_sock("logMessage", timeout=1000, conflate=False) @@ -31,9 +32,11 @@ class TestLogmessaged(unittest.TestCase): managed_processes['logmessaged'].stop(block=True) def _get_log_files(self): - return list(glob.glob(os.path.join(SWAGLOG_DIR, "swaglog.*"))) + return list(glob.glob(os.path.join(self.temp_dir, "swaglog.*"))) - def test_simple_log(self): + @temporary_swaglog_dir + def test_simple_log(self, temp_dir): + self._setup(temp_dir) msgs = [f"abc {i}" for i in range(10)] for m in msgs: cloudlog.error(m) @@ -42,7 +45,9 @@ class TestLogmessaged(unittest.TestCase): assert len(m) == len(msgs) assert len(self._get_log_files()) >= 1 - def test_big_log(self): + @temporary_swaglog_dir + def test_big_log(self, temp_dir): + self._setup(temp_dir) n = 10 msg = "a"*3*1024*1024 for _ in range(n): diff --git a/tools/lib/tests/__init__.py b/tools/lib/tests/__init__.py index 32219c6ce9..e69de29bb2 100644 --- a/tools/lib/tests/__init__.py +++ b/tools/lib/tests/__init__.py @@ -1,12 +0,0 @@ -import tempfile - -from unittest import mock - -def temporary_cache_dir(func): - def wrapper(*args, **kwargs): - with tempfile.TemporaryDirectory() as temp_dir: - cache_dir_patch = mock.patch("openpilot.tools.lib.url_file.CACHE_DIR", temp_dir) - cache_dir_patch.start() - func(*args, **kwargs) - cache_dir_patch.stop() - return wrapper \ No newline at end of file diff --git a/tools/lib/tests/test_caching.py b/tools/lib/tests/test_caching.py index 0cb7d66d54..bd93cd93ec 100644 --- a/tools/lib/tests/test_caching.py +++ b/tools/lib/tests/test_caching.py @@ -2,7 +2,7 @@ import os import unittest from openpilot.tools.lib.url_file import URLFile -from tools.lib.tests import temporary_cache_dir +from openpilot.selfdrive.test.helpers import temporary_cache_dir class TestFileDownload(unittest.TestCase): @@ -32,7 +32,7 @@ class TestFileDownload(unittest.TestCase): self.assertEqual(response_cached, response_downloaded) @temporary_cache_dir - def test_small_file(self): + def test_small_file(self, temp_dir): # Make sure we don't force cache os.environ["FILEREADER_CACHE"] = "0" small_file_url = "https://raw.githubusercontent.com/commaai/openpilot/master/docs/SAFETY.md" @@ -53,7 +53,7 @@ class TestFileDownload(unittest.TestCase): self.compare_loads(small_file_url, 100 * i, 100) @temporary_cache_dir - def test_large_file(self): + def test_large_file(self, temp_dir): large_file_url = "https://commadataci.blob.core.windows.net/openpilotci/0375fdf7b1ce594d/2019-06-13--08-32-25/3/qlog.bz2" # Load the end 100 bytes of both files file_large = URLFile(large_file_url) From d998fd88a80e61e44692c50deefc91a7f94b59a2 Mon Sep 17 00:00:00 2001 From: Mitchell Goff Date: Tue, 29 Aug 2023 14:07:57 -0700 Subject: [PATCH 07/13] Added USE_THNEED environment variable and removed build flag (#29645) --- selfdrive/modeld/modeld.py | 6 ++++-- selfdrive/modeld/models/driving.h | 6 ------ selfdrive/modeld/models/driving.pxd | 1 - selfdrive/modeld/models/driving_pyx.pyx | 3 +-- 4 files changed, 5 insertions(+), 11 deletions(-) diff --git a/selfdrive/modeld/modeld.py b/selfdrive/modeld/modeld.py index 68afa453a9..61edcfb006 100755 --- a/selfdrive/modeld/modeld.py +++ b/selfdrive/modeld/modeld.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +import os import sys import time import numpy as np @@ -7,7 +8,7 @@ from typing import Dict, Optional from setproctitle import setproctitle from cereal.messaging import PubMaster, SubMaster from cereal.visionipc import VisionIpcClient, VisionStreamType, VisionBuf -from openpilot.system.hardware import PC +from openpilot.system.hardware import PC, TICI from openpilot.system.swaglog import cloudlog from openpilot.common.params import Params from openpilot.common.filter_simple import FirstOrderFilter @@ -16,8 +17,9 @@ from openpilot.selfdrive.modeld.models.commonmodel_pyx import ModelFrame, CLCont from openpilot.selfdrive.modeld.models.driving_pyx import ( PublishState, create_model_msg, create_pose_msg, update_calibration, FEATURE_LEN, HISTORY_BUFFER_LEN, DESIRE_LEN, TRAFFIC_CONVENTION_LEN, NAV_FEATURE_LEN, NAV_INSTRUCTION_LEN, - OUTPUT_SIZE, NET_OUTPUT_SIZE, MODEL_FREQ, USE_THNEED) + OUTPUT_SIZE, NET_OUTPUT_SIZE, MODEL_FREQ) +USE_THNEED = int(os.getenv('USE_THNEED', str(int(TICI)))) if USE_THNEED: from selfdrive.modeld.runners.thneedmodel_pyx import ThneedModel as ModelRunner else: diff --git a/selfdrive/modeld/models/driving.h b/selfdrive/modeld/models/driving.h index 422d0e197f..39083dd6a9 100644 --- a/selfdrive/modeld/models/driving.h +++ b/selfdrive/modeld/models/driving.h @@ -9,12 +9,6 @@ #include "common/util.h" #include "selfdrive/modeld/models/nav.h" -#ifdef USE_THNEED - constexpr bool CPP_USE_THNEED = true; -#else - constexpr bool CPP_USE_THNEED = false; -#endif - constexpr int FEATURE_LEN = 128; constexpr int HISTORY_BUFFER_LEN = 99; constexpr int DESIRE_LEN = 8; diff --git a/selfdrive/modeld/models/driving.pxd b/selfdrive/modeld/models/driving.pxd index 7ecb2d8f9d..1b815267db 100644 --- a/selfdrive/modeld/models/driving.pxd +++ b/selfdrive/modeld/models/driving.pxd @@ -21,7 +21,6 @@ cdef extern from "selfdrive/modeld/models/driving.h": cdef int OUTPUT_SIZE cdef int NET_OUTPUT_SIZE cdef int MODEL_FREQ - cdef bool CPP_USE_THNEED cdef struct PublishState: pass mat3 update_calibration(float *, bool, bool) diff --git a/selfdrive/modeld/models/driving_pyx.pyx b/selfdrive/modeld/models/driving_pyx.pyx index c9e09eb609..be96df1658 100644 --- a/selfdrive/modeld/models/driving_pyx.pyx +++ b/selfdrive/modeld/models/driving_pyx.pyx @@ -11,7 +11,7 @@ from .commonmodel cimport mat3 from .driving cimport FEATURE_LEN as CPP_FEATURE_LEN, HISTORY_BUFFER_LEN as CPP_HISTORY_BUFFER_LEN, DESIRE_LEN as CPP_DESIRE_LEN, \ TRAFFIC_CONVENTION_LEN as CPP_TRAFFIC_CONVENTION_LEN, DRIVING_STYLE_LEN as CPP_DRIVING_STYLE_LEN, \ NAV_FEATURE_LEN as CPP_NAV_FEATURE_LEN, NAV_INSTRUCTION_LEN as CPP_NAV_INSTRUCTION_LEN, \ - OUTPUT_SIZE as CPP_OUTPUT_SIZE, NET_OUTPUT_SIZE as CPP_NET_OUTPUT_SIZE, MODEL_FREQ as CPP_MODEL_FREQ, CPP_USE_THNEED + OUTPUT_SIZE as CPP_OUTPUT_SIZE, NET_OUTPUT_SIZE as CPP_NET_OUTPUT_SIZE, MODEL_FREQ as CPP_MODEL_FREQ from .driving cimport MessageBuilder, PublishState as cppPublishState from .driving cimport fill_model_msg, fill_pose_msg, update_calibration as cpp_update_calibration @@ -25,7 +25,6 @@ NAV_INSTRUCTION_LEN = CPP_NAV_INSTRUCTION_LEN OUTPUT_SIZE = CPP_OUTPUT_SIZE NET_OUTPUT_SIZE = CPP_NET_OUTPUT_SIZE MODEL_FREQ = CPP_MODEL_FREQ -USE_THNEED = CPP_USE_THNEED cdef class PublishState: cdef cppPublishState state From 82ea2c568871297cbc65c9c85b53493ba190c8fe Mon Sep 17 00:00:00 2001 From: Justin Newberry Date: Tue, 29 Aug 2023 15:05:17 -0700 Subject: [PATCH 08/13] Devcontainer: add recommended extensions (#29703) * add recommended extensions * add cython and jupter --- .devcontainer/devcontainer.json | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 7c4d53960e..2dfe46b4f0 100755 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -19,5 +19,16 @@ "--volume=/tmp/comma_download_cache:/tmp/comma_download_cache", "--volume=/tmp/devcontainer_scons_cache:/tmp/scons_cache", "--shm-size=1G" - ] + ], + "customizations": { + "vscode": { + "extensions": [ + "ms-python.python", + "ms-vscode.cpptools", + "ms-toolsai.jupyter", + "guyskk.language-cython", + "lharri73.dbc" + ] + } + } } \ No newline at end of file From 5058f31908ec10e1dad10fc8f1e9921d6df52efe Mon Sep 17 00:00:00 2001 From: Greg Hogan Date: Tue, 29 Aug 2023 15:24:37 -0700 Subject: [PATCH 09/13] rename GPIO pin with ublox in the name that is not ublox specific (#29702) * rename UBLOX_PWR_EN to GNSS_PWR_EN * add schematic label as comment --- common/gpio.h | 4 ++-- system/hardware/tici/pins.py | 2 +- system/hardware/tici/power_draw_test.py | 6 +++--- system/sensord/pigeond.py | 4 ++-- system/sensord/rawgps/rawgpsd.py | 6 +++--- system/sensord/tests/test_pigeond.py | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/common/gpio.h b/common/gpio.h index b2f67f8ba3..89cdedd66c 100644 --- a/common/gpio.h +++ b/common/gpio.h @@ -5,7 +5,7 @@ #define GPIO_HUB_RST_N 30 #define GPIO_UBLOX_RST_N 32 #define GPIO_UBLOX_SAFEBOOT_N 33 - #define GPIO_UBLOX_PWR_EN 34 + #define GPIO_GNSS_PWR_EN 34 /* SCHEMATIC LABEL: GPIO_UBLOX_PWR_EN */ #define GPIO_STM_RST_N 124 #define GPIO_STM_BOOT0 134 #define GPIO_BMX_ACCEL_INT 21 @@ -17,7 +17,7 @@ #define GPIO_HUB_RST_N 0 #define GPIO_UBLOX_RST_N 0 #define GPIO_UBLOX_SAFEBOOT_N 0 - #define GPIO_UBLOX_PWR_EN 0 + #define GPIO_GNSS_PWR_EN 0 /* SCHEMATIC LABEL: GPIO_UBLOX_PWR_EN */ #define GPIO_STM_RST_N 0 #define GPIO_STM_BOOT0 0 #define GPIO_BMX_ACCEL_INT 0 diff --git a/system/hardware/tici/pins.py b/system/hardware/tici/pins.py index 5ac0158082..4388351e1f 100644 --- a/system/hardware/tici/pins.py +++ b/system/hardware/tici/pins.py @@ -6,7 +6,7 @@ class GPIO: HUB_RST_N = 30 UBLOX_RST_N = 32 UBLOX_SAFEBOOT_N = 33 - UBLOX_PWR_EN = 34 + GNSS_PWR_EN = 34 # SCHEMATIC LABEL: GPIO_UBLOX_PWR_EN STM_RST_N = 124 STM_BOOT0 = 134 diff --git a/system/hardware/tici/power_draw_test.py b/system/hardware/tici/power_draw_test.py index 28113ad073..a0520638b7 100755 --- a/system/hardware/tici/power_draw_test.py +++ b/system/hardware/tici/power_draw_test.py @@ -53,7 +53,7 @@ if __name__ == "__main__": t.set_screen_brightness(0) gpio_init(GPIO.STM_RST_N, True) gpio_init(GPIO.HUB_RST_N, True) - gpio_init(GPIO.UBLOX_PWR_EN, True) + gpio_init(GPIO.GNSS_PWR_EN, True) gpio_init(GPIO.LTE_RST_N, True) gpio_init(GPIO.LTE_PWRKEY, True) gpio_init(GPIO.CAM0_AVDD_EN, True) @@ -65,7 +65,7 @@ if __name__ == "__main__": os.system("sudo su -c 'echo 0 > /sys/kernel/debug/regulator/camera_rear_ldo/enable'") # cam 1v2 off gpio_set(GPIO.CAM0_AVDD_EN, False) # cam 2v8 off gpio_set(GPIO.LTE_RST_N, True) # quectel off - gpio_set(GPIO.UBLOX_PWR_EN, False) # gps off + gpio_set(GPIO.GNSS_PWR_EN, False) # gps off gpio_set(GPIO.STM_RST_N, True) # panda off gpio_set(GPIO.HUB_RST_N, False) # hub off # cameras in reset @@ -92,7 +92,7 @@ if __name__ == "__main__": gpio_set(GPIO.STM_RST_N, False) time.sleep(5) print("panda: ", read_power_avg()) - gpio_set(GPIO.UBLOX_PWR_EN, True) + gpio_set(GPIO.GNSS_PWR_EN, True) time.sleep(5) print("gps: ", read_power_avg()) gpio_set(GPIO.LTE_RST_N, False) diff --git a/system/sensord/pigeond.py b/system/sensord/pigeond.py index a2b6b08de0..fc5c05e64f 100755 --- a/system/sensord/pigeond.py +++ b/system/sensord/pigeond.py @@ -27,11 +27,11 @@ UBLOX_ASSIST_ACK = b"\xb5\x62\x13\x60\x08\x00" def set_power(enabled: bool) -> None: gpio_init(GPIO.UBLOX_SAFEBOOT_N, True) - gpio_init(GPIO.UBLOX_PWR_EN, True) + gpio_init(GPIO.GNSS_PWR_EN, True) gpio_init(GPIO.UBLOX_RST_N, True) gpio_set(GPIO.UBLOX_SAFEBOOT_N, True) - gpio_set(GPIO.UBLOX_PWR_EN, enabled) + gpio_set(GPIO.GNSS_PWR_EN, enabled) gpio_set(GPIO.UBLOX_RST_N, enabled) def add_ubx_checksum(msg: bytes) -> bytes: diff --git a/system/sensord/rawgps/rawgpsd.py b/system/sensord/rawgps/rawgpsd.py index bb228812dc..e710a16920 100755 --- a/system/sensord/rawgps/rawgpsd.py +++ b/system/sensord/rawgps/rawgpsd.py @@ -271,7 +271,7 @@ def main() -> NoReturn: def cleanup(sig, frame): cloudlog.warning("caught sig disabling quectel gps") - gpio_set(GPIO.UBLOX_PWR_EN, False) + gpio_set(GPIO.GNSS_PWR_EN, False) teardown_quectel(diag) cloudlog.warning("quectel cleanup done") @@ -289,8 +289,8 @@ def main() -> NoReturn: want_assistance = not r current_gps_time = utc_to_gpst(GPSTime.from_datetime(datetime.utcnow())) cloudlog.warning("quectel setup done") - gpio_init(GPIO.UBLOX_PWR_EN, True) - gpio_set(GPIO.UBLOX_PWR_EN, True) + gpio_init(GPIO.GNSS_PWR_EN, True) + gpio_set(GPIO.GNSS_PWR_EN, True) pm = messaging.PubMaster(['qcomGnss', 'gpsLocation']) diff --git a/system/sensord/tests/test_pigeond.py b/system/sensord/tests/test_pigeond.py index d7c7567e4f..90cbf06340 100755 --- a/system/sensord/tests/test_pigeond.py +++ b/system/sensord/tests/test_pigeond.py @@ -56,7 +56,7 @@ class TestPigeond(unittest.TestCase): managed_processes['pigeond'].stop() assert gpio_read(GPIO.UBLOX_RST_N) == 0 - assert gpio_read(GPIO.UBLOX_PWR_EN) == 0 + assert gpio_read(GPIO.GNSS_PWR_EN) == 0 if __name__ == "__main__": From 39d2517d3d9de8175aa2c95491b043580e28500f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20R=C4=85czy?= Date: Tue, 29 Aug 2023 16:01:04 -0700 Subject: [PATCH 10/13] macOS: generate .pyenvrc during setup (#29698) * Create .pyenvrc if it does not exist * Replace source zshrc with pyenvrc * Remove unnecessary variables if pyenv wasn't installed * Add check fo PYENV_SHELL * source instead of eval * printf instead of echo * leave previous pyenvrc path to source * Add newline * Change shebang * Dont source the file after setup * eval virtualenv-init too * modify comment * Just unset broken function on macos --- tools/install_python_dependencies.sh | 20 +++++++++++++++----- tools/mac_setup.sh | 2 +- tools/ubuntu_setup.sh | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/tools/install_python_dependencies.sh b/tools/install_python_dependencies.sh index 79c36d57d9..07bb8ac9a4 100755 --- a/tools/install_python_dependencies.sh +++ b/tools/install_python_dependencies.sh @@ -13,20 +13,30 @@ fi if ! command -v "pyenv" > /dev/null 2>&1; then echo "pyenv install ..." curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash + PYENV_PATH_SETUP="export PATH=\$HOME/.pyenv/bin:\$HOME/.pyenv/shims:\$PATH" +fi +if [ -z "$PYENV_SHELL" ] || [ -n "$PYENV_PATH_SETUP" ]; then + echo "pyenvrc setup ..." cat < "${HOME}/.pyenvrc" if [ -z "\$PYENV_ROOT" ]; then - export PATH=\$HOME/.pyenv/bin:\$HOME/.pyenv/shims:\$PATH + $PYENV_PATH_SETUP export PYENV_ROOT="\$HOME/.pyenv" - eval "\$(pyenv init --path)" eval "\$(pyenv init -)" eval "\$(pyenv virtualenv-init -)" fi EOF - echo -e "\nsource ~/.pyenvrc" >> $RC_FILE - # activate pyenv now - source $RC_FILE + SOURCE_PYENVRC="source ~/.pyenvrc" + if ! grep "^$SOURCE_PYENVRC$" $RC_FILE > /dev/null; then + printf "\n$SOURCE_PYENVRC\n" >> $RC_FILE + fi + + eval "$SOURCE_PYENVRC" + # $(pyenv init -) produces a function which is broken on bash 3.2 which ships on macOS + if [ $(uname) == "Darwin" ]; then + unset -f pyenv + fi fi export MAKEFLAGS="-j$(nproc)" diff --git a/tools/mac_setup.sh b/tools/mac_setup.sh index 3892efd6bb..c767131f51 100755 --- a/tools/mac_setup.sh +++ b/tools/mac_setup.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -e diff --git a/tools/ubuntu_setup.sh b/tools/ubuntu_setup.sh index 6b9cf7eff6..1bdeb50e0d 100755 --- a/tools/ubuntu_setup.sh +++ b/tools/ubuntu_setup.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -e From 7a4eaeaf9f5facdf897fe2404d9bd26ef03a31ec Mon Sep 17 00:00:00 2001 From: Justin Newberry Date: Tue, 29 Aug 2023 17:02:38 -0700 Subject: [PATCH 11/13] bump submodules (#29705) * bump submodules * bump rednose * fix dockerfiles --- body | 2 +- docs/docker/Dockerfile | 2 +- laika_repo | 2 +- panda | 2 +- rednose_repo | 2 +- tools/sim/Dockerfile.sim | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/body b/body index 396fa7b923..6ff44357a3 160000 --- a/body +++ b/body @@ -1 +1 @@ -Subproject commit 396fa7b923099640d6843f338950ed41300793ec +Subproject commit 6ff44357a3e416d29044b1d085a3e9223db9691a diff --git a/docs/docker/Dockerfile b/docs/docker/Dockerfile index 240f828912..1bae2be24a 100644 --- a/docs/docker/Dockerfile +++ b/docs/docker/Dockerfile @@ -16,7 +16,7 @@ COPY ./body ${OPENPILOT_PATH}/body COPY ./third_party ${OPENPILOT_PATH}/third_party COPY ./site_scons ${OPENPILOT_PATH}/site_scons COPY ./laika_repo ${OPENPILOT_PATH}/laika_repo -RUN ln -s ${OPENPILOT_PATH}/laika_repo ${OPENPILOT_PATH}/laika +RUN ln -s ${OPENPILOT_PATH}/laika_repo/laika/ ${OPENPILOT_PATH}/laika COPY ./rednose ${OPENPILOT_PATH}/rednose COPY ./rednose_repo ${OPENPILOT_PATH}/rednose_repo COPY ./tools ${OPENPILOT_PATH}/tools diff --git a/laika_repo b/laika_repo index 6d547801a5..c9baa95ca9 160000 --- a/laika_repo +++ b/laika_repo @@ -1 +1 @@ -Subproject commit 6d547801a5790431b42396a1d48226ff730ba74b +Subproject commit c9baa95ca9b58222370fcccb24bce1d3722c8e73 diff --git a/panda b/panda index ca9d8675b9..91d457cbb1 160000 --- a/panda +++ b/panda @@ -1 +1 @@ -Subproject commit ca9d8675b90e637051786057ad80fe7e534b2ae4 +Subproject commit 91d457cbb13836aa12084b56c732ea27fcf14eef diff --git a/rednose_repo b/rednose_repo index 22f02dd650..e32658ed91 160000 --- a/rednose_repo +++ b/rednose_repo @@ -1 +1 @@ -Subproject commit 22f02dd650361e091f09f1ae94c5c96a9419c2d4 +Subproject commit e32658ed9164d6e8dde882c05c5ece9707acde82 diff --git a/tools/sim/Dockerfile.sim b/tools/sim/Dockerfile.sim index 800e9dac74..9fd8a56101 100644 --- a/tools/sim/Dockerfile.sim +++ b/tools/sim/Dockerfile.sim @@ -23,7 +23,7 @@ COPY ./third_party ${OPENPILOT_PATH}/third_party COPY ./site_scons ${OPENPILOT_PATH}/site_scons COPY ./rednose ${OPENPILOT_PATH}/rednose COPY ./laika_repo ${OPENPILOT_PATH}/laika_repo -RUN ln -s ${OPENPILOT_PATH}/laika_repo ${OPENPILOT_PATH}/laika +RUN ln -s ${OPENPILOT_PATH}/laika_repo/laika/ ${OPENPILOT_PATH}/laika COPY ./common ${OPENPILOT_PATH}/common COPY ./opendbc ${OPENPILOT_PATH}/opendbc COPY ./cereal ${OPENPILOT_PATH}/cereal From d3befb2e04dfd12752fc98599800e911ef6a15d4 Mon Sep 17 00:00:00 2001 From: Justin Newberry Date: Tue, 29 Aug 2023 17:04:42 -0700 Subject: [PATCH 12/13] CI: prepare for pytest by adding marker and avoiding duplicated tests (#29682) prepare for pytest --- pyproject.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index d860dbb6bf..6555c7d5c3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,8 +1,11 @@ [tool.pytest.ini_options] minversion = "6.0" -addopts = "--ignore=opendbc/ --ignore=panda/ --ignore=rednose_repo/ --ignore=tinygrad_repo/ --ignore=laika_repo/ -Werror --strict-config --strict-markers" +addopts = "--ignore=openpilot/ --ignore=opendbc/ --ignore=panda/ --ignore=rednose_repo/ --ignore=tinygrad_repo/ --ignore=laika_repo/ -Werror --strict-config --strict-markers" python_files = "test_*.py" #timeout = "30" # you get this long by default +markers = [ + "parallel: mark tests as parallelizable (tests with no global state, so can be run in parallel)" +] [tool.mypy] python_version = "3.11" From 6333ff94e76376e315ba08b0691b5dea5ec03d3c Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Tue, 29 Aug 2023 18:34:30 -0700 Subject: [PATCH 13/13] common/i2c: make thread safe (#29706) Co-authored-by: Comma Device --- common/i2c.cc | 8 +++++++- common/i2c.h | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/common/i2c.cc b/common/i2c.cc index 9508179c6e..3d6c79efc5 100644 --- a/common/i2c.cc +++ b/common/i2c.cc @@ -31,10 +31,14 @@ I2CBus::I2CBus(uint8_t bus_id) { } I2CBus::~I2CBus() { - if (i2c_fd >= 0) { close(i2c_fd); } + if (i2c_fd >= 0) { + close(i2c_fd); + } } int I2CBus::read_register(uint8_t device_address, uint register_address, uint8_t *buffer, uint8_t len) { + std::lock_guard lk(m); + int ret = 0; ret = HANDLE_EINTR(ioctl(i2c_fd, I2C_SLAVE, device_address)); @@ -48,6 +52,8 @@ fail: } int I2CBus::set_register(uint8_t device_address, uint register_address, uint8_t data) { + std::lock_guard lk(m); + int ret = 0; ret = HANDLE_EINTR(ioctl(i2c_fd, I2C_SLAVE, device_address)); diff --git a/common/i2c.h b/common/i2c.h index 0669116bb8..ca0d4635b8 100644 --- a/common/i2c.h +++ b/common/i2c.h @@ -1,12 +1,14 @@ #pragma once #include +#include #include class I2CBus { private: int i2c_fd; + std::mutex m; public: I2CBus(uint8_t bus_id);