AeroCoder
Open the tools

DO-178C HANDBOOK · CONTENTS

DO-178C HANDBOOK

/

Model-Based Development (DO-331)

Code Generation & Code Verification

Qualified code generators vs verifying the generated code; source-to-model review, equivalence testing and object code.

Desk summary

  • 01There are two ways to gain confidence in generated source code: qualify the code generator (a development tool, DO-330 criteria 1 — TQL-1 at Level A) so its output need not be verified against the model, or use an unqualified generator and verify its output like hand-written code.
  • 02A qualified generator (the SCADE KCG-style approach) can give credit for the source-code objectives of Table MB.A-5 (compliance with LLR and architecture, verifiability, standards, traceability, accuracy and consistency) — only for models inside its qualified input domain, and only if its log shows no errors.
  • 03Verifying the output of an unqualified generator typically combines an automated source-to-model equivalence and traceability checker (a ‘code inspector’ verification tool, TQL-5 or TQL-4 depending on credit), static analysis of the code, and back-to-back model-vs-code testing (MIL → SIL → PIL).
  • 04Neither route removes the downstream obligations: compiler and object code, integration, EOC requirements-based testing on the target, structural coverage of the code (MC/DC plus source-to-object analysis at Level A), data and control coupling, timing and memory.
  • 05Freeze generator version and options; options that optimise away model elements or protective code undermine both traceability and verifiability.

Intuition

Certified translator vs proof-reader

You need a legal contract translated into another language. Either you hire a sworn translator whose qualification the court already accepts — you then check the translator was used properly on a text within their competence — or you use any translator and pay a qualified proof-reader to compare the translation line by line with the original. Either way, someone still has to check that the translated contract works when it is actually executed. The code generator is the translator; the code inspector is the proof-reader; target testing is the execution.

Two routes to trustworthy source code

Route 1: the qualified code generator

A code generator’s output becomes part of the airborne software, so an error in it could insert an error into the product: it meets DO-330 criteria 1. If the applicant wants to skip verification of the generated code against the model, the generator must be qualified at the TQL corresponding to the software level — TQL-1 for Level A, TQL-2 for B, TQL-3 for C, TQL-4 for D. TQL-1 means the generator itself was developed and verified with rigour comparable to Level A airborne software: tool operational requirements, design, MC/DC-level verification of the generator, configuration management, and a qualification data package the applicant reuses and completes in its own environment.

  • —What the credit covers. For models that are correct inputs within the qualified domain, the generated code complies with the model’s LLR and architecture, is verifiable, conforms to the code standard the generator implements, traces to the model, and is accurate and consistent with it — the Table MB.A-5 source code objectives.
  • —Conditions. The model must use only the language features and constraints the qualification covers; generation options must be those qualified; the applicant must check the generation log for errors; and the qualification data must be for the exact tool version used.
  • —What remains for the user. Integration-level properties the generator cannot know: stack usage, worst-case execution time, numerical overflow given real ranges, the interface with hand-written code and the scheduler, compiler behaviour.
  • —Who offers it. Qualified generators exist mainly for formally defined synchronous dataflow/state-machine languages (the SCADE KCG family is the best-known example); some vendors also offer qualifiable generators for other notations.

Model-based development

Why formal languages make generator qualification feasible

A generator can only be qualified against precise requirements for its input language. Synchronous languages with a formal semantics (every operator, clock and type defined mathematically, no ambiguity in execution order) make it possible to state what correct output means for any valid input. That is why the qualified-generator route grew up around formal synchronous notations, while general-purpose modeling environments more often rely on output verification.

Pitfall

‘The generator is qualified, so we are done with code’

A TQL-1 generator removes the need to review the generated source against the model. It does not test the EOC on the target, does not cover the compiler, does not provide structural coverage by itself (unless a specific, accepted model-to-code coverage argument is made), and does not verify the hand-written code around the generated code. Plans that list ‘qualified code generator’ against every verification objective get rejected at SOI #1.

Route 2: unqualified generator, verified output

Most model-based avionics programs using general-purpose dataflow tools take this route: the generator is not qualified, so its output is verified to the Table MB.A-5 objectives exactly as hand-written code would be — but with automation that makes that affordable. The reference helicopter project is an example: its PSAC claims no qualification credit for the modeling, simulation and code generation environment and instead verifies the generated code with a source-to-model inspection tool, code standard checks, run-time error analysis and back-to-back tests.

