diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 465e4ddb80..6b8824cd46 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -10,7 +10,7 @@ env: PERSIST: docker run -v $GITHUB_WORKSPACE:/tmp/openpilot/panda -w /tmp/openpilot/panda --name panda panda /bin/bash -c BUILD: | export DOCKER_BUILDKIT=1 - docker build --pull --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from ghcr.io/commaai/panda:latest -t panda -f Dockerfile.panda . + docker build --pull --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from ghcr.io/commaai/panda:latest -t panda -f Dockerfile . jobs: docker_push: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fb84825144..421fbd6178 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,14 +10,12 @@ repos: rev: v0.910-1 hooks: - id: mypy - exclude: '^(tests/automated)/' additional_dependencies: ['git+https://github.com/numpy/numpy-stubs', 'types-requests', 'types-atomicwrites', 'types-pycurl'] - repo: https://github.com/PyCQA/flake8 rev: 4.0.1 hooks: - id: flake8 - exclude: '^(tests/automated)/' args: - --select=F,E112,E113,E304,E501,E502,E701,E702,E703,E71,E72,E731,W191,W6 - --exclude=tests/gmbitbang/* @@ -30,7 +28,9 @@ repos: entry: pylint language: system types: [python] - exclude: '^(tests/automated)/' args: + - -rn + - -sn + - -j0 - --disable=C,R,W0613,W0511,W0212,W0201,W0311,W0106,W0603,W0621,W0703,E1136 - --generated-members="usb1.*" diff --git a/Dockerfile b/Dockerfile index 6fda9c1485..0663b9cd6c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,50 +1,45 @@ FROM ubuntu:20.04 ENV PYTHONUNBUFFERED 1 +ENV PYTHONPATH /tmp/openpilot:$PYTHONPATH ENV DEBIAN_FRONTEND=noninteractive -RUN apt-get update && apt-get install -y \ +RUN apt-get update && apt-get install -y --no-install-recommends \ autoconf \ automake \ - bash \ - bison \ bzip2 \ ca-certificates \ + capnproto \ + clang \ curl \ - dfu-util \ - flex \ g++ \ - gawk \ - gcc \ + gcc-arm-none-eabi libnewlib-arm-none-eabi \ git \ - gperf \ - help2man \ - iputils-ping \ + libarchive-dev \ + libavformat-dev libavcodec-dev libavdevice-dev libavutil-dev libswscale-dev libavresample-dev libavfilter-dev \ libbz2-dev \ - libexpat-dev \ + libcapnp-dev \ + libcurl4-openssl-dev \ libffi-dev \ - libssl-dev \ - libstdc++-arm-none-eabi-newlib \ libtool \ - libtool-bin \ + libssl-dev \ + libsqlite3-dev \ libusb-1.0-0 \ - locales \ + libzmq3-dev \ + locales \ + opencl-headers \ + ocl-icd-opencl-dev \ make \ - ncurses-dev \ - network-manager \ + patch \ + pkg-config \ + python \ python-dev \ - python3-serial \ - sed \ - texinfo \ - unrar-free \ unzip \ wget \ - build-essential \ - python-dev \ - screen \ - vim \ - wget \ - wireless-tools \ - zlib1g-dev + zlib1g-dev \ + && rm -rf /var/lib/apt/lists/* && \ + cd /usr/lib/gcc/arm-none-eabi/9.2.1 && \ + rm -rf arm/ && \ + rm -rf thumb/nofp thumb/v6* thumb/v8* thumb/v7+fp thumb/v7-r+fp.sp RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && locale-gen ENV LANG en_US.UTF-8 @@ -52,22 +47,45 @@ ENV LANGUAGE en_US:en ENV LC_ALL en_US.UTF-8 RUN curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash - ENV PATH="/root/.pyenv/bin:/root/.pyenv/shims:${PATH}" -RUN pyenv install 3.8.10 -RUN pyenv global 3.8.10 -RUN pyenv rehash -RUN pip install --upgrade pip==18.0 +ENV PANDA_PATH=/tmp/openpilot/panda +ENV OPENPILOT_REF="ee0dd36a3c775dbd82493c84f4e7272c1eb3fcbd" +ENV OPENDBC_REF="296f190000a2e71408e207ba21a2257cc853ec15" COPY requirements.txt /tmp/ -RUN pip install -r /tmp/requirements.txt +RUN pyenv install 3.8.10 && \ + pyenv global 3.8.10 && \ + pyenv rehash && \ + pip install --no-cache-dir -r /tmp/requirements.txt + +ENV CPPCHECK_DIR=/tmp/cppcheck +COPY tests/misra/install.sh /tmp/ +RUN /tmp/install.sh -ENV PYTHONPATH /tmp:$PYTHONPATH +RUN git config --global --add safe.directory /tmp/openpilot/panda +RUN cd /tmp && \ + git clone https://github.com/commaai/openpilot.git tmppilot || true && \ + cd /tmp/tmppilot && \ + git fetch origin $OPENPILOT_REF && \ + git checkout $OPENPILOT_REF && \ + git submodule update --init cereal opendbc rednose_repo && \ + git -C opendbc fetch && \ + git -C opendbc checkout $OPENDBC_REF && \ + git -C opendbc reset --hard HEAD && \ + git -C opendbc clean -xfd && \ + mkdir /tmp/openpilot && \ + cp -pR SConstruct site_scons/ tools/ selfdrive/ system/ common/ cereal/ opendbc/ rednose/ third_party/ /tmp/openpilot && \ + rm -rf /tmp/openpilot/panda && \ + rm -rf /tmp/tmppilot -RUN cd /tmp && git clone https://github.com/commaai/panda_jungle.git && \ +RUN cd /tmp/openpilot && \ + git clone https://github.com/commaai/panda_jungle.git && \ cd panda_jungle && \ git fetch && \ - git checkout 7b7197c605915ac34f3d62f314edd84e2e78a759 + git checkout 7b7197c605915ac34f3d62f314edd84e2e78a759 && \ + rm -rf .git/ -ADD ./panda.tar.gz /tmp/panda +RUN cd /tmp/openpilot && \ + pip install --no-cache-dir -r opendbc/requirements.txt && \ + pip install --no-cache-dir --upgrade aenum lru-dict pycurl tenacity atomicwrites serial smbus2 diff --git a/Dockerfile.panda b/Dockerfile.panda deleted file mode 100644 index b2e77c15c6..0000000000 --- a/Dockerfile.panda +++ /dev/null @@ -1,84 +0,0 @@ -FROM ubuntu:20.04 -ENV PYTHONUNBUFFERED 1 -ENV PYTHONPATH /tmp/openpilot:$PYTHONPATH - -ENV DEBIAN_FRONTEND=noninteractive -RUN apt-get update && apt-get install -y --no-install-recommends \ - autoconf \ - automake \ - bzip2 \ - ca-certificates \ - capnproto \ - clang \ - curl \ - g++ \ - gcc-arm-none-eabi libnewlib-arm-none-eabi \ - git \ - libarchive-dev \ - libavformat-dev libavcodec-dev libavdevice-dev libavutil-dev libswscale-dev libavresample-dev libavfilter-dev \ - libbz2-dev \ - libcapnp-dev \ - libcurl4-openssl-dev \ - libffi-dev \ - libtool \ - libssl-dev \ - libsqlite3-dev \ - libusb-1.0-0 \ - libzmq3-dev \ - locales \ - opencl-headers \ - ocl-icd-opencl-dev \ - make \ - patch \ - pkg-config \ - python \ - python-dev \ - unzip \ - wget \ - zlib1g-dev \ - && rm -rf /var/lib/apt/lists/* && \ - cd /usr/lib/gcc/arm-none-eabi/9.2.1 && \ - rm -rf arm/ && \ - rm -rf thumb/nofp thumb/v6* thumb/v8* thumb/v7+fp thumb/v7-r+fp.sp - -RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && locale-gen -ENV LANG en_US.UTF-8 -ENV LANGUAGE en_US:en -ENV LC_ALL en_US.UTF-8 - -RUN curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash -ENV PATH="/root/.pyenv/bin:/root/.pyenv/shims:${PATH}" - -ENV PANDA_PATH=/tmp/openpilot/panda -ENV OPENPILOT_REF="3fc373b4e4829b03ddc363741006af0589d97588" -ENV OPENDBC_REF="296f190000a2e71408e207ba21a2257cc853ec15" - -COPY requirements.txt /tmp/ -RUN pyenv install 3.8.10 && \ - pyenv global 3.8.10 && \ - pyenv rehash && \ - pip install --no-cache-dir -r /tmp/requirements.txt - -ENV CPPCHECK_DIR=/tmp/cppcheck -COPY tests/misra/install.sh /tmp/ -RUN /tmp/install.sh - -RUN git config --global --add safe.directory /tmp/openpilot/panda -RUN cd /tmp && \ - git clone https://github.com/commaai/openpilot.git tmppilot || true && \ - cd /tmp/tmppilot && \ - git fetch origin $OPENPILOT_REF && \ - git checkout $OPENPILOT_REF && \ - git submodule update --init cereal opendbc rednose_repo && \ - git -C opendbc fetch && \ - git -C opendbc checkout $OPENDBC_REF && \ - git -C opendbc reset --hard HEAD && \ - git -C opendbc clean -xfd && \ - mkdir /tmp/openpilot && \ - cp -pR SConstruct site_scons/ tools/ selfdrive/ system/ common/ cereal/ opendbc/ rednose/ third_party/ /tmp/openpilot && \ - rm -rf /tmp/openpilot/panda && \ - rm -rf /tmp/tmppilot - -RUN cd /tmp/openpilot && \ - pip install --no-cache-dir -r opendbc/requirements.txt && \ - pip install --no-cache-dir --upgrade aenum lru-dict pycurl tenacity atomicwrites serial smbus2 scons diff --git a/Jenkinsfile b/Jenkinsfile index 80a028869a..4e268de7ad 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,6 +1,22 @@ +def docker_run(String step_label, int timeout_mins, String cmd) { + timeout(time: timeout_mins, unit: 'MINUTES') { + sh script: "docker run --rm --privileged \ + --env PARTIAL_TESTS=${env.PARTIAL_TESTS} \ + --volume ${WORKSPACE.replace('/var/jenkins_home', '/data/docker/volumes/jenkins_jenkins-data/_data')}:/tmp/openpilot/panda \ + --volume /dev/bus/usb:/dev/bus/usb \ + --volume /var/run/dbus:/var/run/dbus \ + --workdir /tmp/openpilot/panda \ + --net host \ + ${env.DOCKER_IMAGE_TAG} \ + bash -c '${cmd}'", \ + label: step_label + } +} + pipeline { agent any environment { + PARTIAL_TESTS = "${env.BRANCH_NAME == 'master' ? ' ' : '1'}" DOCKER_IMAGE_TAG = "panda:build-${env.GIT_COMMIT}" } stages { @@ -13,69 +29,49 @@ pipeline { steps { timeout(time: 60, unit: 'MINUTES') { script { - sh 'git archive -v -o panda.tar.gz --format=tar.gz HEAD' dockerImage = docker.build("${env.DOCKER_IMAGE_TAG}") } } } } - stage('reset hardware') { + stage('prep') { steps { - timeout(time: 10, unit: 'MINUTES') { - script { - sh "docker run --rm --privileged \ - --volume /dev/bus/usb:/dev/bus/usb \ - --volume /var/run/dbus:/var/run/dbus \ - --net host \ - ${env.DOCKER_IMAGE_TAG} \ - bash -c 'cd /tmp/panda && scons -j8 && python ./tests/ci_reset_hw.py'" - } + script { + docker_run("build", 1, "scons -j8") + docker_run("reset hardware", 3, "python ./tests/ci_reset_hw.py") } } } stage('pedal tests') { steps { - timeout(time: 10, unit: 'MINUTES') { - script { - sh "docker run --rm --privileged \ - --volume /dev/bus/usb:/dev/bus/usb \ - --volume /var/run/dbus:/var/run/dbus \ - --net host \ - ${env.DOCKER_IMAGE_TAG} \ - bash -c 'cd /tmp/panda && PEDAL_JUNGLE=058010800f51363038363036 python ./tests/pedal/test_pedal.py'" - } + script { + docker_run("test pedal", 1, "PEDAL_JUNGLE=058010800f51363038363036 python ./tests/pedal/test_pedal.py") } } } stage('HITL tests') { steps { - timeout(time: 30, unit: 'MINUTES') { - script { - sh "docker run --rm --privileged \ - --volume /dev/bus/usb:/dev/bus/usb \ - --volume /var/run/dbus:/var/run/dbus \ - --net host \ - ${env.DOCKER_IMAGE_TAG} \ - bash -c 'cd /tmp/panda && scons -j8 && PANDAS_JUNGLE=23002d000851393038373731 PANDAS_EXCLUDE=\"1d0002000c51303136383232 2f002e000c51303136383232\" ./tests/automated/test.sh'" - } + script { + docker_run("HITL tests", 20, 'PANDAS_JUNGLE=23002d000851393038373731 PANDAS_EXCLUDE="1d0002000c51303136383232 2f002e000c51303136383232" ./tests/hitl/test.sh') } } } stage('CANFD tests') { steps { - timeout(time: 10, unit: 'MINUTES') { - script { - sh "docker run --rm --privileged \ - --volume /dev/bus/usb:/dev/bus/usb \ - --volume /var/run/dbus:/var/run/dbus \ - --net host \ - ${env.DOCKER_IMAGE_TAG} \ - bash -c 'cd /tmp/panda && scons -j8 && JUNGLE=058010800f51363038363036 H7_PANDAS_EXCLUDE=\"080021000c51303136383232 33000e001051393133353939\" ./tests/canfd/test_canfd.py'" - } + script { + docker_run("CANFD tets", 6, 'JUNGLE=058010800f51363038363036 H7_PANDAS_EXCLUDE="080021000c51303136383232 33000e001051393133353939" ./tests/canfd/test_canfd.py') } } } } + + post { + always { + docker_run("git clean", 1, "git clean -xdff") + sh "rm -rf ${WORKSPACE}/* || true" + sh "rm -rf .* || true" + } + } } } } diff --git a/requirements.txt b/requirements.txt index fdf4e48a62..c7515326ff 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,4 +12,5 @@ cffi==1.14.3 crcmod pre-commit==2.13.0 pylint==2.5.2 -scons==4.1.0.post1 +scons +flaky diff --git a/tests/black_white_loopback_test.py b/tests/black_white_loopback_test.py index 9ef9f06551..f5c6170fe4 100755 --- a/tests/black_white_loopback_test.py +++ b/tests/black_white_loopback_test.py @@ -23,7 +23,7 @@ def get_test_string(): content_errors = 0 def run_test(sleep_duration): - global counter, nonzero_bus_errors, zero_bus_errors, content_errors + global counter pandas = Panda.list() print(pandas) diff --git a/tests/black_white_relay_endurance.py b/tests/black_white_relay_endurance.py index 32c77f2edb..f44eafd207 100755 --- a/tests/black_white_relay_endurance.py +++ b/tests/black_white_relay_endurance.py @@ -23,7 +23,7 @@ def get_test_string(): content_errors = 0 def run_test(sleep_duration): - global counter, nonzero_bus_errors, zero_bus_errors, content_errors + global counter pandas = Panda.list() print(pandas) diff --git a/tests/black_white_relay_test.py b/tests/black_white_relay_test.py index 3480d0e47b..4de02ec849 100755 --- a/tests/black_white_relay_test.py +++ b/tests/black_white_relay_test.py @@ -22,7 +22,7 @@ def get_test_string(): content_errors = 0 def run_test(sleep_duration): - global counter, open_errors, closed_errors, content_errors + global counter, open_errors, closed_errors pandas = Panda.list() print(pandas) diff --git a/tests/bulk_write_test.py b/tests/bulk_write_test.py index 708258ba66..047e870ce8 100755 --- a/tests/bulk_write_test.py +++ b/tests/bulk_write_test.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +# type: ignore # for jungle stuff import os import time import threading diff --git a/tests/ci_shell.sh b/tests/ci_shell.sh index f0e2dc1230..92c0f96e8a 100755 --- a/tests/ci_shell.sh +++ b/tests/ci_shell.sh @@ -2,11 +2,12 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)" OP_ROOT="$DIR/../../" +PANDA_ROOT="$DIR/../" if [ -z "$BUILD" ]; then docker pull docker.io/commaai/panda:latest else - docker build --cache-from docker.io/commaai/panda:latest -t docker.io/commaai/panda:latest -f $OP_ROOT/Dockerfile.openpilot_base . + docker build --cache-from docker.io/commaai/panda:latest -t docker.io/commaai/panda:latest -f $PANDA_ROOT/Dockerfile $PANDA_ROOT fi docker run \ diff --git a/tests/automated/1_program.py b/tests/hitl/1_program.py similarity index 84% rename from tests/automated/1_program.py rename to tests/hitl/1_program.py index a81a0b8832..6615a8a03e 100644 --- a/tests/automated/1_program.py +++ b/tests/hitl/1_program.py @@ -9,8 +9,8 @@ @panda_connect_and_init(full_reset=False) def test_a_known_bootstub(p): # Test that compiled app can work with known production bootstub - KNOWN_H7_BOOTSTUB_FN = os.path.join(BASEDIR, "tests", "automated", "known_bootstub", "bootstub.panda_h7.bin") - KNOWN_BOOTSTUB_FN = os.path.join(BASEDIR, "tests", "automated", "known_bootstub", "bootstub.panda.bin") + KNOWN_H7_BOOTSTUB_FN = os.path.join(BASEDIR, "tests", "hitl", "known_bootstub", "bootstub.panda_h7.bin") + KNOWN_BOOTSTUB_FN = os.path.join(BASEDIR, "tests", "hitl", "known_bootstub", "bootstub.panda.bin") p.reset(enter_bootstub=True) p.reset(enter_bootloader=True) @@ -39,7 +39,7 @@ def test_b_recover(p): def test_c_flash(p): # test flash from bootstub serial = p._serial - assert serial != None + assert serial is not None p.reset(enter_bootstub=True) p.close() time.sleep(2) diff --git a/tests/automated/2_health.py b/tests/hitl/2_health.py similarity index 100% rename from tests/automated/2_health.py rename to tests/hitl/2_health.py diff --git a/tests/automated/3_usb_to_can.py b/tests/hitl/3_usb_to_can.py similarity index 98% rename from tests/automated/3_usb_to_can.py rename to tests/hitl/3_usb_to_can.py index a2035bd0a7..a67686db39 100644 --- a/tests/automated/3_usb_to_can.py +++ b/tests/hitl/3_usb_to_can.py @@ -1,5 +1,6 @@ import sys import time +from flaky import flaky from nose.tools import assert_equal, assert_less, assert_greater from panda import Panda @@ -49,7 +50,6 @@ def test_safety_nooutput(p): @test_all_pandas @panda_connect_and_init def test_reliability(p): - LOOP_COUNT = 100 MSG_COUNT = 100 p.set_safety_mode(Panda.SAFETY_ALLOUTPUT) @@ -59,8 +59,7 @@ def test_reliability(p): addrs = list(range(100, 100 + MSG_COUNT)) ts = [(j, 0, b"\xaa" * 8, 0) for j in addrs] - # 100 loops - for i in range(LOOP_COUNT): + for _ in range(100): st = time.monotonic() p.can_send_many(ts) @@ -84,6 +83,7 @@ def test_reliability(p): sys.stdout.flush() @test_all_pandas +@flaky(max_runs=3, min_passes=1) @panda_connect_and_init def test_throughput(p): # enable output mode diff --git a/tests/automated/4_can_loopback.py b/tests/hitl/4_can_loopback.py similarity index 95% rename from tests/automated/4_can_loopback.py rename to tests/hitl/4_can_loopback.py index 53b18168a2..6cc0205bbf 100644 --- a/tests/automated/4_can_loopback.py +++ b/tests/hitl/4_can_loopback.py @@ -2,12 +2,15 @@ import time import random import threading -from panda import Panda +from flaky import flaky from collections import defaultdict from nose.tools import assert_equal, assert_less, assert_greater + +from panda import Panda from .helpers import panda_jungle, time_many_sends, test_all_pandas, test_all_gen2_pandas, clear_can_buffers, panda_connect_and_init @test_all_pandas +@flaky(max_runs=3, min_passes=1) @panda_connect_and_init def test_send_recv(p): def test(p_send, p_recv): @@ -44,6 +47,7 @@ def test(p_send, p_recv): @test_all_pandas +@flaky(max_runs=3, min_passes=1) @panda_connect_and_init def test_latency(p): def test(p_send, p_recv): @@ -75,7 +79,7 @@ def test(p_send, p_recv): num_messages = 100 - for i in range(num_messages): + for _ in range(num_messages): st = time.monotonic() p_send.can_send(0x1ab, b"message", bus) r = [] @@ -179,11 +183,10 @@ def flood_tx(panda): packet += [[0xaa, None, msg, 0], [0xaa, None, msg, 1], [0xaa, None, msg, 2]] * NUM_MESSAGES_PER_BUS # Disable timeout + panda.set_safety_mode(Panda.SAFETY_ALLOUTPUT) panda.can_send_many(packet, timeout=0) - print(f"Done sending {4 * NUM_MESSAGES_PER_BUS} messages!") - - # Set safety mode and power saving - p.set_safety_mode(Panda.SAFETY_ALLOUTPUT) + print(f"Done sending {4 * NUM_MESSAGES_PER_BUS} messages!", time.monotonic()) + print(panda.health()) # Start transmisson threading.Thread(target=flood_tx, args=(p,)).start() @@ -195,7 +198,7 @@ def flood_tx(panda): while time.monotonic() - start_time < 5 or len(rx) > old_len: old_len = len(rx) rx.extend(panda_jungle.can_recv()) - print(f"Received {len(rx)} messages") + print(f"Received {len(rx)} messages", time.monotonic()) # All messages should have been received if len(rx) != 4 * NUM_MESSAGES_PER_BUS: diff --git a/tests/automated/5_gps.py b/tests/hitl/5_gps.py similarity index 96% rename from tests/automated/5_gps.py rename to tests/hitl/5_gps.py index ec4bbbcf48..7fb6329c6b 100644 --- a/tests/automated/5_gps.py +++ b/tests/hitl/5_gps.py @@ -7,7 +7,7 @@ def test_gps_version(p): serial = PandaSerial(p, 1, 9600) # Reset and check twice to make sure the enabling works - for i in range(2): + for _ in range(2): # Reset GPS p.set_esp_power(0) time.sleep(2) diff --git a/tests/automated/__init__.py b/tests/hitl/__init__.py similarity index 100% rename from tests/automated/__init__.py rename to tests/hitl/__init__.py diff --git a/tests/automated/helpers.py b/tests/hitl/helpers.py similarity index 86% rename from tests/automated/helpers.py rename to tests/hitl/helpers.py index 5e83393771..8f3070c6a9 100644 --- a/tests/automated/helpers.py +++ b/tests/hitl/helpers.py @@ -18,9 +18,9 @@ GPS_HW_TYPES = [Panda.HW_TYPE_GREY_PANDA, Panda.HW_TYPE_BLACK_PANDA, Panda.HW_TYPE_UNO] PEDAL_SERIAL = 'none' JUNGLE_SERIAL = os.getenv("PANDAS_JUNGLE") -PANDAS_EXCLUDE = [] -if os.getenv("PANDAS_EXCLUDE"): - PANDAS_EXCLUDE = os.getenv("PANDAS_EXCLUDE").strip().split(" ") +PANDAS_EXCLUDE = os.getenv("PANDAS_EXCLUDE", "").strip().split(" ") + +PARTIAL_TESTS = os.environ.get("PARTIAL_TESTS", "0") == "1" # Enable fault debug faulthandler.enable(all_threads=False) @@ -29,9 +29,9 @@ panda_jungle = PandaJungle(JUNGLE_SERIAL) # Find all pandas connected -_all_pandas = None +_all_pandas = [] def init_all_pandas(): - global panda_jungle, _all_pandas + global _all_pandas _all_pandas = [] # power cycle pandas @@ -50,44 +50,31 @@ def init_all_pandas(): _all_panda_serials = [x[0] for x in _all_pandas] # Panda providers -test_all_types = parameterized([ - param(panda_type=Panda.HW_TYPE_WHITE_PANDA), - param(panda_type=Panda.HW_TYPE_GREY_PANDA), - param(panda_type=Panda.HW_TYPE_BLACK_PANDA), - param(panda_type=Panda.HW_TYPE_UNO), - param(panda_type=Panda.HW_TYPE_RED_PANDA), - param(panda_type=Panda.HW_TYPE_RED_PANDA_V2) - ]) +test_pandas = _all_pandas[:] +if PARTIAL_TESTS: + # minimal set of pandas to get most of our coverage + # * red panda covers STM32H7 + # * black panda covers STM32F4, GEN2, and GPS + test_pandas = [p for p in _all_pandas if p[1] in (Panda.HW_TYPE_BLACK_PANDA, Panda.HW_TYPE_RED_PANDA)] test_all_pandas = parameterized( - list(map(lambda x: x[0], _all_pandas)) # type: ignore + list(map(lambda x: x[0], test_pandas)) # type: ignore ) test_all_gen2_pandas = parameterized( - list(map(lambda x: x[0], filter(lambda x: x[1] in GEN2_HW_TYPES, _all_pandas))) # type: ignore + list(map(lambda x: x[0], filter(lambda x: x[1] in GEN2_HW_TYPES, test_pandas))) # type: ignore ) test_all_gps_pandas = parameterized( - list(map(lambda x: x[0], filter(lambda x: x[1] in GPS_HW_TYPES, _all_pandas))) # type: ignore + list(map(lambda x: x[0], filter(lambda x: x[1] in GPS_HW_TYPES, test_pandas))) # type: ignore ) test_white_and_grey = parameterized([ param(panda_type=Panda.HW_TYPE_WHITE_PANDA), param(panda_type=Panda.HW_TYPE_GREY_PANDA) ]) -test_white = parameterized([ - param(panda_type=Panda.HW_TYPE_WHITE_PANDA) - ]) -test_grey = parameterized([ - param(panda_type=Panda.HW_TYPE_GREY_PANDA) - ]) -test_black = parameterized([ - param(panda_type=Panda.HW_TYPE_BLACK_PANDA) - ]) -test_uno = parameterized([ - param(panda_type=Panda.HW_TYPE_UNO) - ]) + def time_many_sends(p, bus, p_recv=None, msg_count=100, msg_id=None, two_pandas=False): - if p_recv == None: + if p_recv is None: p_recv = p - if msg_id == None: + if msg_id is None: msg_id = random.randint(0x100, 0x200) if p == p_recv and two_pandas: raise ValueError("Cannot have two pandas that are the same panda") @@ -129,11 +116,6 @@ def wrapper(panda_type=None, **kwargs): if not isinstance(panda_type, list): panda_type = [panda_type] - # If not done already, get panda serials and their type - global _all_pandas - if _all_pandas == None: - init_all_pandas() - # Find a panda with the correct types and add the corresponding serial serials = [] for p_type in panda_type: diff --git a/tests/automated/known_bootstub/bootstub.panda.bin b/tests/hitl/known_bootstub/bootstub.panda.bin similarity index 100% rename from tests/automated/known_bootstub/bootstub.panda.bin rename to tests/hitl/known_bootstub/bootstub.panda.bin diff --git a/tests/automated/known_bootstub/bootstub.panda_h7.bin b/tests/hitl/known_bootstub/bootstub.panda_h7.bin similarity index 100% rename from tests/automated/known_bootstub/bootstub.panda_h7.bin rename to tests/hitl/known_bootstub/bootstub.panda_h7.bin diff --git a/tests/automated/test.sh b/tests/hitl/test.sh similarity index 62% rename from tests/automated/test.sh rename to tests/hitl/test.sh index 72f866a86b..d2de5f3b7d 100755 --- a/tests/automated/test.sh +++ b/tests/hitl/test.sh @@ -1,6 +1,5 @@ #!/bin/bash - set -e DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)" -nosetests -x -v -s $(ls $DIR/$1*.py) +nosetests -x -v --with-flaky -s $(ls $DIR/$1*.py) diff --git a/tests/message_drop_test.py b/tests/message_drop_test.py index c6991ce7a5..31c6f8cbd1 100755 --- a/tests/message_drop_test.py +++ b/tests/message_drop_test.py @@ -5,7 +5,7 @@ import struct import itertools import threading -from typing import Any, List +from typing import Any, Union, List from panda import Panda @@ -35,6 +35,7 @@ def flood_tx(panda): if __name__ == "__main__": serials = Panda.list() + receiver: Union[Panda, PandaJungle] if JUNGLE: sender = Panda() receiver = PandaJungle()