From SWE.1 to SWE.6: How a Requirement Becomes Tested Code

Most explanations of the V-model draw the letter V, label the boxes and stop there. The V only makes sense when you watch something travel through it. In this post I follow one requirement from the moment a system engineer writes it down to the moment a test report says it is met, and look at what each Automotive SPICE software process, SWE.1 to SWE.6, adds on the way.

The project is fictional and simplified on purpose: a rear-view camera ECU, the kind of system I wrote about in How Vehicle Cameras Calibrate Themselves While Driving. Every ID, timing and test result below is illustrative, not data from a real programme. If you want the overview of the process model first, start with What Is Automotive SPICE?.

One requirement, start to finish

The requirement we will follow is a classic. In the United States, FMVSS No. 111 requires the rear-view image to be displayed within 2.0 seconds of the start of a backing event, and a backing event starts when the driver puts the vehicle in reverse. Our fictional carmaker turns that into a system requirement:

SYS-REQ-041: When the driver selects reverse gear, the system shall display the rear camera image within 2.0 s.

It is a good teaching example because it is short, measurable and impossible to meet in software alone. The camera has to power up, the display has to wake, and the software in between has to react to a CAN signal, start a video pipeline and draw guide lines. Every level of the V sees the same requirement in a different form.

The picture below shows the whole journey and the artefact each step produces. The rest of the post walks it from the top left, down to the code, and back up to the top right.

V-model with one requirement: SYS.2 and SYS.3 on the left, SWE.1 to SWE.3 down to the code, SWE.4 to SWE.6 and SYS.4, SYS.5 back up, each right-hand step checking a left-hand artefact
The V-model as one requirement’s journey (illustrative project)

Before software: SYS.2 and SYS.3

Software never receives a regulation directly. By the time the requirement reaches the software team, two system processes have already shaped it.

SYS.2, System Requirements Analysis, turns stakeholder needs (here: a legal rule, plus the carmaker’s own wish for guide lines on the image) into system requirements that can be verified. SYS-REQ-041 is the result. It names the trigger (reverse selected), the observable result (camera image on the display) and the limit (2.0 s).

SYS.3, System Architectural Design, decides which element of the system does what. For our ECU the system architect splits the 2.0 s budget between hardware and software:

  • 800 ms for the camera to power up and deliver a first valid frame, and for the display to wake up (hardware and supplier parts);
  • 1,200 ms for the ECU software, from the gear message on CAN to the first composed frame sent to the display.

This allocation is the most important decision in the whole story. It is made at system level, it is written down, and it becomes the input for the software requirements. If the allocation is vague, every later step argues about whose milliseconds are whose.

FMVSS 111 need becomes SYS-REQ-041, SYS.3 splits 2.0 s into 800 ms hardware and 1,200 ms software, SWE.1 derives SWE-REQ-112, 113 and 114
From regulation to software requirements (illustrative allocation)

SWE.1: Software Requirements Analysis

SWE.1 takes the system requirements and the architecture allocated to software and turns them into software requirements: things the software must do, stated so that a test can prove them. One system requirement rarely becomes one software requirement. Ours becomes three, because the happy path is only part of the job:

IDSoftware requirementDerived fromVerified in
SWE-REQ-112When CAN signal GearPosition changes to R, the software shall send the first camera frame with guide lines to the display within 1,200 ms.SYS-REQ-041, SYS.3 budgetSWE.6 timing test
SWE-REQ-113If no valid camera frame is available within 1,200 ms of reverse being selected, the software shall show the message “Rear camera unavailable”.SYS-REQ-041, diagnosis conceptSWE.6 fault injection
SWE-REQ-114If GearPosition has not been received for more than 100 ms, the software shall treat the gear as unknown and shall not switch to the camera view.CAN communication matrix, safety analysisSWE.6 fault injection

A few things happen here that are easy to skip and expensive to miss:

  • The interface is named. “Reverse selected” becomes a concrete signal, GearPosition, with its message, cycle time (10 ms in our example) and value table from the communication matrix.
  • The negative cases get their own requirements. A frozen CAN bus or a dead camera is exactly where field complaints and safety findings come from.
  • Each requirement gets a verification criterion. SWE.1 does not just write “shall” sentences; it also says how each one will be shown to be met. That is what makes SWE.6 plannable months later.
  • Bidirectional traceability starts. Each software requirement points to its source, and each system requirement allocated to software is covered by at least one software requirement.