Manual code review against the model

Always possible, always expensive. Reviewers compare generated functions with model subsystems, checking every operation, data type, constant and execution order. Generated code is regular, so checklists can be specific, but review of thousands of lines of generated code is slow and error-prone. In practice manual review is kept for areas the automated tools do not support (custom code blocks, legacy code integrated into the model, unsupported blocks).

Automated source-to-model equivalence checking

A code inspector tool independently analyses the model and the generated source, and checks that each model element has a structurally equivalent code construct and each code construct traces back to a model element — reporting equivalence and traceability per block, with anything it cannot match flagged for manual review. Because its output is used to satisfy verification objectives (compliance of code with LLR, traceability, accuracy and consistency, part of verifiability), it is a verification tool: criteria 3 (TQL-5) if credit is limited to those objectives, or criteria 2 (TQL-4 at Levels A and B) if its use also justifies reducing other activities. Vendors supply qualification kits; the applicant completes them for its environment.

Practitioner tip

Configure for inspectability

Equivalence checkers support a defined subset of blocks and generator options. Code optimisations that fold, reorder or remove model elements can make code uninspectable. Fix the generator configuration to the checker-compatible set in the model standard (some toolchains provide one switch that disables incompatible optimisations — the reference project’s configuration script sets it) and add an automated check that every airborne model uses it.

Back-to-back equivalence testing (MIL / SIL / PIL)

Back-to-back testing runs the same requirements-based cases on the model (model-in-the-loop, MIL), on the generated code compiled for the host (software-in-the-loop, SIL) and on the code compiled with the target compiler running on a target or target-representative processor (processor-in-the-loop, PIL), then compares outputs within defined tolerances. It catches generator, compiler and arithmetic differences on exercised paths and builds confidence cheaply, but because it is test-based it does not by itself prove equivalence everywhere — it complements inspection or qualification rather than replacing them. PIL results on the target compiler and processor are also a natural bridge toward EOC testing.

Worked example

AHRS voter through MIL, SIL and PIL

The voter’s requirements-based simulation cases (three valid, two valid, single valid, none valid, transitions between them, values at the ±180-degree wrap) are run on the model, then on host-compiled generated code with code coverage measured, then on the target processor with the flight compiler. Differences beyond tolerance would point at a type, rounding or compiler issue; the reference project archives the host-code (SIL) requirements-based report alongside the model simulation report so the two can be compared directly.

c

/* Illustrative shape of generated code with model traceability tags */
/* Model: AHRS_voter  Subsystem: Mid_Value  Block: <S3>/Switch */
if (rtu_valid_count == 3U) {
  /* <S3>/MinMax: middle value of three sources */
  rty_theta_voted = mid3(rtu_theta1, rtu_theta2, rtu_theta3);
} else if (rtu_valid_count == 2U) {
  /* <S1>/Avg_Value: average of the two valid sources */
  rty_theta_voted = avg_valid(rtu_theta1, rtu_theta2, rtu_theta3, rtu_valid);
} else {
  /* <S4>/Single_Value */
  rty_theta_voted = single_valid(rtu_theta1, rtu_theta2, rtu_theta3, rtu_valid);
}

What each approach gives you

Credit by verification strategy for generated source (illustrative; agree in the PSAC)

Objective (Table MB.A-5 unless noted)Qualified generator (TQL-1)Code inspector (qualified verification tool)Back-to-back testingManual review
Source complies with LLR (design model)Credited by qualificationYes (equivalence report + review of unsupported parts)Supporting evidence onlyYes
Source complies with architectureCreditedPartly (interfaces, call structure) + reviewNoYes
Source is verifiableCreditedPartly + reviewNoYes
Source conforms to standardsCredited (generator’s coding rules)No — use a code standard checkerNoYes
Source traceable to LLRCreditedYes (traceability report)NoYes
Source accurate and consistentCredited, plus user checks of stack, timing, overflowPartly; add run-time error analysis, stack and WCETPartlyPartly
EOC complies with / robust to HLR and LLR (MB.A-6)Not creditedNot creditedPIL contributes; final tests on targetNot credited
Structural coverage of code (MB.A-7)Only via an accepted model-to-code coverage argumentNot creditedCoverage measured during SIL/PIL/target runsNot credited

