Skip to content

Commit

Permalink
Segmentation API defined + pyroma fix + safety automated in CI (#111)
Browse files Browse the repository at this point in the history
- pyroma execution fix
- payload attribute remuval for packet classes
- add dependency checking with safety package
- define UDS Segmentation API
- prepare user documentation for Segmentation
- update Segmentation chapter in knowledge base
  • Loading branch information
mdabrowski1990 authored Sep 25, 2021
1 parent cb07777 commit 7199236
Show file tree
Hide file tree
Showing 17 changed files with 552 additions and 95 deletions.
125 changes: 79 additions & 46 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,30 @@ jobs:
python-version: [3.7, 3.8, 3.9]

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}

- name: Install project dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools
pip install -r requirements.txt
- name: Install external packages used for dynamic tests
run: |
pip install -r tests/requirements_for_software_tests.txt
- name: Execute unit tests [pytest]
run: |
pytest --cov-report term-missing --cov=uds tests/software_tests -m "not integration"
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}

- name: Install project dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools
pip install -r requirements.txt
- name: Execute integration tests [pytest]
run: |
pytest tests/software_tests -m integration
- name: Install external packages used for dynamic tests
run: |
pip install -r tests/requirements_for_software_tests.txt
- name: Execute unit tests [pytest]
run: |
pytest --cov-report term-missing --cov=uds tests/software_tests -m "not integration"
- name: Execute integration tests [pytest]
run: |
pytest tests/software_tests -m integration
static_code_analysis:
Expand All @@ -46,27 +46,60 @@ jobs:
python-version: [3.7, 3.8, 3.9]

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}

- name: Install project dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools
pip install -r requirements.txt
- name: Install external packages used for static tests
run: |
pip install -r tests/requirements_for_static_code_analysis.txt
- uses: actions/checkout@v2

- name: Uninstall pylint-django (due to issue https://github.com/PyCQA/prospector/issues/443)
run: |
pip uninstall pylint-django -y
- name: Execute static code analysis [prospector]
run: |
prospector --profile tests/prospector_profile.yaml uds
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}

- name: Install project dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools
pip install -r requirements.txt
- name: Install external packages used for static tests
run: |
pip install -r tests/requirements_for_static_code_analysis.txt
- name: Uninstall pylint-django (due to issue https://github.com/PyCQA/prospector/issues/443)
run: |
pip uninstall pylint-django -y
- name: Execute static code analysis [prospector]
run: |
prospector --profile tests/prospector_profile.yaml uds
- name: Execute static code analysis [pyroma]
run: |
pyroma -a .
dependency_checks:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}

- name: Install project dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools
pip install -r requirements.txt
- name: Install external packages used for dependency scanning
run: |
pip install -r tests/requirements_for_dependency_scanning.txt
- name: Execute dependency scanning [safety]
run: |
safety check --full-report
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Welcome to UDS documentation!
Home <self>
pages/installation.rst
pages/message.rst
pages/segmentation.rst
pages/transport.rst
pages/client_simulation.rst
pages/server_simulation.rst
Expand Down
16 changes: 14 additions & 2 deletions docs/source/pages/knowledge_base/segmentation.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
.. _knowledge-base-segmentation:

.. _knowledge-base-desegmentation:

Segmentation
============


.. _knowledge-base-message-segmentation:

Message Segmentation
--------------------
If diagnostic message data to be transmitted does not fit into a single frame, then segmentation process is required
to divide :ref:`diagnostic message <knowledge-base-diagnostic-message>` into smaller pieces called
:ref:`UDS packets <knowledge-base-uds-packet>`.


.. _knowledge-base-packets-desegmentation:

Packets Desegmentation
----------------------
Desegmentation is a reverse process to a `message segmentation`_. It transforms one or more
:ref:`UDS packets <knowledge-base-uds-packet>` into a :ref:`diagnostic message <knowledge-base-diagnostic-message>`.
6 changes: 1 addition & 5 deletions docs/source/pages/message.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ UDS Packet
Each UDS packet class provides containers for :ref:`Network Protocol Data Unit (N_PDU) <knowledge-base-uds-packet>`
information that are specific for a communication bus for which this class is relevant.
**Objects of UDS packet classes might be used to execute complex operations** (provided in other subpackages) such as
packets transmission or :ref:`desegmentation <knowledge-base-desegmentation>`.
packets transmission or :ref:`desegmentation <knowledge-base-packets-desegmentation>`.

Implemented UDS packet classes:
- `AbstractUdsPacket`_
Expand All @@ -138,8 +138,6 @@ Properties implemented in :class:`~uds.messages.uds_packet.AbstractUdsPacket` cl
- :attr:`~uds.messages.uds_packet.AbstractUdsPacket.raw_data` - settable
- :attr:`~uds.messages.uds_packet.AbstractUdsPacket.addressing` - settable
- :attr:`~uds.messages.uds_packet.AbstractUdsPacket.packet_type` - readable
- :attr:`~uds.messages.uds_packet.AbstractUdsPacket.packet_type_enum` - readable and abstract (bus specific)
- :attr:`~uds.messages.uds_packet.AbstractUdsPacket.payload` - readable and abstract (bus specific)


