| Step | Activity | Tool |
|---|---|---|
| 1 | Build speed controller SiL binary | CMake + GCC with coverage flags |
| 2 | Write first BVA test case | Python pytest |
| 3 | Run test; verify PASS | pytest -v |
| 4 | Generate coverage report | gcov + lcov + genhtml |
| 5 | Identify first coverage gap | lcov HTML report |
Lab: First Virtual Test Execution
Exercise 1: CMake SiL Build Configuration
cmake_minimum_required(VERSION 3.20)
project(SpeedController_SiL C)
# SiL build preset: x86-64 host, with coverage
set(CMAKE_C_STANDARD 99)
add_compile_options(-O0 -g --coverage -fprofile-arcs -ftest-coverage
-DSIL_BUILD=1 # disables hardware-specific code
-Wall -Wextra)
add_link_options(--coverage)
# Production source files (same as target build)
set(PROD_SOURCES
src/SpeedController.c
src/SpeedController_data.c
src/FaultManager.c
)
# SiL stub files (replace MCAL hardware drivers)
set(STUB_SOURCES
stubs/Adc_Stub.c
stubs/Can_Stub.c
stubs/Dio_Stub.c
stubs/Os_Stub.c
)
add_library(SpeedController_sil SHARED
${PROD_SOURCES} ${STUB_SOURCES}
)
target_include_directories(SpeedController_sil PUBLIC
include/
include/autosar/
stubs/
)Exercise 2: First pytest Test Case
"""SiL test suite for SpeedController component."""
import ctypes
import pytest
import os
LIB_PATH = os.path.join(os.path.dirname(__file__),
"../build/libSpeedController_sil.so")
@pytest.fixture(scope="module")
def sil():
"""Load SiL shared library once per test module."""
lib = ctypes.CDLL(LIB_PATH)
# Declare function signatures
lib.SpeedController_Init.restype = None
lib.SpeedController_Step.restype = None
lib.SiL_SetSpeedRef.argtypes = [ctypes.c_float]
lib.SiL_SetVehicleSpeed.argtypes = [ctypes.c_float]
lib.SiL_GetPedalRequest.restype = ctypes.c_float
lib.SiL_GetFaultActive.restype = ctypes.c_uint8
lib.SpeedController_Init()
return lib
def step(sil, speed_ref: float, vehicle_speed: float) -> dict:
sil.SiL_SetSpeedRef(ctypes.c_float(speed_ref))
sil.SiL_SetVehicleSpeed(ctypes.c_float(vehicle_speed))
sil.SpeedController_Step()
return {
"pedal": sil.SiL_GetPedalRequest(),
"fault": bool(sil.SiL_GetFaultActive())
}
class TestSpeedControllerNominal:
def test_zero_error_zero_pedal(self, sil):
"""When speed matches reference, pedal should be near zero."""
out = step(sil, speed_ref=50.0, vehicle_speed=50.0)
assert abs(out["pedal"]) < 1.0
assert out["fault"] == False
def test_positive_error_positive_pedal(self, sil):
"""When vehicle is slower than reference, pedal should be positive."""
out = step(sil, speed_ref=80.0, vehicle_speed=60.0)
assert out["pedal"] > 0.0
def test_speed_above_limit_triggers_fault(self, sil):
"""Speed above 120 km/h limit must activate fault flag."""
out = step(sil, speed_ref=130.0, vehicle_speed=125.0)
assert out["fault"] == TrueSummary
The first virtual test execution lab establishes the three components every SiL test project needs: a CMake build preset that compiles production code for the host with MCAL stubs and coverage instrumentation, a pytest test module that loads the compiled shared library and drives inputs via the stub API, and a coverage report that identifies the first gaps. The shared library approach (compiling the SiL binary as a .so/.dll) is preferred over subprocess-based testing because it enables direct function calls without serialisation overhead and allows the coverage instrumentation to capture data from every call. Running this setup in under 30 minutes is the first milestone for any new MBD project adopting SiL testing.
🔬 Deep Dive — Core Concepts Expanded
This section builds on the foundational concepts covered above with additional technical depth, edge cases, and configuration nuances that separate competent engineers from experts. When working on production ECU projects, the details covered here are the ones most commonly responsible for integration delays and late-phase defects.
Key principles to reinforce:
- Configuration over coding: In AUTOSAR and automotive middleware environments, correctness is largely determined by ARXML configuration, not application code. A correctly implemented algorithm can produce wrong results due to a single misconfigured parameter.
- Traceability as a first-class concern: Every configuration decision should be traceable to a requirement, safety goal, or architecture decision. Undocumented configuration choices are a common source of regression defects when ECUs are updated.
- Cross-module dependencies: In tightly integrated automotive software stacks, changing one module's configuration often requires corresponding updates in dependent modules. Always perform a dependency impact analysis before submitting configuration changes.
🏭 How This Topic Appears in Production Projects
- Project integration phase: The concepts covered in this lesson are most commonly encountered during ECU integration testing — when multiple software components from different teams are combined for the first time. Issues that were invisible in unit tests frequently surface at this stage.
- Supplier/OEM interface: This is a topic that frequently appears in technical discussions between Tier-1 ECU suppliers and OEM system integrators. Engineers who can speak fluently about these details earn credibility and are often brought into critical design review meetings.
- Automotive tool ecosystem: Vector CANoe/CANalyzer, dSPACE tools, and ETAS INCA are the standard tools used to validate and measure the correct behaviour of the systems described in this lesson. Familiarity with these tools alongside the conceptual knowledge dramatically accelerates debugging in real projects.
⚠️ Common Mistakes and How to Avoid Them
- Assuming default configuration is correct: Automotive software tools ship with default configurations that are designed to compile and link, not to meet project-specific requirements. Every configuration parameter needs to be consciously set. 'It compiled' is not the same as 'it is correctly configured'.
- Skipping documentation of configuration rationale: In a 3-year ECU project with team turnover, undocumented configuration choices become tribal knowledge that disappears when engineers leave. Document why a parameter is set to a specific value, not just what it is set to.
- Testing only the happy path: Automotive ECUs must behave correctly under fault conditions, voltage variations, and communication errors. Always test the error handling paths as rigorously as the nominal operation. Many production escapes originate in untested error branches.
- Version mismatches between teams: In a multi-team project, the BSW team, SWC team, and system integration team may use different versions of the same ARXML file. Version management of all ARXML files in a shared repository is mandatory, not optional.
📊 Industry Note
Engineers who master both the theoretical concepts and the practical toolchain skills covered in this course are among the most sought-after professionals in the automotive software industry. The combination of AUTOSAR standards knowledge, safety engineering understanding, and hands-on configuration experience commands premium salaries at OEMs and Tier-1 suppliers globally.