System Design

Testing and Validating Embedded Software

A practical guide to testing embedded software: verification vs validation, unit and integration testing, hardware test doubles, HIL, timing and coverage.

On this page
  1. Verification vs validation
  2. Testing levels for embedded software
  3. Integration testing in embedded systems
  4. On-host vs on-target testing
  5. Hardware-in-the-loop testing
  6. Testing what’s unique to embedded
  7. Validating the whole system
  8. Code coverage and traceability
  9. Automating it: continuous integration with hardware
  10. A practical starting plan

Verification vs validation

Two words get used constantly in embedded testing, and they mean different things:

  • Verification asks: did we build the product right? It checks that each piece meets its specification, for example that a driver returns the correct value, or that a function handles every documented input.
  • Validation asks: did we build the right product? It checks that the finished system meets the real needs of its users in its real environment, for example that a thermostat actually keeps a room comfortable, through a winter, with real users.

You need both. Software can pass every verification test and still fail validation because the requirements were wrong or incomplete. If you’re new to the topic, our shorter piece on what embedded testing means gives a quick overview.

Testing levels for embedded software

People sometimes ask about “the stages of testing.” Counts vary between sources, but most embedded teams use some combination of the following levels.

Static analysis and reviews

Before code runs, it can be checked. Static analysis tools examine source code for defects such as null pointer dereferences, buffer overruns, uninitialised variables and violations of coding standards like MISRA C. Code reviews catch logic errors, unclear designs and missed requirements. Both are cheap compared with finding the same bugs on hardware.

Unit testing

Unit tests check individual functions or modules in isolation. In embedded work, they are usually run on a host PC using frameworks such as Unity, CppUTest or GoogleTest, with hardware dependencies replaced by test doubles. Unit tests run in seconds, so they can run on every change.

Integration testing

Integration tests check that modules work correctly together, and that software works correctly with hardware. This is where many embedded defects appear, so it gets its own section below.

System testing

System tests check the complete product against its requirements: functions, performance, power consumption, timing, communication and user interaction. They usually run on production-representative hardware.

Acceptance and field testing

Acceptance tests confirm that the product meets the customer’s or the market’s needs. Field trials put devices into real use, where they meet conditions nobody thought to simulate.

Integration testing in embedded systems

Integration testing in embedded systems has two flavours, and both matter.

Software-software integration

This checks that software modules work together: the application with the communication stack, the sensor driver with the filtering code, tasks sharing data through queues. Typical defects include mismatched data formats or units, incorrect assumptions about who owns a buffer, race conditions between tasks, and errors that are reported by one module but ignored by another.

Hardware-software integration

This checks that the firmware works with the real board: the right pins, the right clock settings, correct bus timing, correct responses from sensors, and correct behaviour when power is applied, removed or disturbed. Many defects here are not “bugs” in code alone, such as a missing pull-up resistor or a sensor that needs longer to start than its driver allows. Our article on hardware-software co-design and integration includes a practical board bring-up order and a list of common integration failures.

Integration strategies: big bang, top-down, bottom-up and sandwich

The classic types of integration testing describe the order in which modules are combined:

  • Big bang: integrate everything at once and test. Simple, but when something fails, it can be very hard to tell where the fault is.
  • Bottom-up: start with low-level modules, such as drivers and the HAL, and add higher layers one at a time. This suits embedded work well because it confirms the hardware foundation first. Higher layers are exercised by test drivers until the real ones are added.
  • Top-down: start with the application logic and replace lower layers with stubs, then swap in real modules progressively. Useful for testing behaviour early, before all drivers are ready.
  • Sandwich (hybrid): combine both, working from the top and the bottom toward the middle.

Incremental approaches, whether bottom-up, top-down or sandwich, are generally preferred over big bang for anything beyond a small project, because faults are easier to isolate.

Test doubles for hardware

When the real hardware isn’t available, or you want to test error paths that are hard to provoke, replace hardware-facing modules with test doubles:

  • Stubs return fixed values, such as a temperature sensor that always reads 21 °C.
  • Fakes have simple working behaviour, such as an in-memory flash driver.
  • Mocks check that the code under test made the expected calls in the expected order, such as verifying that the driver wrote the correct register before reading.

A well-defined hardware abstraction layer makes test doubles much easier to use.

On-host vs on-target testing

  • On-host testing runs code on a development PC. It is fast, cheap and easy to automate, and it doesn’t need hardware. But the compiler, word sizes, memory layout and timing differ from the target, so some defects won’t show up.
  • On-target testing runs code on the real processor or board. It catches compiler and hardware-specific issues, timing problems and resource limits, but it is slower, harder to automate, and needs boards.

Most teams do the bulk of unit testing on the host and run integration and system tests on target, with a subset of unit tests also run on target to catch platform differences.

Hardware-in-the-loop testing

