merge xts_tools and xts_tools_full

Signed-off-by: alex__hold <hejian3@huawei.com>
This commit is contained in:
alex__hold 2021-10-28 14:39:17 +08:00
parent b707bc8e82
commit b6e2b5d4b8
46 changed files with 3240 additions and 480 deletions

0
LICENSE Executable file → Normal file
View File

250
README.md
View File

@ -1,17 +1,18 @@
# X Test Suite<a name="EN-US_TOPIC_0000001132537809"></a>
# XTS<a name="EN-US_TOPIC_0000001126156429"></a>
- [Introduction](#section465982318513)
- [Devices](#section125090457443)
- [System Types](#section125090457443)
- [Directory Structure](#section161941989596)
- [Constraints](#section119744591305)
- [Usage Guidelines](#section137768191623)
- [Test Case Development Guidelines](#section3695134065513)
- [C-based Test Case Development and Compilation \(for Mini-System Devices\)](#section1551164914237)
- [C-based Test Case Execution \(for Mini-System Devices\)](#section10100701294)
- [C++-based Test Case Development and Compilation \(for Small-, Standard-, and Large-System Devices\)](#section5714177113113)
- [C++-based Test Case Execution \(for Small-, Standard-, and Large-System Devices\)](#section42281924184)
- [C-based Test Case Development and Compilation \(for the Mini System\)](#section198193336544)
- [C-based Test Case Execution \(for the Mini System\)](#section13820233175418)
- [C++-based Test Case Development and Compilation \(for Standard and Small Systems\)](#section3822123311540)
- [C++-based Test Case Execution \(for Standard and Small Systems\)](#section128222336544)
- [JavaScript-based Test Case Development \(for the Standard System\)](#section159801435165220)
- [JavaScript-based Test Case Packaging \(for the Standard System\)](#section445519106559)
- [Repositories Involved](#section1371113476307)
## Introduction<a name="section465982318513"></a>
@ -22,44 +23,39 @@ This subsystem contains the ACTS and **tools** software package.
- The **acts** directory stores the source code and configuration files of ACTS test cases. The ACTS helps device vendors detect the software incompatibility as early as possible and ensures that the software is compatible to OpenHarmony during the entire development process.
- The **tools** software package stores the test case development framework related to **acts**.
## Devices<a name="section125090457443"></a>
## System Types<a name="section125090457443"></a>
OpenHarmony supports the following device types:
OpenHarmony supports the following system types:
- **Mini-System Devices \(reference memory ≥ 128 KB\)**
- Mini system
Such devices are equipped with MCU processors such as ARM Cortex-M and 32-bit RISC-V. They provide rich short-distance connection and peripheral bus access capabilities. Typical products include LinkIoT module devices and sensors in the smart home field. The LinkIoT module is usually used for smart Internet of Things \(IoT\) devices as the hardware module that implements connectivity functions. In the smart home field, the LinkIoT module is integrated into devices by vendors. For example, a LinkIoT module provides WLAN/Bluetooth access and data connection, and it usually communicates with the chip of smart home devices via a universal asynchronous receiver-transmitter \(UART\) or general-purpose input/output \(GPIO\) interface.
A mini system runs on the devices whose memory is greater than or equal to 128 KiB and that are equipped with MCU processors such as ARM Cortex-M and 32-bit RISC-V. This system provides multiple lightweight network protocols and graphics frameworks, and a wide range of read/write components for the IoT bus. Typical products include connection modules, sensors, and wearables for smart home.
- **Small-System Devices \(reference memory ≥ 1 MB\)**
- Small system
Such devices are equipped with application processors such as ARM Cortex-A. They provide higher security capabilities, standard graphics framework, and multimedia capabilities for video encoding and decoding. Typical products include IP cameras, electronic cat eyes, and routers in the smart home field, as well as event data recorders \(EDRs\) in the smart travel field.
A small system runs on the devices whose memory is greater than or equal to 1 MiB and that are equipped with application processors such as ARM Cortex-A. This system provides higher security capabilities, standard graphics frameworks, and video encoding and decoding capabilities. Typical products include smart home IP cameras, electronic cat eyes, and routers, and event data recorders \(EDRs\) for smart travel.
- Standard system
- **Standard-System Devices \(reference memory ≥ 128 MB\)**
Such devices are equipped with application processors such as ARM Cortex-A. They provide a complete application framework supporting enhanced interaction, 3D GPU, hardware composer, diverse components, and rich animations. Typical products include high-end refrigerator displays.
- **Large-System Devices \(reference memory ≥ 1 GB\)**
Such devices are equipped with application processors such as ARM Cortex-A and provide a complete compatible application framework. Typical products include smart TVs and smart watches.
A standard system runs on the devices whose memory is greater than or equal to 128 MiB and that are equipped with application processors such as ARM Cortex-A. This system provides a complete application framework supporting the enhanced interaction, 3D GPU, hardware composer, diverse components, and rich animations. This system applies to high-end refrigerator displays.
## Directory Structure<a name="section161941989596"></a>
```
/test/xts
├── acts # Test code
│ └── subsystem # Source code of subsystem test cases for large-system devices
│ └── subsystem_lite # Source code of subsystems test cases for mini- and small-system devices
│ └── BUILD.gn # Build configuration of test cases for large-system devices
│ └── build_lite # Build configuration of test cases for mini-and small-system devices
│ └── build_lite # Build configuration
└── tools # Test tool code
├── acts # Test code
│ └── subsystem # Source code of subsystem test cases for the standard system
│ └── subsystem_lite # Source code of subsystems test cases for mini and small systems
│ └── BUILD.gn # Build configuration of test cases for the standard system
│ └── build_lite
│ └── BUILD.gn # Build configuration of test cases for mini and small systems
└── tools # Test tool code
```
## Constraints<a name="section119744591305"></a>
Test cases for mini system devices must be developed based on C, and those for small system devices must be developed based on C++.
Test cases for the mini system must be developed based on C, and those for the small system must be developed based on C++.
## Usage Guidelines<a name="section137768191623"></a>
@ -216,12 +212,12 @@ Test cases for mini system devices must be developed based on C, and those for s
## Test Case Development Guidelines<a name="section3695134065513"></a>
You should select the appropriate programming language and your target test framework to develop test cases for the devices to test.
You should select the appropriate programming language and your target test framework to develop test cases.
**Table 4** Test frameworks and test case languages for different devices
**Table 4** Test frameworks and test case languages for different systems
<a name="table4418343171415"></a>
<table><thead align="left"><tr id="row34183435145"><th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.1"><p id="p941874311148"><a name="p941874311148"></a><a name="p941874311148"></a>Device Type</p>
<table><thead align="left"><tr id="row34183435145"><th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.1"><p id="p941874311148"><a name="p941874311148"></a><a name="p941874311148"></a>System</p>
</th>
<th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.2"><p id="p1841804341413"><a name="p1841804341413"></a><a name="p1841804341413"></a>Test Framework</p>
</th>
@ -229,40 +225,33 @@ You should select the appropriate programming language and your target test fram
</th>
</tr>
</thead>
<tbody><tr id="row8419164319148"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p7419194312143"><a name="p7419194312143"></a><a name="p7419194312143"></a>Mini-system devices</p>
<tbody><tr id="row8419164319148"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p7419194312143"><a name="p7419194312143"></a><a name="p7419194312143"></a>Mini</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p10419124312145"><a name="p10419124312145"></a><a name="p10419124312145"></a>HCTest</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p11419643191410"><a name="p11419643191410"></a><a name="p11419643191410"></a>C</p>
</td>
</tr>
<tr id="row141915438147"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p441911436141"><a name="p441911436141"></a><a name="p441911436141"></a>Small-system devices</p>
<tr id="row141915438147"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p441911436141"><a name="p441911436141"></a><a name="p441911436141"></a>Small</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p541916432142"><a name="p541916432142"></a><a name="p541916432142"></a>HCPPTest</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p54191643131416"><a name="p54191643131416"></a><a name="p54191643131416"></a>C++</p>
</td>
</tr>
<tr id="row4419134341417"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p341964313143"><a name="p341964313143"></a><a name="p341964313143"></a>Standard-system devices</p>
<tr id="row4419134341417"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p341964313143"><a name="p341964313143"></a><a name="p341964313143"></a>Standard</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p10419443171416"><a name="p10419443171416"></a><a name="p10419443171416"></a>HJUnit and HCPPTest</p>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p10419443171416"><a name="p10419443171416"></a><a name="p10419443171416"></a>HJSUnit and HCPPTest</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p9419143181414"><a name="p9419143181414"></a><a name="p9419143181414"></a>Java and C++</p>
</td>
</tr>
<tr id="row42451815115215"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p324511515528"><a name="p324511515528"></a><a name="p324511515528"></a>Large-system devices</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p724516151520"><a name="p724516151520"></a><a name="p724516151520"></a>HJUnit and HCPPTest</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p748417474533"><a name="p748417474533"></a><a name="p748417474533"></a>Java and C++</p>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p9419143181414"><a name="p9419143181414"></a><a name="p9419143181414"></a>JavaScript and C++</p>
</td>
</tr>
</tbody>
</table>
### C-based Test Case Development and Compilation \(for Mini-System Devices\)<a name="section1551164914237"></a>
### C-based Test Case Development and Compilation \(for the Mini System\)<a name="section198193336544"></a>
**Developing test cases for mini-system devices**
**Developing test cases for the mini system**
The HCTest framework is used to support test cases developed with the C language. HCTest is enhanced and adapted based on the open-source test framework Unity.
@ -323,7 +312,7 @@ The HCTest framework is used to support test cases developed with the C language
3. Create the configuration file \(**BUILD.gn**\) of the test module.
Create a **BUILD.gn** \(example\) compilation file in each test module directory. Specify the name of the compiled static library and its dependent header file and library in the compilation file. The format is as follows:
Create a **BUILD.gn** \(example\) build file in each test module directory. Specify the name of the built static library and its dependent header file and library in the build file. The format is as follows:
```
import("//test/xts/tools/lite/build/suite_lite.gni")
@ -337,7 +326,7 @@ The HCTest framework is used to support test cases developed with the C language
}
```
4. Add compilation options to the **BUILD.gn** file in the **acts** directory.
4. Add build options to the **BUILD.gn** file in the **acts** directory.
You need to add the test module to the **test/xts/acts/build\_lite/BUILD.gn** script in the **acts** directory.
@ -353,17 +342,17 @@ The HCTest framework is used to support test cases developed with the C language
}
```
5. Run compilation commands.
5. Run build commands.
Test suites are compiled along with version compilation. The ACTS is compiled together with the debug version.
Test suites are built along with version build. The ACTS is built together with the debug version.
>![](figures/icon-note.gif) **NOTE:**
>The ACTS compiles middleware as a static library, which will be linked to the image.
>The ACTS build middleware is a static library, which will be linked to the image.
### C-based Test Case Execution \(for Mini-System Devices\)<a name="section10100701294"></a>
### C-based Test Case Execution \(for the Mini System\)<a name="section13820233175418"></a>
**Executing test cases for mini-system devices**
**Executing test cases for the mini system**
Burn the image into the development board.
@ -378,9 +367,9 @@ View the serial port logs, whose format is as follows:
The log for each test suite starts with **Start to run test suite:** and ends with **xx Tests xx Failures xx Ignored**.
### C++-based Test Case Development and Compilation \(for Small-, Standard-, and Large-System Devices\)<a name="section5714177113113"></a>
### C++-based Test Case Development and Compilation \(for Standard and Small Systems\)<a name="section3822123311540"></a>
**Developing test cases for small-system devices**
**Developing test cases for small-system devices** \(For examples of the standard system, go to the **global/i18n\_standard directory**.\)
The HCPPTest framework is enhanced and adapted based on the open-source framework Googletest.
@ -446,7 +435,7 @@ The HCPPTest framework is enhanced and adapted based on the open-source framewor
3. Create a configuration file \(**BUILD.gn**\) of the test module.
Create a **BUILD.gn** compilation file in each test module directory. Specify the name of the compiled static library and its dependent header file and library in the compilation file. Each test module is independently compiled into a **.bin** executable file, which can be directly mounted to the development board for testing.
Create a **BUILD.gn** build file in each test module directory. Specify the name of the built static library and its dependent header file and library in the build file. Each test module is independently built into a **.bin** executable file, which can be directly pushed to the development board for testing.
Example:
@ -467,10 +456,9 @@ The HCPPTest framework is enhanced and adapted based on the open-source framewor
]
cflags = [ "-Wno-error" ]
}
```
4. Add compilation options to the **BUILD.gn** file in the **acts** directory.
4. Add build options to the **BUILD.gn** file in the **acts** directory.
Add the test module to the **test/xts/acts/build\_lite/BUILD.gn** script in the **acts** directory.
@ -486,17 +474,17 @@ The HCPPTest framework is enhanced and adapted based on the open-source framewor
}
```
5. Run compilation commands.
5. Run build commands.
Test suites are compiled along with the version compilation. The ACTS is compiled together with the debug version.
Test suites are built along with the version build. The ACTS is built together with the debug version.
>![](figures/icon-note.gif) **NOTE:**
>The ACTS for a small system device is independently compiled to an executable file \(.bin\) and archived in the **suites\\acts** directory of the compilation result.
>The ACTS for the small system is independently built to an executable file \(.bin\) and archived in the **suites\\acts** directory of the build result.
### C++-based Test Case Execution \(for Small-, Standard-, and Large-System Devices\)<a name="section42281924184"></a>
### C++-based Test Case Execution \(for Standard and Small Systems\)<a name="section128222336544"></a>
**Executing test cases for small-system devices**
**Executing test cases for the small system**
Currently, test cases are shared by the NFS and mounted to the development board for execution.
@ -520,11 +508,141 @@ Currently, test cases are shared by the NFS and mounted to the development board
Execute **ActsDemoTest.bin** to trigger test case execution, and analyze serial port logs generated after the execution is complete.
## Repositories Involved<a name="section1371113476307"></a>
### JavaScript-based Test Case Development \(for the Standard System\)<a name="section159801435165220"></a>
[X Test Suite](https://gitee.com/openharmony/docs/blob/master/en/readme/x-test-suite.md)
The HJSUnit framework is used to support automated test of OpenHarmony apps that are developed using the JavaScript language based on the JS application framework.
[xts\_acts](https://gitee.com/openharmony/xts_acts/blob/master/README.md)
**Basic syntax of test cases**
**xts\_tools**
The test cases are developed with the JavaScript language and must meet the programming specifications of the language.
**Table 5**
<a name="table13980103565212"></a>
<table><thead align="left"><tr id="row1098093545218"><th class="cellrowborder" valign="top" width="17.92179217921792%" id="mcps1.2.4.1.1"><p id="p49811235135214"><a name="p49811235135214"></a><a name="p49811235135214"></a>Syntax</p>
</th>
<th class="cellrowborder" valign="top" width="68.88688868886888%" id="mcps1.2.4.1.2"><p id="p898183565220"><a name="p898183565220"></a><a name="p898183565220"></a>Description</p>
</th>
<th class="cellrowborder" valign="top" width="13.19131913191319%" id="mcps1.2.4.1.3"><p id="p17981143512526"><a name="p17981143512526"></a><a name="p17981143512526"></a>Mandatory</p>
</th>
</tr>
</thead>
<tbody><tr id="row1598183515528"><td class="cellrowborder" valign="top" width="17.92179217921792%" headers="mcps1.2.4.1.1 "><p id="p139810358527"><a name="p139810358527"></a><a name="p139810358527"></a>beforeAll</p>
</td>
<td class="cellrowborder" valign="top" width="68.88688868886888%" headers="mcps1.2.4.1.2 "><p id="p198111352526"><a name="p198111352526"></a><a name="p198111352526"></a>Presets a test-suite-level action executed only once before all test cases are executed. You can pass the action function as the only parameter.</p>
</td>
<td class="cellrowborder" valign="top" width="13.19131913191319%" headers="mcps1.2.4.1.3 "><p id="p298114355529"><a name="p298114355529"></a><a name="p298114355529"></a>No</p>
</td>
</tr>
<tr id="row11981103512529"><td class="cellrowborder" valign="top" width="17.92179217921792%" headers="mcps1.2.4.1.1 "><p id="p20981135135215"><a name="p20981135135215"></a><a name="p20981135135215"></a>afterAll</p>
</td>
<td class="cellrowborder" valign="top" width="68.88688868886888%" headers="mcps1.2.4.1.2 "><p id="p39811935115217"><a name="p39811935115217"></a><a name="p39811935115217"></a>Presets a test-suite-level clear action executed only once after all test cases are executed. You can pass the clear function as the only parameter.</p>
</td>
<td class="cellrowborder" valign="top" width="13.19131913191319%" headers="mcps1.2.4.1.3 "><p id="p998110354527"><a name="p998110354527"></a><a name="p998110354527"></a>No</p>
</td>
</tr>
<tr id="row1298116359526"><td class="cellrowborder" valign="top" width="17.92179217921792%" headers="mcps1.2.4.1.1 "><p id="p898112359526"><a name="p898112359526"></a><a name="p898112359526"></a>beforeEach</p>
</td>
<td class="cellrowborder" valign="top" width="68.88688868886888%" headers="mcps1.2.4.1.2 "><p id="p149811335175215"><a name="p149811335175215"></a><a name="p149811335175215"></a>Presets a test-case-level action executed before each test case is executed. The number of execution times is the same as the number of test cases defined by <strong id="b32523248388"><a name="b32523248388"></a><a name="b32523248388"></a>it</strong>. You can pass the action function as the only parameter.</p>
</td>
<td class="cellrowborder" valign="top" width="13.19131913191319%" headers="mcps1.2.4.1.3 "><p id="p13981133585212"><a name="p13981133585212"></a><a name="p13981133585212"></a>No</p>
</td>
</tr>
<tr id="row6982435115219"><td class="cellrowborder" valign="top" width="17.92179217921792%" headers="mcps1.2.4.1.1 "><p id="p19982133517525"><a name="p19982133517525"></a><a name="p19982133517525"></a>afterEach</p>
</td>
<td class="cellrowborder" valign="top" width="68.88688868886888%" headers="mcps1.2.4.1.2 "><p id="p1398213575219"><a name="p1398213575219"></a><a name="p1398213575219"></a>Presets a test-case-level clear action executed after each test case is executed. The number of execution times is the same as the number of test cases defined by <strong id="b10590142313399"><a name="b10590142313399"></a><a name="b10590142313399"></a>it</strong>. You can pass the clear function as the only parameter.</p>
</td>
<td class="cellrowborder" valign="top" width="13.19131913191319%" headers="mcps1.2.4.1.3 "><p id="p159821535195219"><a name="p159821535195219"></a><a name="p159821535195219"></a>No</p>
</td>
</tr>
<tr id="row16982143513521"><td class="cellrowborder" valign="top" width="17.92179217921792%" headers="mcps1.2.4.1.1 "><p id="p598203510527"><a name="p598203510527"></a><a name="p598203510527"></a>describe</p>
</td>
<td class="cellrowborder" valign="top" width="68.88688868886888%" headers="mcps1.2.4.1.2 "><p id="p5982123595215"><a name="p5982123595215"></a><a name="p5982123595215"></a>Defines a test suite. You can pass two parameters: test suite name and test suite function. The <strong id="b7320205019400"><a name="b7320205019400"></a><a name="b7320205019400"></a>describe</strong> statement supports nesting. You can use <strong id="b138214222410"><a name="b138214222410"></a><a name="b138214222410"></a>beforeall</strong>, <strong id="b18677102314115"><a name="b18677102314115"></a><a name="b18677102314115"></a>beforeEach</strong>, <strong id="b1353142514113"><a name="b1353142514113"></a><a name="b1353142514113"></a>afterEach</strong>, and <strong id="b131041629204111"><a name="b131041629204111"></a><a name="b131041629204111"></a>afterAll</strong> in each <strong id="b590433484116"><a name="b590433484116"></a><a name="b590433484116"></a>describe</strong> statement.</p>
</td>
<td class="cellrowborder" valign="top" width="13.19131913191319%" headers="mcps1.2.4.1.3 "><p id="p898217352527"><a name="p898217352527"></a><a name="p898217352527"></a>Yes</p>
</td>
</tr>
<tr id="row6982113518526"><td class="cellrowborder" valign="top" width="17.92179217921792%" headers="mcps1.2.4.1.1 "><p id="p17982123510526"><a name="p17982123510526"></a><a name="p17982123510526"></a>it</p>
</td>
<td class="cellrowborder" valign="top" width="68.88688868886888%" headers="mcps1.2.4.1.2 "><p id="p598211352522"><a name="p598211352522"></a><a name="p598211352522"></a>Defines a test case. You can pass three parameters: test case name, filter parameter, and test case function.</p>
<p id="p5205769588"><a name="p5205769588"></a><a name="p5205769588"></a>Usage of the filter parameter:</p>
<p id="p1545919528618"><a name="p1545919528618"></a><a name="p1545919528618"></a>The value of the filter parameter is a 32-bit integer. Setting different bits to <strong id="b045919521765"><a name="b045919521765"></a><a name="b045919521765"></a>1</strong> means different configurations:</p>
<a name="ul6932113319395"></a><a name="ul6932113319395"></a><ul id="ul6932113319395"><li>bit 0: whether the filter parameter takes effect. <strong id="b1193293318395"><a name="b1193293318395"></a><a name="b1193293318395"></a>1</strong> means that the test case is used for the function test and other settings of the parameter do not take effect.</li><li>Bits 0-10: test case categories</li><li>Bits 16-18: test case scales</li><li>Bits 24-28: test levels</li></ul>
<p id="p7965165151011"><a name="p7965165151011"></a><a name="p7965165151011"></a><strong id="b15148755145114"><a name="b15148755145114"></a><a name="b15148755145114"></a>Test case categories</strong>: Bits 0-10 indicate FUNCTION (function test), PERFORMANCE (performance test), POWER (power consumption test), RELIABILITY (reliability test), SECURITY (security compliance test), GLOBAL (integrity test), COMPATIBILITY (compatibility test), USER (user test), STANDARD (standard test), SAFETY (security feature test), and RESILIENCE (resilience test), respectively.</p>
<p id="p199651555102"><a name="p199651555102"></a><a name="p199651555102"></a><strong id="b135908568519"><a name="b135908568519"></a><a name="b135908568519"></a>Test case scales</strong>: Bits 16-18 indicate SMALL (small-scale test), MEDIUM (medium-scale test), and LARGE (large-scale test), respectively.</p>
<p id="p296545151020"><a name="p296545151020"></a><a name="p296545151020"></a><strong id="b12181058125111"><a name="b12181058125111"></a><a name="b12181058125111"></a>Test levels</strong>: Bits 24-28 indicate LEVEL0 (level-0 test), LEVEL1 (level-1 test), LEVEL2 (level-2 test), LEVEL3 (level-3 test), and LEVEL4 (level-4 test), respectively.</p>
</td>
<td class="cellrowborder" valign="top" width="13.19131913191319%" headers="mcps1.2.4.1.3 "><p id="p17601752115716"><a name="p17601752115716"></a><a name="p17601752115716"></a>Yes</p>
</td>
</tr>
</tbody>
</table>
Use the standard syntax of Jasmine to write test cases. The ES6 specification is supported.
1. Store the test cases in the **entry/src/main/js/test** directory, whose structure is as follows:
```
├── BUILD.gn
│ └──entry
│ │ └──src
│ │ │ └──main
│ │ │ │ └──js
│ │ │ │ │ └──default
│ │ │ │ │ │ └──pages
│ │ │ │ │ │ │ └──index
│ │ │ │ │ │ │ │ └──index.js # Entry file
│ │ │ │ │ └──test # Test code
│ │ │ └── resources # HAP resources
│ │ │ └── config.json # HAP configuration file
```
2. Start the JS test framework and load test cases. The following is an example for **index.js**.
```
// Start the JS test framework and load test cases.
import {Core, ExpectExtend} from 'deccjsunit/index'
export default {
data: {
title: ""
},
onInit() {
this.title = this.$t('strings.world');
},
onShow() {
console.info('onShow finish')
const core = Core.getInstance()
const expectExtend = new ExpectExtend({
'id': 'extend'
})
core.addService('expect', expectExtend)
core.init()
const configService = core.getDefaultService('config')
configService.setConfig(this)
require('../../../test/List.test')
core.execute()
},
onReady() {
},
}
```
3. Write a unit test case by referring to the following example:
```
// Use HJSUnit to perform the unit test.
describe('appInfoTest', function () {
it('app_info_test_001', 0, function () {
var info = app.getInfo()
expect(info.versionName).assertEqual('1.0')
expect(info.versionCode).assertEqual('3')
})
})
```
### JavaScript-based Test Case Packaging \(for the Standard System\)<a name="section445519106559"></a>
For details about how to build a HAP, see the JS application development guide of the standard system [Building and Creating HAPs](https://developer.harmonyos.com/en/docs/documentation/doc-guides/build_overview-0000001055075201).

View File

@ -1,15 +1,17 @@
# XTS认证子系统开发指南<a name="ZH-CN_TOPIC_0000001132537809"></a>
# XTS子系统<a name="ZH-CN_TOPIC_0000001117409671"></a>
- [简介](#section465982318513)
- [设备类型](#section125090457443)
- [系统类型](#section125090457443)
- [目录](#section161941989596)
- [约束](#section119744591305)
- [使用说明](#section137768191623)
- [用例开发指导](#section3695134065513)
- [C语言用例开发编译指导适用于轻量系统类设备产品用例开发](#section1551164914237)
- [C语言用例执行指导适用于轻量系统类设备产品用例开发](#section10100701294)
- [C++语言用例开发编译指导(适用于小型系统类设备、标准系统类设备、大型系统类设备用例开发)](#section5714177113113)
- [C++语言用例执行指导(适用于小型系统类设备、标准系统类设备、大型系统类设备用例开发)](#section42281924184)
- [C语言用例开发编译指导适用于轻量系统产品用例开发](#section198193336544)
- [C语言用例执行指导适用于轻量系统产品用例开发](#section13820233175418)
- [C++语言用例开发编译指导(适用于小型系统、标准系统用例开发)](#section3822123311540)
- [C++语言用例执行指导(适用于小型系统、标准系统用例开发)](#section128222336544)
- [JS语言用例开发指导适用于标准系统](#section159801435165220)
- [JS语言用例编译打包指导适用于标准系统](#section445519106559)
- [相关仓](#section1371113476307)
@ -22,44 +24,39 @@ XTS子系统当前包括acts与tools软件包
- acts存放acts相关测试用例源码与配置文件其目的是帮助终端设备厂商尽早发现软件与OpenHarmony的不兼容性确保软件在整个开发过程中满足OpenHarmony的兼容性要求。
- tools存放acts相关测试用例开发框架。
## 设备类型<a name="section125090457443"></a>
## 系统类型<a name="section125090457443"></a>
OpenHarmony支持如下几种设备类型:
OpenHarmony支持如下几种系统类型:
- **轻量系统类设备参考内存≥128KB**
- 轻量系统mini system
面向MCU类处理器例如Arm Cortex-M、RISC-V 32位的设备资源极其有限参考内存≥128KB提供丰富的近距连接能力以及丰富的外设总线访问能力。典型产品有智能家居领域的联接类模组、传感器设备等。联接类模组通常应用在智能物联网设备中负责实现联接部分的硬件模块在智能家居领域由厂家集成到其设备中。例如联接类模组提供WLAN/Bluetooth的接入和数据的联接模组与厂家家居的芯片通常通过UART或GPIO等总线接口进行通信
面向MCU类处理器例如Arm Cortex-M、RISC-V 32位的设备硬件资源极其有限支持的设备最小内存为128KiB可以提供多种轻量级网络协议轻量级的图形框架以及丰富的IOT总线读写部件等。可支撑的产品如智能家居领域的连接类模组、传感器设备、穿戴类设备等
- **小型系统类设备参考内存≥1MB**
- 小型系统small system
面向应用处理器例如Arm Cortex-A的设备参考内存≥1MB提供更高的安全能力提供标准的图形框架提供视频编解码的多媒体能力。典型产品有智能家居领域的IPCamera、电子猫眼、路由器以及智慧出行域的行车记录仪等。
面向应用处理器例如Arm Cortex-A的设备支持的设备最小内存为1MiB可以提供更高的安全能力、标准的图形框架、视频编解码的多媒体能力。可支撑的产品如智能家居领域的IP Camera、电子猫眼、路由器以及智慧出行域的行车记录仪等。
- 标准系统standard system
- **标准系统类设备参考内存≥128MB**
面向应用处理器例如Arm Cortex-A的设备参考内存≥128MB提供增强的交互能力提供3D GPU以及硬件合成能力提供更多控件以及动效更丰富的图形能力提供完整的应用框架。典型产品有高端的冰箱显示屏等。
- **大型系统类设备参考内存≥1GB**
面向应用处理器例如Arm Cortex-A的设备参考内存≥1GB提供完整的兼容应用框架。典型的产品有智慧屏、智能手表等。
面向应用处理器例如Arm Cortex-A的设备支持的设备最小内存为128MiB可以提供增强的交互能力、3D GPU以及硬件合成能力、更多控件以及动效更丰富的图形能力、完整的应用框架。可支撑的产品如高端的冰箱显示屏。
## 目录<a name="section161941989596"></a>
```
/test/xts
├── acts # 测试代码存放目录
│ └── subsystem # 大型系统类设备子系统测试用例源码存放目录
│ └── subsystem_lite # 轻量系统类设备、小型系统类设备子系统测试用例源码存放目录
│ └── BUILD.gn # 大型系统类设备测试用例编译配置
│ └── build_lite # 轻量系统类设备、小型系统类设备测试用例编译配置存放目录
│ └── BUILD.gn # 轻量系统类设备、小型系统类设备测试用例编译配置
└── tools # 测试工具代码存放目录
├── acts # 测试代码存放目录
│ └── subsystem # 标准系统子系统测试用例源码存放目录
│ └── subsystem_lite # 轻量系统、小型系统子系统测试用例源码存放目录
│ └── BUILD.gn # 标准系统测试用例编译配置
│ └── build_lite # 轻量系统、小型系统测试用例编译配置存放目录
│ └── BUILD.gn # 轻量系统、小型系统测试用例编译配置
└── tools # 测试工具代码存放目录
```
## 约束<a name="section119744591305"></a>
轻量系统类设备用例开发语言是C小型系统类设备用例开发语言是C++。
轻量系统用例开发语言是C小型系统用例开发语言是C++。
## 使用说明<a name="section137768191623"></a>
@ -216,12 +213,12 @@ OpenHarmony支持如下几种设备类型
## 用例开发指导<a name="section3695134065513"></a>
根据测试设备选择测试框架和对应测试用例语言。
根据测试系统选择测试框架和对应测试用例语言。
**表 4** 设备和测试框架、开发语言对应关系
**表 4** 系统和测试框架、开发语言对应关系
<a name="table4418343171415"></a>
<table><thead align="left"><tr id="row34183435145"><th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.1"><p id="p941874311148"><a name="p941874311148"></a><a name="p941874311148"></a>设备</p>
<table><thead align="left"><tr id="row34183435145"><th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.1"><p id="p941874311148"><a name="p941874311148"></a><a name="p941874311148"></a>系统</p>
</th>
<th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.2"><p id="p1841804341413"><a name="p1841804341413"></a><a name="p1841804341413"></a>测试框架</p>
</th>
@ -229,40 +226,33 @@ OpenHarmony支持如下几种设备类型
</th>
</tr>
</thead>
<tbody><tr id="row8419164319148"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p7419194312143"><a name="p7419194312143"></a><a name="p7419194312143"></a>轻量系统类设备</p>
<tbody><tr id="row8419164319148"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p7419194312143"><a name="p7419194312143"></a><a name="p7419194312143"></a>轻量系统</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p10419124312145"><a name="p10419124312145"></a><a name="p10419124312145"></a>hctest</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p11419643191410"><a name="p11419643191410"></a><a name="p11419643191410"></a>c</p>
</td>
</tr>
<tr id="row141915438147"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p441911436141"><a name="p441911436141"></a><a name="p441911436141"></a>小型系统类设备</p>
<tr id="row141915438147"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p441911436141"><a name="p441911436141"></a><a name="p441911436141"></a>小型系统</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p541916432142"><a name="p541916432142"></a><a name="p541916432142"></a>hcpptest</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p54191643131416"><a name="p54191643131416"></a><a name="p54191643131416"></a>c++</p>
</td>
</tr>
<tr id="row4419134341417"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p341964313143"><a name="p341964313143"></a><a name="p341964313143"></a>标准系统类设备</p>
<tr id="row4419134341417"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p341964313143"><a name="p341964313143"></a><a name="p341964313143"></a>标准系统</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p10419443171416"><a name="p10419443171416"></a><a name="p10419443171416"></a>HJUnit、hcpptest</p>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p10419443171416"><a name="p10419443171416"></a><a name="p10419443171416"></a>HJSUnit、hcpptest</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p9419143181414"><a name="p9419143181414"></a><a name="p9419143181414"></a>java、c++</p>
</td>
</tr>
<tr id="row42451815115215"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p324511515528"><a name="p324511515528"></a><a name="p324511515528"></a>大型系统类设备</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p724516151520"><a name="p724516151520"></a><a name="p724516151520"></a>HJUnit、hcpptest</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p748417474533"><a name="p748417474533"></a><a name="p748417474533"></a>java、c++</p>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p9419143181414"><a name="p9419143181414"></a><a name="p9419143181414"></a>js、c++</p>
</td>
</tr>
</tbody>
</table>
### C语言用例开发编译指导适用于轻量系统类设备产品用例开发)<a name="section1551164914237"></a>
### C语言用例开发编译指导适用于轻量系统产品用例开发<a name="section198193336544"></a>
**示例:轻量系统类设备测试用例开发**
**示例:轻量系统测试用例开发**
当前使用的测试框架是hctesthctest测试框架支持使用C语言编写测试用例是在开源测试框架unity的基础上进行增强和适配。
@ -361,9 +351,9 @@ OpenHarmony支持如下几种设备类型
>acts测试套件编译中间件为静态库最终链接到版本镜像中 。
### C语言用例执行指导适用于轻量系统类设备产品用例开发)<a name="section10100701294"></a>
### C语言用例执行指导适用于轻量系统产品用例开发<a name="section13820233175418"></a>
**示例:轻量系统类设备测试用例执行**
**示例:轻量系统测试用例执行**
将版本镜像烧录进开发板。
@ -378,9 +368,9 @@ OpenHarmony支持如下几种设备类型
每个测试套件执行以Start to run test suite开始以xx Tests xx Failures xx Ignored结束。
### C++语言用例开发编译指导(适用于小型系统类设备、标准系统类设备、大型系统类设备用例开发)<a name="section5714177113113"></a>
### C++语言用例开发编译指导(适用于小型系统、标准系统用例开发)<a name="section3822123311540"></a>
**示例:小型系统类设备测试用例开发**
**示例:小型系统测试用例开发**标准系统参考具体样例目录global/i18n\_standard
当前使用的测试框架是hcpptesthcpptest测试框架是在开源的googletest测试框架的基础上进行的增强和适配。
@ -446,7 +436,7 @@ OpenHarmony支持如下几种设备类型
3. 测试模块下用例配置文件BUILD.gn样例
每个测试模块目录下新建BUILD.gn编译文件用于指定编译后可执行文件的名称、依赖的头文件、依赖的库等具体写法如下。每个测试模块将独立编译成.bin可执行文件 该文件可直接mount到单板上进行测试。
每个测试模块目录下新建BUILD.gn编译文件用于指定编译后可执行文件的名称、依赖的头文件、依赖的库等具体写法如下。每个测试模块将独立编译成.bin可执行文件 该文件可直接push到单板上进行测试。
举例:
@ -491,12 +481,12 @@ OpenHarmony支持如下几种设备类型
随版本编译debug版本编译时会同步编译acts测试套件
>![](figures/icon-note.gif) **说明:**
>小型系统类设备acts独立编译成可执行文件bin格式 在编译产物的suites\\acts目录下归档。
>小型系统acts独立编译成可执行文件bin格式 在编译产物的suites\\acts目录下归档。
### C++语言用例执行指导(适用于小型系统类设备、标准系统类设备、大型系统类设备用例开发)<a name="section42281924184"></a>
### C++语言用例执行指导(适用于小型系统、标准系统用例开发)<a name="section128222336544"></a>
**示例:小型系统类设备测试用例执行**
**示例:小型系统测试用例执行**
目前的用例执行采用nfs共享的方式mount到单板去执行。
@ -520,11 +510,146 @@ OpenHarmony支持如下几种设备类型
测试套件执行 ActsDemoTest.bin 触发用例执行,基于串口打印日志进行分析。
### JS语言用例开发指导适用于标准系统<a name="section159801435165220"></a>
当前使用的测试框架是HJSUnit用于支撑OpenHarmony application测试特指基于JS应用框架使用 Javascript 语言开发的 APP进行自动化测试。
**用例编写基础语法**
测试用例为 js 语言,必须满足 JavaScript 语言编程规范:
**表 5**
<a name="table13980103565212"></a>
<table><thead align="left"><tr id="row1098093545218"><th class="cellrowborder" valign="top" width="17.92179217921792%" id="mcps1.2.4.1.1"><p id="p49811235135214"><a name="p49811235135214"></a><a name="p49811235135214"></a>用例语法</p>
</th>
<th class="cellrowborder" valign="top" width="68.88688868886888%" id="mcps1.2.4.1.2"><p id="p898183565220"><a name="p898183565220"></a><a name="p898183565220"></a>描述</p>
</th>
<th class="cellrowborder" valign="top" width="13.19131913191319%" id="mcps1.2.4.1.3"><p id="p17981143512526"><a name="p17981143512526"></a><a name="p17981143512526"></a>要求</p>
</th>
</tr>
</thead>
<tbody><tr id="row1598183515528"><td class="cellrowborder" valign="top" width="17.92179217921792%" headers="mcps1.2.4.1.1 "><p id="p139810358527"><a name="p139810358527"></a><a name="p139810358527"></a>beforeAll</p>
</td>
<td class="cellrowborder" valign="top" width="68.88688868886888%" headers="mcps1.2.4.1.2 "><p id="p198111352526"><a name="p198111352526"></a><a name="p198111352526"></a>测试套级别的预置条件,在所有测试用例开始前执行且仅执行一次,支持一个参数:预置动作函数</p>
</td>
<td class="cellrowborder" valign="top" width="13.19131913191319%" headers="mcps1.2.4.1.3 "><p id="p298114355529"><a name="p298114355529"></a><a name="p298114355529"></a>可选</p>
</td>
</tr>
<tr id="row11981103512529"><td class="cellrowborder" valign="top" width="17.92179217921792%" headers="mcps1.2.4.1.1 "><p id="p20981135135215"><a name="p20981135135215"></a><a name="p20981135135215"></a>afterAll</p>
</td>
<td class="cellrowborder" valign="top" width="68.88688868886888%" headers="mcps1.2.4.1.2 "><p id="p39811935115217"><a name="p39811935115217"></a><a name="p39811935115217"></a>测试套级别的清理条件,在所有测试用例结束后执行且仅执行一次,支持一个参数:清理动作函数</p>
</td>
<td class="cellrowborder" valign="top" width="13.19131913191319%" headers="mcps1.2.4.1.3 "><p id="p998110354527"><a name="p998110354527"></a><a name="p998110354527"></a>可选</p>
</td>
</tr>
<tr id="row1298116359526"><td class="cellrowborder" valign="top" width="17.92179217921792%" headers="mcps1.2.4.1.1 "><p id="p898112359526"><a name="p898112359526"></a><a name="p898112359526"></a>beforeEach</p>
</td>
<td class="cellrowborder" valign="top" width="68.88688868886888%" headers="mcps1.2.4.1.2 "><p id="p149811335175215"><a name="p149811335175215"></a><a name="p149811335175215"></a>测试用例级别的预置条件,在每条测试用例开始前执行,执行次数与 it 定义的测试用例数一致,支持一个参数:预置动作函数</p>
</td>
<td class="cellrowborder" valign="top" width="13.19131913191319%" headers="mcps1.2.4.1.3 "><p id="p13981133585212"><a name="p13981133585212"></a><a name="p13981133585212"></a>可选</p>
</td>
</tr>
<tr id="row6982435115219"><td class="cellrowborder" valign="top" width="17.92179217921792%" headers="mcps1.2.4.1.1 "><p id="p19982133517525"><a name="p19982133517525"></a><a name="p19982133517525"></a>afterEach</p>
</td>
<td class="cellrowborder" valign="top" width="68.88688868886888%" headers="mcps1.2.4.1.2 "><p id="p1398213575219"><a name="p1398213575219"></a><a name="p1398213575219"></a>测试用例级别的清理条件,在每条测试用例结束后执行,执行次数与 it 定义的测试用例数一致,支持一个参数:清理动作函数</p>
</td>
<td class="cellrowborder" valign="top" width="13.19131913191319%" headers="mcps1.2.4.1.3 "><p id="p159821535195219"><a name="p159821535195219"></a><a name="p159821535195219"></a>可选</p>
</td>
</tr>
<tr id="row16982143513521"><td class="cellrowborder" valign="top" width="17.92179217921792%" headers="mcps1.2.4.1.1 "><p id="p598203510527"><a name="p598203510527"></a><a name="p598203510527"></a>describe</p>
</td>
<td class="cellrowborder" valign="top" width="68.88688868886888%" headers="mcps1.2.4.1.2 "><p id="p5982123595215"><a name="p5982123595215"></a><a name="p5982123595215"></a>定义一个测试套,支持两个参数:测试套名称和测试套函数; describe 支持嵌套,每个 describe 内均可以定义 beforeAll 、beforeEach 、afterEach 和 afterAll</p>
</td>
<td class="cellrowborder" valign="top" width="13.19131913191319%" headers="mcps1.2.4.1.3 "><p id="p898217352527"><a name="p898217352527"></a><a name="p898217352527"></a>必选</p>
</td>
</tr>
<tr id="row6982113518526"><td class="cellrowborder" valign="top" width="17.92179217921792%" headers="mcps1.2.4.1.1 "><p id="p17982123510526"><a name="p17982123510526"></a><a name="p17982123510526"></a>it</p>
</td>
<td class="cellrowborder" valign="top" width="68.88688868886888%" headers="mcps1.2.4.1.2 "><p id="p598211352522"><a name="p598211352522"></a><a name="p598211352522"></a>定义一条测试用例,支持三个参数:用例名称,过滤参数和用例函数</p>
<p id="p5205769588"><a name="p5205769588"></a><a name="p5205769588"></a>备注:</p>
<p id="p6965058101"><a name="p6965058101"></a><a name="p6965058101"></a>过滤参数:过滤参数为一个 32 位的 Int 类型参数0 位 置1表示不筛选、默认执行0-10 位 置1表示<strong id="b9169154410212"><a name="b9169154410212"></a><a name="b9169154410212"></a>测试用例类型</strong>16-18 位 置1表示<strong id="b1427947428"><a name="b1427947428"></a><a name="b1427947428"></a>测试用例规模</strong>24-28 位 置1表示<strong id="b289818491213"><a name="b289818491213"></a><a name="b289818491213"></a>测试层级</strong></p>
<p id="p7965165151011"><a name="p7965165151011"></a><a name="p7965165151011"></a><strong id="b69449534215"><a name="b69449534215"></a><a name="b69449534215"></a>测试用例类型</strong>。置位0-10分别表示FUNCTION 方法类测试、PERFORMANCE 性能类测试、POWER 功耗类测试、RELIABILITY 可靠性测试、SECURITY 安全合规测试、GLOBAL 整体性测试、COMPATIBILITY 兼容性测试、USER 用户测试、STANDARD 标准测试、SAFETY 安全特性测试RESILIENCE 压力测试。</p>
<p id="p199651555102"><a name="p199651555102"></a><a name="p199651555102"></a><strong id="b10114125712211"><a name="b10114125712211"></a><a name="b10114125712211"></a>测试用例规模</strong>。置位16-18分别表示SMALL 小型测试、MEDIUM 中型测试、LARGE 大型测试。</p>
<p id="p296545151020"><a name="p296545151020"></a><a name="p296545151020"></a><strong id="b167975581223"><a name="b167975581223"></a><a name="b167975581223"></a>测试层级</strong>。置位24-28分别表示LEVEL0-0 级测试、LEVEL1-1 级测试、LEVEL2-2 级测试、LEVEL3-3 级测试、LEVEL4-4 级测试。</p>
</td>
<td class="cellrowborder" valign="top" width="13.19131913191319%" headers="mcps1.2.4.1.3 "><p id="p17601752115716"><a name="p17601752115716"></a><a name="p17601752115716"></a>必选</p>
</td>
</tr>
</tbody>
</table>
用例编写语法采用 jasmine 的标准语法格式支持ES6格式。
1. 规范用例目录测试用例存储到entry/src/main/js/test目录。
```
├── BUILD.gn
│ └──entry
│ │ └──src
│ │ │ └──main
│ │ │ │ └──js
│ │ │ │ │ └──default
│ │ │ │ │ │ └──pages
│ │ │ │ │ │ │ └──index
│ │ │ │ │ │ │ │ └──index.js # 入口文件
│ │ │ │ │ └──test # 测试代码存放目录
│ │ │ └── resources # hap资源存放目录
│ │ │ └── config.json # hap配置文件
```
2. index.js示例
```
// 拉起js测试框架加载测试用例
import {Core, ExpectExtend} from 'deccjsunit/index'
export default {
data: {
title: ""
},
onInit() {
this.title = this.$t('strings.world');
},
onShow() {
console.info('onShow finish')
const core = Core.getInstance()
const expectExtend = new ExpectExtend({
'id': 'extend'
})
core.addService('expect', expectExtend)
core.init()
const configService = core.getDefaultService('config')
configService.setConfig(this)
require('../../../test/List.test')
core.execute()
},
onReady() {
},
}
```
3. 单元测试用例示例
```
// Example1: 使用HJSUnit进行单元测试
describe('appInfoTest', function () {
it('app_info_test_001', 0, function () {
var info = app.getInfo()
expect(info.versionName).assertEqual('1.0')
expect(info.versionCode).assertEqual('3')
})
})
```
### JS语言用例编译打包指导适用于标准系统<a name="section445519106559"></a>
hap包编译请参考[标准系统js应用开发指导](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/build_overview-0000001055075201)。
## 相关仓<a name="section1371113476307"></a>
[XTS认证子系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/XTS%E8%AE%A4%E8%AF%81%E5%AD%90%E7%B3%BB%E7%BB%9F.md)
xts\_acts
[xts\_acts](https://gitee.com/openharmony/xts_acts/blob/master/README_zh.md)
**xts\_tools**
xts\_tools

49
build/ohos.build Normal file
View File

@ -0,0 +1,49 @@
{
"subsystem": "xts",
"parts":{
"phone_tests": {
"variants": [
"phone"
],
"module_list": [],
"inner_kits": [],
"system_kits": [],
"test_list": [
"//test/xts/acts:acts"
]
},
"ivi_tests": {
"variants": [
"ivi"
],
"module_list": [],
"inner_kits": [],
"system_kits": [],
"test_list": [
"//test/xts/acts:acts_ivi"
]
},
"intellitv_tests": {
"variants": [
"intellitv"
],
"module_list": [],
"inner_kits": [],
"system_kits": [],
"test_list": [
"//test/xts/acts:acts_intellitv"
]
},
"wearable_tests": {
"variants": [
"wearable"
],
"module_list": [],
"inner_kits": [],
"system_kits": [],
"test_list": [
"//test/xts/acts:acts_wearable"
]
}
}
}

454
build/suite.gni Executable file
View File

@ -0,0 +1,454 @@
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/ohos.gni")
import("//build/test.gni")
declare_args() {
SUITES_OUTPUT_ROOT = "$root_out_dir/suites"
SUITE_ARCHIVE_DIR = "$root_out_dir/suites/archives"
TESTCONFIG_FILENAME = "Test.xml"
XTS_ROOT = "//test/xts"
ACTS_ROOT = "//test/xts/acts"
# create testsuite archive is time-consuming, do it only if necessary
make_archive = false
XTS_SUITENAME = getenv("XTS_SUITENAME")
}
template("ohos_testsuite_base") {
assert(defined(invoker.project_type),
"project_type is required in target ${target_name}")
_project_type = invoker.project_type
_subsystem_name = ""
if (defined(invoker.subsystem_name)) {
_subsystem_name = invoker.subsystem_name
}
_test_files = ""
if (defined(invoker.generated_testfiles)) {
foreach(file, invoker.generated_testfiles) {
_test_files =
_test_files + "," + rebase_path("$root_gen_dir") + "/" + file
}
}
_is_testbundle = defined(invoker.is_testbundle) && invoker.is_testbundle
if (defined(invoker.sub_output_dir)) {
_output_file_dir =
rebase_path("$root_out_dir/tests/moduletest/${invoker.sub_output_dir}")
} else if (defined(invoker.module_out_path)) {
_output_file_dir =
rebase_path("$root_out_dir/tests/moduletest/${invoker.module_out_path}")
} else {
_output_file_dir = rebase_path("$root_out_dir/tests/moduletest")
}
_output_file = "${_output_file_dir}/module_${target_name}"
if (_project_type == "gtest" || _project_type == "ctestbundle") {
_output_file = "${_output_file_dir}/${target_name}"
_archive_filename = "${target_name}"
target("ohos_moduletest", "module_${target_name}") {
forward_variables_from(invoker, "*")
testonly = true
}
} else if (_project_type == "zunit" || _project_type == "javatestbundle") {
_output_file = "${_output_file_dir}/module_${target_name}.dex"
_archive_filename = "${target_name}.dex"
target("ohos_java_moduletest", "module_${target_name}") {
forward_variables_from(invoker, "*")
testonly = true
}
} else if (_project_type == "hostjunit") {
_output_file = "${_output_file_dir}/module_${target_name}.jar"
if (defined(invoker.final_jar_path)) {
_output_file = invoker.final_jar_path
}
_archive_filename = "${target_name}.jar"
target("java_library", "module_${target_name}") {
forward_variables_from(invoker, "*")
is_host_library = true
}
} else if (_project_type == "testhap" || _project_type == "haptestbundle") {
assert(defined(invoker.hap_name),
"hap_name is required in target ${target_name}")
assert(!defined(invoker.final_hap_path),
"please use hap_name instead of final_hap_path")
_hap_name = invoker.hap_name
_final_hap_path = "${SUITES_OUTPUT_ROOT}/haps/${_hap_name}.hap"
_output_file = _final_hap_path
_archive_filename = "${_hap_name}.hap"
target("ohos_hap", "module_${target_name}") {
forward_variables_from(invoker, "*")
subsystem_name = XTS_SUITENAME
final_hap_path = _final_hap_path
testonly = true
}
} else if (_project_type == "pythontest") {
if (defined(invoker.outputs_dir)) {
_out_put_dir = invoker.outputs_dir
_archive_filename = "${_subsystem_name}/${_out_put_dir}"
} else {
_archive_filename = "${_subsystem_name}"
}
_test_files = invoker.output_file
_deps = []
if (defined(invoker.deps)) {
_deps = invoker.deps
}
}
_apilibrary_deps = ""
if (_is_testbundle && defined(invoker.deps)) {
foreach(dep, invoker.deps) {
_apilibrary_deps = _apilibrary_deps + "," + dep
}
}
if (_project_type != "pythontest") {
_deps = [ ":module_${target_name}" ]
} else {
_deps = []
}
_suite_out_dir = "${SUITES_OUTPUT_ROOT}/${XTS_SUITENAME}"
_archive_testfile = "${_suite_out_dir}/testcases/${_archive_filename}"
_arguments = [
"build_module_with_testbundle",
"--build_gen_dir",
rebase_path("$root_gen_dir"),
"--build_target_name",
target_name,
"--buildgen_testfile",
rebase_path(_output_file),
"--project_path",
rebase_path("."),
"--test_xml",
rebase_path(TESTCONFIG_FILENAME),
"--project_type",
_project_type,
"--suite_out_dir",
rebase_path("${_suite_out_dir}"),
"--archive_testfile",
rebase_path("${_archive_testfile}"),
]
if (_subsystem_name != "") {
_arguments += [
"--subsystem_name",
_subsystem_name,
]
}
if (_apilibrary_deps != "") {
_arguments += [
"--apilibrary_deps",
_apilibrary_deps,
]
}
if (_test_files != "") {
_arguments += [
"--test_files",
_test_files,
]
}
action(target_name) {
deps = _deps
script = rebase_path("//test/xts/tools/build/suite.py")
args = _arguments
outputs = [ _archive_testfile ]
testonly = true
}
}
template("ohos_moduletest_suite") {
target("ohos_testsuite_base", "${target_name}") {
forward_variables_from(invoker, "*")
if (!defined(module_out_path)) {
module_out_path = "xts/modules"
}
project_type = "gtest"
}
}
template("ohos_hap_suite") {
target("ohos_testsuite_base", "${target_name}") {
forward_variables_from(invoker, "*")
# auto add HJUnitRunner entry ability and test-framework
if (defined(hap_profile)) {
# NOTE:: the GN tool disallow source files located in the ${out_dir}
# so we put the generated files in the xts dir. remember to REMOVE these.
_profile_relative_path = rebase_path(hap_profile, rebase_path(XTS_ROOT))
_fixed_profile_path =
"${XTS_ROOT}/autogen_apiobjs/${_profile_relative_path}"
_fixer_script = rebase_path(
"//test/xts/tools/build/adapter/haptest_manifest_fixer.py")
exec_script(_fixer_script,
[
"add_entryability",
"--raw_file=" + rebase_path(hap_profile),
"--dest_file=" + rebase_path(_fixed_profile_path),
])
hap_profile = _fixed_profile_path
}
if (defined(deps)) {
deps += [ "//test/xts/tools/hjunit:testkit_harmonyjunitrunner_java" ]
} else {
deps = [ "//test/xts/tools/hjunit:testkit_harmonyjunitrunner_java" ]
}
project_type = "testhap"
}
}
template("ohos_js_hap_suite") {
target("ohos_testsuite_base", "${target_name}") {
forward_variables_from(invoker, "*")
project_type = "testhap"
js_build_mode = "debug"
}
}
template("ohos_shell_app_suite") {
target("ohos_adapter_shell_app_suite", "${target_name}") {
forward_variables_from(invoker, "*")
}
}
template("ohos_prebuilt_suite") {
assert(!defined(invoker.source_files) || !defined(invoker.jar_path) ||
!defined(invoker.source_dir),
"source_files, jar_path or source_dir must be specified one.")
assert(!defined(invoker.final_jar_path),
"final_jar_path is not allowed in target ${target_name}")
if (defined(invoker.jar_path)) {
_output_name = "${target_name}.jar"
if (defined(invoker.output_name)) {
_output_name = "${invoker.output_name}.jar"
}
_output_type = "tools"
if (defined(invoker.output_type)) {
_output_type = invoker.output_type
}
_final_jar_path =
"${SUITES_OUTPUT_ROOT}/${XTS_SUITENAME}/${_output_type}/${_output_name}"
target("java_prebuilt", "${target_name}") {
forward_variables_from(invoker, "*")
final_jar_path = _final_jar_path
is_host_library = true
}
} else {
assert(defined(invoker.output_dir),
"output_dir is require in target ${target_name}")
_outputs = []
_copy_args = [
"--method_name",
"copy_file",
]
_deps = []
_output_dir = "${SUITES_OUTPUT_ROOT}/${XTS_SUITENAME}/${invoker.output_dir}"
if (defined(invoker.source_dir)) {
_copy_args += [
"--arguments",
"output=" + rebase_path(_output_dir) + "#source_dirs=" +
rebase_path(invoker.source_dir) + "#to_dir=True",
]
_outputs = [ _output_dir ]
} else if (defined(invoker.source_files)) {
_sources = ""
foreach(src, invoker.source_files) {
_sources = _sources + rebase_path(src) + ","
}
_copy_args += [
"--arguments",
"output=" + rebase_path(_output_dir) + "#sources=" + _sources +
"#to_dir=True",
]
_outputs = [ _output_dir ]
}
if (defined(invoker.deps)) {
_deps = invoker.deps
}
action(target_name) {
script = rebase_path("//test/xts/tools/build/utils.py")
deps = _deps
args = _copy_args
outputs = _outputs
}
}
}
template("ohos_deploy_xdevice") {
_suite_out_dir = "${SUITES_OUTPUT_ROOT}/${XTS_SUITENAME}"
_args = [
"build_xdevice",
"--source_dir",
rebase_path("//test/xdevice"),
"--suite_out_dir",
rebase_path(_suite_out_dir),
]
if (defined(invoker.configs_dir)) {
_args += [
"--configs_dir",
rebase_path(rebase_path(invoker.configs_dir)),
]
}
if (defined(invoker.resources_dir)) {
_args += [
"--resources_dir",
rebase_path(rebase_path(invoker.resources_dir)),
]
}
action(target_name) {
testonly = true
script = rebase_path("//test/xts/tools/build/suite.py")
args = _args
outputs = [
"${_suite_out_dir}/tools/xdevice-extension-0.0.0.tar.gz",
"${_suite_out_dir}/tools/xdevice-0.0.0.tar.gz",
"${_suite_out_dir}/tools/run.sh",
"${_suite_out_dir}/tools/run.bat",
]
}
}
template("ohos_test_suite") {
_output = "${SUITES_OUTPUT_ROOT}/${target_name}.zip"
_suite_path = rebase_path("${SUITES_OUTPUT_ROOT}/${XTS_SUITENAME}")
_suite_archive_dir = rebase_path("${SUITE_ARCHIVE_DIR}")
_prebuilts_files = rebase_path("//xts/resource")
_gen_args = [
"archive_suite",
"--suite_path",
_suite_path,
"--prebuilts_resource",
_prebuilts_files,
"--suite_archive_dir",
_suite_archive_dir,
"--make_archive",
"${make_archive}",
]
_deps = []
if (defined(invoker.deps)) {
_deps += invoker.deps
}
action(target_name) {
testonly = true
script = rebase_path("//test/xts/tools/build/suite.py")
deps = _deps
args = _gen_args
outputs = [ _output ]
}
}
template("pythontest_suite") {
assert(defined(invoker.script), "script is required in target ${target_name}")
_subsystem_name = ""
if (defined(invoker.subsystem_name)) {
_subsystem_name = invoker.subsystem_name
} else {
_local_path = rebase_path(".")
_args1 = [
"--method_name",
"get_subsystem_name",
"--arguments",
"path=${_local_path}",
]
_subsystem_name =
exec_script(rebase_path("//test/xts/tools/build/utils.py"),
_args1,
"trim string")
}
_deps = []
if (defined(invoker.deps)) {
_deps = invoker.deps + _deps
}
_outputs_dir = ""
if (defined(invoker.outputs_dir)) {
_outputs_dir = invoker.outputs_dir
}
_output_file = rebase_path("${invoker.script}")
target("ohos_testsuite_base", "${target_name}") {
project_type = "pythontest"
subsystem_name = _subsystem_name
output_file = _output_file
deps = _deps
outputs_dir = _outputs_dir
}
}
template("executable_suite") {
assert(defined(invoker.suite_name),
"suite_name is required in target ${target_name}")
_suite_name = invoker.suite_name
_local_path = rebase_path(".")
_args1 = [
"--method_name",
"get_subsystem_name",
"--arguments",
"path=${_local_path}",
]
_subsystem_name = exec_script(rebase_path("//test/xts/tools/build/utils.py"),
_args1,
"trim string")
_outputs_dir = ""
if (defined(invoker.outputs_dir)) {
_outputs_dir = "${invoker.outputs_dir}"
}
ohos_executable(target_name) {
forward_variables_from(invoker,
"*",
[
"test_type",
"module_out_path",
"visibility",
])
forward_variables_from(invoker, [ "visibility" ])
if (!defined(deps)) {
deps = []
}
subsystem_name = "tests"
part_name = "ssts"
ohos_test = true
testonly = true
output_name = "$target_name"
test_output_dir = "$SUITES_OUTPUT_ROOT/${_suite_name}/testcases/${_subsystem_name}/${_outputs_dir}"
if (defined(invoker.output_extension)) {
output_extension = invoker.output_extension
}
}
}

442
build/suite.py Normal file → Executable file
View File

@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Copyright (c) 2021 Huawei Device Co., Ltd.
Copyright (c) 2020-2021 Huawei Device Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
@ -27,150 +27,48 @@ from string import Template
import utils
import json
import shutil
import platform
import glob
import stat
class SuiteModuleBuilder:
"""
To Build Suite Module
@arguments(build_target_name, target_file...)
"""
def __init__(self, arguments):
self.arguments = arguments
self.args = None
def build_module(self):
"""
build_target_name='wifiaware_test',
javalib_file=None,
project_path='xxx/communication_lite/wifiaware',
project_type='hctest',
source_path='xxx/x.c,xxx/x.c
subsystem_name='communication',
suite_filename='libwifiaware_test.a',
suite_out_paths='out/x/suites/acts/testcases/communication,'
target_file='xxxx/libs/libmodule_wifiaware_test.a',
test_xml='xxx/Test.json'
:return:
"""
parser = argparse.ArgumentParser()
parser.add_argument('--build_target_name', help='', required=False)
parser.add_argument('--target_file', help='', required=False)
parser.add_argument('--hap_name', help='', required=False)
parser.add_argument('--project_path', help='', required=True)
parser.add_argument('--test_xml', help='', required=False)
parser.add_argument('--project_type', help='', required=True)
parser.add_argument('--suite_out_paths', help='', required=True)
parser.add_argument('--suite_filename', help='', required=True)
parser.add_argument('--subsystem_name', help='', required=False)
parser.add_argument('--build_root_path', help='', required=False)
parser.add_argument('--hap_sign', help='', required=False)
self.args = parser.parse_args(self.arguments)
XTS_RESOURCE_ROOT = 'ivbxfj`qspqsjfubsz0sftpvsdf'
for _suite_out_file in self.args.suite_out_paths.split(","):
if not _suite_out_file:
continue
if self.args.project_type == "pythontest":
_out_file = _suite_out_file
else:
_out_file = os.path.join(_suite_out_file,
self.args.suite_filename)
if self.args.project_type == "pythontest":
utils.copy_file(output=_out_file,
source_dirs=self.args.target_file,
to_dir=True)
elif self.args.project_type == "open_source_test":
utils.copy_file(output=_out_file,
sources=self.args.target_file,
to_dir=True)
elif self.args.project_type == "hjsunit":
utils.build_js_hap(self.args.project_path, self.args.
suite_out_paths, self.args.hap_name)
elif self.args.project_type != "hctest":
utils.copy_file(output=_out_file,
sources=self.args.target_file,
to_dir=False)
def _get_xts_rootpath(project_path):
if project_path is not None:
return project_path[0:project_path.find('/xts/') + len('/xts/')]
raise ValueError('Illegal xts project path ' + project_path)
_testsuite_name = self.args.suite_filename
_matcher = re.match(r"(lib|libmodule_)?(\S+)\.\S+",
_testsuite_name)
if _matcher:
_testsuite_name = _matcher.group(2)
if self.args.project_type != "open_source_test":
_config_file = os.path.join(_suite_out_file,
_testsuite_name + ".json")
else:
_config_file = os.path.join(_out_file,
_testsuite_name + ".json")
utils.record_testmodule_info(self.args.build_target_name,
_testsuite_name,
self.args.subsystem_name,
_suite_out_file)
_test_xml = self.args.test_xml
if _test_xml and os.path.exists(_test_xml):
utils.copy_file(output=_config_file, sources=_test_xml,
to_dir=False)
else:
self._generate_xml_by_template(_test_xml, _testsuite_name,
_config_file)
@staticmethod
def _record_testmodule_info(build_target_name, module_name,
subsystem_name, suite_out_dir):
if not build_target_name or not subsystem_name:
print(
'build_target_name or subsystem_name of testmodule "%s" '
'is invalid!' % module_name)
return
module_info_dir = os.path.dirname(suite_out_dir)
module_info_list_file = os.path.join(module_info_dir,
'module_info.json')
module_info_data = {}
if os.path.exists(module_info_list_file):
try:
with open(module_info_list_file, 'r') as module_file:
module_info_data = json.load(module_file)
except ValueError:
print("NO json object could be decoded but continue")
module_info = {'subsystem': subsystem_name,
'build_target_name': build_target_name}
module_info_data[module_name] = module_info
with open(module_info_list_file, 'w') as out_file:
json.dump(module_info_data, out_file)
def _get_subsystem_name(project_path):
if '/hits/' in project_path:
index0 = project_path.find('/hits/') + len('/hits/')
elif '/acts/' in project_path:
index0 = project_path.find('/acts/') + len('/acts/')
else:
raise ValueError('Illegal xts project path ' + project_path)
index1 = project_path.find('/', index0)
return project_path[index0:index1]
def _generate_xml_by_template(self, test_xml, module_name,
config_file):
index = test_xml.rfind(".json")
tmpl_file = test_xml[:index] + ".tmpl"
if not os.path.exists(tmpl_file):
raise Exception(
"Can't find the Test.json or Test.tmpl in the "
"path %s " % os.path.dirname(
test_xml))
tmpl_content = utils.read_file(tmpl_file)
values = {"module": module_name, "subsystem": self.args.subsystem_name}
xml_content = Template(tmpl_content).substitute(values)
utils.write_file(config_file, xml_content, False)
@staticmethod
def _check_file_exist(file_path):
if not os.path.exists(file_path):
raise Exception("File [%s] does not exist!" % file_path)
def _get_resource_rootpath(project_path):
xts_root = _get_xts_rootpath(project_path)
resource_reldir = ''.join(chr(ord(ch) - 1) for ch in XTS_RESOURCE_ROOT)
return os.path.join(xts_root, resource_reldir)
class XDeviceBuilder:
"""
To build XTS as a egg package
To build XTS as an egg package
@arguments(project_dir, output_dirs)
"""
def __init__(self, arguments):
parser = argparse.ArgumentParser()
parser.add_argument('--project_dir', help='', required=True)
parser.add_argument('--output_dirs', help='', required=True)
parser.add_argument('--source_dir', help='', required=True)
parser.add_argument('--configs_dir', help='', required=False)
parser.add_argument('--resources_dir', help='', required=False)
parser.add_argument('--suite_out_dir', help='', required=True)
self.args = parser.parse_args(arguments)
def build_xdevice(self):
@ -178,39 +76,41 @@ class XDeviceBuilder:
build xdevice package
:return:
"""
command = [utils.get_python_cmd(), "setup.py", "install", "--user"]
factory_script = os.path.join(self.args.project_dir, "factory.sh")
if os.path.exists(factory_script):
os.chmod(factory_script, 0o775)
command = factory_script
extension_dir = os.path.join(self.args.source_dir, 'extension')
gen_dir0 = os.path.join(self.args.source_dir, 'dist')
gen_dir1 = os.path.join(extension_dir, 'dist')
shutil.rmtree(gen_dir0, ignore_errors=True)
shutil.rmtree(gen_dir1, ignore_errors=True)
command0 = ["python", "setup.py", "sdist"]
command1 = ["python", "setup.py", "sdist"]
try:
subprocess.check_call(command, cwd=self.args.project_dir)
subprocess.check_call(command0, cwd=self.args.source_dir)
subprocess.check_call(command1, cwd=extension_dir)
except subprocess.CalledProcessError as exc:
print('returncode: {} cmd: {} output: {}'.format(
exc.returncode, exc.cmd, exc.output))
exc.returncode, exc.cmd, exc.output))
dist_dir = os.path.join(self.args.project_dir, 'dist')
run_scripts = ",".join(
[os.path.join(self.args.project_dir, "run.bat"),
os.path.join(self.args.project_dir, "run.sh")])
config_dir = os.path.join(self.args.project_dir, "config")
res_dir = os.path.join(self.args.project_dir, "resource")
for tool_dir in self.args.output_dirs.split(","):
if tool_dir:
utils.copy_file(output=tool_dir, source_dirs=dist_dir,
to_dir=True)
root_dir = os.path.dirname(tool_dir)
utils.copy_file(output=root_dir, sources=run_scripts,
to_dir=True)
to_dir = os.path.join(root_dir, "config")
utils.copy_file(output=to_dir, source_dirs=config_dir,
to_dir=True)
utils.copy_file(os.path.join(root_dir, "resource"),
source_dirs=res_dir)
if not os.path.exists(os.path.join(
root_dir, "resource", "tools")):
os.mkdir(os.path.join(root_dir, "resource", "tools"))
return 0
[os.path.join(self.args.source_dir, "run.bat"),
os.path.join(self.args.source_dir, "run.sh")])
dist_tools_dir = os.path.join(self.args.suite_out_dir, 'tools')
utils.copy_file(output=dist_tools_dir, source_dirs=gen_dir0,
to_dir=True)
utils.copy_file(output=dist_tools_dir, source_dirs=gen_dir1,
to_dir=True)
utils.copy_file(output=self.args.suite_out_dir, sources=run_scripts,
to_dir=True)
if self.args.configs_dir:
dist_configs_dir = os.path.join(self.args.suite_out_dir, 'config')
utils.copy_file(output=dist_configs_dir,
source_dirs=self.args.configs_dir, to_dir=True)
if self.args.resources_dir:
dist_resources_dir = os.path.join(self.args.suite_out_dir,
'resource')
utils.copy_file(output=dist_resources_dir,
source_dirs=self.args.resources_dir, to_dir=True)
class SuiteArchiveBuilder:
@ -221,26 +121,240 @@ class SuiteArchiveBuilder:
def archive_suite(self):
parser = argparse.ArgumentParser()
parser.add_argument('--suite_path', help='', required=True)
parser.add_argument('--build_enabled', help='', required=True)
parser.add_argument('--prebuilts_resource', help='', required=True)
parser.add_argument('--suite_archive_dir', help='', required=True)
parser.add_argument('--make_archive', help='', required=True)
args = parser.parse_args(self.arguments)
if not args.build_enabled.lower() == 'true':
print('build hit not enabled, skip making archive')
if not args.make_archive.lower() == 'true':
print('make archive disabled')
return 0
suite_path = args.suite_path
if not os.path.isdir(suite_path):
raise Exception("[%s] does not exist" % suite_path)
copyfiles = args.prebuilts_resource.split(",")
for file_path in copyfiles:
subprocess.call(["cp", "-rf", file_path, suite_path])
archive_name = os.path.basename(suite_path)
suite_root_path = os.path.dirname(suite_path)
shutil.make_archive(suite_path, "zip", suite_root_path, archive_name)
archive_root_path = args.suite_archive_dir
if not os.path.isdir(archive_root_path):
os.mkdir(archive_root_path)
# remove the extra output of target "java_prebuilt"
# such as ztest-tradefed-common.interface.jar
subprocess.call(["find", suite_path, "-name", "*.interface.jar",
"-exec", "rm", "{}", "+"])
shutil.make_archive(os.path.join(archive_root_path, archive_name),
"zip", suite_path)
return 0
class SuiteModuleWithTestbundleBuilder:
def __init__(self, arguments):
self.arguments = arguments
self.args = None
def build_module_with_testbundle(self):
parser = argparse.ArgumentParser()
parser.add_argument('--build_gen_dir', help='', required=True)
parser.add_argument('--build_target_name', help='', required=True)
parser.add_argument('--subsystem_name', help='',
required=False)
parser.add_argument('--buildgen_testfile', help='', required=True)
parser.add_argument('--project_path', help='', required=True)
parser.add_argument('--test_xml', help='', required=False)
parser.add_argument('--project_type', help='', required=True)
parser.add_argument('--suite_out_dir', help='', required=True)
parser.add_argument('--archive_testfile', help='', required=True)
parser.add_argument('--apilibrary_deps', help='', required=False)
parser.add_argument('--test_files', help='', required=False)
self.args = parser.parse_args(self.arguments)
self._create_testsuite(self.args)
return 0
def _create_testsuite(self, args):
_test_xml = args.test_xml
_testcases_dir = os.path.dirname(args.archive_testfile)
_testsuite_name = os.path.basename(args.archive_testfile)\
.replace('.hap', '').replace('module_', '')
_testcase_xml = os.path.join(_testcases_dir, _testsuite_name + ".xml")
_config_file = os.path.join(_testcases_dir,
_testsuite_name + ".config")
_json_file = os.path.join(_testcases_dir, _testsuite_name + ".json")
if args.project_type == "js_test_hap":
self._generate_json_by_template(_test_xml.replace(".xml", ".json"),
_testsuite_name, _json_file)
dest_file = os.path.join(
_testcases_dir, "{}.hap".format(_testsuite_name))
self._copy_file(args.buildgen_testfile, dest_file)
os.chmod(dest_file, stat.S_IRWXU|stat.S_IRWXG|stat.S_IRWXO)
return
if args.project_type == "pythontest":
self._generate_json_by_template(_test_xml.replace(".xml", ".json"),
_testsuite_name, os.path.join(
args.archive_testfile, _testsuite_name + ".json"))
utils.copy_file(output=self.args.archive_testfile,
source_dirs=self.args.test_files)
return
self._check_file_exist(args.buildgen_testfile)
self._copy_file(args.buildgen_testfile, args.archive_testfile)
if args.project_type == "app":
return
self._record_testmodule_info(args.build_target_name,
_testsuite_name,
_testcases_dir)
if _test_xml and os.path.exists(_test_xml):
self._copy_file(_test_xml, _config_file)
elif _test_xml.replace(".xml", ".json") and \
os.path.exists(_test_xml.replace(".xml", ".json")):
self._generate_json_by_template(_test_xml.replace(".xml", ".json"),
_testsuite_name, _json_file)
else:
self._generate_xml_by_template(_test_xml, _testsuite_name,
_config_file)
#self._generate_testcase_xml(args)
_resource_srcroot = _get_resource_rootpath(args.project_path)
try:
self._archive_test_resource(_config_file, _resource_srcroot,
args.suite_out_dir)
except Exception as error:
print("Archive resource error: %s" % error, file=sys.stderr)
self._archive_test_file_to_testcase(_testcases_dir)
@staticmethod
def _record_testmodule_info(build_target_name, module_name, testcases_dir):
if not build_target_name or not module_name:
raise ValueError(
'Ethire build_target_name or module_name is invalid')
module_info_list_file = os.path.join(testcases_dir, 'module_info.list')
lines = []
if os.path.isfile(module_info_list_file):
with open(module_info_list_file, 'r') as file_read:
for line in file_read:
lines.append(line.strip())
new_lines = ['%s %s' % (build_target_name, module_name)]
for line in lines:
arr = line.strip().split(' ')
if len(arr) == 0 or arr[0] == build_target_name:
continue
new_lines.append(line)
# add module info
with open(module_info_list_file, 'w') as file_write:
file_write.write('\n'.join(new_lines) + '\n')
@staticmethod
def _generate_json_by_template(source_file, module_name, dest_file):
source_content = utils.read_file(source_file)
values = {"module": module_name}
xml_content = Template(source_content).substitute(values)
utils.write_file(dest_file, xml_content, False)
@staticmethod
def _generate_xml_by_template(test_xml, module_name,
config_file):
# find the template file
index = test_xml.rfind(".xml")
tmpl_file = test_xml[:index] + ".tmpl"
if not os.path.exists(tmpl_file):
raise Exception("Can't find the Test.xml or "
"Test.tmpl in the path %s " %
os.path.dirname(test_xml))
tmpl_content = utils.read_file(tmpl_file)
values = {"module": module_name}
xml_content = Template(tmpl_content).substitute(values)
utils.write_file(config_file, xml_content, False)
def _copy_file(self, source, target):
if not os.path.exists(os.path.dirname(target)):
os.makedirs(os.path.dirname(target))
if not os.path.exists(target) or (
os.path.exists(target) and
(os.stat(target).st_mtime != os.stat(source).st_mtime)):
print('Trying to copy "%s" to "%s"' % (source, target))
subprocess.call(["rm", "-rf", target])
subprocess.call(["cp", "-rf", source, target])
def _copy_file_to_target(self, source_file, dest_file):
if not os.path.exists(source_file):
print("[ERROR] source_file is not exist. %s" % source_file,
file=sys.stderr)
return
else:
self._copy_file(source_file, dest_file)
def _archive_test_resource(self, xml_file, root_dir, resource_dir):
_pattern = re.compile("[-=]>")
if os.path.exists(xml_file):
try:
dom = xml.dom.minidom.parse(xml_file)
childroot = dom.getElementsByTagName("target_preparer")
for child in childroot:
for child_atrr in child.getElementsByTagName("option"):
name = child_atrr.getAttribute("name")
attr_value = child_atrr.getAttribute("value")
value = _pattern.split(attr_value)[0].strip()
if name != "" or value != "":
if name == "push" and \
value.startswith("resource/"):
self._copy_file_to_target(
os.path.join(root_dir, "../", value),
os.path.join(resource_dir, value))
else:
raise Exception("Test.xml node name and "
"value not is null")
except IOError as error:
print("IO Error: %s" % error, file=sys.stderr)
except ExpatError as error:
print("ExpatError Error: %s" % error, file=sys.stderr)
finally:
pass
else:
with open(xml_file.replace(".config", ".json"),
"r", encoding="UTF-8") as json_file:
json_str = json.load(json_file)
kits = json_str["kits"]
for kit in kits:
types = kit["type"]
if types == "PushKit":
push_resources = kit["push"]
for resource in push_resources:
value = _pattern.split(resource)[0].strip()
if value.startswith("resource/"):
self._copy_file_to_target(
os.path.join(root_dir, "../", value),
os.path.join(resource_dir, value))
def _archive_test_file_to_testcase(self, cases_dir):
if self.args.test_files is None:
return
arr_test_files = self.args.test_files.split(',')
for file in arr_test_files:
if file == "":
continue
self._copy_file_to_target(file,
os.path.join(cases_dir,
os.path.basename(file)))
def _check_file_exist(self, file_path):
if not os.path.exists(file_path):
raise Exception("File [%s] does not exist!" % file_path)
ACTION_MAP = {"build_module": "SuiteModuleBuilder",
"build_xdevice": "XDeviceBuilder",
"archive_suite": "SuiteArchiveBuilder",
}
"build_module_with_testbundle":
"SuiteModuleWithTestbundleBuilder"}
def _find_action(action, arguments):

60
build/test_package_select.py Executable file
View File

@ -0,0 +1,60 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Copyright (c) 2021 Huawei Device Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import json
import sys
def filter_modules(subsystem_data_file, test_packages):
subsystems = set()
with open(subsystem_data_file) as fd:
subsystem_data = json.load(fd)
subsystems = set(subsystem_data)
subsystems.add("demo")
subsystems.add("storage")
selected_packages = []
for dep in test_packages:
if 'selected_subsystem=' in dep:
selected_subsystem = dep.split('=')[1]
init_subsystems = subsystems.copy()
subsystems.clear()
for item in selected_subsystem.split(','):
if item in init_subsystems:
subsystems.add(item)
break
for dep in test_packages:
rslash_index = dep.find('/hits')
if rslash_index < 0:
rslash_index = dep.find('/acts')
colon_index = dep.find(':')
if rslash_index < 0 or colon_index < 0:
continue
rslash_index += 5
subsystem_name = dep[rslash_index + 1:colon_index]
if subsystem_name in subsystems:
selected_packages.append(dep)
else:
pass
return selected_packages
if __name__ == "__main__":
main_subsystem_data_file = sys.argv[1]
main_test_packages = sys.argv[2:]
main_selected_packages = filter_modules(main_subsystem_data_file,
main_test_packages)
sys.stdout.write('\n'.join(main_selected_packages))

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python3
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Copyright (c) 2021 Huawei Device Co., Ltd.
Copyright (c) 2020-2021 Huawei Device Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
@ -19,14 +19,10 @@ import os
import fnmatch
import sys
import argparse
import json
import platform
import subprocess
import distutils.dir_util as dir_util
import distutils.file_util as file_util
from distutils.errors import DistutilsError
import json
import subprocess
# all sub system list, must be lowercase.
_SUB_SYSTEM_LIST = [
@ -34,43 +30,25 @@ _SUB_SYSTEM_LIST = [
"hiviewdfx",
"communication",
"security",
"update",
"updater",
"sstsutils",
"utils",
"uikit",
"multimedia",
"hdf",
"aafwk",
"appexecfwk",
"distributed_schedule",
"appexecfwk",
"distributedschedule",
"startup",
"sensors",
"sample",
"iot_hardware",
"iothardware",
"open_posix_testsuite",
"graphic",
"ace",
"applications",
"ai",
"global",
"telephony",
"dcts"
]
_GRADLE_PARAMS = ["SIGN_USER_NAME", "SIGN_PWD", "SIGN_MATERIAL_PATH",
"SIGN_PROFILE", "SIGN_CERT_FILE"]
_NO_FILTE_SUB_SYSTEM_LIST = [
"applications",
"kernel",
"open_posix_testsuite",
"sample",
"telephony",
"dcts",
"hiviewdfx",
"communication",
"security",
"update",
"sstsutils",
"hdf",
"distributed_schedule"
]
_DEFAULT_USER_NAME = "user"
_DEFAULT_PWD = "decrypt_pwd"
def main():
@ -85,9 +63,7 @@ def main():
for argument in args.arguments.split("#"):
key_value = argument.strip().split("=")
if len(key_value) != 2:
raise ValueError(
"The arguments' format is 'key=value#key=value'. Wrong format:"
" " + argument)
raise ValueError("Wrong format : '%s' % argument")
arguments.setdefault(key_value[0].strip(), key_value[1].strip())
method(**arguments)
return 0
@ -138,32 +114,20 @@ def copy_file(output, sources="", source_dirs="", to_dir=True):
except OSError:
if not os.path.isdir(_output):
raise
try:
if _sources:
_copy_files(_sources.split(","), _output)
if _sources:
_copy_files(_sources.split(","), _output)
if _source_dirs:
_copy_dir(_source_dirs.split(","), _output)
if _source_dirs:
_copy_dir(_source_dirs.split(","), _output)
except DistutilsError:
print("ignore file exist error")
return 0
def _copy_files(sources, output):
copy_set = set()
for source_file in sources:
source_file = source_file.strip()
if os.path.isfile(source_file) and os.path.exists(source_file):
# if same file name exist, add dir path
if os.path.basename(source_file) in copy_set:
new_output = os.path.join(output, os.path.dirname(source_file).
split(os.sep)[-1])
if not os.path.exists(new_output):
os.makedirs(new_output)
file_util.copy_file(source_file, new_output)
else:
file_util.copy_file(source_file, output)
copy_set.add(os.path.basename(source_file))
if os.path.isfile(source_file):
file_util.copy_file(source_file, output)
def _copy_dir(sources, output):
@ -188,12 +152,12 @@ def gen_suite_out(suite_output_prefix, suite_names, out_suffix):
def get_subsystem_name(path):
subsystem_name = ""
for subsystem in _SUB_SYSTEM_LIST:
subsystem_path = "/" + subsystem + "/"
subsystem_path = "/%s/" % (subsystem)
_path = path.lower()
if subsystem_path in _path:
subsystem_name = subsystem
break
subsystem_path = "/" + subsystem + "_lite/"
subsystem_path = "/%s/_lite" % (subsystem)
if subsystem_path in _path:
subsystem_name = subsystem
break
@ -204,6 +168,7 @@ def get_subsystem_name(path):
def get_modulename_by_buildtarget(module_list_file, build_target):
if not os.path.exists(module_list_file):
return ""
module_info_data = {}
with open(module_list_file, "r") as module_file:
module_info_data = json.load(module_file)
for module in module_info_data:
@ -221,128 +186,6 @@ def glob(path, filename_pattern):
return files
def filter_by_subsystem(testsuites, product_json):
product_info = {}
filtered_features = []
subs_comps = {}
# parses product json to obtain all the subsystem name
if os.path.exists(product_json):
try:
with open(product_json, 'r') as product_info:
product_info = json.load(product_info)
except ValueError:
print("NO json object could be decoded.")
subsystem_info = product_info.get("subsystems")
for subsystem in subsystem_info:
subs_comps[subsystem.get("subsystem")] = \
subsystem.get("components", [])
feature_list = testsuites.split(",")
for feature in feature_list:
# if subsytem name match
subsystem = get_subsystem_name_no_output(feature)
if subsystem in _NO_FILTE_SUB_SYSTEM_LIST:
filtered_features.append(feature)
print(feature)
elif subsystem in subs_comps:
components = subs_comps.get(subsystem, [])
if check_component(feature, components):
filtered_features.append(feature)
print(feature)
return filtered_features
def get_subsystem_name_no_output(path):
subsystem_name = ""
for subsystem in _SUB_SYSTEM_LIST:
subsystem_path = "/" + subsystem
_path = path.lower()
if subsystem_path in _path:
subsystem_name = subsystem
break
subsystem_path = "/" + subsystem + "_lite"
if subsystem_path in _path:
subsystem_name = subsystem
break
return subsystem_name
def check_component(path, components):
for component in components:
component_name = component.get("component", "")
component_name = component_name.replace("_lite", "")
if component_name in path or "{}_hal".format(component_name) in path \
or "{}_posix".format(component_name) in path:
return True
return False
def get_python_cmd():
major, _, _ = platform.python_version_tuple()
if major == "3":
return "python"
else:
return "python3"
def record_testmodule_info(build_target_name, module_name,
subsystem_name, suite_out_dir, same_file=False):
if not build_target_name or not subsystem_name:
print(
'build_target_name or subsystem_name of testmodule "%s" '
'is invalid!' % module_name)
return
if same_file:
module_info_list_file = os.path.join(suite_out_dir, 'module_info.json')
else:
module_info_list_file = os.path.join(suite_out_dir,
'{}_module_info.json'.format
(build_target_name))
module_info_data = {}
if os.path.exists(module_info_list_file):
try:
with open(module_info_list_file, 'r') as module_file:
module_info_data = json.load(module_file)
except ValueError:
print("NO json object could be decoded but continue")
module_info = {'subsystem': subsystem_name,
'build_target_name': build_target_name}
module_info_data[module_name] = module_info
with open(module_info_list_file, 'w') as out_file:
json.dump(module_info_data, out_file)
def record_test_component_info(out_dir, version):
if not os.path.exists(out_dir):
os.makedirs(out_dir)
all_module_file = os.path.join(out_dir, 'module_info.json')
all_module_data = {}
for root, dirs, files in os.walk(out_dir):
for file in files:
if file.endswith("module_info.json"):
with open(os.path.join(root, file), 'r') as json_data:
module_data = json.load(json_data)
all_module_data.update(module_data)
os.remove(os.path.join(root, file))
with open(all_module_file, 'w') as out_file:
json.dump(all_module_data, out_file)
test_component_file = os.path.join(out_dir, 'test_component.json')
test_component_data = {'version': version, }
with open(test_component_file, 'w') as out_file:
json.dump(test_component_data, out_file)
def get_target_modules(all_features):
feature_list = []
if all_features:
for feature in all_features.split(","):
if feature:
feature_list.append(feature)
print(feature)
return feature_list
def cmd_popen(cmd):
proc = subprocess.Popen(cmd)
proc.wait()
@ -351,25 +194,60 @@ def cmd_popen(cmd):
raise Exception("{} failed, return code is {}".format(cmd, ret_code))
def build_js_hap(project_path, out_put_dir, hap_name):
def build_js_hap(**kwargs):
if not check_env():
return
if "project_path" not in kwargs or "out_put_dir" not in kwargs:
return
project_path = kwargs.get("project_path")
gradle_dir = os.path.join(project_path, "gradle")
os.chdir(gradle_dir)
build_clean = ["gradle", "clean"]
cmd_popen(build_clean)
build_cmd = ["gradle", "entry:packageDebugHap"]
cmd_popen(build_cmd)
gralde_output_dir = os.path.join(gradle_dir, "entry", "build", "outputs")
if os.path.exists(gralde_output_dir):
for root, _, files in os.walk(gralde_output_dir):
for file in files:
if file.endswith(".hap"):
file_util.copy_file(os.path.join(root, file),
os.path.join(out_put_dir.rstrip(','),
hap_name))
return
if "SIGN_USER_NAME" not in kwargs:
pass
gradle_parm_cmd = get_gradle_cmd(**kwargs)
# build sign debug hap
build_hap_cmd = ["gradle"]
build_hap_cmd.extend(gradle_parm_cmd)
build_hap_cmd.append("entry:aD")
cmd_popen(build_hap_cmd)
# build sign ohos test hap
build_test_hap_cmd = ["gradle"]
build_test_hap_cmd.extend(gradle_parm_cmd)
build_test_hap_cmd.append("entry:aDOT")
cmd_popen(build_test_hap_cmd)
gradle_output_dir = os.path.join(gradle_dir, "entry", "build", "outputs")
if not os.path.exists(gradle_output_dir):
return
out_put_dir = kwargs.get("out_put_dir")
if not os.path.exists(out_put_dir):
os.makedirs(out_put_dir)
hap_name = kwargs.get("hap_name")
for root, _, files in os.walk(gradle_output_dir):
for file in files:
if file.endswith(".hap") and "unsigned" not in file:
if "debugOhosTest" in root:
target_file = "{}_OhosTest.hap".format(hap_name)
else:
target_file = "{}.hap".format(hap_name)
file_util.copy_file(os.path.join(root, file),
os.path.join(out_put_dir.rstrip(','),
target_file))
def get_gradle_cmd(**kwargs):
cmd = []
if kwargs:
kwargs.setdefault("SIGN_USER_NAME", _DEFAULT_USER_NAME)
kwargs.setdefault("SIGN_PWD", _DEFAULT_PWD)
for param in _GRADLE_PARAMS:
if param in kwargs:
cmd.append("-P{}={}".format(param, kwargs.get(param)))
return cmd
def check_env():
@ -377,12 +255,14 @@ def check_env():
check all the env for js hap build
return: return true if all env ready, otherwise return false
"""
env_list = ['OHOS_SDK_HOME', 'NODE_HOME', 'GRADLE_HOME']
env_list = ['OHOS_SDK_HOME']
for env in env_list:
if not os.environ.get(env):
print("the env {} not set, skip build!".format(env))
return False
else:
return True
if __name__ == '__main__':
sys.exit(main())

177
lite/LICENSE Executable file
View File

@ -0,0 +1,177 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS

62
lite/OAT.xml Normal file
View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (c) 2021 Huawei Device Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- OAT(OSS Audit Tool) configuration guide:
basedir: Root dir, the basedir + project path is the real source file location.
licensefile:
1.If the project don't have "LICENSE" in root dir, please define all the license files in this project in , OAT will check license files according to this rule.
tasklist(only for batch mode):
1. task: Define oat check thread, each task will start a new thread.
2. task name: Only an name, no practical effect.
3. task policy: Default policy for projects under this task, this field is required and the specified policy must defined in policylist.
4. task filter: Default filefilter for projects under this task, this field is required and the specified filefilter must defined in filefilterlist.
5. task project: Projects to be checked, the path field define the source root dir of the project.
policyList:
1. policy: All policyitems will be merged to default OAT.xml rules, the name of policy doesn't affect OAT check process.
2. policyitem: The fields type, name, path, desc is required, and the fields rule, group, filefilter is optional,the default value is:
<policyitem type="" name="" path="" desc="" rule="may" group="defaultGroup" filefilter="defaultPolicyFilter"/>
3. policyitem type:
"compatibility" is used to check license compatibility in the specified path;
"license" is used to check source license header in the specified path;
"copyright" is used to check source copyright header in the specified path;
"import" is used to check source dependency in the specified path, such as import ... ,include ...
"filetype" is used to check file type in the specified path, supported file types: archive, binary
"filename" is used to check whether the specified file exists in the specified path(support projectroot in default OAT.xml), supported file names: LICENSE, README, README.OpenSource
4. policyitem name: This field is used for define the license, copyright, "*" means match all, the "!" prefix means could not match this value. For example, "!GPL" means can not use GPL license.
5. policyitem path: This field is used for define the source file scope to apply this policyitem, the "!" prefix means exclude the files. For example, "!.*/lib/.*" means files in lib dir will be exclude while process this policyitem.
6. policyitem rule and group: These two fields are used together to merge policy results. "may" policyitems in the same group means any one in this group passed, the result will be passed.
7. policyitem filefilter: Used to bind filefilter which define filter rules.
8. filefilter: Filter rules, the type filename is used to filter file name, the type filepath is used to filter file path.
Note:If the text contains special characters, please escape them according to the following rules:
" == &gt;
& == &gt;
' == &gt;
< == &gt;
> == &gt;
-->
<configuration>
<oatconfig>
<filefilterlist>
<filefilter name="binaryFileTypePolicyFilter" desc="Filters for binaryFile" >
<filteritem type="filename" name="*.gif" desc="all gif file have check "/>
</filefilter>
</filefilterlist>
</oatconfig>
</configuration>

530
lite/README.md Executable file
View File

@ -0,0 +1,530 @@
# X Test Suite<a name="EN-US_TOPIC_0000001132537809"></a>
- [Introduction](#section465982318513)
- [Devices](#section125090457443)
- [Directory Structure](#section161941989596)
- [Constraints](#section119744591305)
- [Usage Guidelines](#section137768191623)
- [Test Case Development Guidelines](#section3695134065513)
- [C-based Test Case Development and Compilation \(for Mini-System Devices\)](#section1551164914237)
- [C-based Test Case Execution \(for Mini-System Devices\)](#section10100701294)
- [C++-based Test Case Development and Compilation \(for Small-, Standard-, and Large-System Devices\)](#section5714177113113)
- [C++-based Test Case Execution \(for Small-, Standard-, and Large-System Devices\)](#section42281924184)
- [Repositories Involved](#section1371113476307)
## Introduction<a name="section465982318513"></a>
The X test suite \(XTS\) subsystem contains a set of OpenHarmony certification test suites, including the currently supported application compatibility test suite \(ACTS\) and the device compatibility test suite \(DCTS\) that will be supported in the future.
This subsystem contains the ACTS and **tools** software package.
- The **acts** directory stores the source code and configuration files of ACTS test cases. The ACTS helps device vendors detect the software incompatibility as early as possible and ensures that the software is compatible to OpenHarmony during the entire development process.
- The **tools** software package stores the test case development framework related to **acts**.
## Devices<a name="section125090457443"></a>
OpenHarmony supports the following device types:
- **Mini-System Devices \(reference memory ≥ 128 KB\)**
Such devices are equipped with MCU processors such as ARM Cortex-M and 32-bit RISC-V. They provide rich short-distance connection and peripheral bus access capabilities. Typical products include LinkIoT module devices and sensors in the smart home field. The LinkIoT module is usually used for smart Internet of Things \(IoT\) devices as the hardware module that implements connectivity functions. In the smart home field, the LinkIoT module is integrated into devices by vendors. For example, a LinkIoT module provides WLAN/Bluetooth access and data connection, and it usually communicates with the chip of smart home devices via a universal asynchronous receiver-transmitter \(UART\) or general-purpose input/output \(GPIO\) interface.
- **Small-System Devices \(reference memory ≥ 1 MB\)**
Such devices are equipped with application processors such as ARM Cortex-A. They provide higher security capabilities, standard graphics framework, and multimedia capabilities for video encoding and decoding. Typical products include IP cameras, electronic cat eyes, and routers in the smart home field, as well as event data recorders \(EDRs\) in the smart travel field.
- **Standard-System Devices \(reference memory ≥ 128 MB\)**
Such devices are equipped with application processors such as ARM Cortex-A. They provide a complete application framework supporting enhanced interaction, 3D GPU, hardware composer, diverse components, and rich animations. Typical products include high-end refrigerator displays.
- **Large-System Devices \(reference memory ≥ 1 GB\)**
Such devices are equipped with application processors such as ARM Cortex-A and provide a complete compatible application framework. Typical products include smart TVs and smart watches.
## Directory Structure<a name="section161941989596"></a>
```
/test/xts
├── acts # Test code
│ └── subsystem # Source code of subsystem test cases for large-system devices
│ └── subsystem_lite # Source code of subsystems test cases for mini- and small-system devices
│ └── BUILD.gn # Build configuration of test cases for large-system devices
│ └── build_lite # Build configuration of test cases for mini-and small-system devices
│ └── build_lite # Build configuration
└── tools # Test tool code
```
## Constraints<a name="section119744591305"></a>
Test cases for mini system devices must be developed based on C, and those for small system devices must be developed based on C++.
## Usage Guidelines<a name="section137768191623"></a>
**Table 1** Test case levels
<a name="table12856113719456"></a>
<table><thead align="left"><tr id="row88561737114517"><th class="cellrowborder" valign="top" width="33.333333333333336%" id="mcps1.2.4.1.1"><p id="p54711456452"><a name="p54711456452"></a><a name="p54711456452"></a>Level</p>
</th>
<th class="cellrowborder" valign="top" width="33.283328332833285%" id="mcps1.2.4.1.2"><p id="p114834544518"><a name="p114834544518"></a><a name="p114834544518"></a>Definition</p>
</th>
<th class="cellrowborder" valign="top" width="33.383338333833386%" id="mcps1.2.4.1.3"><p id="p348154574518"><a name="p348154574518"></a><a name="p348154574518"></a>Scope</p>
</th>
</tr>
</thead>
<tbody><tr id="row78561137134514"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.2.4.1.1 "><p id="p17481345124512"><a name="p17481345124512"></a><a name="p17481345124512"></a>Level0</p>
</td>
<td class="cellrowborder" valign="top" width="33.283328332833285%" headers="mcps1.2.4.1.2 "><p id="p1548945204514"><a name="p1548945204514"></a><a name="p1548945204514"></a>Smoke</p>
</td>
<td class="cellrowborder" valign="top" width="33.383338333833386%" headers="mcps1.2.4.1.3 "><p id="p174824517456"><a name="p174824517456"></a><a name="p174824517456"></a>Verifies basic functionalities of key features and basic DFX attributes with the most common input. The pass result indicates that the features are runnable.</p>
</td>
</tr>
<tr id="row28563372451"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.2.4.1.1 "><p id="p448445144512"><a name="p448445144512"></a><a name="p448445144512"></a>Level1</p>
</td>
<td class="cellrowborder" valign="top" width="33.283328332833285%" headers="mcps1.2.4.1.2 "><p id="p44813452452"><a name="p44813452452"></a><a name="p44813452452"></a>Basic</p>
</td>
<td class="cellrowborder" valign="top" width="33.383338333833386%" headers="mcps1.2.4.1.3 "><p id="p648184584514"><a name="p648184584514"></a><a name="p648184584514"></a>Verifies basic functionalities of key features and basic DFX attributes with common input. The pass result indicates that the features are testable.</p>
</td>
</tr>
<tr id="row12856137204514"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.2.4.1.1 "><p id="p164834520453"><a name="p164834520453"></a><a name="p164834520453"></a>Level2</p>
</td>
<td class="cellrowborder" valign="top" width="33.283328332833285%" headers="mcps1.2.4.1.2 "><p id="p148245184511"><a name="p148245184511"></a><a name="p148245184511"></a>Major</p>
</td>
<td class="cellrowborder" valign="top" width="33.383338333833386%" headers="mcps1.2.4.1.3 "><p id="p348945124510"><a name="p348945124510"></a><a name="p348945124510"></a>Verifies basic functionalities of key features and basic DFX attributes with common input and errors. The pass result indicates that the features are functional and ready for beta testing.</p>
</td>
</tr>
<tr id="row48571137204514"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.2.4.1.1 "><p id="p7481545184513"><a name="p7481545184513"></a><a name="p7481545184513"></a>Level3</p>
</td>
<td class="cellrowborder" valign="top" width="33.283328332833285%" headers="mcps1.2.4.1.2 "><p id="p1748184514455"><a name="p1748184514455"></a><a name="p1748184514455"></a>Regular</p>
</td>
<td class="cellrowborder" valign="top" width="33.383338333833386%" headers="mcps1.2.4.1.3 "><p id="p8481245104519"><a name="p8481245104519"></a><a name="p8481245104519"></a>Verifies functionalities of all key features, and all DFX attributes with common and uncommon input combinations or normal and abnormal preset conditions.</p>
</td>
</tr>
<tr id="row14857133712451"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.2.4.1.1 "><p id="p1248144515456"><a name="p1248144515456"></a><a name="p1248144515456"></a>Level4</p>
</td>
<td class="cellrowborder" valign="top" width="33.283328332833285%" headers="mcps1.2.4.1.2 "><p id="p94804514519"><a name="p94804514519"></a><a name="p94804514519"></a>Rare</p>
</td>
<td class="cellrowborder" valign="top" width="33.383338333833386%" headers="mcps1.2.4.1.3 "><p id="p1248445164516"><a name="p1248445164516"></a><a name="p1248445164516"></a>Verifies functionalities of key features under extremely abnormal presets and uncommon input combinations.</p>
</td>
</tr>
</tbody>
</table>
**Table 2** Test case granularities
<a name="table1690733521014"></a>
<table><thead align="left"><tr id="row9907143516105"><th class="cellrowborder" valign="top" width="19.591959195919593%" id="mcps1.2.4.1.1"><p id="p1141312416102"><a name="p1141312416102"></a><a name="p1141312416102"></a>Test Scale</p>
</th>
<th class="cellrowborder" valign="top" width="35.17351735173517%" id="mcps1.2.4.1.2"><p id="p34131416109"><a name="p34131416109"></a><a name="p34131416109"></a>Test Objects</p>
</th>
<th class="cellrowborder" valign="top" width="45.23452345234523%" id="mcps1.2.4.1.3"><p id="p12413141171010"><a name="p12413141171010"></a><a name="p12413141171010"></a>Test Environment</p>
</th>
</tr>
</thead>
<tbody><tr id="row2907335181017"><td class="cellrowborder" valign="top" width="19.591959195919593%" headers="mcps1.2.4.1.1 "><p id="p6414134117109"><a name="p6414134117109"></a><a name="p6414134117109"></a>LargeTest</p>
</td>
<td class="cellrowborder" valign="top" width="35.17351735173517%" headers="mcps1.2.4.1.2 "><p id="p20414104113101"><a name="p20414104113101"></a><a name="p20414104113101"></a>Service functionalities, all-scenario features, and mechanical power environment (MPE) and scenario-level DFX</p>
</td>
<td class="cellrowborder" valign="top" width="45.23452345234523%" headers="mcps1.2.4.1.3 "><p id="p5414841121013"><a name="p5414841121013"></a><a name="p5414841121013"></a>Devices close to real devices</p>
</td>
</tr>
<tr id="row10907635131015"><td class="cellrowborder" valign="top" width="19.591959195919593%" headers="mcps1.2.4.1.1 "><p id="p19414134117104"><a name="p19414134117104"></a><a name="p19414134117104"></a>MediumTest</p>
</td>
<td class="cellrowborder" valign="top" width="35.17351735173517%" headers="mcps1.2.4.1.2 "><p id="p114141241141018"><a name="p114141241141018"></a><a name="p114141241141018"></a>Modules, subsystem functionalities after module integration, and DFX</p>
</td>
<td class="cellrowborder" valign="top" width="45.23452345234523%" headers="mcps1.2.4.1.3 "><p id="p14414941111015"><a name="p14414941111015"></a><a name="p14414941111015"></a>Single device that is actually used. You can perform message simulation, but do not mock functions.</p>
</td>
</tr>
<tr id="row1990713353100"><td class="cellrowborder" valign="top" width="19.591959195919593%" headers="mcps1.2.4.1.1 "><p id="p641414110109"><a name="p641414110109"></a><a name="p641414110109"></a>SmallTest</p>
</td>
<td class="cellrowborder" valign="top" width="35.17351735173517%" headers="mcps1.2.4.1.2 "><p id="p54141541181018"><a name="p54141541181018"></a><a name="p54141541181018"></a>Modules, classes, and functions</p>
</td>
<td class="cellrowborder" valign="top" width="45.23452345234523%" headers="mcps1.2.4.1.3 "><p id="p1841494131013"><a name="p1841494131013"></a><a name="p1841494131013"></a>Local PC. Use a large number of mocks to replace dependencies with other modules.</p>
</td>
</tr>
</tbody>
</table>
**Table 3** Test types
<a name="table18811230124619"></a>
<table><thead align="left"><tr id="row48163019466"><th class="cellrowborder" valign="top" width="19.040000000000003%" id="mcps1.2.3.1.1"><p id="p1791784418465"><a name="p1791784418465"></a><a name="p1791784418465"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="80.96%" id="mcps1.2.3.1.2"><p id="p2917164444614"><a name="p2917164444614"></a><a name="p2917164444614"></a>Definition</p>
</th>
</tr>
</thead>
<tbody><tr id="row682630104615"><td class="cellrowborder" valign="top" width="19.040000000000003%" headers="mcps1.2.3.1.1 "><p id="p1091784414469"><a name="p1091784414469"></a><a name="p1091784414469"></a>Function</p>
</td>
<td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><p id="p16917344104618"><a name="p16917344104618"></a><a name="p16917344104618"></a>Tests the correctness of both service and platform functionalities provided by the tested object for end users or developers.</p>
</td>
</tr>
<tr id="row1821930154611"><td class="cellrowborder" valign="top" width="19.040000000000003%" headers="mcps1.2.3.1.1 "><p id="p591714474612"><a name="p591714474612"></a><a name="p591714474612"></a>Performance</p>
</td>
<td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><p id="p15917154410463"><a name="p15917154410463"></a><a name="p15917154410463"></a>Tests the processing capability of the tested object under specific preset conditions and load models. The processing capability is measured by the service volume that can be processed in a unit time, for example, call per second, frame per second, or event processing volume per second.</p>
</td>
</tr>
<tr id="row13821030104616"><td class="cellrowborder" valign="top" width="19.040000000000003%" headers="mcps1.2.3.1.1 "><p id="p691711440467"><a name="p691711440467"></a><a name="p691711440467"></a>Power</p>
</td>
<td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><p id="p159171544104616"><a name="p159171544104616"></a><a name="p159171544104616"></a>Tests the power consumption of the tested object in a certain period of time under specific preset conditions and load models.</p>
</td>
</tr>
<tr id="row6821330114618"><td class="cellrowborder" valign="top" width="19.040000000000003%" headers="mcps1.2.3.1.1 "><p id="p13917164454612"><a name="p13917164454612"></a><a name="p13917164454612"></a>Reliability</p>
</td>
<td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><p id="p11917194416465"><a name="p11917194416465"></a><a name="p11917194416465"></a>Tests the service performance of the tested object under common and uncommon input conditions, or specified service volume pressure and long-term continuous running pressure. The test covers stability, pressure handling, fault injection, and Monkey test times.</p>
</td>
</tr>
<tr id="row11821930184612"><td class="cellrowborder" valign="top" width="19.040000000000003%" headers="mcps1.2.3.1.1 "><p id="p1691774474618"><a name="p1691774474618"></a><a name="p1691774474618"></a>Security</p>
</td>
<td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><a name="ul112421652121513"></a><a name="ul112421652121513"></a><ul id="ul112421652121513"><li>Tests the capability of defending against security threats, including but not limited to unauthorized access, use, disclosure, damage, modification, and destruction, to ensure information confidentiality, integrity, and availability.</li><li>Tests the privacy protection capability to ensure that the collection, use, retention, disclosure, and disposal of users' private data comply with laws and regulations.</li><li>Tests the compliance with various security specifications, such as security design, security requirements, and security certification of the Ministry of Industry and Information Technology (MIIT).</li></ul>
</td>
</tr>
<tr id="row16825307467"><td class="cellrowborder" valign="top" width="19.040000000000003%" headers="mcps1.2.3.1.1 "><p id="p129188444462"><a name="p129188444462"></a><a name="p129188444462"></a>Global</p>
</td>
<td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><p id="p179186444465"><a name="p179186444465"></a><a name="p179186444465"></a>Tests the internationalized data and localization capabilities of the tested object, including multi-language display, various input/output habits, time formats, and regional features, such as currency, time, and culture taboos.</p>
</td>
</tr>
<tr id="row08211308464"><td class="cellrowborder" valign="top" width="19.040000000000003%" headers="mcps1.2.3.1.1 "><p id="p191814447465"><a name="p191814447465"></a><a name="p191814447465"></a>Compatibility</p>
</td>
<td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><a name="ul186961827111612"></a><a name="ul186961827111612"></a><ul id="ul186961827111612"><li>Tests backward compatibility of an application with its own data, the forward and backward compatibility with the system, and the compatibility with different user data, such as audio file content of the player and smart SMS messages.</li><li>Tests system backward compatibility with its own data and the compatibility of common applications in the ecosystem.</li><li>Tests software compatibility with related hardware.</li></ul>
</td>
</tr>
<tr id="row1782730124618"><td class="cellrowborder" valign="top" width="19.040000000000003%" headers="mcps1.2.3.1.1 "><p id="p13918144134614"><a name="p13918144134614"></a><a name="p13918144134614"></a>User</p>
</td>
<td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><p id="p1291844494611"><a name="p1291844494611"></a><a name="p1291844494611"></a>Tests user experience of the object in real user scenarios. All conclusions and comments should come from the users, which are all subjective evaluation in this case.</p>
</td>
</tr>
<tr id="row58243024617"><td class="cellrowborder" valign="top" width="19.040000000000003%" headers="mcps1.2.3.1.1 "><p id="p1291884474614"><a name="p1291884474614"></a><a name="p1291884474614"></a>Standard</p>
</td>
<td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><p id="p0918124424614"><a name="p0918124424614"></a><a name="p0918124424614"></a>Tests the compliance with industry and company-specific standards, protocols, and specifications. The standards here do not include any security standards that should be classified into the security test.</p>
</td>
</tr>
<tr id="row382830124619"><td class="cellrowborder" valign="top" width="19.040000000000003%" headers="mcps1.2.3.1.1 "><p id="p119181044164619"><a name="p119181044164619"></a><a name="p119181044164619"></a>Safety</p>
</td>
<td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><p id="p1291818443468"><a name="p1291818443468"></a><a name="p1291818443468"></a>Tests the safety property of the tested object to avoid possible hazards to personal safety, health, and the object itself.</p>
</td>
</tr>
<tr id="row1083153014465"><td class="cellrowborder" valign="top" width="19.040000000000003%" headers="mcps1.2.3.1.1 "><p id="p39187441469"><a name="p39187441469"></a><a name="p39187441469"></a>Resilience</p>
</td>
<td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><p id="p891815444462"><a name="p891815444462"></a><a name="p891815444462"></a>Tests the resilience property of the tested object to ensure that it can withstand and maintain the defined running status (including downgrading) when being attacked, and recover from and adapt defense to the attacks to approach mission assurance.</p>
</td>
</tr>
</tbody>
</table>
## Test Case Development Guidelines<a name="section3695134065513"></a>
You should select the appropriate programming language and your target test framework to develop test cases for the devices to test.
**Table 4** Test frameworks and test case languages for different devices
<a name="table4418343171415"></a>
<table><thead align="left"><tr id="row34183435145"><th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.1"><p id="p941874311148"><a name="p941874311148"></a><a name="p941874311148"></a>Device Type</p>
</th>
<th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.2"><p id="p1841804341413"><a name="p1841804341413"></a><a name="p1841804341413"></a>Test Framework</p>
</th>
<th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.3"><p id="p2418104311148"><a name="p2418104311148"></a><a name="p2418104311148"></a>Language</p>
</th>
</tr>
</thead>
<tbody><tr id="row8419164319148"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p7419194312143"><a name="p7419194312143"></a><a name="p7419194312143"></a>Mini-system devices</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p10419124312145"><a name="p10419124312145"></a><a name="p10419124312145"></a>HCTest</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p11419643191410"><a name="p11419643191410"></a><a name="p11419643191410"></a>C</p>
</td>
</tr>
<tr id="row141915438147"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p441911436141"><a name="p441911436141"></a><a name="p441911436141"></a>Small-system devices</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p541916432142"><a name="p541916432142"></a><a name="p541916432142"></a>HCPPTest</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p54191643131416"><a name="p54191643131416"></a><a name="p54191643131416"></a>C++</p>
</td>
</tr>
<tr id="row4419134341417"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p341964313143"><a name="p341964313143"></a><a name="p341964313143"></a>Standard-system devices</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p10419443171416"><a name="p10419443171416"></a><a name="p10419443171416"></a>HJUnit and HCPPTest</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p9419143181414"><a name="p9419143181414"></a><a name="p9419143181414"></a>Java and C++</p>
</td>
</tr>
<tr id="row42451815115215"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p324511515528"><a name="p324511515528"></a><a name="p324511515528"></a>Large-system devices</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p724516151520"><a name="p724516151520"></a><a name="p724516151520"></a>HJUnit and HCPPTest</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p748417474533"><a name="p748417474533"></a><a name="p748417474533"></a>Java and C++</p>
</td>
</tr>
</tbody>
</table>
### C-based Test Case Development and Compilation \(for Mini-System Devices\)<a name="section1551164914237"></a>
**Developing test cases for mini-system devices**
The HCTest framework is used to support test cases developed with the C language. HCTest is enhanced and adapted based on the open-source test framework Unity.
1. Access the **test/xts/acts** repository where the test cases will be stored.
```
├── acts
│ └──subsystem_lite
│ │ └── module_hal
│ │ │ └── BUILD.gn
│ │ │ └── src
│ └──build_lite
│ │ └── BUILD.gn
```
2. Write the test case in the **src** directory.
1 Import the test framework header file.
```
#include "hctest.h"
```
2. Use the **LITE\_TEST\_SUIT** macro to define names of the subsystem, module, and test suite.
```
/**
* @brief Registers a test suite named IntTestSuite.
* @param test Subsystem name
* @param example Module name
* @param IntTestSuite Test suite name
*/
LITE_TEST_SUIT(test, example, IntTestSuite);
```
3. Define Setup and TearDown.
Format: Test suite name+Setup, Test suite name+TearDown.
The Setup and TearDown functions must exist, but function bodies can be empty.
4. Use the **LITE\_TEST\_CASE** macro to write the test case.
Three parameters are involved: test suite name, test case name, and test case properties \(including type, granularity, and level\).
```
LITE_TEST_CASE(IntTestSuite, TestCase001, Function | MediumTest | Level1)
{
// Do something
};
```
5. Use the **RUN\_TEST\_SUITE** macro to register the test suite.
```
RUN_TEST_SUITE(IntTestSuite);
```
3. Create the configuration file \(**BUILD.gn**\) of the test module.
Create a **BUILD.gn** \(example\) compilation file in each test module directory. Specify the name of the compiled static library and its dependent header file and library in the compilation file. The format is as follows:
```
import("//test/xts/tools/lite/build/suite_lite.gni")
hctest_suite("ActsDemoTest") {
suite_name = "acts"
sources = [
"src/test_demo.c",
]
include_dirs = [ ]
cflags = [ "-Wno-error" ]
}
```
4. Add compilation options to the **BUILD.gn** file in the **acts** directory.
You need to add the test module to the **test/xts/acts/build\_lite/BUILD.gn** script in the **acts** directory.
```
lite_component("acts") {
...
if(board_name == "liteos_m") {
features += [
...
"//xts/acts/subsystem_lite/module_hal:ActsDemoTest"
]
}
}
```
5. Run compilation commands.
Test suites are compiled along with version compilation. The ACTS is compiled together with the debug version.
>![](figures/icon-note.gif) **NOTE:**
>The ACTS compiles middleware as a static library, which will be linked to the image.
### C-based Test Case Execution \(for Mini-System Devices\)<a name="section10100701294"></a>
**Executing test cases for mini-system devices**
Burn the image into the development board.
**Executing the test**
1. Use a serial port tool to log in to the development board and save information about the serial port.
2. Restart the device and view serial port logs.
**Analyzing the test result**
View the serial port logs, whose format is as follows:
The log for each test suite starts with **Start to run test suite:** and ends with **xx Tests xx Failures xx Ignored**.
### C++-based Test Case Development and Compilation \(for Small-, Standard-, and Large-System Devices\)<a name="section5714177113113"></a>
**Developing test cases for small-system devices**
The HCPPTest framework is enhanced and adapted based on the open-source framework Googletest.
1. Access the **test/xts/acts** repository where the test cases will be stored.
```
├── acts
│ └──subsystem_lite
│ │ └── module_posix
│ │ │ └── BUILD.gn
│ │ │ └── src
│ └──build_lite
│ │ └── BUILD.gn
```
2. Write the test case in the **src** directory.
1. Import the test framework header file.
The following statement includes **gtest.h**.
```
#include "gtest/gtest.h"
```
2. Define Setup and TearDown.
```
using namespace std;
using namespace testing::ext;
class TestSuite: public testing::Test {
protected:
// Preset action of the test suite, which is executed before the first test case
static void SetUpTestCase(void){
}
// Test suite cleanup action, which is executed after the last test case
static void TearDownTestCase(void){
}
// Preset action of the test case
virtual void SetUp()
{
}
// Cleanup action of the test case
virtual void TearDown()
{
}
};
```
3. Use the **HWTEST** or **HWTEST\_F** macro to write the test case.
**HWTEST**: definition of common test cases, including the test suite name, test case name, and case annotation.
**HWTEST\_F**: definition of SetUp and TearDown test cases, including the test suite name, test case name, and case annotation.
Three parameters are involved: test suite name, test case name, and test case properties \(including type, granularity, and level\).
```
HWTEST_F(TestSuite, TestCase_0001, Function | MediumTest | Level1) {
// Do something
}
```
3. Create a configuration file \(**BUILD.gn**\) of the test module.
Create a **BUILD.gn** compilation file in each test module directory. Specify the name of the compiled static library and its dependent header file and library in the compilation file. Each test module is independently compiled into a **.bin** executable file, which can be directly mounted to the development board for testing.
Example:
```
import("//test/xts/tools/lite/build/suite_lite.gni")
hcpptest_suite("ActsDemoTest") {
suite_name = "acts"
sources = [
"src/TestDemo.cpp"
]
include_dirs = [
"src",
...
]
deps = [
...
]
cflags = [ "-Wno-error" ]
}
```
4. Add compilation options to the **BUILD.gn** file in the **acts** directory.
Add the test module to the **test/xts/acts/build\_lite/BUILD.gn** script in the **acts** directory.
```
lite_component("acts") {
...
else if(board_name == "liteos_a") {
features += [
...
"//xts/acts/subsystem_lite/module_posix:ActsDemoTest"
]
}
}
```
5. Run compilation commands.
Test suites are compiled along with the version compilation. The ACTS is compiled together with the debug version.
>![](figures/icon-note.gif) **NOTE:**
>The ACTS for a small system device is independently compiled to an executable file \(.bin\) and archived in the **suites\\acts** directory of the compilation result.
### C++-based Test Case Execution \(for Small-, Standard-, and Large-System Devices\)<a name="section42281924184"></a>
**Executing test cases for small-system devices**
Currently, test cases are shared by the NFS and mounted to the development board for execution.
**Setting up the environment**
1. Use a network cable or wireless network to connect the development board to your PC.
2. Configure the IP address, subnet mask, and gateway for the development board. Ensure that the development board and the PC are in the same network segment.
3. Install and register the NFS server on the PC and start the NFS service.
4. Run the **mount** command for the development board to ensure that the development board can access NFS shared files on the PC.
Format: **mount** _NFS server IP address_**:/**_NFS shared directory_ **/**_development board directory_ **nfs**
Example:
```
mount 192.168.1.10:/nfs /nfs nfs
```
**Executing test cases**
Execute **ActsDemoTest.bin** to trigger test case execution, and analyze serial port logs generated after the execution is complete.
## Repositories Involved<a name="section1371113476307"></a>
[X Test Suite](https://gitee.com/openharmony/docs/blob/master/en/readme/x-test-suite.md)
[xts\_acts](https://gitee.com/openharmony/xts_acts/blob/master/README.md)
**xts\_tools**

530
lite/README_zh.md Executable file
View File

@ -0,0 +1,530 @@
# XTS认证子系统开发指南<a name="ZH-CN_TOPIC_0000001132537809"></a>
- [简介](#section465982318513)
- [设备类型](#section125090457443)
- [目录](#section161941989596)
- [约束](#section119744591305)
- [使用说明](#section137768191623)
- [用例开发指导](#section3695134065513)
- [C语言用例开发编译指导适用于轻量系统类设备产品用例开发](#section1551164914237)
- [C语言用例执行指导适用于轻量系统类设备产品用例开发](#section10100701294)
- [C++语言用例开发编译指导(适用于小型系统类设备、标准系统类设备、大型系统类设备用例开发)](#section5714177113113)
- [C++语言用例执行指导(适用于小型系统类设备、标准系统类设备、大型系统类设备用例开发)](#section42281924184)
- [相关仓](#section1371113476307)
## 简介<a name="section465982318513"></a>
XTS子系统是OpenHarmony生态认证测试套件的集合当前包括actsapplication compatibility test suite应用兼容性测试套件后续会拓展dctsdevice compatibility test suite设备兼容性测试套件等。
XTS子系统当前包括acts与tools软件包
- acts存放acts相关测试用例源码与配置文件其目的是帮助终端设备厂商尽早发现软件与OpenHarmony的不兼容性确保软件在整个开发过程中满足OpenHarmony的兼容性要求。
- tools存放acts相关测试用例开发框架。
## 设备类型<a name="section125090457443"></a>
OpenHarmony支持如下几种设备类型
- **轻量系统类设备参考内存≥128KB**
面向MCU类处理器例如Arm Cortex-M、RISC-V 32位的设备资源极其有限参考内存≥128KB提供丰富的近距连接能力以及丰富的外设总线访问能力。典型产品有智能家居领域的联接类模组、传感器设备等。联接类模组通常应用在智能物联网设备中负责实现联接部分的硬件模块在智能家居领域由厂家集成到其设备中。例如联接类模组提供WLAN/Bluetooth的接入和数据的联接模组与厂家家居的芯片通常通过UART或GPIO等总线接口进行通信。
- **小型系统类设备参考内存≥1MB**
面向应用处理器例如Arm Cortex-A的设备参考内存≥1MB提供更高的安全能力提供标准的图形框架提供视频编解码的多媒体能力。典型产品有智能家居领域的IPCamera、电子猫眼、路由器以及智慧出行域的行车记录仪等。
- **标准系统类设备参考内存≥128MB**
面向应用处理器例如Arm Cortex-A的设备参考内存≥128MB提供增强的交互能力提供3D GPU以及硬件合成能力提供更多控件以及动效更丰富的图形能力提供完整的应用框架。典型产品有高端的冰箱显示屏等。
- **大型系统类设备参考内存≥1GB**
面向应用处理器例如Arm Cortex-A的设备参考内存≥1GB提供完整的兼容应用框架。典型的产品有智慧屏、智能手表等。
## 目录<a name="section161941989596"></a>
```
/test/xts
├── acts # 测试代码存放目录
│ └── subsystem # 大型系统类设备子系统测试用例源码存放目录
│ └── subsystem_lite # 轻量系统类设备、小型系统类设备子系统测试用例源码存放目录
│ └── BUILD.gn # 大型系统类设备测试用例编译配置
│ └── build_lite # 轻量系统类设备、小型系统类设备测试用例编译配置存放目录
│ └── BUILD.gn # 轻量系统类设备、小型系统类设备测试用例编译配置
└── tools # 测试工具代码存放目录
```
## 约束<a name="section119744591305"></a>
轻量系统类设备用例开发语言是C小型系统类设备用例开发语言是C++。
## 使用说明<a name="section137768191623"></a>
**表 1** 用例级别说明
<a name="table12856113719456"></a>
<table><thead align="left"><tr id="row88561737114517"><th class="cellrowborder" valign="top" width="33.333333333333336%" id="mcps1.2.4.1.1"><p id="p54711456452"><a name="p54711456452"></a><a name="p54711456452"></a>级别名称</p>
</th>
<th class="cellrowborder" valign="top" width="33.283328332833285%" id="mcps1.2.4.1.2"><p id="p114834544518"><a name="p114834544518"></a><a name="p114834544518"></a>基本定义</p>
</th>
<th class="cellrowborder" valign="top" width="33.383338333833386%" id="mcps1.2.4.1.3"><p id="p348154574518"><a name="p348154574518"></a><a name="p348154574518"></a>测试范围</p>
</th>
</tr>
</thead>
<tbody><tr id="row78561137134514"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.2.4.1.1 "><p id="p17481345124512"><a name="p17481345124512"></a><a name="p17481345124512"></a>Level0</p>
</td>
<td class="cellrowborder" valign="top" width="33.283328332833285%" headers="mcps1.2.4.1.2 "><p id="p1548945204514"><a name="p1548945204514"></a><a name="p1548945204514"></a>冒烟</p>
</td>
<td class="cellrowborder" valign="top" width="33.383338333833386%" headers="mcps1.2.4.1.3 "><p id="p174824517456"><a name="p174824517456"></a><a name="p174824517456"></a>验证关键功能点基本功能/最基本DFX属性在最常见输入下的表现通过表示功能基本可运行。</p>
</td>
</tr>
<tr id="row28563372451"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.2.4.1.1 "><p id="p448445144512"><a name="p448445144512"></a><a name="p448445144512"></a>Level1</p>
</td>
<td class="cellrowborder" valign="top" width="33.283328332833285%" headers="mcps1.2.4.1.2 "><p id="p44813452452"><a name="p44813452452"></a><a name="p44813452452"></a>基本</p>
</td>
<td class="cellrowborder" valign="top" width="33.383338333833386%" headers="mcps1.2.4.1.3 "><p id="p648184584514"><a name="p648184584514"></a><a name="p648184584514"></a>验证各功能点基本功能/基本DFX属性在常见输入下的表现通过表示功能基本可测试。</p>
</td>
</tr>
<tr id="row12856137204514"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.2.4.1.1 "><p id="p164834520453"><a name="p164834520453"></a><a name="p164834520453"></a>Level2</p>
</td>
<td class="cellrowborder" valign="top" width="33.283328332833285%" headers="mcps1.2.4.1.2 "><p id="p148245184511"><a name="p148245184511"></a><a name="p148245184511"></a>重要</p>
</td>
<td class="cellrowborder" valign="top" width="33.383338333833386%" headers="mcps1.2.4.1.3 "><p id="p348945124510"><a name="p348945124510"></a><a name="p348945124510"></a>验证各功能点的基本功能/基本DFX属性在常规输入/常见异常情况下的表现通过表示功能基本正常可用可开展Beta。</p>
</td>
</tr>
<tr id="row48571137204514"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.2.4.1.1 "><p id="p7481545184513"><a name="p7481545184513"></a><a name="p7481545184513"></a>Level3</p>
</td>
<td class="cellrowborder" valign="top" width="33.283328332833285%" headers="mcps1.2.4.1.2 "><p id="p1748184514455"><a name="p1748184514455"></a><a name="p1748184514455"></a>一般</p>
</td>
<td class="cellrowborder" valign="top" width="33.383338333833386%" headers="mcps1.2.4.1.3 "><p id="p8481245104519"><a name="p8481245104519"></a><a name="p8481245104519"></a>验证各功能点的全部功能/全部DFX属性在各种常规/非常规输入组合下,或各种正常/异常预置条件组合下的表现。</p>
</td>
</tr>
<tr id="row14857133712451"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.2.4.1.1 "><p id="p1248144515456"><a name="p1248144515456"></a><a name="p1248144515456"></a>Level4</p>
</td>
<td class="cellrowborder" valign="top" width="33.283328332833285%" headers="mcps1.2.4.1.2 "><p id="p94804514519"><a name="p94804514519"></a><a name="p94804514519"></a>生僻</p>
</td>
<td class="cellrowborder" valign="top" width="33.383338333833386%" headers="mcps1.2.4.1.3 "><p id="p1248445164516"><a name="p1248445164516"></a><a name="p1248445164516"></a>验证关键功能点在极端异常预置条件下、用户难以触及的异常输入组合下的表现。</p>
</td>
</tr>
</tbody>
</table>
**表 2** 用例粒度说明
<a name="table1690733521014"></a>
<table><thead align="left"><tr id="row9907143516105"><th class="cellrowborder" valign="top" width="19.591959195919593%" id="mcps1.2.4.1.1"><p id="p1141312416102"><a name="p1141312416102"></a><a name="p1141312416102"></a>用例规模</p>
</th>
<th class="cellrowborder" valign="top" width="35.17351735173517%" id="mcps1.2.4.1.2"><p id="p34131416109"><a name="p34131416109"></a><a name="p34131416109"></a>被测试对象</p>
</th>
<th class="cellrowborder" valign="top" width="45.23452345234523%" id="mcps1.2.4.1.3"><p id="p12413141171010"><a name="p12413141171010"></a><a name="p12413141171010"></a>测试环境</p>
</th>
</tr>
</thead>
<tbody><tr id="row2907335181017"><td class="cellrowborder" valign="top" width="19.591959195919593%" headers="mcps1.2.4.1.1 "><p id="p6414134117109"><a name="p6414134117109"></a><a name="p6414134117109"></a>LargeTest</p>
</td>
<td class="cellrowborder" valign="top" width="35.17351735173517%" headers="mcps1.2.4.1.2 "><p id="p20414104113101"><a name="p20414104113101"></a><a name="p20414104113101"></a>业务功能/全场景特性/整机及场景级DFX</p>
</td>
<td class="cellrowborder" valign="top" width="45.23452345234523%" headers="mcps1.2.4.1.3 "><p id="p5414841121013"><a name="p5414841121013"></a><a name="p5414841121013"></a>尽量使用贴近真实的环境设备</p>
</td>
</tr>
<tr id="row10907635131015"><td class="cellrowborder" valign="top" width="19.591959195919593%" headers="mcps1.2.4.1.1 "><p id="p19414134117104"><a name="p19414134117104"></a><a name="p19414134117104"></a>MediumTest</p>
</td>
<td class="cellrowborder" valign="top" width="35.17351735173517%" headers="mcps1.2.4.1.2 "><p id="p114141241141018"><a name="p114141241141018"></a><a name="p114141241141018"></a>模块/子系统集成至设备后的功能/DFX</p>
</td>
<td class="cellrowborder" valign="top" width="45.23452345234523%" headers="mcps1.2.4.1.3 "><p id="p14414941111015"><a name="p14414941111015"></a><a name="p14414941111015"></a>使用真实的单设备进行验证可进行消息模拟尽量不对函数进行MOCK</p>
</td>
</tr>
<tr id="row1990713353100"><td class="cellrowborder" valign="top" width="19.591959195919593%" headers="mcps1.2.4.1.1 "><p id="p641414110109"><a name="p641414110109"></a><a name="p641414110109"></a>SmallTest</p>
</td>
<td class="cellrowborder" valign="top" width="35.17351735173517%" headers="mcps1.2.4.1.2 "><p id="p54141541181018"><a name="p54141541181018"></a><a name="p54141541181018"></a>模块/类/函数</p>
</td>
<td class="cellrowborder" valign="top" width="45.23452345234523%" headers="mcps1.2.4.1.3 "><p id="p1841494131013"><a name="p1841494131013"></a><a name="p1841494131013"></a>在开发者个人环境进行测试尽量不依赖其他模块存在大量的MOCK</p>
</td>
</tr>
</tbody>
</table>
**表 3** 测试类型说明
<a name="table18811230124619"></a>
<table><thead align="left"><tr id="row48163019466"><th class="cellrowborder" valign="top" width="19.040000000000003%" id="mcps1.2.3.1.1"><p id="p1791784418465"><a name="p1791784418465"></a><a name="p1791784418465"></a>测试类型名称</p>
</th>
<th class="cellrowborder" valign="top" width="80.96%" id="mcps1.2.3.1.2"><p id="p2917164444614"><a name="p2917164444614"></a><a name="p2917164444614"></a>测试类型定义</p>
</th>
</tr>
</thead>
<tbody><tr id="row682630104615"><td class="cellrowborder" valign="top" width="19.040000000000003%" headers="mcps1.2.3.1.1 "><p id="p1091784414469"><a name="p1091784414469"></a><a name="p1091784414469"></a>Function</p>
</td>
<td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><p id="p16917344104618"><a name="p16917344104618"></a><a name="p16917344104618"></a>验证被测对象提供给用户的业务功能实现正确性的测试项,这里的“用户”可以是终端用户或开发者,功能包括业务功能及平台功能</p>
</td>
</tr>
<tr id="row1821930154611"><td class="cellrowborder" valign="top" width="19.040000000000003%" headers="mcps1.2.3.1.1 "><p id="p591714474612"><a name="p591714474612"></a><a name="p591714474612"></a>Performance</p>
</td>
<td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><p id="p15917154410463"><a name="p15917154410463"></a><a name="p15917154410463"></a>验证被测对象在特定预置条件/负载模型下的处理能力的测试项,“处理能力”一般以单位时间内可处理的业务量来衡量,如呼叫/秒,帧率/秒,事件处理量/秒等</p>
</td>
</tr>
<tr id="row13821030104616"><td class="cellrowborder" valign="top" width="19.040000000000003%" headers="mcps1.2.3.1.1 "><p id="p691711440467"><a name="p691711440467"></a><a name="p691711440467"></a>Power</p>
</td>
<td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><p id="p159171544104616"><a name="p159171544104616"></a><a name="p159171544104616"></a>验证被测对象在特定预置条件/负载模型下在一定时间内能源消耗量的测试项</p>
</td>
</tr>
<tr id="row6821330114618"><td class="cellrowborder" valign="top" width="19.040000000000003%" headers="mcps1.2.3.1.1 "><p id="p13917164454612"><a name="p13917164454612"></a><a name="p13917164454612"></a>Reliability</p>
</td>
<td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><p id="p11917194416465"><a name="p11917194416465"></a><a name="p11917194416465"></a>验证被测对象在正常/异常输入情况下或业务量压力和长时间连续运行压力情况下业务表现的测试项含稳定性、压力、故障注入、Monkey测试项</p>
</td>
</tr>
<tr id="row11821930184612"><td class="cellrowborder" valign="top" width="19.040000000000003%" headers="mcps1.2.3.1.1 "><p id="p1691774474618"><a name="p1691774474618"></a><a name="p1691774474618"></a>Security</p>
</td>
<td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><p id="p1791784410463"><a name="p1791784410463"></a><a name="p1791784410463"></a>验证系统对恶意威胁的防护能力,威胁包括但不限于未授权访问、使用、泄露、破坏、修改、毁灭,以保障信息的机密性、完整性和可用性; 验证系统对用户隐私的保护能力,保障用户的隐私数据被收集、使用、保有、披露和处置符合法律规范,保障用户的隐私权; 验证对各类安全规范的遵从情况,如安全设计规范、安全红线、工信部安全认证规范等,保障安全相关法律法规的合规。</p>
</td>
</tr>
<tr id="row16825307467"><td class="cellrowborder" valign="top" width="19.040000000000003%" headers="mcps1.2.3.1.1 "><p id="p129188444462"><a name="p129188444462"></a><a name="p129188444462"></a>Global</p>
</td>
<td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><p id="p179186444465"><a name="p179186444465"></a><a name="p179186444465"></a>验证被测对象在是否具有国际化数据支持和本地化能力的测试项,包括语言显示、输入/输出习惯、时间显示、区域特性如货币时间禁忌等等</p>
</td>
</tr>
<tr id="row08211308464"><td class="cellrowborder" valign="top" width="19.040000000000003%" headers="mcps1.2.3.1.1 "><p id="p191814447465"><a name="p191814447465"></a><a name="p191814447465"></a>Compatibility</p>
</td>
<td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><p id="p99181344144613"><a name="p99181344144613"></a><a name="p99181344144613"></a>当被测对象为应用时,包括被测对象对于自身数据的后向兼容性、对于系统的前后向兼容性、对于不同用户数据(如播放器之音频文件格式/智能短信之用户短信内容)的兼容性测试项; 当被测对象为系统时,包括被测系统对于系统自身数据的后向兼容性、以及对于生态中常用应用的兼容性测试项;当被测对象为软件时,包括被测系统对于相关的硬件的兼容性;</p>
</td>
</tr>
<tr id="row1782730124618"><td class="cellrowborder" valign="top" width="19.040000000000003%" headers="mcps1.2.3.1.1 "><p id="p13918144134614"><a name="p13918144134614"></a><a name="p13918144134614"></a>User</p>
</td>
<td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><p id="p1291844494611"><a name="p1291844494611"></a><a name="p1291844494611"></a>验证被测对象在真实用户场景下的用户体验感受的测试项,注意此种情况下没有客观的“正确”与“失败”,所有的结论及评价都应该来自于用户</p>
</td>
</tr>
<tr id="row58243024617"><td class="cellrowborder" valign="top" width="19.040000000000003%" headers="mcps1.2.3.1.1 "><p id="p1291884474614"><a name="p1291884474614"></a><a name="p1291884474614"></a>Standard</p>
</td>
<td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><p id="p0918124424614"><a name="p0918124424614"></a><a name="p0918124424614"></a>验证被测对象对于行业及公司内标准/协议/规范的遵从情况的测试项,注意此处的“标准”不包含任何安全标准,针对安全标准的测试项划归为“安全测试”类型</p>
</td>
</tr>
<tr id="row382830124619"><td class="cellrowborder" valign="top" width="19.040000000000003%" headers="mcps1.2.3.1.1 "><p id="p119181044164619"><a name="p119181044164619"></a><a name="p119181044164619"></a>Safety</p>
</td>
<td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><p id="p1291818443468"><a name="p1291818443468"></a><a name="p1291818443468"></a>验证被测对象的Safety属性避免产品可能对人身安全、健康以及产品本身带来的危害。</p>
</td>
</tr>
<tr id="row1083153014465"><td class="cellrowborder" valign="top" width="19.040000000000003%" headers="mcps1.2.3.1.1 "><p id="p39187441469"><a name="p39187441469"></a><a name="p39187441469"></a>Resilience</p>
</td>
<td class="cellrowborder" valign="top" width="80.96%" headers="mcps1.2.3.1.2 "><p id="p891815444462"><a name="p891815444462"></a><a name="p891815444462"></a>验证被测对象的韧性属性确保系统受攻击时承受并保持在有定义的运行状态包括降级、恢复并适应攻击以保障Mission达成。</p>
</td>
</tr>
</tbody>
</table>
## 用例开发指导<a name="section3695134065513"></a>
根据测试设备选择测试框架和对应测试用例语言。
**表 4** 设备和测试框架、开发语言对应关系
<a name="table4418343171415"></a>
<table><thead align="left"><tr id="row34183435145"><th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.1"><p id="p941874311148"><a name="p941874311148"></a><a name="p941874311148"></a>设备</p>
</th>
<th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.2"><p id="p1841804341413"><a name="p1841804341413"></a><a name="p1841804341413"></a>测试框架</p>
</th>
<th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.2.4.1.3"><p id="p2418104311148"><a name="p2418104311148"></a><a name="p2418104311148"></a>语言</p>
</th>
</tr>
</thead>
<tbody><tr id="row8419164319148"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p7419194312143"><a name="p7419194312143"></a><a name="p7419194312143"></a>轻量系统类设备</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p10419124312145"><a name="p10419124312145"></a><a name="p10419124312145"></a>hctest</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p11419643191410"><a name="p11419643191410"></a><a name="p11419643191410"></a>c</p>
</td>
</tr>
<tr id="row141915438147"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p441911436141"><a name="p441911436141"></a><a name="p441911436141"></a>小型系统类设备</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p541916432142"><a name="p541916432142"></a><a name="p541916432142"></a>hcpptest</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p54191643131416"><a name="p54191643131416"></a><a name="p54191643131416"></a>c++</p>
</td>
</tr>
<tr id="row4419134341417"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p341964313143"><a name="p341964313143"></a><a name="p341964313143"></a>标准系统类设备</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p10419443171416"><a name="p10419443171416"></a><a name="p10419443171416"></a>HJUnit、hcpptest</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p9419143181414"><a name="p9419143181414"></a><a name="p9419143181414"></a>java、c++</p>
</td>
</tr>
<tr id="row42451815115215"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.1 "><p id="p324511515528"><a name="p324511515528"></a><a name="p324511515528"></a>大型系统类设备</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.2 "><p id="p724516151520"><a name="p724516151520"></a><a name="p724516151520"></a>HJUnit、hcpptest</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.2.4.1.3 "><p id="p748417474533"><a name="p748417474533"></a><a name="p748417474533"></a>java、c++</p>
</td>
</tr>
</tbody>
</table>
### C语言用例开发编译指导适用于轻量系统类设备产品用例开发<a name="section1551164914237"></a>
**示例:轻量系统类设备测试用例开发**
当前使用的测试框架是hctesthctest测试框架支持使用C语言编写测试用例是在开源测试框架unity的基础上进行增强和适配。
1. 用例目录规范测试用例存储到test/xts/acts仓中
```
├── acts
│ └──subsystem_lite
│ │ └── module_hal
│ │ │ └── BUILD.gn
│ │ │ └── src
│ └──build_lite
│ │ └── BUILD.gn
```
2. src目录下用例编写样例。
1.引用测试框架
```
#include "hctest.h"
```
2. 使用宏定义LITE\_TEST\_SUIT定义子系统、模块、测试套件名称
```
/**
* @brief register a test suit named "IntTestSuite"
* @param test subsystem name
* @param example module name
* @param IntTestSuite test suit name
*/
LITE_TEST_SUIT(test, example, IntTestSuite);
```
3. 定义Setup与TearDown
命名方式:测试套件名称+Setup测试套件名称+TearDown。
Setup与TearDown必须存在可以为空函数。
4. 使用宏定义LITE\_TEST\_CASE写测试用例
包括三个参数:测试套件名称,测试用例名称,用例属性(测试类型、用例粒度、用例级别)。
```
LITE_TEST_CASE(IntTestSuite, TestCase001, Function | MediumTest | Level1)
{
//do something
};
```
5. 使用宏定义 RUN\_TEST\_SUITE注册测试套件
```
RUN_TEST_SUITE(IntTestSuite);
```
3. 测试模块的配置文件BUILD.gn样例
在每个测试模块目录下新建BUILD.gn编译文件用于指定编译后静态库的名称、依赖的头文件、依赖的库等具体写法如下
```
import("//test/xts/tools/lite/build/suite_lite.gni")
hctest_suite("ActsDemoTest") {
suite_name = "acts"
sources = [
"src/test_demo.c",
]
include_dirs = [ ]
cflags = [ "-Wno-error" ]
}
```
4. acts下BUILD.gn增加编译选项。
需要将测试模块加入到acts目录下的编译脚本中编译脚本路径test/xts/acts/build\_lite/BUILD.gn。
```
lite_component("acts") {
...
if(board_name == "liteos_m") {
features += [
...
"//xts/acts/subsystem_lite/module_hal:ActsDemoTest"
]
}
}
```
5. 测试套件编译命令。
随版本编译debug版本编译时会同步编译acts测试套件
>![](figures/icon-note.gif) **说明:**
>acts测试套件编译中间件为静态库最终链接到版本镜像中 。
### C语言用例执行指导适用于轻量系统类设备产品用例开发<a name="section10100701294"></a>
**示例:轻量系统类设备测试用例执行**
将版本镜像烧录进开发板。
**测试步骤**
1. 使用串口工具登录开发板,并保存串口打印信息。
2. 重启设备,查看串口日志。
**测试结果分析指导**
基于串口打印日志进行分析;
每个测试套件执行以Start to run test suite开始以xx Tests xx Failures xx Ignored结束。
### C++语言用例开发编译指导(适用于小型系统类设备、标准系统类设备、大型系统类设备用例开发)<a name="section5714177113113"></a>
**示例:小型系统类设备测试用例开发**
当前使用的测试框架是hcpptesthcpptest测试框架是在开源的googletest测试框架的基础上进行的增强和适配。
1. 规范用例目录测试用例存储到test/xts/acts仓中。
```
├── acts
│ └──subsystem_lite
│ │ └── module_posix
│ │ │ └── BUILD.gn
│ │ │ └── src
│ └──build_lite
│ │ └── BUILD.gn
```
2. 测试模块src下用例编写样例
1. 引用测试框架:
需要引用gtest.h 如:\#include "gtest/gtest.h"
```
#include "gtest/gtest.h"
```
2. 定义Setup与TearDown
```
using namespace std;
using namespace testing::ext;
class TestSuite: public testing::Test {
protected:
// Preset action of the test suite, which is executed before the first test case
static void SetUpTestCase(void){
}
// Test suite cleanup action, which is executed after the last test case
static void TearDownTestCase(void){
}
// Preset action of the test case
virtual void SetUp()
{
}
// Cleanup action of the test case
virtual void TearDown()
{
}
};
```
3. 使用宏定义HWTEST或HWTEST\_F写测试用例
普通测试用例的定义HWTEST测试套名称 测试用例名称, 用例标注)。
包含SetUp和TearDown的测试用例的定义 HWTEST\_F测试套名称 测试用例名称,用例标注)。
宏定义包括三个参数:测试套件名称,测试用例名称,用例属性(测试类型、用例粒度、用例级别)。
```
HWTEST_F(TestSuite, TestCase_0001, Function | MediumTest | Level1) {
// do something
}
```
3. 测试模块下用例配置文件BUILD.gn样例
每个测试模块目录下新建BUILD.gn编译文件用于指定编译后可执行文件的名称、依赖的头文件、依赖的库等具体写法如下。每个测试模块将独立编译成.bin可执行文件 该文件可直接mount到单板上进行测试。
举例:
```
import("//test/xts/tools/lite/build/suite_lite.gni")
hcpptest_suite("ActsDemoTest") {
suite_name = "acts"
sources = [
"src/TestDemo.cpp"
]
include_dirs = [
"src",
...
]
deps = [
...
]
cflags = [ "-Wno-error" ]
}
```
4. acts目录下增加编译选项BUILD.gn样例
将测试模块加入到acts目录下的编译脚本中编译脚本为test/xts/acts/build\_lite/BUILD.gn。
```
lite_component("acts") {
...
else if(board_name == "liteos_a") {
features += [
...
"//xts/acts/subsystem_lite/module_posix:ActsDemoTest"
]
}
}
```
5. 测试套件编译命令。
随版本编译debug版本编译时会同步编译acts测试套件
>![](figures/icon-note.gif) **说明:**
>小型系统类设备acts独立编译成可执行文件bin格式 在编译产物的suites\\acts目录下归档。
### C++语言用例执行指导(适用于小型系统类设备、标准系统类设备、大型系统类设备用例开发)<a name="section42281924184"></a>
**示例:小型系统类设备测试用例执行**
目前的用例执行采用nfs共享的方式mount到单板去执行。
**环境搭建**
1. 使用有限网线或无线将开发板与PC进行连接。
2. 开发板配置IP、子网掩码、网关确保开发板与PC处于同一个网段。
3. PC安装nfs服务器并完成注册启动nfs服务。
4. 开发板配置mount命令确保开发板可以访问PC端的nfs共享文件。
格式mount \[nfs服务器IP\]:\[/nfs共享目录\] \[/开发板目录\] nfs
举例:
```
mount 192.168.1.10:/nfs /nfs nfs
```
**用例执行**
测试套件执行 ActsDemoTest.bin 触发用例执行,基于串口打印日志进行分析。
## 相关仓<a name="section1371113476307"></a>
[XTS认证子系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/XTS%E8%AE%A4%E8%AF%81%E5%AD%90%E7%B3%BB%E7%BB%9F.md)
[xts\_acts](https://gitee.com/openharmony/xts_acts/blob/master/README_zh.md)
**xts\_tools**

273
lite/build/suite.py Normal file
View File

@ -0,0 +1,273 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Copyright (c) 2021 Huawei Device Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import os
import sys
import argparse
import re
import subprocess
import xml.dom.minidom
from xml.parsers.expat import ExpatError
from string import Template
import utils
import json
import shutil
import platform
class SuiteModuleBuilder:
"""
To Build Suite Module
@arguments(build_target_name, target_file...)
"""
def __init__(self, arguments):
self.arguments = arguments
self.args = None
def build_module(self):
"""
build_target_name='wifiaware_test',
javalib_file=None,
project_path='xxx/communication_lite/wifiaware',
project_type='hctest',
source_path='xxx/x.c,xxx/x.c
subsystem_name='communication',
suite_filename='libwifiaware_test.a',
suite_out_paths='out/x/suites/acts/testcases/communication,'
target_file='xxxx/libs/libmodule_wifiaware_test.a',
test_xml='xxx/Test.json'
:return:
"""
parser = argparse.ArgumentParser()
parser.add_argument('--build_target_name', help='', required=False)
parser.add_argument('--target_file', help='', required=False)
parser.add_argument('--hap_name', help='', required=False)
parser.add_argument('--project_path', help='', required=True)
parser.add_argument('--test_xml', help='', required=False)
parser.add_argument('--project_type', help='', required=True)
parser.add_argument('--suite_out_paths', help='', required=True)
parser.add_argument('--suite_filename', help='', required=True)
parser.add_argument('--subsystem_name', help='', required=False)
parser.add_argument('--build_root_path', help='', required=False)
parser.add_argument('--hap_sign', help='', required=False)
self.args = parser.parse_args(self.arguments)
for _suite_out_file in self.args.suite_out_paths.split(","):
if not _suite_out_file:
continue
if self.args.project_type == "pythontest":
_out_file = _suite_out_file
else:
_out_file = os.path.join(_suite_out_file,
self.args.suite_filename)
if self.args.project_type == "pythontest":
utils.copy_file(output=_out_file,
source_dirs=self.args.target_file,
to_dir=True)
elif self.args.project_type == "open_source_test":
utils.copy_file(output=_out_file,
sources=self.args.target_file,
to_dir=True)
elif self.args.project_type == "hjsunit":
utils.build_js_hap(self.args.project_path, self.args.
suite_out_paths, self.args.hap_name)
elif self.args.project_type != "hctest":
utils.copy_file(output=_out_file,
sources=self.args.target_file,
to_dir=False)
_testsuite_name = self.args.suite_filename
_matcher = re.match(r"(lib|libmodule_)?(\S+)\.\S+",
_testsuite_name)
if _matcher:
_testsuite_name = _matcher.group(2)
if self.args.project_type != "open_source_test":
_config_file = os.path.join(_suite_out_file,
_testsuite_name + ".json")
else:
_config_file = os.path.join(_out_file,
_testsuite_name + ".json")
utils.record_testmodule_info(self.args.build_target_name,
_testsuite_name,
self.args.subsystem_name,
_suite_out_file)
_test_xml = self.args.test_xml
if _test_xml and os.path.exists(_test_xml):
utils.copy_file(output=_config_file, sources=_test_xml,
to_dir=False)
else:
self._generate_xml_by_template(_test_xml, _testsuite_name,
_config_file)
@staticmethod
def _record_testmodule_info(build_target_name, module_name,
subsystem_name, suite_out_dir):
if not build_target_name or not subsystem_name:
print(
'build_target_name or subsystem_name of testmodule "%s" '
'is invalid!' % module_name)
return
module_info_dir = os.path.dirname(suite_out_dir)
module_info_list_file = os.path.join(module_info_dir,
'module_info.json')
module_info_data = {}
if os.path.exists(module_info_list_file):
try:
with open(module_info_list_file, 'r') as module_file:
module_info_data = json.load(module_file)
except ValueError:
print("NO json object could be decoded but continue")
module_info = {'subsystem': subsystem_name,
'build_target_name': build_target_name}
module_info_data[module_name] = module_info
with open(module_info_list_file, 'w') as out_file:
json.dump(module_info_data, out_file)
def _generate_xml_by_template(self, test_xml, module_name,
config_file):
index = test_xml.rfind(".json")
tmpl_file = test_xml[:index] + ".tmpl"
if not os.path.exists(tmpl_file):
raise Exception(
"Can't find the Test.json or Test.tmpl in the "
"path %s " % os.path.dirname(
test_xml))
tmpl_content = utils.read_file(tmpl_file)
values = {"module": module_name, "subsystem": self.args.subsystem_name}
xml_content = Template(tmpl_content).substitute(values)
utils.write_file(config_file, xml_content, False)
@staticmethod
def _check_file_exist(file_path):
if not os.path.exists(file_path):
raise Exception("File [%s] does not exist!" % file_path)
class XDeviceBuilder:
"""
To build XTS as a egg package
@arguments(project_dir, output_dirs)
"""
def __init__(self, arguments):
parser = argparse.ArgumentParser()
parser.add_argument('--project_dir', help='', required=True)
parser.add_argument('--output_dirs', help='', required=True)
self.args = parser.parse_args(arguments)
def build_xdevice(self):
"""
build xdevice package
:return:
"""
command = [utils.get_python_cmd(), "setup.py", "install", "--user"]
factory_script = os.path.join(self.args.project_dir, "factory.sh")
if os.path.exists(factory_script):
os.chmod(factory_script, 0o775)
command = factory_script
try:
subprocess.check_call(command, cwd=self.args.project_dir)
except subprocess.CalledProcessError as exc:
print('returncode: {} cmd: {} output: {}'.format(
exc.returncode, exc.cmd, exc.output))
dist_dir = os.path.join(self.args.project_dir, 'dist')
run_scripts = ",".join(
[os.path.join(self.args.project_dir, "run.bat"),
os.path.join(self.args.project_dir, "run.sh")])
config_dir = os.path.join(self.args.project_dir, "config")
res_dir = os.path.join(self.args.project_dir, "resource")
for tool_dir in self.args.output_dirs.split(","):
if tool_dir:
utils.copy_file(output=tool_dir, source_dirs=dist_dir,
to_dir=True)
root_dir = os.path.dirname(tool_dir)
utils.copy_file(output=root_dir, sources=run_scripts,
to_dir=True)
to_dir = os.path.join(root_dir, "config")
utils.copy_file(output=to_dir, source_dirs=config_dir,
to_dir=True)
utils.copy_file(os.path.join(root_dir, "resource"),
source_dirs=res_dir)
if not os.path.exists(os.path.join(
root_dir, "resource", "tools")):
os.mkdir(os.path.join(root_dir, "resource", "tools"))
return 0
class SuiteArchiveBuilder:
def __init__(self, arguments):
self.module_info_dir = None
self.arguments = arguments
def archive_suite(self):
parser = argparse.ArgumentParser()
parser.add_argument('--suite_path', help='', required=True)
parser.add_argument('--build_enabled', help='', required=True)
args = parser.parse_args(self.arguments)
if not args.build_enabled.lower() == 'true':
print('build hit not enabled, skip making archive')
return 0
suite_path = args.suite_path
if not os.path.isdir(suite_path):
raise Exception("[%s] does not exist" % suite_path)
archive_name = os.path.basename(suite_path)
suite_root_path = os.path.dirname(suite_path)
shutil.make_archive(suite_path, "zip", suite_root_path, archive_name)
return 0
ACTION_MAP = {"build_module": "SuiteModuleBuilder",
"build_xdevice": "XDeviceBuilder",
"archive_suite": "SuiteArchiveBuilder",
}
def _find_action(action, arguments):
class_name = ACTION_MAP[action]
if not class_name:
raise ValueError('Unsupported operation: %s' % action)
this_module = sys.modules[__name__]
class_def = getattr(this_module, class_name, None)
if not class_def:
raise ValueError(
'Unsupported operation(No Implementation Class): %s' % action)
class_obj = class_def(arguments)
func = getattr(class_obj, action, None)
if not func:
raise ValueError(
'Unsupported operation(No Implementation Method): %s' % action)
return func
def main(arguments):
action = arguments[0]
args = arguments[1:]
func = _find_action(action, args)
func()
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))

388
lite/build/utils.py Executable file
View File

@ -0,0 +1,388 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Copyright (c) 2021 Huawei Device Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import os
import fnmatch
import sys
import argparse
import json
import platform
import subprocess
import distutils.dir_util as dir_util
import distutils.file_util as file_util
from distutils.errors import DistutilsError
# all sub system list, must be lowercase.
_SUB_SYSTEM_LIST = [
"kernel",
"hiviewdfx",
"communication",
"security",
"update",
"sstsutils",
"utils",
"multimedia",
"hdf",
"aafwk",
"appexecfwk",
"distributed_schedule",
"startup",
"sensors",
"sample",
"iot_hardware",
"open_posix_testsuite",
"graphic",
"ace",
"applications",
"ai",
"global",
"telephony",
"dcts"
]
_NO_FILTE_SUB_SYSTEM_LIST = [
"applications",
"kernel",
"open_posix_testsuite",
"sample",
"telephony",
"dcts",
"hiviewdfx",
"communication",
"security",
"update",
"sstsutils",
"hdf",
"distributed_schedule"
]
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--method_name', help='', required=True)
parser.add_argument('--arguments', help='',
required=True) # format key=value#key=value
args = parser.parse_args()
this_module = sys.modules[__name__]
method = getattr(this_module, args.method_name)
arguments = {}
for argument in args.arguments.split("#"):
key_value = argument.strip().split("=")
if len(key_value) != 2:
raise ValueError(
"The arguments' format is 'key=value#key=value'. Wrong format:"
" " + argument)
arguments.setdefault(key_value[0].strip(), key_value[1].strip())
method(**arguments)
return 0
def read_file(input_file):
if not os.path.exists(input_file):
return ""
with open(input_file, 'r') as input_f:
content = input_f.read().strip()
return content
def write_file(output_file, content, append):
file_dir = os.path.dirname(os.path.abspath(output_file))
if not os.path.exists(file_dir):
os.makedirs(file_dir)
mode = 'a+' if append else 'w'
with open(output_file, mode) as output_f:
output_f.write("%s\n" % content)
def copy_file(output, sources="", source_dirs="", to_dir=True):
"""
copy source files or source dir to output.
if sources is not empty, the output can be file(will be created
automatically)
or directory(must be exist).
:param output: If source_dirs is not empty, output must be directory.
:param sources: source files is separated by dot
:param source_dirs: source directory is separated by dot
:param to_dir: output is directory or not
:return:
"""
if not sources and not source_dirs:
raise Exception(
"sources or source_dirs parameter must be specified one")
_output = output.strip()
_sources = sources.strip()
_source_dirs = source_dirs.strip()
_parent_output = os.path.dirname(_output)
try:
if to_dir and not os.path.exists(_output):
os.makedirs(_output)
if not to_dir and not os.path.exists(_parent_output):
os.makedirs(_parent_output)
except OSError:
if not os.path.isdir(_output):
raise
try:
if _sources:
_copy_files(_sources.split(","), _output)
if _source_dirs:
_copy_dir(_source_dirs.split(","), _output)
except DistutilsError:
print("ignore file exist error")
return 0
def _copy_files(sources, output):
copy_set = set()
for source_file in sources:
source_file = source_file.strip()
if os.path.isfile(source_file) and os.path.exists(source_file):
# if same file name exist, add dir path
if os.path.basename(source_file) in copy_set:
new_output = os.path.join(output, os.path.dirname(source_file).
split(os.sep)[-1])
if not os.path.exists(new_output):
os.makedirs(new_output)
file_util.copy_file(source_file, new_output)
else:
file_util.copy_file(source_file, output)
copy_set.add(os.path.basename(source_file))
def _copy_dir(sources, output):
for source_file in sources:
source_file = source_file.strip()
if os.path.isdir(source_file):
dir_util.copy_tree(source_file, output)
def gen_suite_out(suite_output_prefix, suite_names, out_suffix):
outputs = []
_suite_output_prefix = suite_output_prefix.strip()
_dirname_suffix = out_suffix.strip().rstrip(os.sep)
for suite in suite_names.split(","):
path = "%s%s/%s" % (
_suite_output_prefix, suite.strip(), _dirname_suffix)
outputs.append(path)
print(path)
return outputs
def get_subsystem_name(path):
subsystem_name = ""
for subsystem in _SUB_SYSTEM_LIST:
subsystem_path = "/" + subsystem + "/"
_path = path.lower()
if subsystem_path in _path:
subsystem_name = subsystem
break
subsystem_path = "/" + subsystem + "_lite/"
if subsystem_path in _path:
subsystem_name = subsystem
break
sys.stdout.write(subsystem_name)
return subsystem_name
def get_modulename_by_buildtarget(module_list_file, build_target):
if not os.path.exists(module_list_file):
return ""
with open(module_list_file, "r") as module_file:
module_info_data = json.load(module_file)
for module in module_info_data:
if module_info_data[module]["build_target_name"] == build_target:
sys.stdout.write(module)
return module
return ""
def glob(path, filename_pattern):
files = []
for dir_path, _, files in os.walk(path):
for filename in fnmatch.filter(files, filename_pattern):
files.append(os.path.join(dir_path, filename))
return files
def filter_by_subsystem(testsuites, product_json):
product_info = {}
filtered_features = []
subs_comps = {}
# parses product json to obtain all the subsystem name
if os.path.exists(product_json):
try:
with open(product_json, 'r') as product_info:
product_info = json.load(product_info)
except ValueError:
print("NO json object could be decoded.")
subsystem_info = product_info.get("subsystems")
for subsystem in subsystem_info:
subs_comps[subsystem.get("subsystem")] = \
subsystem.get("components", [])
feature_list = testsuites.split(",")
for feature in feature_list:
# if subsytem name match
subsystem = get_subsystem_name_no_output(feature)
if subsystem in _NO_FILTE_SUB_SYSTEM_LIST:
filtered_features.append(feature)
print(feature)
elif subsystem in subs_comps:
components = subs_comps.get(subsystem, [])
if check_component(feature, components):
filtered_features.append(feature)
print(feature)
return filtered_features
def get_subsystem_name_no_output(path):
subsystem_name = ""
for subsystem in _SUB_SYSTEM_LIST:
subsystem_path = "/" + subsystem
_path = path.lower()
if subsystem_path in _path:
subsystem_name = subsystem
break
subsystem_path = "/" + subsystem + "_lite"
if subsystem_path in _path:
subsystem_name = subsystem
break
return subsystem_name
def check_component(path, components):
for component in components:
component_name = component.get("component", "")
component_name = component_name.replace("_lite", "")
if component_name in path or "{}_hal".format(component_name) in path \
or "{}_posix".format(component_name) in path:
return True
return False
def get_python_cmd():
major, _, _ = platform.python_version_tuple()
if major == "3":
return "python"
else:
return "python3"
def record_testmodule_info(build_target_name, module_name,
subsystem_name, suite_out_dir, same_file=False):
if not build_target_name or not subsystem_name:
print(
'build_target_name or subsystem_name of testmodule "%s" '
'is invalid!' % module_name)
return
if same_file:
module_info_list_file = os.path.join(suite_out_dir, 'module_info.json')
else:
module_info_list_file = os.path.join(suite_out_dir,
'{}_module_info.json'.format
(build_target_name))
module_info_data = {}
if os.path.exists(module_info_list_file):
try:
with open(module_info_list_file, 'r') as module_file:
module_info_data = json.load(module_file)
except ValueError:
print("NO json object could be decoded but continue")
module_info = {'subsystem': subsystem_name,
'build_target_name': build_target_name}
module_info_data[module_name] = module_info
with open(module_info_list_file, 'w') as out_file:
json.dump(module_info_data, out_file)
def record_test_component_info(out_dir, version):
if not os.path.exists(out_dir):
os.makedirs(out_dir)
all_module_file = os.path.join(out_dir, 'module_info.json')
all_module_data = {}
for root, dirs, files in os.walk(out_dir):
for file in files:
if file.endswith("module_info.json"):
with open(os.path.join(root, file), 'r') as json_data:
module_data = json.load(json_data)
all_module_data.update(module_data)
os.remove(os.path.join(root, file))
with open(all_module_file, 'w') as out_file:
json.dump(all_module_data, out_file)
test_component_file = os.path.join(out_dir, 'test_component.json')
test_component_data = {'version': version, }
with open(test_component_file, 'w') as out_file:
json.dump(test_component_data, out_file)
def get_target_modules(all_features):
feature_list = []
if all_features:
for feature in all_features.split(","):
if feature:
feature_list.append(feature)
print(feature)
return feature_list
def cmd_popen(cmd):
proc = subprocess.Popen(cmd)
proc.wait()
ret_code = proc.returncode
if ret_code != 0:
raise Exception("{} failed, return code is {}".format(cmd, ret_code))
def build_js_hap(project_path, out_put_dir, hap_name):
if not check_env():
return
gradle_dir = os.path.join(project_path, "gradle")
os.chdir(gradle_dir)
build_clean = ["gradle", "clean"]
cmd_popen(build_clean)
build_cmd = ["gradle", "entry:packageDebugHap"]
cmd_popen(build_cmd)
gralde_output_dir = os.path.join(gradle_dir, "entry", "build", "outputs")
if os.path.exists(gralde_output_dir):
for root, _, files in os.walk(gralde_output_dir):
for file in files:
if file.endswith(".hap"):
file_util.copy_file(os.path.join(root, file),
os.path.join(out_put_dir.rstrip(','),
hap_name))
return
def check_env():
"""
check all the env for js hap build
return: return true if all env ready, otherwise return false
"""
env_list = ['OHOS_SDK_HOME', 'NODE_HOME', 'GRADLE_HOME']
for env in env_list:
if not os.environ.get(env):
print("the env {} not set, skip build!".format(env))
return False
else:
return True
if __name__ == '__main__':
sys.exit(main())

Binary file not shown.

After

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 580 B

BIN
lite/figures/icon-note.gif Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 394 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 406 B

BIN
lite/figures/icon-tip.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 580 B