The requirements are then agreed with the people who will build and test against them, and that agreement is recorded. A review where the tester asks “how exactly will I measure this?” catches more ambiguity than any template.

SWE.2: Software Architectural Design

SWE.2 decides how the software is cut into components, what flows between them and how they behave over time. For our requirement the architect needs a static view (which components exist and how they talk) and a dynamic view (what happens, in what order, when reverse is selected).

The static view for the camera path has seven components:

Static architecture: ComIn, GearMonitor and ViewManager on the gear path; VideoInput, OverlayRenderer and DisplayOut on the video path; Diagnostics for missing frames
Static view of the camera path (illustrative architecture)

ComIn and GearMonitor turn a CAN signal into a gear value people can trust; ViewManager decides; VideoInput, OverlayRenderer and DisplayOut move pixels; Diagnostics handles the case where the camera never delivers.

The dynamic view is where SWE-REQ-112 really lives. The 1,200 ms is now split again, this time across components. In our example the architect keeps 150 ms as margin and gives the rest away. These numbers are budgets, not measurements: they are targets each component owner designs against, and they are checked again in SWE.5.

Stacked bar of the 1,200 ms software timing budget: ComIn 40, GearMonitor 60, VideoInput 700, OverlayRenderer 150, DisplayOut 100 and 150 ms margin
Illustrative SWE.2 timing budget: six segments summing to 1,200 ms

Two architectural decisions come straight from the requirement. First, VideoInput starts the camera path as soon as GearMonitor reports a candidate R, without waiting for the debounce to finish; if the debounce fails, the frames are thrown away. This parallel start saves around 30 ms of the most expensive segment. Second, the interfaces get explicit value ranges (for example GearPosition 0 to 4, with every other value treated as invalid), because SWE.5 will test exactly those ranges.

SWE.3: Software Detailed Design and Unit Construction

SWE.3 goes one level deeper: each component is broken into units, each unit gets a detailed design, and then the code is written. Let us zoom into one unit, GearMonitor, because it carries SWE-REQ-114 almost on its own.

The detailed design answers the questions the architecture left open:

  • It runs every 10 ms, the cycle time of the gear message.
  • A new value becomes the stable gear only after 3 equal messages in a row (30 ms).
  • If no message arrives for 100 ms, the stable gear becomes UNKNOWN.
  • Raw values outside the defined range are treated as “no valid message”.

The state machine below captures that behaviour, and the code follows it closely:

GearMonitor state machine with states Gear UNKNOWN, Confirming and Gear stable, and a 100 ms timeout back to UNKNOWN
GearMonitor detailed design: three states, timeout from any state
#define GEAR_DEBOUNCE_COUNT   (3u)     /* 3 x 10 ms = 30 ms */
#define GEAR_TIMEOUT_MS       (100u)

typedef enum { GEAR_UNKNOWN = 0, GEAR_P, GEAR_R, GEAR_N, GEAR_D } gear_t;

typedef struct {
    gear_t   stable;
    gear_t   candidate;
    uint8_t  count;
    uint16_t age_ms;
} gear_monitor_t;

/* Called every 10 ms. 'received' is true when a new, in-range CAN value arrived. */
void GearMonitor_Step(gear_monitor_t *gm, bool received, gear_t raw)
{
    if (!received) {
        if (gm->age_ms < GEAR_TIMEOUT_MS) {
            gm->age_ms = (uint16_t)(gm->age_ms + 10u);
        }
        if (gm->age_ms >= GEAR_TIMEOUT_MS) {
            gm->stable = GEAR_UNKNOWN;
            gm->count  = 0u;
        }
    } else {
        gm->age_ms = 0u;
        if (raw == gm->candidate) {
            if (gm->count < GEAR_DEBOUNCE_COUNT) {
                gm->count++;
            }
        } else {
            gm->candidate = raw;
            gm->count     = 1u;
        }
        if (gm->count >= GEAR_DEBOUNCE_COUNT) {
            gm->stable = gm->candidate;
        }
    }
}