Hardware-in-the-loop (HIL) testing connects the real embedded hardware to a test system that simulates its environment. The test system drives inputs (sensor signals, bus messages, button presses), controls power, and monitors outputs (actuator signals, serial logs, network traffic).

HIL is useful for:

  • Repeating tests exactly, which helps catch intermittent faults.
  • Simulating conditions that are dangerous, expensive or rare in real life, such as sensor failures, power loss during a flash write, or extreme inputs.
  • Running large regression suites automatically against each firmware build.

HIL setups range from a simple rig with a USB relay board, a programmable power supply and a serial adapter, to commercial real-time simulators used in automotive and aerospace work. In model-based projects, HIL is the final stage after model-in-the-loop, software-in-the-loop and processor-in-the-loop testing, which we describe in our article on model-based design and UML.

Testing what’s unique to embedded

Timing and real-time behaviour

Measure how long critical code paths take, and check that deadlines are met under worst-case conditions, not just typical ones. Techniques include toggling a GPIO pin around a code section and measuring it with an oscilloscope or logic analyser, using the processor’s cycle counter, and using trace tools. Safety-critical projects may require formal worst-case execution time analysis.

Interrupts and concurrency

Defects involving interrupts and tasks are often timing-dependent and intermittent. Test with high interrupt loads, vary timing deliberately, and use stress tests that run for hours. Review shared data access carefully; static analysis and RTOS-aware debugging tools can help find race conditions and priority inversion.

Resource limits

Check stack usage (for example by filling the stack with a known pattern and checking how much was overwritten), heap usage if dynamic allocation is used, flash and RAM headroom, and CPU load. Running out of stack is a classic source of baffling embedded failures.

Fault handling and robustness

Test what happens when things go wrong: a sensor disconnects, a bus locks up, a message is corrupted, power drops mid-operation, the watchdog fires. Fault injection, whether in software through test doubles or physically through a HIL rig, is the main way to exercise these paths. Fuzz testing of communication interfaces can also uncover robustness and security issues.

Validating the whole system

Validation confirms that the complete product does its job for real users in real conditions. That includes functional behaviour, performance, power consumption and battery life, usability, and behaviour over long periods.

Environmental and EMC testing

Embedded products live in the physical world, so validation often includes:

  • Temperature and humidity testing across the rated operating range.
  • Vibration and shock testing for products that move or get dropped.
  • Electromagnetic compatibility (EMC) testing, which checks that the device doesn’t emit excessive interference and tolerates interference from its environment. Many markets require EMC compliance before sale.
  • Power quality testing, such as brownouts, surges and supply noise.

These tests often reveal problems that no amount of software testing would find, such as a reset caused by electrostatic discharge, or a sensor reading that drifts with temperature.

Code coverage and traceability

Code coverage measures how much of the code your tests exercise. Common measures, in increasing order of rigour, are:

  • Function coverage: was each function called?
  • Statement coverage: was each statement executed?
  • Branch (decision) coverage: was each branch of each decision taken both ways?
  • Modified condition/decision coverage (MC/DC): was each condition in a decision shown to independently affect the outcome?

Safety standards specify coverage expectations according to the criticality of the software; MC/DC is associated with the highest levels in some aerospace and automotive contexts. Coverage tells you what wasn’t tested; high coverage doesn’t by itself prove the tests check the right things.

Traceability links requirements to design, code and tests, so you can show every requirement has been verified and assess the impact of changes. Standards such as DO-178C, ISO 26262, IEC 62304 and IEC 61508 expect it.

Automating it: continuous integration with hardware

Continuous integration (CI) builds and tests the firmware automatically on every change. A practical embedded CI pipeline might:

  1. Build the firmware for each target configuration and check for compiler warnings.
  2. Run static analysis.
  3. Run host-based unit tests and report coverage.
  4. Flash the build onto boards connected to a test machine, and run integration tests over serial, debug probe or a HIL rig.
  5. Archive the build artefacts, test results and logs so any failure can be reproduced.

Even one board on a lab bench connected to a CI runner can catch many regressions before they reach a release.

A practical starting plan

If your project has little testing today, a sensible order is:

  1. Turn on all compiler warnings and add a static analysis tool.
  2. Introduce a hardware abstraction layer and start unit-testing new logic on the host.
  3. Write a small set of on-target smoke tests: boot, peripherals respond, main functions work.
  4. Automate those tests in CI with one board.
  5. Add fault injection and long-duration stress tests for the riskiest areas.
  6. Plan environmental and EMC validation early, especially if certification is required.

Testing fits into every stage of the embedded development life cycle, not just the end. The earlier a defect is found, the cheaper it usually is to fix.

The complete guide to system design

Introduction to Embedded System Design: The Design Flow
Read the guide

Keep exploring

Guides from other topics

All topics →