Skip to content

Commit

Permalink
Merge branch 'commaai:master' into PA-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Edison-CBS authored Jun 4, 2024
2 parents b07c6cb + 1492388 commit a3dac2a
Show file tree
Hide file tree
Showing 83 changed files with 1,606 additions and 1,644 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/selfdrive_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ env:
DOCKER_LOGIN: docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }}
BUILD: selfdrive/test/docker_build.sh base

RUN: docker run --shm-size 2G -v $PWD:/tmp/openpilot -w /tmp/openpilot -e CI=1 -e PRE_COMMIT_HOME=/tmp/pre-commit -e PYTHONWARNINGS=error -e FILEREADER_CACHE=1 -e PYTHONPATH=/tmp/openpilot -e NUM_JOBS -e JOB_ID -e GITHUB_ACTION -e GITHUB_REF -e GITHUB_HEAD_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_RUN_ID -v $GITHUB_WORKSPACE/.ci_cache/pre-commit:/tmp/pre-commit -v $GITHUB_WORKSPACE/.ci_cache/scons_cache:/tmp/scons_cache -v $GITHUB_WORKSPACE/.ci_cache/comma_download_cache:/tmp/comma_download_cache -v $GITHUB_WORKSPACE/.ci_cache/openpilot_cache:/tmp/openpilot_cache $BASE_IMAGE /bin/bash -c
RUN: docker run --shm-size 1G -v $PWD:/tmp/openpilot -w /tmp/openpilot -e CI=1 -e PRE_COMMIT_HOME=/tmp/pre-commit -e PYTHONWARNINGS=error -e FILEREADER_CACHE=1 -e PYTHONPATH=/tmp/openpilot -e NUM_JOBS -e JOB_ID -e GITHUB_ACTION -e GITHUB_REF -e GITHUB_HEAD_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_RUN_ID -v $GITHUB_WORKSPACE/.ci_cache/pre-commit:/tmp/pre-commit -v $GITHUB_WORKSPACE/.ci_cache/scons_cache:/tmp/scons_cache -v $GITHUB_WORKSPACE/.ci_cache/comma_download_cache:/tmp/comma_download_cache -v $GITHUB_WORKSPACE/.ci_cache/openpilot_cache:/tmp/openpilot_cache $BASE_IMAGE /bin/bash -c

PYTEST: pytest --continue-on-collection-errors --cov --cov-report=xml --cov-append --durations=0 --durations-min=5 --hypothesis-seed 0 -n logical

Expand Down Expand Up @@ -116,6 +116,8 @@ jobs:
submodules: true
- uses: ./.github/workflows/setup-pre-commit
- uses: ./.github/workflows/setup-with-retry
- name: Build openpilot
run: ${{ env.RUN }} "scons -j$(nproc)"
- name: pre-commit
timeout-minutes: 4
run: ${{ env.RUN }} "unset PYTHONWARNINGS && pre-commit run --all && chmod -R 777 /tmp/pre-commit"
Expand Down Expand Up @@ -143,7 +145,7 @@ jobs:
$PYTEST --timeout 60 -m 'not slow' && \
./selfdrive/ui/tests/create_test_translations.sh && \
QT_QPA_PLATFORM=offscreen ./selfdrive/ui/tests/test_translations && \
./selfdrive/ui/tests/test_translations.py"
pytest ./selfdrive/ui/tests/test_translations.py"
- name: "Upload coverage to Codecov"
uses: codecov/codecov-action@v4
with:
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ repos:
hooks:
- id: test_translations
name: test translations
entry: selfdrive/ui/tests/test_translations.py
language: script
entry: pytest selfdrive/ui/tests/test_translations.py
language: system
pass_filenames: false
files: '^selfdrive/ui/translations/'
- repo: https://github.com/python-poetry/poetry
Expand Down
2 changes: 0 additions & 2 deletions common/transformations/tests/test_coordinates.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python3

import numpy as np

import openpilot.common.transformations.coordinates as coord
Expand Down
2 changes: 0 additions & 2 deletions common/transformations/tests/test_orientation.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python3

import numpy as np

from openpilot.common.transformations.orientation import euler2quat, quat2euler, euler2rot, rot2euler, \
Expand Down
3,053 changes: 1,538 additions & 1,515 deletions poetry.lock