Nothing here is clever, and that is the point. The constants carry the numbers from the design, the unit has no hidden state, and every branch maps to a line in the design. The detailed design is also where the unit is linked back to the software requirement, so that a reviewer can see that SWE-REQ-114 is implemented by the timeout branch and not just hoped for.

SWE.4: Software Unit Verification

SWE.4 is the first step up the right-hand side of the V, and it mirrors SWE.3: it checks that each unit does what its detailed design says. Since Automotive SPICE 4.0 this is deliberately called verification, not just testing, because a unit test is only one of several verification measures. For GearMonitor we would plan four:

  1. Unit tests against the detailed design, run on the host and, for selected cases, on the target compiler.
  2. Static analysis against the coding guideline, in our case MISRA C. I wrote about building a realistic strategy for that in MISRA C:2012 Without the Pain.
  3. Code review with a checklist that includes “does every branch trace to the design?”.
  4. Structural coverage of the unit tests, here statement and branch coverage, to find logic that no test exercises.

The unit tests are derived from the detailed design, not from the code. That keeps them honest: a test written by reading the code tends to confirm what the code does, not what it should do.

Test caseStimulusExpectedDesign rule checked
UT-GM-01R, R, RStable gear becomes R on the third messageDebounce 3 x 10 ms
UT-GM-02R, R, N, RStable gear stays UNKNOWN; count restartsDebounce restarts on change
UT-GM-03R stable, then 9 cycles without a message (90 ms)Stable gear stays RTimeout boundary, just below
UT-GM-04R stable, then 10 cycles without a message (100 ms)Stable gear becomes UNKNOWNTimeout 100 ms
UT-GM-05R stable, timeout, then R, R, RR again after three messagesRecovery after timeout

In code, the first test looks like this (Unity-style asserts):

void test_reverse_is_stable_after_three_messages(void)
{
    gear_monitor_t gm = {GEAR_UNKNOWN, GEAR_UNKNOWN, 0u, 0u};

    GearMonitor_Step(&gm, true, GEAR_R);
    GearMonitor_Step(&gm, true, GEAR_R);
    TEST_ASSERT_EQUAL(GEAR_UNKNOWN, gm.stable);

    GearMonitor_Step(&gm, true, GEAR_R);
    TEST_ASSERT_EQUAL(GEAR_R, gm.stable);
}

The results are recorded with the version of the code they ran against, and the test cases are linked to the detailed design. That link is what lets you answer, later, “which unit tests do I rerun if the debounce changes?” in seconds instead of hours.

SWE.5: Software Component Verification and Integration Verification

SWE.5 mirrors SWE.2. Units that each work on their own are put together step by step, and at each step you check that they work together the way the architecture says. For our requirement, “the way the architecture says” means three concrete things: the interfaces carry the agreed values, the components run in the agreed order, and each segment stays inside its timing budget.

The integration is done in increments, so that a failure points to a small set of suspects:

  1. Gear path on the host. ComIn, GearMonitor and ViewManager run together, fed with recorded CAN traces from a test vehicle, including traces with dropped messages and invalid values.
  2. Full camera path in software-in-the-loop. VideoInput, OverlayRenderer and DisplayOut join, with the camera replaced by a recorded video stream.
  3. Everything on the target ECU. The same tests run on the real hardware with the real operating system, the real camera and a display simulator, so that timing and resource use become real.

On the target, each segment is timed with instrumentation points at the component boundaries and compared with the SWE.2 budget. In our story, one segment does not fit:

SegmentBudget (ms)Measured, worst of 200 runs (ms)Result
ComIn4022Within budget
GearMonitor6041Within budget
VideoInput700760Over by 60 ms
OverlayRenderer150118Within budget
DisplayOut10084Within budget

VideoInput is 60 ms over its budget. The total still fits, because the other segments are under budget and the architect kept 150 ms of margin. A weak process would stop there. A good one records the deviation, decides it consciously (accept for this release, open an improvement item on the video receiver initialisation) and updates the architecture so that the budget table matches reality. SWE.5 is also where CPU load and memory use are checked against the limits the architecture set, because a camera pipeline that meets its timing at 95 % CPU load will not survive the next feature.

SWE.6: Software Verification

