From 6823f61579d5877e809d5ac513488263d601d1b8 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Tue, 7 Jul 2026 13:47:54 -0700 Subject: [PATCH] real pkg --- .gitignore | 3 ++- Dockerfile | 6 ++--- MANIFEST.in | 4 ++++ README.md | 4 ++-- SConscript | 14 +++++++----- __init__.py | 13 ----------- board/__init__.py | 0 board/body/can.h | 2 +- board/body/flash.py | 4 ++-- board/debug/dfu_util_h7.sh | 2 +- board/drivers/drivers.h | 2 +- board/flash.py | 2 +- board/jungle/flash.py | 2 +- board/jungle/main.c | 4 ++-- board/jungle/recover.py | 2 +- board/main.c | 2 +- board/recover.py | 2 +- {python => panda}/__init__.py | 13 +++++++---- {python => panda}/base.py | 0 {board => panda}/body/__init__.py | 0 {python => panda}/constants.py | 2 +- {python => panda}/dfu.py | 0 {board => panda}/health.h | 0 {board => panda}/jungle/__init__.py | 3 +-- {board => panda}/jungle/jungle_health.h | 0 {python => panda}/serial.py | 0 {python => panda}/socketpanda.py | 0 {python => panda}/spi.py | 0 {python => panda}/usb.py | 0 {python => panda}/utils.py | 0 pyproject.toml | 29 ++++++++++++------------- scripts/benchmark.py | 5 ++++- scripts/test_canfd.py | 5 ++++- setup.py | 19 ++++++++++++++++ tests/hitl/3_usb.py | 2 +- tests/hitl/4_can_loopback.py | 2 +- tests/hitl/5_spi.py | 8 +++---- tests/hitl/conftest.py | 2 +- tests/hitl/reset_jungles.py | 6 ++++- tests/libpanda/panda.c | 2 +- tests/misra/test_mutation.py | 2 +- tests/usbprotocol/test_comms.py | 2 +- 42 files changed, 98 insertions(+), 72 deletions(-) create mode 100644 MANIFEST.in delete mode 100644 __init__.py delete mode 100644 board/__init__.py rename {python => panda}/__init__.py (98%) rename {python => panda}/base.py (100%) rename {board => panda}/body/__init__.py (100%) rename {python => panda}/constants.py (94%) rename {python => panda}/dfu.py (100%) rename {board => panda}/health.h (100%) rename {board => panda}/jungle/__init__.py (97%) rename {board => panda}/jungle/jungle_health.h (100%) rename {python => panda}/serial.py (100%) rename {python => panda}/socketpanda.py (100%) rename {python => panda}/spi.py (100%) rename {python => panda}/usb.py (100%) rename {python => panda}/utils.py (100%) create mode 100644 setup.py diff --git a/.gitignore b/.gitignore index 67edc8b6904..eb218e9a225 100644 --- a/.gitignore +++ b/.gitignore @@ -13,8 +13,9 @@ a.out .#* dist/ build/ -pandacan.egg-info/ +*.egg-info/ obj/ +panda/fw/ examples/output.csv .DS_Store .vscode* diff --git a/Dockerfile b/Dockerfile index a41d0c6f002..c6f8ccc5972 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,9 +7,9 @@ ENV PATH="$WORKDIR/.venv/bin:$PATH" WORKDIR $WORKDIR # deps install -COPY pyproject.toml __init__.py setup.sh $WORKDIR -RUN mkdir -p $WORKDIR/python/ $WORKDIR/board/body/ $WORKDIR/board/jungle/ && \ - touch $WORKDIR/__init__.py $WORKDIR/board/__init__.py $WORKDIR/board/body/__init__.py $WORKDIR/board/jungle/__init__.py +COPY pyproject.toml setup.py setup.sh $WORKDIR +RUN mkdir -p $WORKDIR/panda/body/ $WORKDIR/panda/jungle/ && \ + touch $WORKDIR/panda/__init__.py $WORKDIR/panda/body/__init__.py $WORKDIR/panda/jungle/__init__.py RUN apt-get update && apt-get install -y --no-install-recommends sudo && DEBIAN_FRONTEND=noninteractive $WORKDIR/setup.sh # second pass for the opendbc moving tag diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 00000000000..096889ebae3 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,4 @@ +include SConstruct SConscript +graft board +prune board/obj +global-exclude __pycache__ *.pyc *.o *.os *.d *.elf *.bin *.so diff --git a/README.md b/README.md index 7e28f1142a6..5187eed9861 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ panda speaks CAN and CAN FD, and it runs on the [STM32H725](https://www.st.com/r ``` . ├── board # Code that runs on the STM32 -├── python # Python userspace library for interfacing with the panda +├── panda # Python userspace library for interfacing with the panda ├── tests # Tests for panda ├── scripts # Miscellaneous used for panda development and debugging ├── examples # Example scripts for using a panda in a car @@ -50,7 +50,7 @@ cd panda ./test.sh ``` -See [the Panda class](https://github.com/commaai/panda/blob/master/python/__init__.py) for how to interact with the panda. +See [the Panda class](https://github.com/commaai/panda/blob/master/panda/__init__.py) for how to interact with the panda. For example, to receive CAN messages: ``` python diff --git a/SConscript b/SConscript index de770920385..706d36e8ff9 100644 --- a/SConscript +++ b/SConscript @@ -27,7 +27,7 @@ def objcopy(source, target, env, for_signature): def get_version(builder, build_type): try: git = subprocess.check_output(["git", "rev-parse", "--short=8", "HEAD"], encoding='utf8').strip() - except subprocess.CalledProcessError: + except (subprocess.CalledProcessError, OSError): git = "unknown" return f"{builder}-{git}-{build_type}" @@ -110,7 +110,7 @@ def build_project(project_name, project, main, extra_flags): "./board/crypto/sha.c", "./board/bootstub.c", ]) - bs_env.Objcopy(f"./board/obj/bootstub.{project_name}.bin", bs_elf) + bs_env.Objcopy(f"./panda/fw/bootstub.{project_name}.bin", bs_elf) # Build + sign main (aka app) main_elf = env.Program(f"{project_dir}/main.elf", [ @@ -119,7 +119,7 @@ def build_project(project_name, project, main, extra_flags): ], LINKFLAGS=[f"-Wl,--section-start,.isr_vector={project['APP_START_ADDRESS']}"] + flags) main_bin = env.Objcopy(f"{project_dir}/main.bin", main_elf) sign_py = File(f"./board/crypto/sign.py").srcnode().relpath - env.Command(f"./board/obj/{project_name}.bin.signed", main_bin, f"SETLEN=1 {sign_py} $SOURCE $TARGET {cert_fn}") + env.Command(f"./panda/fw/{project_name}.bin.signed", main_bin, f"SETLEN=1 {sign_py} $SOURCE $TARGET {cert_fn}") @@ -138,6 +138,7 @@ base_project_h7 = { } # Common autogenerated includes +os.makedirs("board/obj", exist_ok=True) with open("board/obj/gitversion.h", "w") as f: version = get_version(BUILDER, BUILD_TYPE) f.write(f'extern const uint8_t gitversion[{len(version)+1}];\n') @@ -156,7 +157,7 @@ def version_hash(path): with open(path, "rb") as f: # Normalize line endings on Windows return int.from_bytes(hashlib.sha256(f.read().replace(b'\r', b'')).digest()[:4], 'little') -hh, ch, jh = version_hash("board/health.h"), version_hash(os.path.join(opendbc.INCLUDE_PATH, "opendbc/safety/can.h")), version_hash("board/jungle/jungle_health.h") +hh, ch, jh = version_hash("panda/health.h"), version_hash(os.path.join(opendbc.INCLUDE_PATH, "opendbc/safety/can.h")), version_hash("panda/jungle/jungle_health.h") common_flags += [f"-DHEALTH_PACKET_VERSION=0x{hh:08X}U", f"-DCAN_PACKET_VERSION_HASH=0x{ch:08X}U", f"-DJUNGLE_HEALTH_PACKET_VERSION=0x{jh:08X}U"] @@ -172,5 +173,6 @@ build_project("panda_jungle_h7", base_project_h7, "./board/jungle/main.c", flags # body fw build_project("body_h7", base_project_h7, "./board/body/main.c", ["-DPANDA_BODY"]) -# test files -SConscript('tests/libpanda/SConscript') +# test files (not present in the package sdist) +if os.path.exists(File('tests/libpanda/SConscript').srcnode().abspath): + SConscript('tests/libpanda/SConscript') diff --git a/__init__.py b/__init__.py deleted file mode 100644 index 99a94c68d49..00000000000 --- a/__init__.py +++ /dev/null @@ -1,13 +0,0 @@ -from .python.constants import McuType, BASEDIR, FW_PATH, USBPACKET_MAX_SIZE # noqa: F401 -from .python.spi import PandaSpiException, PandaProtocolMismatch, STBootloaderSPIHandle # noqa: F401 -from .python.serial import PandaSerial # noqa: F401 -from .python.utils import logger # noqa: F401 -from .python import (Panda, PandaDFU, # noqa: F401 - pack_can_buffer, unpack_can_buffer, calculate_checksum, - DLC_TO_LEN, LEN_TO_DLC, CANPACKET_HEAD_SIZE) - -# panda jungle -from .board.jungle import PandaJungle, PandaJungleDFU # noqa: F401 - -# panda body -from .board.body import PandaBody # noqa: F401 diff --git a/board/__init__.py b/board/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/board/body/can.h b/board/body/can.h index 50dea369ab4..8c4c38488be 100644 --- a/board/body/can.h +++ b/board/body/can.h @@ -4,7 +4,7 @@ #include #include "board/can.h" -#include "board/health.h" +#include "panda/health.h" #include "board/body/boards/board_declarations.h" #include "board/drivers/drivers.h" #include "opendbc/safety/declarations.h" diff --git a/board/body/flash.py b/board/body/flash.py index 8f820ce9711..f425aed135a 100644 --- a/board/body/flash.py +++ b/board/body/flash.py @@ -8,12 +8,12 @@ BODY_DIR = os.path.dirname(os.path.realpath(__file__)) BOARD_DIR = os.path.abspath(os.path.join(BODY_DIR, "..")) REPO_ROOT = os.path.abspath(os.path.join(BOARD_DIR, "..")) -DEFAULT_FIRMWARE = os.path.join(BOARD_DIR, "obj", "body_h7.bin.signed") +DEFAULT_FIRMWARE = os.path.join(REPO_ROOT, "panda", "fw", "body_h7.bin.signed") def build_body() -> None: subprocess.check_call( - f"scons -C {REPO_ROOT} -j$(nproc) board/obj/body_h7.bin.signed", + f"scons -C {REPO_ROOT} -j$(nproc) panda/fw/body_h7.bin.signed", shell=True, ) diff --git a/board/debug/dfu_util_h7.sh b/board/debug/dfu_util_h7.sh index c39a24ec7b7..4f09da0341e 100755 --- a/board/debug/dfu_util_h7.sh +++ b/board/debug/dfu_util_h7.sh @@ -5,7 +5,7 @@ DFU_UTIL="dfu-util" scons -u -j$(nproc) -PYTHONPATH=.. python3 -c "from python import Panda; Panda().reset(enter_bootstub=True); Panda().reset(enter_bootloader=True)" || true +PYTHONPATH=.. python3 -c "from panda import Panda; Panda().reset(enter_bootstub=True); Panda().reset(enter_bootloader=True)" || true sleep 1 $DFU_UTIL -d 0483:df11 -a 0 -s 0x08020000 -D obj/panda_h7.bin.signed $DFU_UTIL -d 0483:df11 -a 0 -s 0x08000000:leave -D obj/bootstub.panda_h7.bin diff --git a/board/drivers/drivers.h b/board/drivers/drivers.h index 900409fd0ec..19f03a4d192 100644 --- a/board/drivers/drivers.h +++ b/board/drivers/drivers.h @@ -1,7 +1,7 @@ #pragma once #include "board/can.h" -#include "board/health.h" +#include "panda/health.h" #include "board/crc.h" #ifdef STM32H7 #include "board/stm32h7/lladc_declarations.h" diff --git a/board/flash.py b/board/flash.py index 3943814625d..64ef40e718e 100755 --- a/board/flash.py +++ b/board/flash.py @@ -12,7 +12,7 @@ parser.add_argument("--all", action="store_true", help="Recover all Panda devices") args = parser.parse_args() - subprocess.check_call(f"scons -C {board_path}/.. -j$(nproc) {board_path}", shell=True) + subprocess.check_call(f"scons -C {board_path}/.. -j$(nproc) panda/fw", shell=True) if args.all: serials = Panda.list() diff --git a/board/jungle/flash.py b/board/jungle/flash.py index 6f60f70b12b..87f2e205c14 100755 --- a/board/jungle/flash.py +++ b/board/jungle/flash.py @@ -12,7 +12,7 @@ parser.add_argument("--all", action="store_true", help="Recover all panda jungle devices") args = parser.parse_args() - subprocess.check_call(f"scons -C {board_path}/.. -u -j$(nproc) .", shell=True) + subprocess.check_call(f"scons -C {board_path}/../.. -j$(nproc) panda/fw", shell=True) if args.all: serials = PandaJungle.list() diff --git a/board/jungle/main.c b/board/jungle/main.c index 4ef9950666d..f2eac86cc53 100644 --- a/board/jungle/main.c +++ b/board/jungle/main.c @@ -10,8 +10,8 @@ #include "board/early_init.h" #include "board/provision.h" -#include "board/health.h" -#include "board/jungle/jungle_health.h" +#include "panda/health.h" +#include "panda/jungle/jungle_health.h" #include "board/drivers/can_common.h" diff --git a/board/jungle/recover.py b/board/jungle/recover.py index 228f0c56187..e4b4ddd540d 100755 --- a/board/jungle/recover.py +++ b/board/jungle/recover.py @@ -13,7 +13,7 @@ parser.add_argument("--all", action="store_true", help="Recover all panda jungle devices") args = parser.parse_args() - subprocess.check_call(f"scons -C {board_path}/.. -u -j$(nproc) .", shell=True) + subprocess.check_call(f"scons -C {board_path}/../.. -j$(nproc) panda/fw", shell=True) serials = PandaJungle.list() if args.all else [None] for s in serials: diff --git a/board/main.c b/board/main.c index ba60de57fd6..541d9279703 100644 --- a/board/main.c +++ b/board/main.c @@ -12,7 +12,7 @@ #include "opendbc/safety/safety.h" -#include "board/health.h" +#include "panda/health.h" #include "board/drivers/can_common.h" diff --git a/board/recover.py b/board/recover.py index 6268a07d967..a39d45651ba 100755 --- a/board/recover.py +++ b/board/recover.py @@ -8,7 +8,7 @@ board_path = os.path.dirname(os.path.realpath(__file__)) if __name__ == "__main__": - subprocess.check_call(f"scons -C {board_path}/.. -j$(nproc) {board_path}", shell=True) + subprocess.check_call(f"scons -C {board_path}/.. -j$(nproc) panda/fw", shell=True) for s in Panda.list(): with Panda(serial=s) as p: diff --git a/python/__init__.py b/panda/__init__.py similarity index 98% rename from python/__init__.py rename to panda/__init__.py index 4c954b23950..60c0f852964 100644 --- a/python/__init__.py +++ b/panda/__init__.py @@ -15,9 +15,9 @@ from opendbc.car.structs import CarParams from .base import BaseHandle -from .constants import BASEDIR, FW_PATH, McuType, compute_version_hash +from .constants import BASEDIR, FW_PATH, McuType, USBPACKET_MAX_SIZE, compute_version_hash # noqa: F401 from .dfu import PandaDFU -from .spi import PandaSpiHandle, PandaSpiException, PandaProtocolMismatch +from .spi import PandaSpiHandle, PandaSpiException, PandaProtocolMismatch, STBootloaderSPIHandle # noqa: F401 from .usb import PandaUsbHandle from .utils import logger @@ -137,8 +137,8 @@ class Panda: HW_TYPE_BODY = b'\xb1' CAN_PACKET_VERSION = compute_version_hash(os.path.join(opendbc.INCLUDE_PATH, "opendbc/safety/can.h")) - HEALTH_PACKET_VERSION = compute_version_hash(os.path.join(BASEDIR, "board/health.h")) - HEALTH_STRUCT = _parse_c_struct(os.path.join(BASEDIR, "board/health.h"), "health_t") + HEALTH_PACKET_VERSION = compute_version_hash(os.path.join(os.path.dirname(__file__), "health.h")) + HEALTH_STRUCT = _parse_c_struct(os.path.join(os.path.dirname(__file__), "health.h"), "health_t") CAN_HEALTH_STRUCT = struct.Struct(" bool: r = self._handle.controlRead(Panda.REQUEST_IN, 0xc6, 0, 0, 1) return r[0] == 1 + + +from .serial import PandaSerial # noqa: F401 +from .jungle import PandaJungle, PandaJungleDFU # noqa: F401 +from .body import PandaBody # noqa: F401 diff --git a/python/base.py b/panda/base.py similarity index 100% rename from python/base.py rename to panda/base.py diff --git a/board/body/__init__.py b/panda/body/__init__.py similarity index 100% rename from board/body/__init__.py rename to panda/body/__init__.py diff --git a/python/constants.py b/panda/constants.py similarity index 94% rename from python/constants.py rename to panda/constants.py index d69f205050b..48f705d30b3 100644 --- a/python/constants.py +++ b/panda/constants.py @@ -4,7 +4,7 @@ from typing import NamedTuple BASEDIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../") -FW_PATH = os.path.join(BASEDIR, "board/obj/") +FW_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), "fw/") def compute_version_hash(filepath): with open(filepath, "rb") as f: diff --git a/python/dfu.py b/panda/dfu.py similarity index 100% rename from python/dfu.py rename to panda/dfu.py diff --git a/board/health.h b/panda/health.h similarity index 100% rename from board/health.h rename to panda/health.h diff --git a/board/jungle/__init__.py b/panda/jungle/__init__.py similarity index 97% rename from board/jungle/__init__.py rename to panda/jungle/__init__.py index 3fe8afd7f2f..fda5e79c24f 100644 --- a/board/jungle/__init__.py +++ b/panda/jungle/__init__.py @@ -4,10 +4,9 @@ from functools import wraps from panda import Panda, PandaDFU -from panda.python.constants import McuType, compute_version_hash +from panda.constants import FW_PATH, McuType, compute_version_hash BASEDIR = os.path.dirname(os.path.realpath(__file__)) -FW_PATH = os.path.join(BASEDIR, "../obj/") def ensure_jungle_health_packet_version(fn): diff --git a/board/jungle/jungle_health.h b/panda/jungle/jungle_health.h similarity index 100% rename from board/jungle/jungle_health.h rename to panda/jungle/jungle_health.h diff --git a/python/serial.py b/panda/serial.py similarity index 100% rename from python/serial.py rename to panda/serial.py diff --git a/python/socketpanda.py b/panda/socketpanda.py similarity index 100% rename from python/socketpanda.py rename to panda/socketpanda.py diff --git a/python/spi.py b/panda/spi.py similarity index 100% rename from python/spi.py rename to panda/spi.py diff --git a/python/usb.py b/panda/usb.py similarity index 100% rename from python/usb.py rename to panda/usb.py diff --git a/python/utils.py b/panda/utils.py similarity index 100% rename from python/utils.py rename to panda/utils.py diff --git a/pyproject.toml b/pyproject.toml index e30b39954d2..8b547559efc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [project] -name = "pandacan" +name = "panda" version = "0.0.10" description = "Code powering the comma.ai panda" readme = "README.md" @@ -35,24 +35,22 @@ dev = [ ] [build-system] -requires = ["setuptools>=61", "wheel"] +requires = [ + "setuptools>=64", + # setup.py builds the firmware into the wheel (not supported on Windows) + "scons; platform_system != 'Windows'", + "pycryptodome >= 3.9.8; platform_system != 'Windows'", + "opendbc @ git+https://github.com/commaai/opendbc.git@master ; platform_system != 'Windows'", + "gcc-arm-none-eabi @ git+https://github.com/commaai/dependencies.git@release-gcc-arm-none-eabi#subdirectory=gcc-arm-none-eabi ; platform_system != 'Windows'", +] build-backend = "setuptools.build_meta" -[tool.setuptools] -packages = [ - "panda", - "panda.python", - "panda.board", - "panda.board.body", - "panda.board.jungle", -] +[tool.setuptools.packages.find] +include = ["panda", "panda.*"] [tool.setuptools.package-data] -"panda.board" = ["health.h"] -"panda.board.jungle" = ["jungle_health.h"] - -[tool.setuptools.package-dir] -panda = "." +panda = ["health.h", "fw/*"] +"panda.jungle" = ["jungle_health.h"] # https://beta.ruff.rs/docs/configuration/#using-pyprojecttoml [tool.ruff] @@ -69,6 +67,7 @@ flake8-implicit-str-concat.allow-multiline=false [tool.pytest.ini_options] addopts = "-Werror --strict-config --strict-markers --maxprocesses=8 -nauto --durations=10 --ignore-glob='*.sh' --ignore=tests/som --ignore=tests/hitl" +pythonpath = ["."] python_files = "test_*.py" testpaths = [ "tests/" diff --git a/scripts/benchmark.py b/scripts/benchmark.py index 6063380479c..9956b35b726 100755 --- a/scripts/benchmark.py +++ b/scripts/benchmark.py @@ -6,8 +6,11 @@ import cProfile from contextlib import contextmanager +import sys +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) + from panda import Panda, PandaDFU -from panda.tests.hitl.helpers import get_random_can_messages +from tests.hitl.helpers import get_random_can_messages PROFILE = "PROFILE" in os.environ diff --git a/scripts/test_canfd.py b/scripts/test_canfd.py index ee61e8c30e4..5f2aa6a6160 100755 --- a/scripts/test_canfd.py +++ b/scripts/test_canfd.py @@ -1,12 +1,15 @@ #!/usr/bin/env python3 import os +import sys import time import random + +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) from collections import defaultdict from opendbc.car.structs import CarParams from panda import Panda, calculate_checksum, DLC_TO_LEN from panda import PandaJungle -from panda.tests.hitl.helpers import time_many_sends +from tests.hitl.helpers import time_many_sends H7_HW_TYPES = [Panda.HW_TYPE_RED_PANDA, Panda.HW_TYPE_RED_PANDA_V2] JUNGLE_SERIAL = os.getenv("JUNGLE") diff --git a/setup.py b/setup.py new file mode 100644 index 00000000000..74b5d395066 --- /dev/null +++ b/setup.py @@ -0,0 +1,19 @@ +import os +import platform +import subprocess + +from setuptools import setup +from setuptools.command.build_py import build_py + + +class BuildPyWithFirmware(build_py): + def run(self): + # Build the firmware into panda/fw/ so it ships with the package. + # Skipped for editable installs, where scons is run directly, + # and on Windows, where the toolchain isn't available. + if not getattr(self, "editable_mode", False) and platform.system() != "Windows": + subprocess.check_call(["scons", f"-j{os.cpu_count()}", "panda/fw"], cwd=os.path.dirname(os.path.abspath(__file__))) + super().run() + + +setup(cmdclass={"build_py": BuildPyWithFirmware}) diff --git a/tests/hitl/3_usb.py b/tests/hitl/3_usb.py index f3ae43e2c1a..e1d31a0e94c 100644 --- a/tests/hitl/3_usb.py +++ b/tests/hitl/3_usb.py @@ -4,7 +4,7 @@ from opendbc.car.structs import CarParams from panda import Panda -from panda.tests.hitl.helpers import time_many_sends +from tests.hitl.helpers import time_many_sends pytestmark = [ pytest.mark.test_panda_types((Panda.HW_TYPE_RED_PANDA, )) diff --git a/tests/hitl/4_can_loopback.py b/tests/hitl/4_can_loopback.py index 63fce9d9681..0d2328af26f 100644 --- a/tests/hitl/4_can_loopback.py +++ b/tests/hitl/4_can_loopback.py @@ -7,7 +7,7 @@ from collections import defaultdict from opendbc.car.structs import CarParams -from panda.tests.hitl.helpers import time_many_sends, get_random_can_messages, clear_can_buffers +from tests.hitl.helpers import time_many_sends, get_random_can_messages, clear_can_buffers @flaky(max_runs=3, min_passes=1) @pytest.mark.timeout(35) diff --git a/tests/hitl/5_spi.py b/tests/hitl/5_spi.py index 106a1c7d4b2..a754e351fca 100644 --- a/tests/hitl/5_spi.py +++ b/tests/hitl/5_spi.py @@ -4,7 +4,7 @@ from unittest.mock import patch from panda import Panda -from panda.python.spi import PandaProtocolMismatch, PandaSpiNackResponse +from panda.spi import PandaProtocolMismatch, PandaSpiNackResponse class TestSpi: @@ -18,7 +18,7 @@ def _ping(self, mocker, panda): def test_protocol_version_check(self, p): for bootstub in (False, True): p.reset(enter_bootstub=bootstub) - with patch('panda.python.spi.PandaSpiHandle.PROTOCOL_VERSION', return_value="abc"): + with patch('panda.spi.PandaSpiHandle.PROTOCOL_VERSION', return_value="abc"): # list should still work with wrong version assert p._serial in Panda.list() @@ -54,14 +54,14 @@ def test_all_comm_types(self, mocker, p): assert spy.call_count == 2*4 def test_bad_header(self, mocker, p): - with patch('panda.python.spi.SYNC', return_value=0): + with patch('panda.spi.SYNC', return_value=0): with pytest.raises(PandaSpiNackResponse): p._handle.controlRead(Panda.REQUEST_IN, 0xd2, 0, 0, p.HEALTH_STRUCT.size, timeout=50) self._ping(mocker, p) def test_bad_checksum(self, mocker, p): cnt = p.health()['spi_error_count'] - with patch('panda.python.spi.PandaSpiHandle._calc_checksum', return_value=0): + with patch('panda.spi.PandaSpiHandle._calc_checksum', return_value=0): with pytest.raises(PandaSpiNackResponse): p._handle.controlRead(Panda.REQUEST_IN, 0xd2, 0, 0, p.HEALTH_STRUCT.size, timeout=50) self._ping(mocker, p) diff --git a/tests/hitl/conftest.py b/tests/hitl/conftest.py index d6881b5436a..3e37bc5ee14 100644 --- a/tests/hitl/conftest.py +++ b/tests/hitl/conftest.py @@ -2,7 +2,7 @@ import pytest from panda import Panda, PandaDFU, PandaJungle -from panda.tests.hitl.helpers import clear_can_buffers +from tests.hitl.helpers import clear_can_buffers SPEED_NORMAL = 500 BUS_SPEEDS = [(0, SPEED_NORMAL), (1, SPEED_NORMAL), (2, SPEED_NORMAL)] diff --git a/tests/hitl/reset_jungles.py b/tests/hitl/reset_jungles.py index 97702d806a6..2cccc050cc2 100755 --- a/tests/hitl/reset_jungles.py +++ b/tests/hitl/reset_jungles.py @@ -1,8 +1,12 @@ #!/usr/bin/env python3 import concurrent.futures +import os +import sys + +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../..")) from panda import PandaJungle, PandaJungleDFU, McuType -from panda.tests.libs.resetter import Resetter +from tests.libs.resetter import Resetter SERIALS = { '180019001451313236343430', # jungle v2 diff --git a/tests/libpanda/panda.c b/tests/libpanda/panda.c index 5c82a7b7d4e..4041c7a0575 100644 --- a/tests/libpanda/panda.c +++ b/tests/libpanda/panda.c @@ -11,7 +11,7 @@ void refresh_can_tx_slots_available(void); void can_tx_comms_resume_usb(void) { }; void can_tx_comms_resume_spi(void) { }; -#include "health.h" +#include "panda/health.h" #include "sys/faults.h" #include "libc.h" #include "boards/board_declarations.h" diff --git a/tests/misra/test_mutation.py b/tests/misra/test_mutation.py index 1f25f5ff1a5..d264cf8c874 100755 --- a/tests/misra/test_mutation.py +++ b/tests/misra/test_mutation.py @@ -53,7 +53,7 @@ r"$a #define TEST 1\n#undef TEST\n", ] -all_files = glob.glob('board/**', root_dir=ROOT, recursive=True) +all_files = glob.glob('board/**', root_dir=ROOT, recursive=True) + ['panda/health.h'] files = sorted(f for f in all_files if f.endswith(('.c', '.h')) and not f.startswith(IGNORED_PATHS)) assert len(files) > 50, all(d in files for d in ('board/main.c', 'board/stm32h7/llfdcan.h')) diff --git a/tests/usbprotocol/test_comms.py b/tests/usbprotocol/test_comms.py index 86cd798ebaf..b505cd10f81 100755 --- a/tests/usbprotocol/test_comms.py +++ b/tests/usbprotocol/test_comms.py @@ -4,7 +4,7 @@ from opendbc.car.structs import CarParams from panda import DLC_TO_LEN, USBPACKET_MAX_SIZE, pack_can_buffer, unpack_can_buffer -from panda.tests.libpanda import libpanda_py +from tests.libpanda import libpanda_py lpp = libpanda_py.libpanda