From 244e8807df75feb88c0fe825569bcd87409bd250 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Thu, 29 Oct 2020 13:53:48 -0700 Subject: [PATCH] ubuntu 16.04 -> 20.04 (#309) --- .github/workflows/tests.yml | 11 +++++------ .pre-commit-config.yaml | 1 + Dockerfile | 7 ++++--- can/common.cc | 9 +++------ can/tests/test_packer_parser.py | 5 +---- 5 files changed, 14 insertions(+), 19 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8631705..3c9013e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,4 +1,4 @@ -name: Tests +name: tests on: [push, pull_request] @@ -11,8 +11,7 @@ env: jobs: test: - runs-on: ubuntu-16.04 - + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - name: Build Docker image @@ -20,9 +19,6 @@ jobs: - name: Static analysis run: | docker run opendbc bash -c "cd opendbc && git init && git add -A && pre-commit run --all" - - name: Unit tests - run: | - docker run opendbc bash -c "python -m unittest discover opendbc" - name: Python linter run: | docker run opendbc bash -c "cd opendbc/can/tests/linter_python; PYTHONPATH=/ ./flake8_opendbc.sh" @@ -30,6 +26,9 @@ jobs: - name: Generator test run: | docker run opendbc bash -c "cd opendbc/can/tests/; PYTHONPATH=/ ./test_generator.sh" + - name: Unit tests + run: | + docker run opendbc bash -c "python -m unittest discover opendbc" - name: Push to dockerhub if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request' && github.repository == 'commaai/opendbc' run: | diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fea47ca..cf85d51 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -36,6 +36,7 @@ repos: exclude: 'can/dbc_template.cc' args: - --error-exitcode=1 + - --language=c++ - --force - --quiet - -j4 diff --git a/Dockerfile b/Dockerfile index cedbce4..4d976a5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,6 @@ -FROM ubuntu:16.04 +FROM ubuntu:20.04 +ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update && apt-get install -y --no-install-recommends \ autoconf \ build-essential \ @@ -30,8 +31,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ 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.7.3 -RUN pyenv global 3.7.3 +RUN pyenv install 3.8.2 +RUN pyenv global 3.8.2 RUN pyenv rehash COPY requirements.txt /tmp/ diff --git a/can/common.cc b/can/common.cc index b303391..d0ace8c 100644 --- a/can/common.cc +++ b/can/common.cc @@ -97,18 +97,17 @@ unsigned int volkswagen_crc(unsigned int address, uint64_t d, int l) { // a magic variable padding byte tacked onto the end of the payload. // https://www.autosar.org/fileadmin/user_upload/standards/classic/4-3/AUTOSAR_SWS_CRCLibrary.pdf - uint8_t *dat = (uint8_t *)&d; uint8_t crc = 0xFF; // Standard init value for CRC8 8H2F/AUTOSAR // CRC the payload first, skipping over the first byte where the CRC lives. for (int i = 1; i < l; i++) { - crc ^= dat[i]; + crc ^= (d >> (i*8)) & 0xFF; crc = crc8_lut_8h2f[crc]; } // Look up and apply the magic final CRC padding byte, which permutes by CAN // address, and additionally (for SOME addresses) by the message counter. - uint8_t counter = dat[1] & 0x0F; + uint8_t counter = ((d >> 8) & 0xFF) & 0x0F; switch(address) { case 0x86: // LWI_01 Steering Angle crc ^= (uint8_t[]){0x86,0x86,0x86,0x86,0x86,0x86,0x86,0x86,0x86,0x86,0x86,0x86,0x86,0x86,0x86,0x86}[counter]; @@ -176,11 +175,9 @@ unsigned int pedal_checksum(uint64_t d, int l) { d >>= ((8-l)*8); // remove padding d >>= 8; // remove checksum - uint8_t *dat = (uint8_t *)&d; - int i, j; for (i = 0; i < l - 1; i++) { - crc ^= dat[i]; + crc ^= (d >> (i*8)) & 0xFF; for (j = 0; j < 8; j++) { if ((crc & 0x80) != 0) { crc = (uint8_t)((crc << 1) ^ poly); diff --git a/can/tests/test_packer_parser.py b/can/tests/test_packer_parser.py index 1fc7d0a..a47009c 100644 --- a/can/tests/test_packer_parser.py +++ b/can/tests/test_packer_parser.py @@ -1,11 +1,9 @@ #!/usr/bin/env python3 - import unittest +import cereal.messaging as messaging from opendbc.can.parser import CANParser from opendbc.can.packer import CANPacker -import cereal.messaging as messaging - # Python implementation so we don't have to depend on boardd def can_list_to_can_capnp(can_msgs, msgtype='can'): @@ -70,7 +68,6 @@ class TestCanParserPacker(unittest.TestCase): ("LKAS_Output", "ES_LKAS", 0), ("LKAS_Request", "ES_LKAS", 0), ("SET_1", "ES_LKAS", 0), - ] checks = []