Large diffs are not rendered by default.

35 changes: 25 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Homepage = "https://comma.ai"

[tool.pytest.ini_options]
minversion = "6.0"
addopts = "--ignore=selfdrive/test/process_replay/test_processes.py --ignore=selfdrive/test/process_replay/test_regen.py -Werror --strict-config --strict-markers --durations=10 -n auto --dist=loadgroup"
cpp_files = "test_*.cc"
addopts = "--ignore=openpilot/ --ignore=cereal/ --ignore=opendbc/ --ignore=panda/ --ignore=rednose_repo/ --ignore=tinygrad_repo/ --ignore=teleoprtc_repo/ -Werror --strict-config --strict-markers --durations=10 -n auto --dist=loadgroup"
cpp_files = "test_*"
cpp_harness = "selfdrive/test/cpp_harness.py"
python_files = "test_*.py"
#timeout = "30" # you get this long by default
Expand All @@ -19,10 +19,28 @@ markers = [
"tici: tests that are only meant to run on the C3/C3X",
]
testpaths = [
"tools/",
"common/",
"system/",
"selfdrive/",
"common",
"selfdrive/boardd",
"selfdrive/car",
"selfdrive/controls",
"selfdrive/locationd",
"selfdrive/monitoring",
"selfdrive/navd/tests",
"selfdrive/test/longitudinal_maneuvers",
"selfdrive/test/process_replay/test_fuzzy.py",
"system/updated",
"system/thermald",
"system/athena",
"system/camerad",
"system/hardware/tici",
"system/loggerd",
"system/proclogd",
"system/tests",
"system/ubloxd",
"system/webrtc",
"tools/lib/tests",
"tools/replay",
"tools/cabana"
]

[tool.mypy]
Expand Down Expand Up @@ -147,6 +165,7 @@ pytest-timeout = "*"
pytest-randomly = "*"
pytest-asyncio = "*"
pytest-mock = "*"
pytest-repeat = "*"
rerun-sdk = "*"
ruff = "*"
sphinx = "*"
Expand Down Expand Up @@ -209,10 +228,6 @@ lint.flake8-implicit-str-concat.allow-multiline=false
"unittest".msg = "Use pytest"

[tool.coverage.run]
omit = [
"config.py",
"config-3.py"
]
concurrency = ["multiprocessing", "thread"]
[tool.ruff.format]
quote-style = "preserve"
3 changes: 2 additions & 1 deletion selfdrive/boardd/tests/test_boardd_loopback.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
import os
import copy
import random
Expand All @@ -9,6 +8,7 @@

import cereal.messaging as messaging
from cereal import car, log
from openpilot.common.retry import retry
from openpilot.common.params import Params
from openpilot.common.timeout import Timeout
from openpilot.selfdrive.boardd.boardd import can_list_to_can_capnp
Expand All @@ -17,6 +17,7 @@
from openpilot.selfdrive.test.helpers import phone_only, with_processes


@retry(attempts=3)
def setup_boardd(num_pandas):
params = Params()
params.put_bool("IsOnroad", False)
Expand Down
37 changes: 30 additions & 7 deletions selfdrive/boardd/tests/test_boardd_spi.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/usr/bin/env python3
import os
import time
import numpy as np
import pytest
import random

import cereal.messaging as messaging
from cereal.services import SERVICE_LIST
from openpilot.system.hardware import HARDWARE
from openpilot.selfdrive.test.helpers import phone_only, with_processes
from openpilot.selfdrive.boardd.tests.test_boardd_loopback import setup_boardd
from openpilot.selfdrive.boardd.tests.test_boardd_loopback import setup_boardd, send_random_can_messages


@pytest.mark.tici
Expand All @@ -19,37 +19,56 @@ def setup_class(cls):
pytest.skip("only for spi pandas")
os.environ['STARTED'] = '1'
os.environ['BOARDD_LOOPBACK'] = '1'
#os.environ['SPI_ERR_PROB'] = '-1'
os.environ['SPI_ERR_PROB'] = '0.001'

@phone_only
@with_processes(['pandad'])
def test_spi_corruption(self, subtests):
setup_boardd(1)

