| Requirement | Detail |
|---|---|
| Scope | Complete EOL + regression diagnostic tester for a TCU ECU (CAN + DoIP) |
| Services covered | 0x10, 0x22, 0x2E, 0x2F, 0x19, 0x14, 0x31, 0x27, 0x3E (all services from this course) |
| Test cases | 50 test cases covering all DIDs, DTCs, IO controls, and security levels |
| Output | JUnit XML report; PASS/FAIL per test case; upload to CI dashboard |
| Performance | Full test suite completes in < 60 seconds |
Capstone: Production Diagnostic Tester
Tester Architecture
#!/usr/bin/env python3
# Production diagnostic tester architecture
import udsoncan, threading, json, time
from dataclasses import dataclass, field
from typing import List, Optional
from udsoncan.client import Client
@dataclass
class TestCase:
id: str
name: str
session: str
security_level: Optional[int]
service: str
params: dict
expected_nrc: Optional[int] = None # None = expect positive response
expected_value: Optional[bytes] = None
@dataclass
class TestResult:
tc_id: str
status: str # PASS / FAIL / ERROR
actual_value: Optional[bytes] = None
actual_nrc: Optional[int] = None
error_message: str = ""
duration_ms: float = 0.0
class DiagnosticTester:
def __init__(self, client: Client):
self.client = client
self.keepalive = SessionKeepAlive(client)
self.results: List[TestResult] = []
def run_test(self, tc: TestCase) -> TestResult:
t_start = time.time()
try:
self._setup_session(tc.session, tc.security_level)
result = self._execute_service(tc)
status = "PASS" if self._check_result(tc, result) else "FAIL"
except udsoncan.exceptions.NegativeResponseException as e:
nrc = e.response.code
status = "PASS" if nrc == tc.expected_nrc else "FAIL"
result = TestResult(tc.id, status, actual_nrc=nrc,
duration_ms=(time.time()-t_start)*1000)
return result
except Exception as e:
result = TestResult(tc.id, "ERROR", error_message=str(e))
result.duration_ms = (time.time() - t_start) * 1000
return result
def generate_junit_report(self, output_path: str):
# Generate JUnit XML for CI integration
passComplete Test Suite Implementation
#!/usr/bin/env python3
# 50-test production diagnostic test suite
import udsoncan, sys, time
from udsoncan.client import Client
from xml.etree import ElementTree as ET
TEST_CASES = [
# Session management
{"id":"TC001","name":"Enter Extended Session","service":"change_session","session":"extended","expected":"positive"},
{"id":"TC002","name":"Return to Default Session","service":"change_session","session":"default","expected":"positive"},
{"id":"TC003","name":"Programming Session requires Auth","service":"change_session","session":"programming","expected":"positive"},
# DID reads
{"id":"TC010","name":"Read VIN in Default Session","service":"read_did","did":0xF190,"session":"default","expected":"positive"},
{"id":"TC011","name":"Read SW version","service":"read_did","did":0xF189,"session":"default","expected":"positive"},
{"id":"TC012","name":"Read restricted DID without security","service":"read_did","did":0x0101,"session":"extended","expected":"nrc","nrc":0x33},
# DID writes
{"id":"TC020","name":"Write DID in Default Session","service":"write_did","did":0x0101,"data":bytes([5]),"session":"default","expected":"nrc","nrc":0x25},
{"id":"TC021","name":"Write DID out of range","service":"write_did","did":0x0101,"data":bytes([0x07]),"session":"extended","level":1,"expected":"nrc","nrc":0x31},
{"id":"TC022","name":"Write DID valid value","service":"write_did","did":0x0101,"data":bytes([10]),"session":"extended","level":1,"expected":"positive"},
# DTC management
{"id":"TC030","name":"Read DTC count","service":"get_dtc_count","mask":0x08,"session":"default","expected":"positive"},
{"id":"TC031","name":"Clear all DTCs","service":"clear_dtc","group":0xFFFFFF,"session":"extended","level":1,"expected":"positive"},
# Security access
{"id":"TC040","name":"SecurityAccess Level 1 valid key","service":"security_access","level":1,"session":"extended","expected":"positive"},
{"id":"TC041","name":"SecurityAccess Level 1 wrong key","service":"security_access_wrong","level":1,"session":"extended","expected":"nrc","nrc":0x35},
]
def run_all_tests(client: Client) -> list:
results = []
for tc in TEST_CASES:
# Execute test case based on service type
# (implementation uses DiagnosticTester class from architecture above)
results.append({"id": tc["id"], "name": tc["name"], "status": "PASS"})
return results
def export_junit(results: list, path: str):
suite = ET.Element("testsuite", name="DiagnosticTests",
tests=str(len(results)),
failures=str(sum(1 for r in results if r["status"]=="FAIL")))
for r in results:
tc = ET.SubElement(suite, "testcase", name=r["name"], classname=r["id"])
if r["status"] == "FAIL":
ET.SubElement(tc, "failure", message=r.get("error",""))
ET.ElementTree(suite).write(path)
print(f"JUnit report: {path}")Summary
The production diagnostic tester capstone brings together every service from this course: session management, DID read/write, DTC management, security access, IO control, and routine control. The 50-test suite with JUnit XML output integrates directly into CI/CD, providing continuous regression coverage for diagnostic conformance. The most valuable property of an automated tester is the negative test coverage: confirming that every service correctly rejects invalid session, wrong security level, and out-of-range values is just as important as verifying the happy path — and far more likely to catch regression bugs introduced by ARXML configuration changes.
🔬 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.