changxiushanwu / dSpace_pytest

Tutorial on using pytest to simplify dSpace HIL tests.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

dSpace HIL Testing with pytest

For the purposes of this article I will follow a fake company "Common Motors" and the evolution of testing software for each of their three product lines: Vans, Cars, & Trucks.

1. Manual Testing

On Vehicle Testing

In the dark ages, before the days of hardware in the loop testing, it was a test engineer or technician's job to test everything. This means that with every release of software they had to sit down and validate all of the features in the software that was released.

For example, in the case of our CM Truck line, a software checkout will have started with an engineer sitting in the "CM Truck 101" following a simple checklist:

  • Flash Software
  • Key On
  • [] Start Engine
    • [] Check Idle
    • [] Check Red Line
  • [] Test Turn
    • [] Left
    • [] Right
  • [] Brake Lights
  • [] ...

As time went on managers and engineers both realized this was time consuming and expensive. You had to schedule time to get on a prototype vehicle, the vehicle was unable to do other testing to do a software checkout, etc.

Then along came bench testing.

Bench Testing

2. Automated Testing

In most cases hardware in the loop testing grew organically and in parrallel over time. For most hardware grou

in the loop testing grew organically and often in parallel.

In most instances this meant

keyswitch.py:

import rtplib2
import CANape

platformIdentifier = "SCALEXIO"
applicationPath = r"C:\TurnSignal_SCALEXIO\BuildResult\turnlamp.sdf"
appl = rtplib2.Appl(applicationPath, platformIdentifier)

canape = canapy.CANape(a2l="turnlamp.a2l",
                       channels=["TurnSignalLevel"])

...

turnSignalLeverValue = appl.Variable("Model Root/TurnSignalLever[-1..1]/Value")

for turn_value in [0.0, 0.5, 1.0]:
    turnSignalLeverValue.Write(turn_value)
    assert canape.TurnSignalLevel == turn_value

...

app.close()
del app

3. pytest

pytest is a mature full-featured Python testing tool that helps you write better programs. - pytest.org

A software test fixture sets up the system for the testing process by providing it with all the necessary code to initialize it, thereby satisfying whatever preconditions there may be. - Wiki: Software Test Fixture

conftest.py:

import pytest

@pytest.fixture(scope="module",)
def app(request):
    platformIdentifier = "SCALEXIO"
    applicationPath = r"C:\TurnSignal_SCALEXIO\BuildResult\turnlamp.sdf"
    app = rtplib2.Appl(applicationPath, platformIdentifier)
    yield app
    app.close()
    del app

@pytest.fixture(scope="module")
def canape(request):
    yield canapy.CANape(a2l="turnlamp.a2l",
                       channels=["TurnSignalLevel"])
    

test_turnsignal.py:

def test_left(app, canape):
    turnSignalLeverValue = appl.Variable("Model Root/TurnSignalLever[-1..1]/Value")

    for turn_value in [0.0, 0.5, 1.0]:
        turnSignalLeverValue.Write(turn_value)
        assert canape.TurnSignalLevel == turn_value

Jenkins

Continuous integration

Further Reading/Watching/Listening

Articles

pytest

Jenkins / Continous Integration

YouTube

pytest

Jenkins

Podcasts

pytest

Jenkins

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

About

Tutorial on using pytest to simplify dSpace HIL tests.

License:BSD 2-Clause "Simplified" License


Languages

Language:Python 100.0%