Skip to content

Embedded software: HIL testing and functional safety

B2Bnetwork team · · 6 min

IT in manufacturing

In brief

A HIL (hardware-in-the-loop) test runs a real controller with its target software connected to a real-time simulator that emulates the rest of the system: sensors, actuators and the vehicle or machine network. It lets you check, safely and repeatably, how the controller reacts to faults and boundary conditions you cannot trigger on the real object. In safety-related systems, HIL tests are part of the verification evidence required by functional safety standards: IEC 61508 with its SIL levels and ISO 26262 with its ASIL levels.

From MIL to HIL: test levels for embedded software

Controller software is tested in stages. At each stage a larger part of the system is real:

LevelWhat is realWhat is simulatedWhat it finds
MIL (model-in-the-loop)the algorithm modelthe controlled planterrors in logic and algorithm
SIL (software-in-the-loop)source code compiled for a PCplant and hardwareimplementation errors, deviations from the model
PIL (processor-in-the-loop)code on the target processorplant and peripheralscompiler, execution time and arithmetic issues
HIL (hardware-in-the-loop)the whole controller with softwareplant, sensors, rest of the networkI/O, diagnostics, response time and communication errors
Tests on the real objecteverythingnothingintegration errors with real mechanics and environment

The earlier a defect surfaces, the cheaper it is to fix. MIL and SIL tests run in the CI pipeline on every change, HIL usually in nightly runs and before a release, tests on the real object during final validation. The difference between verification and validation is described in the article Verification vs validation of software.

How a HIL test bench is built

A HIL bench consists of several elements:

  • device under test (DUT): a production or pre-production controller with the target software;
  • real-time simulator: a computer that computes the plant model (engine, battery, drive, hydraulic system) in steps of a millisecond or less;
  • I/O boards: turn model output into voltages, currents and sensor signals, and controller signals into model inputs;
  • rest-of-network simulation: the other controllers on CAN, LIN or Ethernet buses, sending the expected messages;
  • fault injection: open circuits, shorts to ground or supply, noise and corrupted messages;
  • automation and logging: test scripts, a run schedule, signal recording and a report tied to the software version.

The credibility of the result is limited by the plant model. If the battery model does not reproduce the voltage drop at low temperature, the test will not catch a defect that shows up in winter. That is why the model also needs validation against data from the real object, just like a digital twin.

Functional safety: IEC 61508 and ISO 26262

Functional safety is about whether an electronic system responds correctly to faults so that it does not create a hazard for people. IEC 61508 is the base standard for electrical, electronic and programmable electronic safety-related systems. The current edition from 2010 has seven parts and defines four safety integrity levels, SIL 1 to SIL 4. Sector standards for machinery, process industries and railways build on it.

ISO 26262 applies these principles to road vehicles. The ASIL level, from A to D, comes out of hazard analysis and risk assessment, which rates the severity of consequences, the probability of exposure and the driver's ability to control the situation. Functions without safety requirements are marked QM, meaning they are handled by the normal quality management system.

Three things follow from both standards for testing:

  1. Rigor grows with the level. A higher SIL or ASIL means more recommended verification methods, higher coverage requirements and more independence of the people doing verification.
  2. Requirements traceability. Every safety requirement must have tests assigned to it, and every test result must refer to a specific software version and bench configuration.
  3. A suitable environment. The standards do not prescribe one environment, but they require it to be adequate for the purpose of the test. A HIL bench is the typical way to check the response to hardware faults and response times.

Choosing test depth by risk is covered in more depth in the article Risk-based testing.

What to test on a HIL bench

  • Safety functions and the safe state. Whether the controller enters its safe state within the required time after detecting a fault.
  • Diagnostics. Whether an open sensor circuit sets the right fault code and clearing the fault resets it.
  • Power supply. Voltage dips during cranking, overvoltage, power loss and recovery in the middle of a memory write.
  • Communication. A missing message from another controller, a bad checksum, bus overload.
  • Software updates. An interrupted update, rollback to the previous version, compatibility with the rest of the network, as in test automation for OTA updates.
  • Regression. The full automated test suite after every change, run without human involvement.

Most defects usually show up at the boundaries: in handling faults nobody triggered on the developer's desk.

Process and documentation: Automotive SPICE and requirements traceability

Automotive SPICE, maintained by VDA QMC, is a model for assessing software and system development processes in the automotive industry. An assessment assigns processes capability levels from 0 to 5, and vehicle manufacturers often require a specific level from their suppliers. For the test team that means a documented strategy, traceability from requirements to test cases and results, and version control of everything, including the model on the HIL bench.

A few rules help in practice:

  • every HIL run records the version of the software, model, scripts and bench configuration;
  • results flow automatically into the tool where requirements are managed;
  • test cases are reviewed like code, and a requirement change triggers a review of the linked tests;
  • bench time is planned like a production resource, because there are fewer benches than teams.

That is how the team of HIL testers and validation engineers for an R&D center works. Choosing a language for new controllers is covered in the article Rust in critical systems.

Questions and answers

What is the difference between a HIL test and a SIL test?

In a SIL (software-in-the-loop) test the controller code runs on an ordinary computer together with the plant model, without real hardware. In a HIL test it runs on the target controller, and the simulator feeds it real electrical signals. SIL is cheaper and faster, so it runs on every change. HIL finds defects SIL cannot see: in I/O, response times, diagnostics and power supply.

Does ISO 26262 require HIL testing?

The standard does not explicitly mandate a single test environment. It requires the environment to be suitable for the purpose of the test and verification rigor to grow with the ASIL level. HIL tests are the typical way to check how the controller responds to hardware faults and whether it meets the required timing, so in projects with higher ASIL levels they are effectively standard practice.

How does SIL in IEC 61508 differ from SIL as software-in-the-loop?

It is the same acronym for two different things. In IEC 61508, SIL means safety integrity level, from 1 to 4, the required level of risk reduction by a safety function. In testing, SIL means software-in-the-loop, running the code with a plant model on a computer. In documentation it is worth spelling out the acronym on first use.

How do you start testing when there is no hardware yet?

With MIL and SIL tests on a plant model that will later serve the HIL bench. Write test scripts from the start so they can run at every level by changing only the configuration. When a controller prototype arrives, the same test suite moves to the HIL bench, and differences in the results point to hardware and timing issues.

What it looks like in a project

Connecting the shop floor with your business systems? Talk to an engineer who has worked on MES and OT.

Let's talk

Read more: IT in manufacturing