# Unit Test Framework Package
## About
This package provides unit test frameworks capable of building tests for multiple contexts including
the UEFI shell environment and host-based environments. It allows for unit test development to focus
on the tests and leave error logging, result formatting, context persistence, and test running to the framework.
The unit test framework works well for low level unit tests as well as system level tests and
fits easily in automation frameworks.
### Framework
The first unit test framework is called **Framework** and is implemented as a set of EDK II libraries.
The Framework supports both host-based unit tests and target-based unit tests that share the same
source style, macros, and APIs. In some scenarios, the same unit test case sources can be built
for both host-based unit test execution and target-based unit test execution. Host-based unit tests
that require mocked interfaces can use the mocking infrastructure provided by
[cmocka](https://api.cmocka.org/) that is included in the UnitTestFrameworkPkg as a submodule.
### GoogleTest
The second unit test framework supported by the UnitTestFrameworkPkg is
[GoogleTest](http://google.github.io/googletest/) and can be used to implement host-based unit tests.
[GoogleTest on GitHub](https://github.com/google/googletest) is included in the UnitTestFrameworkPkg
as a submodule. Use of GoogleTest for target-based unit tests of EDK II components is not supported.
Host-based unit tests that require mocked interfaces can use the mocking infrastructure included with
GoogleTest called [gMock](https://github.com/google/googletest/tree/main/googlemock). Note that the
gMock framework does not directly support mocking of free (C style) functions, so the FunctionMockLib
(containing a set of macros that wrap gMock's MOCK_METHOD macro) was created within the
UnitTestFrameworkPkg to enable this support. The details and usage of these macros in the
FunctionMockLib are described later.
GoogleTest requires less overhead to register test suites and test cases compared to the Framework.
There are also a number of tools that layer on top of GoogleTest that improve developer productivity.
One example is the VS Code extension
[C++ TestMate](https://marketplace.visualstudio.com/items?itemName=matepek.vscode-catch2-test-adapter)
that may be used to implement, run, and debug unit tests implemented using GoogleTest.
If a component can be tested with host-based unit tests, then GoogleTest is recommended. The MdePkg
contains a port of the BaseSafeIntLib unit tests in the GoogleTest style so the differences between
GoogleTest and Framework unit tests can be reviewed. The paths to the BaseSafeIntLib unit tests are:
* `MdePkg/Test/UnitTest/Library/BaseSafeIntLib`
* `MdePkg/Test/GoogleTest/Library/BaseSafeIntLib`
Furthermore, the SecurityPkg contains unit tests for the SecureBootVariableLib using mocks in both
the Framework/cmocka and GoogleTest/gMock style so the differences between cmocka and gMock can be
reviewed. The paths to the SecureBootVariableLib unit tests are:
* `SecurityPkg/Library/SecureBootVariableLib/UnitTest`
* `SecurityPkg/Library/SecureBootVariableLib/GoogleTest`
## Framework and GoogleTest Feature Comparison
| Feature | Framework | GoogleTest |
|:----------------------------|:---------:|:----------:|
| Host Based Unit Tests | YES | YES |
| Target Based Unit Tests | YES | NO |
| Unit Test Source Language | C | C++ |
| Register Test Suite | YES | Auto |
| Register Test Case | YES | Auto |
| Death/Expected Assert Tests | YES | YES |
| Setup/Teardown Hooks | YES | YES |
| Value-Parameterized Tests | NO | YES |
| Typed Tests | NO | YES |
| Type-Parameterized Tests | NO | YES |
| Timeout Support | NO | YES |
| Mocking Support | Cmocka | gMock |
| JUNIT XML Reports | YES | YES |
| Execute subset of tests | NO | YES |
| VS Code Extensions | NO | YES |
## Framework Libraries
### UnitTestLib
The main "framework" library. The core of the framework is the Framework object, which can have any number
of test cases and test suites registered with it. The Framework object is also what drives test execution.
The Framework also provides helper macros and functions for checking test conditions and
reporting errors. Status and error info will be logged into the test context. There are a number
of Assert macros that make the unit test code friendly to view and easy to understand.
Finally, the Framework also supports logging strings during the test execution. This data is logged
to the test context and will be available in the test reporting phase. This should be used for
logging test details and helpful messages to resolve test failures.
### UnitTestPersistenceLib
Persistence lib has the main job of saving and restoring test context to a storage medium so that for tests
that require exiting the active process and then resuming state can be maintained. This is critical
in supporting a system reboot in the middle of a test run.
### UnitTestResultReportLib
Library provides function to run at the end of a framework test run and handles formatting the report.
This is a common customization point and allows the unit test framework to fit its output reports into
other test infrastructure. In this package simple library instances have been supplied to output test
results to the console as plain text.
## Framework Samples
There is a sample unit test provided as both an example of how to write a unit test and leverage
many of the features of the framework. This sample can be found in the `Test/UnitTest/Sample/SampleUnitTest`
directory.
The sample is provided in PEI, SMM, DXE, and UEFI App flavors. It also has a flavor for the HOST_APPLICATION
build type, which can be run on a host system without needing a target.
## Framework Usage
This section is built a lot like a "Getting Started". We'll go through some of the components that are needed
when constructing a unit test and some of the decisions that are made by the test writer. We'll also describe
how to check for expected conditions in test cases and a bit of the logging characteristics.
Most of these examples will refer to the `SampleUnitTestUefiShell` app found in this package.
### Framework Requirements - INF
In our INF file, we'll need to bring in the `UnitTestLib` library. Conveniently, the interface
header for the `UnitTestLib` is located in `MdePkg`, so you shouldn't need to depend on any other
packages. As long as your DSC file knows where to find the lib implementation that you want to use,
you should be good to go.
See this example in `SampleUnitTestUefiShell.inf`...
```
[Packages]
MdePkg/MdePkg.dec
[LibraryClasses]
UefiApplicationEntryPoint
BaseLib
DebugLib
UnitTestLib
PrintLib
```
Also, if you want your test to automatically be picked up by the Test Runner plugin, you will need
to make sure that the module `BASE_NAME` contains the word `Test`...
```
[Defines]
BASE_NAME = SampleUnitTestUefiShell
```
### Framework Requirements - DSC
In our DSC file, we'll need to bring in the INF file that was just created into the `[Components]`
section so that the unit tests will be built.
See this example in `UnitTestFrameworkPkg.dsc`...
```
[Components]
UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTestUefiShell.inf
```
Also, based on the type of tests that are being created, the associated DSC include file from the
UnitTestFrameworkPkg for Host or Target based tests should also be included at the top of the DSC
file
EDK2压缩包(edk2.tar.gz)
需积分: 0 32 浏览量
更新于2023-07-24
收藏 862.64MB GZ 举报
EDK2,全称为EFI Development Kit 2,是UEFI(统一可扩展固件接口)标准的开源实现,由Tianocore项目维护。这个压缩包"edk2.tar.gz"包含了开发UEFI驱动和固件所需的源代码、工具以及构建系统。EDK2作为一个开放源码的平台,为开发者提供了构建、调试和测试UEFI应用程序和模块的环境。
1. **UEFI介绍**:
UEFI是一种现代固件标准,用于替代传统的BIOS,它提供了一个图形化的用户界面,更快的启动时间,以及更安全的引导过程。UEFI通过提供一个一致的应用程序接口(API),使得操作系统和硬件之间的交互更加标准化。
2. **EDK2结构**:
EDK2项目包括多个组件,如基础模块(BaseTools)、构建工具(Build)、库(Libraries)、驱动(Drivers)和平台(Platforms)。这些组件按照模块化的方式组织,便于开发和维护。
3. **BaseTools**:
BaseTools是EDK2的核心组成部分,包含了一系列用于编译、打包、验证和调试UEFI代码的工具,如GenFv(生成固件体积文件)、GenPkg(生成打包文件)和Build(构建系统)等。
4. **构建系统**:
EDK2使用基于Makefile的构建系统,可以跨平台构建UEFI应用和驱动。开发者可以通过修改配置文件(DSC)来定义构建目标和选项,以适应不同的硬件平台和操作系统。
5. **库和驱动**:
EDK2提供了一系列预定义的库函数和驱动模板,帮助开发者快速构建UEFI应用程序。这些库包括基本的数学运算、内存管理、I/O操作等。驱动则覆盖了从基本的硬件初始化到复杂的协议处理。
6. **平台支持**:
EDK2支持多种平台,包括x86、x64、ARM和AMD64架构。每个平台都有相应的配置文件和指导,帮助开发者针对特定硬件进行开发。
7. **调试工具**:
EDK2包含了调试工具,如EdkDebugAgent和UefiShell,它们可以帮助开发者在固件层面上进行问题定位和性能分析。
8. **贡献与社区**:
EDK2是一个活跃的开源社区项目,开发者可以通过参与贡献代码、报告问题或提出改进建议来参与到项目中。项目的文档和开发指南都在GitHub上公开,便于新手入门。
9. **应用案例**:
EDK2不仅用于开发UEFI驱动,还可以用于开发UEFI应用,如预操作系统环境(Pre-OS Environment)和固件更新工具。此外,它也是虚拟机和嵌入式系统的常用固件解决方案。
10. **学习与开发**:
对于想要进入UEFI开发领域的人员,理解EDK2的结构和工作原理至关重要。可以通过阅读官方文档,参与社区讨论,以及实践编写简单的驱动或应用来开始学习。
"edk2.tar.gz"压缩包提供了完整的UEFI开发环境,无论你是硬件制造商、操作系统开发者还是对固件感兴趣的爱好者,都能从中受益。通过深入研究和实践,你可以掌握UEFI编程,创建自定义的固件解决方案。
Biunelor
- 粉丝: 16
- 资源: 1
最新资源
- 25混合A星算法路径规划Hybrid-Astar 以车辆的运动学模型为节点,以当前点到终点的Astar距离和RS距离两者最大的距离作为H(n)函数的估计代价,使用matlab实现(2016a以上版本)
- 光储电压电流双环并网控制MATLAB仿真,包含光伏阵列模型、MPPT升压回路、储能电池模型、电压电流双环控制模型等,模型中各个环节均有注释,还有对仿真的讲解Word文件
- 2024年下半年小红书热门行业趋势报告解析
- 模块化多电平流器,MMC-HVDC直流输电系统,单个桥臂4个子模块(5电平),采用载波移相调制 simulink仿真模型 直流电压4KV,功率等级5MW 流站1:定直流母线电压控制+定无功功率控制;
- 【PMSM自抗扰控制】 PMSM 永磁同步电机 ADRC 自抗扰控制 matlab simulink 仿真 (1)采用转速、电流双闭环控制; (2)外环转速环,采用ADRC控制器控制; (3)内环电
- PFC单轴压缩声发射模拟演化规律及胶结破坏能监测
- 红外小目标检测中的深度学习方法:HCF-Net层次化上下文融合网络模型及其应用
- 基于时变干扰观测器和调节边界层厚度滑模控制的微机电系统陀螺仪鲁棒控制方法
- 源码-基于SSM的儿童玩具商城系统的设计与实现
- CNC机床预测健康管理及故障诊断数据集构建与分类算法研究
- yolo+吸烟数据集+目标检测+机器视觉识别+5000张图片抽烟识别数据集
- 星环大数据平台手册详细使用过程
- 机器学习中基于Adaboost的MAGIC伽马射电望远镜数据分类与性能评估
- MATLAB实现图像处理与机器视觉项目任务-Swinburne大学机器视觉课程作业
- 脑启发决策脉冲神经网络及其应用于无人机自主任务
- 【Unity天气和天空系统插件】Enviro 3 - Sky and Weather