sendcan = messaging.pub_sock('sendcan')
socks = {s: messaging.sub_sock(s, conflate=False, timeout=100) for s in ('can', 'pandaStates', 'peripheralState')}
time.sleep(2)
for s in socks.values():
messaging.drain_sock_raw(s)

total_recv_count = 0
total_sent_count = 0
sent_msgs = {bus: list() for bus in range(3)}

st = time.monotonic()
ts = {s: list() for s in socks.keys()}
for _ in range(20):
# send some CAN messages
sent = send_random_can_messages(sendcan, random.randrange(2, 20))
for k, v in sent.items():
sent_msgs[k].extend(list(v))
total_sent_count += len(v)

for service, sock in socks.items():
for m in messaging.drain_sock(sock):
ts[service].append(m.logMonoTime)

# sanity check for corruption
assert m.valid
assert m.valid or (service == "can")
if service == "can":
assert len(m.can) == 0
for msg in m.can:
if msg.src > 4:
continue
key = (msg.address, msg.dat)
assert key in sent_msgs[msg.src], f"got unexpected msg: {msg.src=} {msg.address=} {msg.dat=}"
# TODO: enable this
#sent_msgs[msg.src].remove(key)
total_recv_count += 1
elif service == "pandaStates":
assert len(m.pandaStates) == 1
ps = m.pandaStates[0]
assert ps.uptime < 100
assert ps.uptime < 1000
assert ps.pandaType == "tres"
assert ps.ignitionLine
assert not ps.ignitionCan
assert ps.voltage < 14000
assert 4000 < ps.voltage < 14000
elif service == "peripheralState":
ps = m.peripheralState
assert ps.pandaType == "tres"
Expand All @@ -67,6 +86,10 @@ def test_spi_corruption(self, subtests):
with subtests.test(msg="timing check", service=service):
edt = 1e3 / SERVICE_LIST[service].frequency
assert edt*0.9 < np.mean(dts) < edt*1.1
assert np.max(dts) < edt*3
assert np.max(dts) < edt*20
assert np.min(dts) < edt
assert len(dts) >= ((et-0.5)*SERVICE_LIST[service].frequency*0.8)

with subtests.test(msg="CAN traffic"):
print(f"Sent {total_sent_count} CAN messages, got {total_recv_count} back. {total_recv_count/total_sent_count:.2%} received")
assert total_recv_count > 20
1 change: 0 additions & 1 deletion selfdrive/boardd/tests/test_pandad.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
import os
import pytest
import time
Expand Down
1 change: 0 additions & 1 deletion selfdrive/car/ford/tests/test_ford.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
import random
from collections.abc import Iterable

Expand Down
1 change: 0 additions & 1 deletion selfdrive/car/gm/tests/test_gm.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
from parameterized import parameterized

from openpilot.selfdrive.car.gm.fingerprints import FINGERPRINTS
Expand Down
1 change: 0 additions & 1 deletion selfdrive/car/honda/tests/test_honda.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
import re

from openpilot.selfdrive.car.honda.fingerprints import FW_VERSIONS
Expand Down
1 change: 0 additions & 1 deletion selfdrive/car/hyundai/tests/test_hyundai.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
from hypothesis import settings, given, strategies as st

import pytest
Expand Down
1 change: 0 additions & 1 deletion selfdrive/car/tests/test_can_fingerprint.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
from parameterized import parameterized

from cereal import log, messaging
Expand Down
1 change: 0 additions & 1 deletion selfdrive/car/tests/test_car_interfaces.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
import os
import math
import hypothesis.strategies as st
Expand Down
1 change: 0 additions & 1 deletion selfdrive/car/tests/test_docs.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
from collections import defaultdict
import os
import pytest
Expand Down
1 change: 0 additions & 1 deletion selfdrive/car/tests/test_fingerprints.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
import os
import sys

Expand Down
1 change: 0 additions & 1 deletion selfdrive/car/tests/test_fw_fingerprint.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
import pytest
import random
import time
Expand Down
1 change: 0 additions & 1 deletion selfdrive/car/tests/test_lateral_limits.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
from collections import defaultdict
import importlib
from parameterized import parameterized_class
Expand Down
1 change: 0 additions & 1 deletion selfdrive/car/tests/test_models.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
import capnp
import os
import importlib
Expand Down
2 changes: 0 additions & 2 deletions selfdrive/car/tests/test_platform_configs.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python3