UDS Packet Record
Expand Down Expand Up @@ -169,10 +167,8 @@ Properties implemented in :class:`~uds.messages.uds_packet.AbstractUdsPacketReco
- :attr:`~uds.messages.uds_packet.AbstractUdsPacketRecord.direction` - readable
- :attr:`~uds.messages.uds_packet.AbstractUdsPacketRecord.packet_type` - readable
- :attr:`~uds.messages.uds_packet.AbstractUdsPacketRecord.raw_data` - readable and abstract (bus specific)
- :attr:`~uds.messages.uds_packet.AbstractUdsPacketRecord.payload` - readable and abstract (bus specific)
- :attr:`~uds.messages.uds_packet.AbstractUdsPacketRecord.addressing` - readable and abstract (bus specific)
- :attr:`~uds.messages.uds_packet.AbstractUdsPacketRecord.transmission_time` - readable and abstract (bus specific)
- :attr:`~uds.messages.uds_packet.AbstractUdsPacketRecord.packet_type_enum` - readable and abstract (bus specific)


UDS Messages Data
Expand Down
29 changes: 29 additions & 0 deletions docs/source/pages/segmentation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Segmentation
============
Implementation related to :ref:`segmentation <knowledge-base-segmentation>` is located in :mod:`uds.segmentation`
sub-package.


AbstractSegmenter
-----------------
:class:`~uds.segmentation.abstract_segmenter.AbstractSegmenter` defines common API and contains common code for all
segmenter classes. Each concrete segmenter class implements segmentation
`strategy <https://www.tutorialspoint.com/design_pattern/strategy_pattern.htm>`_ for a specific bus.

A **user shall not use** :class:`~uds.segmentation.abstract_segmenter.AbstractSegmenter` **directly**, but one is able
(and encouraged) to use :class:`~uds.segmentation.abstract_segmenter.AbstractSegmenter` implementation with any of its
children classes.

Attributes defined in :class:`~uds.messages.uds_packet.AbstractUdsPacketType` class:
- :attr:`~uds.segmentation.abstract_segmenter.AbstractSegmenter.supported_packet_classes` - readable and abstract (bus specific)
- :attr:`~uds.segmentation.abstract_segmenter.AbstractSegmenter.initial_packet_types` - readable and abstract (bus specific)

Methods defined in :class:`~uds.messages.uds_packet.AbstractUdsPacketType` class:
- :meth:`~uds.segmentation.abstract_segmenter.AbstractSegmenter.is_supported_packet`
- :meth:`~uds.segmentation.abstract_segmenter.AbstractSegmenter.is_supported_packets_sequence`
- :meth:`~uds.segmentation.abstract_segmenter.AbstractSegmenter.is_initial_packet`
- :meth:`~uds.segmentation.abstract_segmenter.AbstractSegmenter.get_consecutive_packets_number`
- :meth:`~uds.segmentation.abstract_segmenter.AbstractSegmenter.is_following_packets_sequence`
- :meth:`~uds.segmentation.abstract_segmenter.AbstractSegmenter.is_complete_packets_sequence`
- :meth:`~uds.segmentation.abstract_segmenter.AbstractSegmenter.segmentation`
- :meth:`~uds.segmentation.abstract_segmenter.AbstractSegmenter.desegmentation`
9 changes: 9 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ classifiers =
package_dir =
=uds
python_requires = >=3.6
keywords =
automotive
vehicle-diagnostic
uds
unified-diagnostic-services
iso14229
iso-14229,
obd
on-board-diagnostic


[options]
Expand Down
6 changes: 3 additions & 3 deletions tests/prospector_profile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ mypy:
vulture:
run: true

pyroma:
bandit: # there is probably no use of it (not applicable for this project), but it is run anyways to make sure everything is secured
run: true

bandit: # there is probably no use of it (not applicable for this project), but it is run anyways to make sure everything is secured
run: true
pyroma:
run: false
1 change: 1 addition & 0 deletions tests/requirements_for_dependency_scanning.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
safety>=1.10.3
18 changes: 6 additions & 12 deletions tests/software_tests/messages/test_uds_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,13 @@ def teardown(self):

# __init__

@pytest.mark.parametrize("packets_records, payload", [
([Mock(payload=[1])], (1,)),
([Mock(payload=[0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00])],
(0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00)),
([Mock(payload=[0x12, 0x34, 0x56]), Mock(payload=(0x78, 0x9A, 0xBC, 0xDE, 0xF0))],
(0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0)),
((Mock(payload=(0,)), Mock(payload=(1, 2)), Mock(payload=(3, 4, 5, 6, 7, 8)), Mock(payload=[9])),
tuple(range(10)))
])
def test_init(self, packets_records, payload):
UdsMessageRecord.__init__(self=self.mock_uds_message_record, packets_records=packets_records)
assert self.mock_uds_message_record.packets_records == packets_records
@pytest.mark.parametrize("payload", [None, [0x1, 0x02], "some message"])
@pytest.mark.parametrize("packets_records", [False, [1, 2, 3, 4], "abcdef"])
def test_init(self, payload, packets_records):
UdsMessageRecord.__init__(self=self.mock_uds_message_record, payload=payload,
packets_records=packets_records)
assert self.mock_uds_message_record.payload == payload
assert self.mock_uds_message_record.packets_records == packets_records

# __validate_packets_records

Expand Down
Empty file.
Loading

0 comments on commit 7199236

Please sign in to comment.