交叉编译和C++ test交叉平台测试

来源:互联网 发布:分期购物商城源码 编辑:程序博客网 时间:2024/06/01 10:21

嵌入式开发的C++test 通过自动生成可扩展的测试用例,来消除嵌入式系统测试中的壁垒,使其更为全面有效。这些测试用例可以在主机、仿真器和实际的目标环境下执行,以验证代码的健壮性,核实函数结果以及获得代码的覆盖率指标。

在主机环境中,开发者可以自动生成指定单元和API 的测试用例核心集,来确认未预期函数对边界条件的响应。使用不同的配置,生成的测试将在方法/功能级上获得当前的软件行为。然后该测试套件就可根据功能测试的需要进行扩展,自动对回归测试进行配置,如果需要的话还可在主机上执行(由可配置的桩函数自动的替代目标依赖关系)。

相同的测试套件随后可以在目标环境下交叉编译执行。为了评价/分析,目标测试结果被保存到一个可以被载入到C++test GUI 的文件中。通过TCP/IP 套接字,测试结果可以自动的被送到C++test GUI 中。包括分支覆盖率,简单条件覆盖率和MC/DC覆盖率在内的覆盖率指标,被所有的测试收集起来。C++test GUI 为调试测试用例提供了广泛的便利性,包括对很多主机调试器的支持、堆栈轨迹报告、调用序列报告和测试用例结果的详细显示等等。

 

 

执行基于目标的单元测试的一般过程如下:

1.使用交叉编译器,编译目标平台的C++test 运行时库。

2.在C++test中定义一个用户编译器。

3.配置工程的编译设置。

   设置编译器选项为你定义的用户编译器。

   设置链接器选项指向你用用户编译器编译的库。

4.编译测试可执行文件。

a.生成测试用例

b.创建一个用户测试配置去编译测试可执行文件。比如,你可以禁用桩函数的使用,定制测试执行流去指定你想要的结果日志文件被写的位置。

c.通过运行以上的测试配置。

5.移动可执行文件到目标机。

6.在目标机上运行可执行文件。

7.确保主机能够访问结果,然后通过运行Embedded Systems> Collect Results,使用C++test GUI精心结果分析 。

 

 

1.Using a cross compiler, build the C++test Runtime library for the target platform.
2. Define a custom compiler in C++test.
3. Configure the project’s build settings:
• Set the compiler option to the customer compiler you just defined.
• Set the linker options to point to the library that you built with the custom compiler.
4. Build the test executable.
a. Generate the test cases with a built-in or custom test generation Test Configuration
(for example, Generate Unit Tests).
b. Create a custom Test Configuration to build the test executable. For instance, you can
disable the use of stubs and customize the test execution flow to specify where you
want the results log files written.
c. Build the test executable by running the above Test Configuration.
5. Move the executable to the target.
6. Run the test executable on the target.
7. Ensure that the host can access results, then use the C++test GUI for results analysis by running
one of the "Embedded Systems> Collect Results" Test Configurations.
These steps are described in detail in the topics included in this section.

 

 

测试可执行文件包括由一个测试执行器,测试源码和C++test 运行时库一起构建所得。

 

为了在平台上的而不是主机上(C++test 的安装环境)使用C++test 来执行单元测试,运行时库必须要用交叉编译器建立。如果您打算仅在主机上运行单元测试的话,您不需要建立C++test 运行时库(因为C++test 使用基于主机测试的预建库来装载)。

 

。对于
基于主机的测试,C++test 使用一个预建的C++test 运行时库版本,它由C++test 分布来提供。对于基于目标的C++test,您需要交叉编译C++test 运行时库的源码(如在第333页上的“建立C++test 运行时库”中所描述的一样)并使用一个交叉编译器来建立测试执行器源码。之后交叉编译的测试执行器和运行时库需要与包含着标准操作系统函数的库连接到一起(将提供一个在C++test 运行时中使用的外部函数的列表,该列表在第339 页上的“由C++test 运行时库提供的使用符号”可见)。

交叉编译测试执行器和与C++test 运行时库的连接通常是由C++test 自动完成的(请参见第333 页上的“建立C++test 运行时库”),而且还要求交叉编译器已经在C++test 中被正确定义(请参见第342 页上的“用交叉编译器配制测试”)。这个过程并不需要用户之间的交互。