# 软件在环仿真

软件在环（SIL）仿真是一种验证方法：它将为主机编译的控制软件与一个被控对象仿真模型（即被控物理系统的仿真模型）对接运行，以便在目标硬件尚不存在时检查软件行为。在汽车V模型（V字型汽车开发与验证流程模型）的验证阶梯上，它位于模型在环（MIL）与处理器在环（PIL）测试之间，理想的顺序是MIL、SiL、PiL，然后在系统集成之前进行HiL。<sup>[1](https://sol.sbc.org.br/index.php/sast/article/download/30216/30023/)</sup><sup> • </sup><sup>[2](https://www.analogictips.com/how-do-mil-sil-pil-and-hil-simulation-and-testing-relate-to-mbse-faq/)</sup>

| 关键事实 | 详情 |
|---|---|
| 运行什么 | 为开发计算机编译的生成代码或量产控制代码，作为独立进程与被控对象模型耦合执行<sup>[3](https://www.mathworks.com/help/sltest/ug/back-to-back-equivalence-testing.html)</sup> |
| 核心检查 | 模型仿真与代码结果之间的数值等价性（背靠背测试）<sup>[3](https://www.mathworks.com/help/sltest/ug/back-to-back-equivalence-testing.html)</sup> |
| 时序 | 传统基于主机的SIL通常不实时运行；模型与代码在每个采样周期交换I/O数据，不过RTSiL等实时变体使用实时仿真器运行<sup>[4](https://www.mathworks.com/help/ecoder/ug/about-sil-and-pil-simulations.html)</sup> |
| 速度示例 | 一个指令精确的虚拟ECU在2.4 GHz Intel i5（约40 MIPS）上以实时速度的20倍运行了一个3.5分钟的场景<sup>[5](https://qacf-www.synopsys.com/content/dam/synopsys/verification/presentations/mbenz-chip-simulation-automotive.pdf)</sup> |
| 吞吐量 | 以实时速度的20倍运行，加上测试自动化，测试吞吐量为HiL系统的20倍<sup>[5](https://qacf-www.synopsys.com/content/dam/synopsys/verification/presentations/mbenz-chip-simulation-automotive.pdf)</sup> |
| 覆盖率指标 | 结构覆盖率指标，如判定覆盖、条件覆盖和MCDC覆盖；ISO 26262-6根据ASIL等级对这些指标提出不同要求，例如在较低ASIL等级下以语句覆盖为基线，在ASIL D等级下强烈推荐MCDC<sup>[3](https://www.mathworks.com/help/sltest/ug/back-to-back-equivalence-testing.html)</sup> |
| 关键局限 | 无法对软件是否符合时序要求做出任何断言；目标编译器和处理器效应未被检验<sup>[6](https://elib.dlr.de/46744/1/ics_maibaum.pdf)</sup><sup> • </sup><sup>[4](https://www.mathworks.com/help/ecoder/ug/about-sil-and-pil-simulations.html)</sup> |

## 工作原理

在SIL测试中，控制器不再是[框图](https://www.edgepedia.org/zh/block-diagram)，而是可执行代码。生成的C或C++源代码为开发计算机编译，并作为独立于Simulink模型其余部分的进程运行；在每个采样周期，模型和目标代码通过通信通道交换输入和输出数据。<sup>[3](https://www.mathworks.com/help/sltest/ug/back-to-back-equivalence-testing.html)</sup><sup> • </sup><sup>[4](https://www.mathworks.com/help/ecoder/ug/about-sil-and-pil-simulations.html)</sup>这与PIL形成对比——在PIL中，源代码被交叉编译，目标代码在目标处理器或指令集仿真器上运行。<sup>[4](https://www.mathworks.com/help/ecoder/ug/about-sil-and-pil-simulations.html)</sup>

核心检查是背靠背（等价性）测试：生成的代码必须产生与模型仿真相同的结果。在一个实例中，正常模式与SIL输出信号之间的差值为零，等价性通过比较记录信号来判定。<sup>[3](https://www.mathworks.com/help/sltest/ug/back-to-back-equivalence-testing.html)</sup>覆盖率和代码执行剖析在同一次运行中收集。<sup>[4](https://www.mathworks.com/help/ecoder/ug/about-sil-and-pil-simulations.html)</sup>

工业虚拟ECU扩展了这一理念。dSPACE将从真实量产代码构建的虚拟ECU分为五个抽象等级；三级V-ECU包含基础软件的量产代码，用于ECU及多ECU集成测试，而四级需要对硬件相关代码进行指令集仿真。<sup>[7](https://www.dspace.com/en/pub/home/news/engineers-insights/sil-introduction.cfm)</sup>

## 实施方法

从业者的工作流程从模型到自动化回归：

1. **准备模型和代码。** 生成量产代码；在AMG DCT案例中，由TargetLink生成的TCU软件和来自Dymola的车辆模型以DLL形式导入QTronic Silver环境。<sup>[8](https://www.synopsys.com/content/dam/synopsys/verification/presentations/amg-testweavercti.pdf)</sup>
2. **为主机编译。** 配置硬件实现设置，如用于主机编译的本机字长；可移植字长可避免在SIL和PIL之间更改设置。<sup>[3](https://www.mathworks.com/help/sltest/ug/back-to-back-equivalence-testing.html)</sup><sup> • </sup><sup>[4](https://www.mathworks.com/help/ecoder/ug/about-sil-and-pil-simulations.html)</sup>
3. **选择运行模式。** SIL/PIL仿真可以作为顶层模型运行，通过Model模块运行，或通过从子系统创建的SIL/PIL模块运行。<sup>[3](https://www.mathworks.com/help/sltest/ug/back-to-back-equivalence-testing.html)</sup>
4. **构建测试夹具和测试用例。** 测试用例和夹具可以自动创建；<sup>[3](https://www.mathworks.com/help/sltest/ug/back-to-back-equivalence-testing.html)</sup>德国宇航中心的SiLEST环境以XML格式定义测试用例，并自动化测试管理访问、仿真初始化、结果分析和符合审计要求的报告归档。<sup>[6](https://elib.dlr.de/46744/1/ics_maibaum.pdf)</sup>TestWeaver等场景生成工具每个版本产生超过3000个本质不同的驾驶场景。<sup>[8](https://www.synopsys.com/content/dam/synopsys/verification/presentations/amg-testweavercti.pdf)</sup>
5. **带容差比较结果。** 对于单精度算法，误差容限可定义为单精度正常仿真结果机器精度的四倍，`tolerance = 4 * eps(single(yout_normal))`。<sup>[3](https://www.mathworks.com/help/sltest/ug/back-to-back-equivalence-testing.html)</sup>

生产级SIL框架还需要C代码构建与调试、标定加载器、XCP/ASAP2支持以及总线分析仪，这些功能在一篇2025年SAE论文中描述为符合[AUTOSAR](https://www.edgepedia.org/zh/autosar)和FMI的内部框架所具备的特性。<sup>[9](https://saemobilus.sae.org/papers/building-house-sil-framework-key-design-choices-features-performance-evaluation-2025-24-0018)</sup>

## 起源

最早有日期记载的公开记录是一篇SAE技术论文，2005-01-0049，该文将SiL技术应用于发动机ECU功能开发，并指出虽然HiL测试是基于模型的ECU开发中最常见的部分，但当时SiL“并不那么常见”。<sup>[10](https://trid.trb.org/View/1803280)</sup>德国宇航中心的SiLEST项目于2007年4月结项，按被测软件与环境之间的耦合类型对HiL、PiL、SiL和MiL测试进行了系统比较。<sup>[6](https://elib.dlr.de/46744/1/ics_maibaum.pdf)</sup>富士通Ten的技术期刊指出，MILS、PILS、HILS和SILS的定义和用法在不同文献中各不相同，并未标准化。<sup>[11](https://www.denso-ten.com/business/technicaljournal/pdf/32-1.pdf)</sup>

该方法源于早期的在环实践。Joseph L. Gross于1967年在《SIMULATION》期刊上描述了用于验证Gemini计算机及其操作程序的实时硬件在环仿真，<sup>[12](https://doi.org/10.1177/003754976700900309)</sup>R. Isermann、J. Schaffnit和S. Sinsel于1999年在《Control Engineering Practice》上发表了关于HIL仿真用于发动机控制系统设计与测试的文章。<sup>[13](https://doi.org/10.1016/s0967-0661%2898%2900205-6)</sup>SIL测试本身并非由一篇奠基性论文确立，而是由其在功能安全框架中的角色所规范：汽车领域的IEC/[ISO 26262](https://www.edgepedia.org/zh/iso-26262)，以及航空航天软件和硬件领域的DO-178/ED-12与DO-254/ED-80。<sup>[14](https://www.mdpi.com/2079-9292/11/15/2462)</sup>

## 变体

各变体的区别在于用什么替代真实控制器和被控对象。MIL在开发早期在虚拟模型上验证控制器设计；SIL在虚拟模型上验证控制器代码；PIL验证在目标硬件上执行的控制器代码；HIL将物理控制器连接到实时仿真的被控对象，成本更高且反馈周期更慢，不过功率硬件在环等专用设置可能包含物理被控对象组件。<sup>[15](https://link.springer.com/article/10.1186/s42162-024-00312-8)</sup>HIL将物理控制器硬件与虚拟实时被控对象配对。<sup>[3](https://www.mathworks.com/help/sltest/ug/back-to-back-equivalence-testing.html)</sup>文献中出现了一个总称X在环（XiL），其中X替换为模型、软件、处理器或硬件，代表被测设计。<sup>[16](https://publications.gc.ca/collections/collection_2023/cnrc-nrc/NR16-370-2021-eng.pdf)</sup>根据系统架构，PIL也可以称为FIL（FPGA在环）。<sup>[2](https://www.analogictips.com/how-do-mil-sil-pil-and-hil-simulation-and-testing-relate-to-mbse-faq/)</sup>

工具链实现在抽象层次上有所不同。MathWorks Simulink为主机编译生成的代码，并提供IEC认证工具包标准（ISO 26262-6、IEC 61508-3、IEC 62304、EN 50128、EN 50657）的鉴定套件，以及针对DO-178C和DO-333目标的DO鉴定套件。<sup>[4](https://www.mathworks.com/help/ecoder/ug/about-sil-and-pil-simulations.html)</sup>dSPACE VEOS运行虚拟ECU，具有确定性、可复现的时间同步，独立于实时条件，在许多情况下比在HIL上更快。<sup>[7](https://www.dspace.com/en/pub/home/news/engineers-insights/sil-introduction.cfm)</sup>

## 应用

**汽车**是主导应用领域。有记录的案例包括发动机管理系统和BIRD微型卫星姿态控制系统的SiL测试，后者的SiL结果与卫星在轨记录行为进行了比较。<sup>[6](https://elib.dlr.de/46744/1/ics_maibaum.pdf)</sup>AMG SPEEDSHIFT DCT控制软件仅在6个软件开发周期内完成开发，每个版本用超过3000个驾驶场景进行测试，整个编译构建循环耗时不到10分钟。<sup>[8](https://www.synopsys.com/content/dam/synopsys/verification/presentations/amg-testweavercti.pdf)</sup>开发了一个将需求簇与vECU分类相关联的矩阵，发现相当一部分HiL需求可以有效地使用vECU进行测试。<sup>[17](https://fis.tu-dresden.de/portal/en/publications/evaluation-of-sil-testing-potentialshifting-from-hil-by-identifying-compatible-requirements-with-vecus%2893e2ed84-1aa7-4d72-930e-51cc1a2d503d%29.html)</sup>

**能源与电力系统**构成第二个领域。2024年的一项范围综述分析了88篇全文文章，发现在能源和电力系统中，基于硬件的范式主要用于测试底层信号，而SIL用于控制策略测试、优化、调度和实验；MATLAB/Simulink是最常用的技术。<sup>[15](https://link.springer.com/article/10.1186/s42162-024-00312-8)</sup>实时软件在环（RTSiL）用风力发电机或发电厂控制器的真实源代码代替专有控制硬件，与[PSCAD](https://www.edgepedia.org/zh/pscad)或RTDS等实时仿真器构成回路，几乎不需要额外硬件。<sup>[18](https://backend.orbit.dtu.dk/ws/portalfiles/portal/413490887/Real-time_software-in-the-loop_EMT_models_of_wind_turbine_and_power_plant_controller_applicability_and_experiences.pdf)</sup>

**持续集成与云扩展**拓展了该方法的应用范围。dSPACE的VEOS平台支持云扩展和24/7执行，并具有ISO 26262推荐的需求、测试用例和测试报告的可追溯性。<sup>[7](https://www.dspace.com/en/pub/home/news/engineers-insights/sil-introduction.cfm)</sup>2025年[约翰迪尔](https://www.edgepedia.org/zh/john-deere)的Karegaonkar及其同事在SAE文章中报告了机器学习代理模型和降阶模型，在保持预期保真度的同时加速仿真，以便编译到SIL和HIL目标上，以及用于测试计划创建和自动化的生成式AI工具，已为自主相关功能累积了数百小时的测试执行。<sup>[19](https://saemobilus.sae.org/articles/leveraging-ai-autonomous-vehicle-simulations-sil-hil-frameworks-2025-28-0271)</sup>

## 局限与替代方案

**时序是主要缺口。** 模型级SiL无法对控制单元软件是否符合时序要求做出断言，而HIL可以，但只能在开发后期使用成本高昂的实时硬件；PiL通过替代接口在接近量产配置的控制单元上运行软件，这会改变时序行为。<sup>[6](https://elib.dlr.de/46744/1/ics_maibaum.pdf)</sup>芯片仿真是指令精确的但不是周期精确的，因此无法精确预测在真实目标上的执行时间。<sup>[5](https://qacf-www.synopsys.com/content/dam/synopsys/verification/presentations/mbenz-chip-simulation-automotive.pdf)</sup>

**编译器和架构效应缺失。** 由于SIL代码是为开发计算机编译的，它不测试为目标硬件编译的代码；需要PIL来验证代码替换优化、编译器优化效应以及有限内存等硬件约束。<sup>[4](https://www.mathworks.com/help/ecoder/ug/about-sil-and-pil-simulations.html)</sup>

**数值不匹配**可能在SIL与量产硬件之间出现，当TLC模块、整数除法舍入、大端字节序或Stateflow自定义代码在主机与目标上的行为不同时。<sup>[4](https://www.mathworks.com/help/ecoder/ug/about-sil-and-pil-simulations.html)</sup>SiL还必须以计算方式仿真车辆的复杂性，并且在仿真真实系统输入方面存在局限。<sup>[1](https://sol.sbc.org.br/index.php/sast/article/download/30216/30023/)</sup>被控对象模型的保真度涉及精度与计算时间之间的权衡。<sup>[15](https://link.springer.com/article/10.1186/s42162-024-00312-8)</sup>

**与HIL的可互换性存在争议。** 一项ABS研究发现SIL响应时间与HIL几乎相同，信号略更平滑，<sup>[20](https://www.mdpi.com/2673-4591/79/1/34)</sup>富士通Ten报告其无ISS的SILS信号波形和时序与HILS结果一致。<sup>[11](https://www.denso-ten.com/business/technicaljournal/pdf/32-1.pdf)</sup>相比之下，一项交通信号研究发现HILS与SILS平台之间的差异大到无法在不影响最终结果的情况下自信地在平台之间切换。<sup>[21](https://journals.sagepub.com/doi/10.1177/0361198118784168)</sup>RTSiL工作同样指出它与HiL并非一一对应，因为SiL中假设了延迟、采样和滤波等硬件依赖性。<sup>[18](https://backend.orbit.dtu.dk/ws/portalfiles/portal/413490887/Real-time_software-in-the-loop_EMT_models_of_wind_turbine_and_power_plant_controller_applicability_and_experiences.pdf)</sup>实际分工源于成本：SIL在每位工程师自己的机器上运行，无需专用硬件，<sup>[20](https://www.mdpi.com/2673-4591/79/1/34)</sup>而HIL对于汽车和航空航天中的时序验证及安全关键功能仍然必要。<sup>[2](https://www.analogictips.com/how-do-mil-sil-pil-and-hil-simulation-and-testing-relate-to-mbse-faq/)</sup>

## References

1. [Rapid review on SiL closed-loop verification in automotive software verification (SBC SAST)](https://sol.sbc.org.br/index.php/sast/article/download/30216/30023/)
2. [How do MIL, SIL, PIL and HIL simulation and testing relate to MBSE?](https://www.analogictips.com/how-do-mil-sil-pil-and-hil-simulation-and-testing-relate-to-mbse-faq/)
3. [Back-to-Back Equivalence Testing, MATLAB & Simulink](https://www.mathworks.com/help/sltest/ug/back-to-back-equivalence-testing.html)
4. [SIL and PIL Simulations, MATLAB & Simulink (MathWorks documentation)](https://www.mathworks.com/help/ecoder/ug/about-sil-and-pil-simulations.html)
5. [Chip Simulation of Automotive ECUs (QTronic Silver, Daimler application)](https://qacf-www.synopsys.com/content/dam/synopsys/verification/presentations/mbenz-chip-simulation-automotive.pdf)
6. [Comparison of Approaches to the Test of Control Unit Software (O. Maibaum, DLR, SiLEST project)](https://elib.dlr.de/46744/1/ics_maibaum.pdf)
7. [Automotive SIL Testing: How do I do it right?, dSPACE](https://www.dspace.com/en/pub/home/news/engineers-insights/sil-introduction.cfm)
8. [Automated Test of the AMG Speedshift DCT Control Software (Synopsys/Silver/TestWeaver)](https://www.synopsys.com/content/dam/synopsys/verification/presentations/amg-testweavercti.pdf)
9. [Building an In-House SIL Framework: Key Design Choices, Features, and Performance Evaluation (SAE 2025-24-0018, Dumarey Softronix)](https://saemobilus.sae.org/papers/building-house-sil-framework-key-design-choices-features-performance-evaluation-2025-24-0018)
10. [Engine ECU Function Development Using Software-in-the-Loop Methodology (SAE Technical Paper 2005-01-0049)](https://trid.trb.org/View/1803280)
11. [Application of ISS-less technology to VirtualCRAMAS (SILS), Fujitsu Ten Technical Journal No. 32](https://www.denso-ten.com/business/technicaljournal/pdf/32-1.pdf)
12. [Joseph L. Gross (1967). Real time hardware-in-the-loop simulation verifies performance of Gemini computer and operational program. SIMULATION.](https://doi.org/10.1177/003754976700900309)
13. [Hardware-in-the-loop simulation for the design and testing of engine-control systems (Control Engineering Practice, 1999)](https://doi.org/10.1016/s0967-0661%2898%2900205-6)
14. [Hardware-in-the-Loop Simulations: A Historical Overview of Engineering Challenges (Electronics 11(15):2462)](https://www.mdpi.com/2079-9292/11/15/2462)
15. [A scoping review of In-the-loop paradigms in the energy sector focusing on software-in-the-loop (Energy Informatics, Springer, 2024)](https://link.springer.com/article/10.1186/s42162-024-00312-8)
16. [Technical Review of Modeling and Simulation-Based Testing of CAV Systems (National Research Council Canada)](https://publications.gc.ca/collections/collection_2023/cnrc-nrc/NR16-370-2021-eng.pdf)
17. [evaluation of sil testing potentialshifting from hil by identifying compatible requirements with vecus(93e2ed84 1aa7 4d72 930e 51cc1a2d503d) (fis.tu-dresden.de)](https://fis.tu-dresden.de/portal/en/publications/evaluation-of-sil-testing-potentialshifting-from-hil-by-identifying-compatible-requirements-with-vecus%2893e2ed84-1aa7-4d72-930e-51cc1a2d503d%29.html)
18. [Real-Time Software-in-the-Loop EMT Models of Wind Turbine and Power Plant Controller (23rd Wind & Solar Integration Workshop, Helsinki, 8–11 Oct 2024, DTU)](https://backend.orbit.dtu.dk/ws/portalfiles/portal/413490887/Real-time_software-in-the-loop_EMT_models_of_wind_turbine_and_power_plant_controller_applicability_and_experiences.pdf)
19. [Leveraging AI for Autonomous Vehicle Simulations in SIL and HIL Frameworks (SAE 2025-28-0271, John Deere)](https://saemobilus.sae.org/articles/leveraging-ai-autonomous-vehicle-simulations-sil-hil-frameworks-2025-28-0271)
20. [Enhancing Safety-Critical Brake System Testing with Vector SIL over Complex Vector HIL (MDPI Engineering Proceedings)](https://www.mdpi.com/2673-4591/79/1/34)
21. [Evaluation of Multiple Hardware and Software in the Loop Signal Controllers in Simulation Environment (Transportation Research Record)](https://journals.sagepub.com/doi/10.1177/0361198118784168)

---
*Initially written Sep 29, 2026 · Reviewed: Sep 30, 2026 · Edited: Sep 30, 2026 · Last review: Sep 30, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Software engineering and development process › Software testing and quality

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/software-in-the-loop-simulation

English original: https://www.edgepedia.org/software-in-the-loop-simulation