from openpilot.selfdrive.car.values import PLATFORMS


Expand Down
2 changes: 1 addition & 1 deletion selfdrive/car/torque_data/override.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ legend = ["LAT_ACCEL_FACTOR", "MAX_LAT_ACCEL_MEASURED", "FRICTION"]
"GMC_ACADIA" = [1.6, 1.6, 0.2]
"LEXUS_IS_TSS2" = [2.0, 2.0, 0.1]
"HYUNDAI_KONA_EV_2ND_GEN" = [2.5, 2.5, 0.1]
"HYUNDAI_IONIQ_6" = [2.5, 2.5, 0.1]
"HYUNDAI_IONIQ_6" = [2.5, 2.5, 0.005]
"HYUNDAI_AZERA_6TH_GEN" = [1.8, 1.8, 0.1]
"HYUNDAI_AZERA_HEV_6TH_GEN" = [1.8, 1.8, 0.1]
"KIA_K8_HEV_1ST_GEN" = [2.5, 2.5, 0.1]
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/car/torque_data/params.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ legend = ["LAT_ACCEL_FACTOR", "MAX_LAT_ACCEL_MEASURED", "FRICTION"]
"HYUNDAI_TUCSON_4TH_GEN" = [2.960174, 2.860284, 0.108745]
"JEEP_GRAND_CHEROKEE_2019" = [2.30972, 1.289689569171081, 0.117048]
"JEEP_GRAND_CHEROKEE" = [2.27116, 1.4057367824262523, 0.11725947414922003]
"KIA_EV6" = [3.2, 2.093457, 0.05]
"KIA_EV6" = [3.2, 2.093457, 0.005]
"KIA_K5_2021" = [2.405339728085138, 1.460032270828705, 0.11650989850813716]
"KIA_NIRO_EV" = [2.9215954981365337, 2.1500583840260044, 0.09236802474810267]
"KIA_SORENTO" = [2.464854685101844, 1.5335274218367956, 0.12056170567599558]
Expand Down
1 change: 0 additions & 1 deletion selfdrive/car/toyota/tests/test_toyota.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
from hypothesis import given, settings, strategies as st

from cereal import car
Expand Down
1 change: 0 additions & 1 deletion selfdrive/car/volkswagen/tests/test_volkswagen.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
import random
import re

Expand Down
1 change: 0 additions & 1 deletion selfdrive/controls/lib/tests/test_alertmanager.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
import random

from openpilot.selfdrive.controls.lib.events import Alert, EVENTS
Expand Down
1 change: 0 additions & 1 deletion selfdrive/controls/lib/tests/test_latcontrol.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
from parameterized import parameterized

from cereal import car, log
Expand Down
1 change: 0 additions & 1 deletion selfdrive/controls/lib/tests/test_vehicle_model.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
import pytest
import math

Expand Down
1 change: 0 additions & 1 deletion selfdrive/controls/tests/test_alerts.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
import copy
import json
import os
Expand Down
1 change: 0 additions & 1 deletion selfdrive/controls/tests/test_cruise_speed.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
import pytest
import itertools
import numpy as np
Expand Down
1 change: 0 additions & 1 deletion selfdrive/controls/tests/test_following_distance.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
import pytest
import itertools
from parameterized import parameterized_class
Expand Down
1 change: 0 additions & 1 deletion selfdrive/controls/tests/test_leads.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
import cereal.messaging as messaging

from openpilot.selfdrive.test.process_replay import replay_process_with_name
Expand Down
2 changes: 0 additions & 2 deletions selfdrive/controls/tests/test_state_machine.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python3

from cereal import car, log
from openpilot.common.realtime import DT_CTRL
from openpilot.selfdrive.car.car_helpers import interfaces
Expand Down
1 change: 0 additions & 1 deletion selfdrive/locationd/test/test_calibrationd.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
import random

import numpy as np
Expand Down
1 change: 0 additions & 1 deletion selfdrive/locationd/test/test_locationd.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
import pytest
import json
import random
Expand Down
1 change: 0 additions & 1 deletion selfdrive/locationd/test/test_locationd_scenarios.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
import pytest
import numpy as np
from collections import defaultdict
Expand Down
Loading

0 comments on commit a3dac2a

Please sign in to comment.