SWE.6 closes the software part of the V. It mirrors SWE.1: the integrated software, on the target, is verified against the software requirements, and nothing else. It no longer matters how VideoInput is built; what matters is whether SWE-REQ-112, 113 and 114 are met, measured at the software’s own boundary.

For SWE-REQ-112 the test runs on a hardware-in-the-loop bench. The bench sends the GearPosition message, the ECU runs its real software, and a capture card on the video output timestamps the first frame that contains guide lines. One measurement is not evidence for a timing requirement, so the test repeats the reverse engagement 1,000 times, under different conditions: cold and warm start, other CAN traffic, the ECU’s other functions busy.

The chart below shows our invented results. All 1,000 runs met the limit. The worst case was 1,138 ms, 62 ms below 1,200 ms. That margin is thinner than the 150 ms the architect planned, which is exactly the VideoInput overrun found in SWE.5 showing up again. The test report says so in one sentence, because the next person to add a feature to this ECU needs to know it.

Histogram of 1,000 HIL reverse engagements; all below the 1,200 ms limit, worst case 1,138 ms
Invented HIL results: 1,000 reverse engagements in 20 ms bins

The negative requirements are verified by fault injection on the same bench:

  • SWE-REQ-113: the camera is disconnected, and the test checks that “Rear camera unavailable” appears and that the expected fault is stored.
  • SWE-REQ-114: the gear message is stopped for 90 ms and for 110 ms, and the test checks that the camera view does not start on stale data.

The test cases are selected and recorded with the release scope. When a later release changes only the overlay colours, the traceability tells you which of these tests to rerun, and the regression strategy says why the rest can be skipped.

The thread that holds it together: traceability

If you look back at the journey, every step left an artefact with an ID, and every artefact pointed to the one it came from. That chain is not paperwork for the assessor. It is what turns a change request from a week of meetings into an afternoon of work.

Here is a realistic one. Halfway through the project, purchasing switches to a cheaper camera. The new camera needs 200 ms longer to deliver its first valid frame. Follow the change down the chain:

  1. SYS.3: the hardware part of the 2.0 s budget grows from 800 ms to 1,000 ms, so the software allocation shrinks from 1,200 ms to 1,000 ms.
  2. SWE.1: SWE-REQ-112 and SWE-REQ-113 change from 1,200 ms to 1,000 ms. SWE-REQ-114 is untouched.
  3. SWE.2: the timing budget no longer fits. VideoInput alone needs 760 ms. The architect has to find 200 ms, for example by starting the camera path when the driver presses the brake with the gear lever in P, before reverse is even selected.
  4. SWE.3 and SWE.4: ViewManager and VideoInput change, their unit tests change. GearMonitor does not change, so its unit tests do not need to be rerun.
  5. SWE.5 and SWE.6: the timing measurements and the HIL latency test are rerun. Last time the worst case was 1,138 ms; against the new 1,000 ms limit it would fail without the redesign.

Without traceability, someone has to remember all of this. With it, a query from the changed system requirement lists the affected software requirements, components, units and tests, and the impact analysis is a review of that list rather than an archaeology project. The picture below shows the ripple.

Impact of a camera change request through SYS.3 and SWE.1 to SWE.6: 12 artefacts change or are rerun, 3 are traced and found untouched
Impact analysis of one change request (illustrative project)

What I take away

  • The V is about pairs, not phases. Each step on the left creates something that a step on the right checks: SWE.1 with SWE.6, SWE.2 with SWE.5, SWE.3 with SWE.4. If you know which artefact a test checks, you understand the model.
  • Numbers travel down and evidence travels up. 2.0 s became 1,200 ms, then a budget per component, then constants in C. The evidence went the other way: unit results, segment timings, 1,000 HIL runs.
  • The negative requirements are where the work is. The happy path took one requirement; the missing camera and the silent bus took two more, and most of the interesting tests.
  • Deviations found early are cheap. The VideoInput overrun was visible in SWE.5, months before a vehicle test would have shown a thin margin.
  • Traceability pays for itself on the first change request. Not on the day of the assessment.

Sources

The rear-view camera project, its requirement IDs, budgets, code and test results are fictional and simplified for teaching. Cover photo by Markus Spiske on Unsplash.