Note

Two paths can be better than one

Rierson points out that when confidence in one tool path is limited, using two independent ones — for example a qualified generator plus independent back-to-back testing, or two dissimilar toolchains for dissimilar lanes of a flight control computer — increases confidence and reduces the risk of a common tool error across redundant channels.

The obligations that remain on every route

  • —Compiler and object code. The compiler is not qualified (DO-178C §4.4.2 expects its options and limitations to be controlled instead); its correctness is covered by testing the EOC. At Level A, if structural coverage is measured on source, an analysis must show that object code not directly traceable to source is verified (source-to-object code traceability, §6.4.4.2.b).
  • —Requirements-based testing of the EOC on the target (Table MB.A-6), normal range and robustness, against HLR and LLR — simulation cases are usually reused here.
  • —Structural coverage of the code at the criterion for the level (statement, decision, MC/DC), including hand-written code, unless an accepted argument derives it from model coverage — see Model Coverage Analysis.
  • —Data and control coupling between generated components, hand code and the RTOS — see Data & Control Coupling.
  • —Resource analyses: worst-case execution time, stack, memory, numerical overflow with real ranges.
  • —Integration: build and load data reviewed; generated code integrated with drivers and scheduler per the architecture — see Integration & Executable Object Code.
  • —Configuration management of generator version, options, configuration sets and generated files; regeneration must be reproducible.

What the auditor looks for

Questions on code generation

Is the generator qualified, at which TQL, for which version and options, and what does the qualification cover? If not, how is each Table MB.A-5 objective satisfied for generated code? Which model constructs were outside the inspector’s supported subset, and how were they reviewed? Is the code inspector or static analyser qualified, and at which TQL? Is the generator configuration identical across all airborne models and recorded in the environment configuration index? Where are EOC tests run, and how is structural coverage — and at Level A object-code traceability — achieved?

Tool qualification levels at a glance

DO-178C §12.2 criteria and DO-330 TQL for typical MBD tools

ToolCriteriaLevel ALevel BLevel CLevel D
Code generator whose output is not verified1 (output is part of the software)TQL-1TQL-2TQL-3TQL-4
Code inspector / model checker / simulator used to eliminate or reduce other activities2TQL-4TQL-4TQL-5TQL-5
Code inspector, rule checker, coverage tool, simulator used only for its own objective3TQL-5TQL-5TQL-5TQL-5
Code generator whose output is fully verified—No qualificationNo qualificationNo qualificationNo qualification

Practitioner tip

Decide the route before choosing the toolchain

The route drives everything: modeling language, block subset, generator options, standard, verification budget and schedule. Write it down in the PSAC early, cross-check with Mapping Tools to Objectives, and see how a real project sequenced it in An End-to-End MBD Workflow and Case Study: Helicopter Flight Control.

Self-check

A Level A project uses an unqualified code generator and a code inspector qualified at TQL-5. The inspector reports full equivalence. Which activity is still required?

Sources & further reading

  • RTCA DO-331 (2011) — MB.6.3.4 source code verification, Annex Tables MB.A-5, MB.A-6, MB.A-7
  • RTCA DO-330 (2011) and DO-178C §12.2 — tool qualification criteria and TQL
  • RTCA DO-178C (2011) — §4.4.2 compiler considerations, §6.4.4.2.b source-to-object code analysis
  • Rierson, Developing Safety-Critical Software (2013), ch. 13 (tool qualification) and ch. 14 (benefit 7, risk 14)
  • Ansys, SCADE Suite methodology handbook for DO-178C/DO-331 — KCG qualification and Table MB.A-5 objective achievement
  • MathWorks, DO Qualification Kit and Simulink Code Inspector documentation; ‘Simulink Code Inspector and Polyspace qualified under DO-330’ (2015)
  • Model-based DO-178C/DO-331 reference project: PSAC tool qualification section, model configuration scripts, AHRS_voter SIL requirements-based test report

← Previous

Model Coverage Analysis

Model-Based Development (DO-331)

Next →

Traceability Through Models

Model-Based Development (DO-331)

On this page

Two routes to trustworthy source codeRoute 1: the qualified code generatorRoute 2: unqualified generator, verified outputWhat each approach gives youThe obligations that remain on every routeTool qualification levels at a glance