19762338dSopenharmony_ci# XTS<a name="EN-US_TOPIC_0000001126156429"></a> 29762338dSopenharmony_ci 39762338dSopenharmony_ci- [Introduction](#section465982318513) 49762338dSopenharmony_ci- [System Types](#section125090457443) 59762338dSopenharmony_ci- [Directory Structure](#section161941989596) 69762338dSopenharmony_ci- [Constraints](#section119744591305) 79762338dSopenharmony_ci- [Usage Guidelines](#section137768191623) 89762338dSopenharmony_ci- [Test Case Development Guidelines](#section3695134065513) 99762338dSopenharmony_ci - [C-based Test Case Development and Compilation \(for the Mini System\)](#section198193336544) 109762338dSopenharmony_ci - [C-based Test Case Execution \(for the Mini System\)](#section13820233175418) 119762338dSopenharmony_ci - [C++-based Test Case Development and Compilation \(for Standard and Small Systems\)](#section3822123311540) 129762338dSopenharmony_ci - [C++-based Test Case Execution \(for Standard and Small Systems\)](#section128222336544) 139762338dSopenharmony_ci 149762338dSopenharmony_ci 159762338dSopenharmony_ci## Introduction<a name="section465982318513"></a> 169762338dSopenharmony_ci 179762338dSopenharmony_ciThe X test suite \(XTS\) subsystem contains a set of OpenHarmony certification test suites, including the currently supported hardware abstract test suite \(HATS\). 189762338dSopenharmony_ci 199762338dSopenharmony_ciThis subsystem contains the HATS and **tools** software package. 209762338dSopenharmony_ci 219762338dSopenharmony_ci- The **hats** directory stores the source code and configuration files of HATS test cases. The HATS helps device vendors detect the HAL software incompatibility as early as possible and ensures that the software is compatible to OpenHarmony during the entire development process. 229762338dSopenharmony_ci- The **tools** software package stores the test case development framework related to **hats**. 239762338dSopenharmony_ci 249762338dSopenharmony_ci## System Types<a name="section125090457443"></a> 259762338dSopenharmony_ci 269762338dSopenharmony_ciOpenHarmony supports the following system types: 279762338dSopenharmony_ci 289762338dSopenharmony_ci- Mini system 299762338dSopenharmony_ci 309762338dSopenharmony_ci 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. 319762338dSopenharmony_ci 329762338dSopenharmony_ci- Small system 339762338dSopenharmony_ci 349762338dSopenharmony_ci 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. 359762338dSopenharmony_ci 369762338dSopenharmony_ci- Standard system 379762338dSopenharmony_ci 389762338dSopenharmony_ci 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. 399762338dSopenharmony_ci 409762338dSopenharmony_ci 419762338dSopenharmony_ci## Directory Structure<a name="section161941989596"></a> 429762338dSopenharmony_ci 439762338dSopenharmony_ci``` 449762338dSopenharmony_ci/test/xts 459762338dSopenharmony_ci├── hats # Test code 469762338dSopenharmony_ci│ └── subsystem # Source code of subsystem test cases for the standard system 479762338dSopenharmony_ci│ └── subsystem_lite # Source code of subsystems test cases for mini and small systems 489762338dSopenharmony_ci│ └── BUILD.gn # Build configuration of test cases for the standard system 499762338dSopenharmony_ci│ └── build_lite 509762338dSopenharmony_ci│ └── BUILD.gn # Build configuration of test cases for mini and small systems 519762338dSopenharmony_ci└── tools # Test tool code 529762338dSopenharmony_ci``` 539762338dSopenharmony_ci 549762338dSopenharmony_ci## Constraints<a name="section119744591305"></a> 559762338dSopenharmony_ci 569762338dSopenharmony_ciTest cases for the mini system must be developed based on C, and those for the small system must be developed based on C++. 579762338dSopenharmony_ci 589762338dSopenharmony_ci## Usage Guidelines<a name="section137768191623"></a> 599762338dSopenharmony_ci 609762338dSopenharmony_ci**Table 1** Test case levels 619762338dSopenharmony_ci 629762338dSopenharmony_ci<a name="table12856113719456"></a> 639762338dSopenharmony_ci<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> 649762338dSopenharmony_ci</th> 659762338dSopenharmony_ci<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> 669762338dSopenharmony_ci</th> 679762338dSopenharmony_ci<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> 689762338dSopenharmony_ci</th> 699762338dSopenharmony_ci</tr> 709762338dSopenharmony_ci</thead> 719762338dSopenharmony_ci<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> 729762338dSopenharmony_ci</td> 739762338dSopenharmony_ci<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> 749762338dSopenharmony_ci</td> 759762338dSopenharmony_ci<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> 769762338dSopenharmony_ci</td> 779762338dSopenharmony_ci</tr> 789762338dSopenharmony_ci<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> 799762338dSopenharmony_ci</td> 809762338dSopenharmony_ci<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> 819762338dSopenharmony_ci</td> 829762338dSopenharmony_ci<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> 839762338dSopenharmony_ci</td> 849762338dSopenharmony_ci</tr> 859762338dSopenharmony_ci<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> 869762338dSopenharmony_ci</td> 879762338dSopenharmony_ci<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> 889762338dSopenharmony_ci</td> 899762338dSopenharmony_ci<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> 909762338dSopenharmony_ci</td> 919762338dSopenharmony_ci</tr> 929762338dSopenharmony_ci<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> 939762338dSopenharmony_ci</td> 949762338dSopenharmony_ci<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> 959762338dSopenharmony_ci</td> 969762338dSopenharmony_ci<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> 979762338dSopenharmony_ci</td> 989762338dSopenharmony_ci</tr> 999762338dSopenharmony_ci<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> 1009762338dSopenharmony_ci</td> 1019762338dSopenharmony_ci<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> 1029762338dSopenharmony_ci</td> 1039762338dSopenharmony_ci<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> 1049762338dSopenharmony_ci</td> 1059762338dSopenharmony_ci</tr> 1069762338dSopenharmony_ci</tbody> 1079762338dSopenharmony_ci</table> 1089762338dSopenharmony_ci 1099762338dSopenharmony_ci**Table 2** Test case granularities 1109762338dSopenharmony_ci 1119762338dSopenharmony_ci<a name="table1690733521014"></a> 1129762338dSopenharmony_ci<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> 1139762338dSopenharmony_ci</th> 1149762338dSopenharmony_ci<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> 1159762338dSopenharmony_ci</th> 1169762338dSopenharmony_ci<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> 1179762338dSopenharmony_ci</th> 1189762338dSopenharmony_ci</tr> 1199762338dSopenharmony_ci</thead> 1209762338dSopenharmony_ci<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> 1219762338dSopenharmony_ci</td> 1229762338dSopenharmony_ci<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> 1239762338dSopenharmony_ci</td> 1249762338dSopenharmony_ci<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> 1259762338dSopenharmony_ci</td> 1269762338dSopenharmony_ci</tr> 1279762338dSopenharmony_ci<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> 1289762338dSopenharmony_ci</td> 1299762338dSopenharmony_ci<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> 1309762338dSopenharmony_ci</td> 1319762338dSopenharmony_ci<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> 1329762338dSopenharmony_ci</td> 1339762338dSopenharmony_ci</tr> 1349762338dSopenharmony_ci<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> 1359762338dSopenharmony_ci</td> 1369762338dSopenharmony_ci<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> 1379762338dSopenharmony_ci</td> 1389762338dSopenharmony_ci<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> 1399762338dSopenharmony_ci</td> 1409762338dSopenharmony_ci</tr> 1419762338dSopenharmony_ci</tbody> 1429762338dSopenharmony_ci</table> 1439762338dSopenharmony_ci 1449762338dSopenharmony_ci**Table 3** Test types 1459762338dSopenharmony_ci 1469762338dSopenharmony_ci<a name="table18811230124619"></a> 1479762338dSopenharmony_ci<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> 1489762338dSopenharmony_ci</th> 1499762338dSopenharmony_ci<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> 1509762338dSopenharmony_ci</th> 1519762338dSopenharmony_ci</tr> 1529762338dSopenharmony_ci</thead> 1539762338dSopenharmony_ci<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> 1549762338dSopenharmony_ci</td> 1559762338dSopenharmony_ci<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> 1569762338dSopenharmony_ci</td> 1579762338dSopenharmony_ci</tr> 1589762338dSopenharmony_ci<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> 1599762338dSopenharmony_ci</td> 1609762338dSopenharmony_ci<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> 1619762338dSopenharmony_ci</td> 1629762338dSopenharmony_ci</tr> 1639762338dSopenharmony_ci<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> 1649762338dSopenharmony_ci</td> 1659762338dSopenharmony_ci<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> 1669762338dSopenharmony_ci</td> 1679762338dSopenharmony_ci</tr> 1689762338dSopenharmony_ci<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> 1699762338dSopenharmony_ci</td> 1709762338dSopenharmony_ci<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> 1719762338dSopenharmony_ci</td> 1729762338dSopenharmony_ci</tr> 1739762338dSopenharmony_ci<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> 1749762338dSopenharmony_ci</td> 1759762338dSopenharmony_ci<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> 1769762338dSopenharmony_ci</td> 1779762338dSopenharmony_ci</tr> 1789762338dSopenharmony_ci<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> 1799762338dSopenharmony_ci</td> 1809762338dSopenharmony_ci<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> 1819762338dSopenharmony_ci</td> 1829762338dSopenharmony_ci</tr> 1839762338dSopenharmony_ci<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> 1849762338dSopenharmony_ci</td> 1859762338dSopenharmony_ci<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> 1869762338dSopenharmony_ci</td> 1879762338dSopenharmony_ci</tr> 1889762338dSopenharmony_ci<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> 1899762338dSopenharmony_ci</td> 1909762338dSopenharmony_ci<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> 1919762338dSopenharmony_ci</td> 1929762338dSopenharmony_ci</tr> 1939762338dSopenharmony_ci<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> 1949762338dSopenharmony_ci</td> 1959762338dSopenharmony_ci<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> 1969762338dSopenharmony_ci</td> 1979762338dSopenharmony_ci</tr> 1989762338dSopenharmony_ci<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> 1999762338dSopenharmony_ci</td> 2009762338dSopenharmony_ci<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> 2019762338dSopenharmony_ci</td> 2029762338dSopenharmony_ci</tr> 2039762338dSopenharmony_ci<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> 2049762338dSopenharmony_ci</td> 2059762338dSopenharmony_ci<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> 2069762338dSopenharmony_ci</td> 2079762338dSopenharmony_ci</tr> 2089762338dSopenharmony_ci</tbody> 2099762338dSopenharmony_ci</table> 2109762338dSopenharmony_ci 2119762338dSopenharmony_ci## Test Case Development Guidelines<a name="section3695134065513"></a> 2129762338dSopenharmony_ci 2139762338dSopenharmony_ciYou should select the appropriate programming language and your target test framework to develop test cases. 2149762338dSopenharmony_ci 2159762338dSopenharmony_ci**Table 4** Test frameworks and test case languages for different systems 2169762338dSopenharmony_ci 2179762338dSopenharmony_ci<a name="table4418343171415"></a> 2189762338dSopenharmony_ci<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> 2199762338dSopenharmony_ci</th> 2209762338dSopenharmony_ci<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> 2219762338dSopenharmony_ci</th> 2229762338dSopenharmony_ci<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> 2239762338dSopenharmony_ci</th> 2249762338dSopenharmony_ci</tr> 2259762338dSopenharmony_ci</thead> 2269762338dSopenharmony_ci<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> 2279762338dSopenharmony_ci</td> 2289762338dSopenharmony_ci<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> 2299762338dSopenharmony_ci</td> 2309762338dSopenharmony_ci<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> 2319762338dSopenharmony_ci</td> 2329762338dSopenharmony_ci</tr> 2339762338dSopenharmony_ci<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> 2349762338dSopenharmony_ci</td> 2359762338dSopenharmony_ci<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> 2369762338dSopenharmony_ci</td> 2379762338dSopenharmony_ci<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> 2389762338dSopenharmony_ci</td> 2399762338dSopenharmony_ci</tr> 2409762338dSopenharmony_ci<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> 2419762338dSopenharmony_ci</td> 2429762338dSopenharmony_ci<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> 2439762338dSopenharmony_ci</td> 2449762338dSopenharmony_ci<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> 2459762338dSopenharmony_ci</td> 2469762338dSopenharmony_ci</tr> 2479762338dSopenharmony_ci</tbody> 2489762338dSopenharmony_ci</table> 2499762338dSopenharmony_ci 2509762338dSopenharmony_ci### C-based Test Case Development and Compilation \(for the Mini System\)<a name="section198193336544"></a> 2519762338dSopenharmony_ci 2529762338dSopenharmony_ci**Developing test cases for the mini system** 2539762338dSopenharmony_ci 2549762338dSopenharmony_ciThe 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. 2559762338dSopenharmony_ci 2569762338dSopenharmony_ci1. Access the **test/xts/hats** repository where the test cases will be stored. 2579762338dSopenharmony_ci 2589762338dSopenharmony_ci ``` 2599762338dSopenharmony_ci ├── hats 2609762338dSopenharmony_ci │ └──subsystem_lite 2619762338dSopenharmony_ci │ │ └── module_hal 2629762338dSopenharmony_ci │ │ │ └── BUILD.gn 2639762338dSopenharmony_ci │ │ │ └── src 2649762338dSopenharmony_ci │ └──build_lite 2659762338dSopenharmony_ci │ │ └── BUILD.gn 2669762338dSopenharmony_ci ``` 2679762338dSopenharmony_ci 2689762338dSopenharmony_ci2. Write the test case in the **src** directory. 2699762338dSopenharmony_ci 2709762338dSopenharmony_ci 1 Import the test framework header file. 2719762338dSopenharmony_ci 2729762338dSopenharmony_ci ``` 2739762338dSopenharmony_ci #include "hctest.h" 2749762338dSopenharmony_ci ``` 2759762338dSopenharmony_ci 2769762338dSopenharmony_ci 2. Use the **LITE\_TEST\_SUIT** macro to define names of the subsystem, module, and test suite. 2779762338dSopenharmony_ci 2789762338dSopenharmony_ci ``` 2799762338dSopenharmony_ci /** 2809762338dSopenharmony_ci * @brief Registers a test suite named IntTestSuite. 2819762338dSopenharmony_ci * @param test Subsystem name 2829762338dSopenharmony_ci * @param example Module name 2839762338dSopenharmony_ci * @param IntTestSuite Test suite name 2849762338dSopenharmony_ci */ 2859762338dSopenharmony_ci LITE_TEST_SUIT(test, example, IntTestSuite); 2869762338dSopenharmony_ci ``` 2879762338dSopenharmony_ci 2889762338dSopenharmony_ci 3. Define Setup and TearDown. 2899762338dSopenharmony_ci 2909762338dSopenharmony_ci Format: Test suite name+Setup, Test suite name+TearDown. 2919762338dSopenharmony_ci 2929762338dSopenharmony_ci The Setup and TearDown functions must exist, but function bodies can be empty. 2939762338dSopenharmony_ci 2949762338dSopenharmony_ci 4. Use the **LITE\_TEST\_CASE** macro to write the test case. 2959762338dSopenharmony_ci 2969762338dSopenharmony_ci Three parameters are involved: test suite name, test case name, and test case properties \(including type, granularity, and level\). 2979762338dSopenharmony_ci 2989762338dSopenharmony_ci ``` 2999762338dSopenharmony_ci LITE_TEST_CASE(IntTestSuite, TestCase001, Function | MediumTest | Level1) 3009762338dSopenharmony_ci { 3019762338dSopenharmony_ci // Do something 3029762338dSopenharmony_ci }; 3039762338dSopenharmony_ci ``` 3049762338dSopenharmony_ci 3059762338dSopenharmony_ci 5. Use the **RUN\_TEST\_SUITE** macro to register the test suite. 3069762338dSopenharmony_ci 3079762338dSopenharmony_ci ``` 3089762338dSopenharmony_ci RUN_TEST_SUITE(IntTestSuite); 3099762338dSopenharmony_ci ``` 3109762338dSopenharmony_ci 3119762338dSopenharmony_ci3. Create the configuration file \(**BUILD.gn**\) of the test module. 3129762338dSopenharmony_ci 3139762338dSopenharmony_ci 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: 3149762338dSopenharmony_ci 3159762338dSopenharmony_ci ``` 3169762338dSopenharmony_ci import("//test/xts/tools/lite/build/suite_lite.gni") 3179762338dSopenharmony_ci hctest_suite("HatsDemoTest") { 3189762338dSopenharmony_ci suite_name = "hats" 3199762338dSopenharmony_ci sources = [ 3209762338dSopenharmony_ci "src/test_demo.c", 3219762338dSopenharmony_ci ] 3229762338dSopenharmony_ci include_dirs = [ ] 3239762338dSopenharmony_ci cflags = [ "-Wno-error" ] 3249762338dSopenharmony_ci } 3259762338dSopenharmony_ci ``` 3269762338dSopenharmony_ci 3279762338dSopenharmony_ci4. Add build options to the **BUILD.gn** file in the **hats** directory. 3289762338dSopenharmony_ci 3299762338dSopenharmony_ci You need to add the test module to the **test/xts/hats/build\_lite/BUILD.gn** script in the **hats** directory. 3309762338dSopenharmony_ci 3319762338dSopenharmony_ci ``` 3329762338dSopenharmony_ci lite_component("hats") { 3339762338dSopenharmony_ci ... 3349762338dSopenharmony_ci if(board_name == "liteos_m") { 3359762338dSopenharmony_ci features += [ 3369762338dSopenharmony_ci ... 3379762338dSopenharmony_ci "//xts/hats/subsystem_lite/module_hal:HatsDemoTest" 3389762338dSopenharmony_ci ] 3399762338dSopenharmony_ci } 3409762338dSopenharmony_ci } 3419762338dSopenharmony_ci ``` 3429762338dSopenharmony_ci 3439762338dSopenharmony_ci5. Run build commands. 3449762338dSopenharmony_ci 3459762338dSopenharmony_ci Test suites are built along with version build. The HATS is built together with the debug version. 3469762338dSopenharmony_ci 3479762338dSopenharmony_ci > **NOTE:** 3489762338dSopenharmony_ci >The HATS build middleware is a static library, which will be linked to the image. 3499762338dSopenharmony_ci 3509762338dSopenharmony_ci 3519762338dSopenharmony_ci### C-based Test Case Execution \(for the Mini System\)<a name="section13820233175418"></a> 3529762338dSopenharmony_ci 3539762338dSopenharmony_ci**Executing test cases for the mini system** 3549762338dSopenharmony_ci 3559762338dSopenharmony_ciBurn the image into the development board. 3569762338dSopenharmony_ci 3579762338dSopenharmony_ci**Executing the test** 3589762338dSopenharmony_ci 3599762338dSopenharmony_ci1. Use a serial port tool to log in to the development board and save information about the serial port. 3609762338dSopenharmony_ci2. Restart the device and view serial port logs. 3619762338dSopenharmony_ci 3629762338dSopenharmony_ci**Analyzing the test result** 3639762338dSopenharmony_ci 3649762338dSopenharmony_ciView the serial port logs, whose format is as follows: 3659762338dSopenharmony_ci 3669762338dSopenharmony_ciThe log for each test suite starts with **Start to run test suite:** and ends with **xx Tests xx Failures xx Ignored**. 3679762338dSopenharmony_ci 3689762338dSopenharmony_ci### C++-based Test Case Development and Compilation \(for Standard and Small Systems\)<a name="section3822123311540"></a> 3699762338dSopenharmony_ci 3709762338dSopenharmony_ci**Developing test cases for small-system devices** \(For examples of the standard system, go to the **global/i18n\_standard directory**.\) 3719762338dSopenharmony_ci 3729762338dSopenharmony_ciThe HCPPTest framework is enhanced and adapted based on the open-source framework Googletest. 3739762338dSopenharmony_ci 3749762338dSopenharmony_ci1. Access the **test/xts/hats** repository where the test cases will be stored. 3759762338dSopenharmony_ci 3769762338dSopenharmony_ci ``` 3779762338dSopenharmony_ci ├── hats 3789762338dSopenharmony_ci │ └──subsystem_lite 3799762338dSopenharmony_ci │ │ └── module_posix 3809762338dSopenharmony_ci │ │ │ └── BUILD.gn 3819762338dSopenharmony_ci │ │ │ └── src 3829762338dSopenharmony_ci │ └──build_lite 3839762338dSopenharmony_ci │ │ └── BUILD.gn 3849762338dSopenharmony_ci ``` 3859762338dSopenharmony_ci 3869762338dSopenharmony_ci2. Write the test case in the **src** directory. 3879762338dSopenharmony_ci 3889762338dSopenharmony_ci 1. Import the test framework header file. 3899762338dSopenharmony_ci 3909762338dSopenharmony_ci The following statement includes **gtest.h**. 3919762338dSopenharmony_ci 3929762338dSopenharmony_ci ``` 3939762338dSopenharmony_ci #include "gtest/gtest.h" 3949762338dSopenharmony_ci ``` 3959762338dSopenharmony_ci 3969762338dSopenharmony_ci 2. Define Setup and TearDown. 3979762338dSopenharmony_ci 3989762338dSopenharmony_ci ``` 3999762338dSopenharmony_ci using namespace std; 4009762338dSopenharmony_ci using namespace testing::ext; 4019762338dSopenharmony_ci class TestSuite: public testing::Test { 4029762338dSopenharmony_ci protected: 4039762338dSopenharmony_ci // Preset action of the test suite, which is executed before the first test case 4049762338dSopenharmony_ci static void SetUpTestCase(void){ 4059762338dSopenharmony_ci } 4069762338dSopenharmony_ci // Test suite cleanup action, which is executed after the last test case 4079762338dSopenharmony_ci static void TearDownTestCase(void){ 4089762338dSopenharmony_ci } 4099762338dSopenharmony_ci // Preset action of the test case 4109762338dSopenharmony_ci virtual void SetUp() 4119762338dSopenharmony_ci { 4129762338dSopenharmony_ci } 4139762338dSopenharmony_ci // Cleanup action of the test case 4149762338dSopenharmony_ci virtual void TearDown() 4159762338dSopenharmony_ci { 4169762338dSopenharmony_ci } 4179762338dSopenharmony_ci }; 4189762338dSopenharmony_ci ``` 4199762338dSopenharmony_ci 4209762338dSopenharmony_ci 3. Use the **HWTEST** or **HWTEST\_F** macro to write the test case. 4219762338dSopenharmony_ci 4229762338dSopenharmony_ci **HWTEST**: definition of common test cases, including the test suite name, test case name, and case annotation. 4239762338dSopenharmony_ci 4249762338dSopenharmony_ci **HWTEST\_F**: definition of SetUp and TearDown test cases, including the test suite name, test case name, and case annotation. 4259762338dSopenharmony_ci 4269762338dSopenharmony_ci Three parameters are involved: test suite name, test case name, and test case properties \(including type, granularity, and level\). 4279762338dSopenharmony_ci 4289762338dSopenharmony_ci ``` 4299762338dSopenharmony_ci HWTEST_F(TestSuite, TestCase_0001, Function | MediumTest | Level1) { 4309762338dSopenharmony_ci // Do something 4319762338dSopenharmony_ci } 4329762338dSopenharmony_ci ``` 4339762338dSopenharmony_ci 4349762338dSopenharmony_ci3. Create a configuration file \(**BUILD.gn**\) of the test module. 4359762338dSopenharmony_ci 4369762338dSopenharmony_ci 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. 4379762338dSopenharmony_ci 4389762338dSopenharmony_ci Example: 4399762338dSopenharmony_ci 4409762338dSopenharmony_ci ``` 4419762338dSopenharmony_ci import("//test/xts/tools/lite/build/suite_lite.gni") 4429762338dSopenharmony_ci hcpptest_suite("HatsDemoTest") { 4439762338dSopenharmony_ci suite_name = "hats" 4449762338dSopenharmony_ci sources = [ 4459762338dSopenharmony_ci "src/TestDemo.cpp" 4469762338dSopenharmony_ci ] 4479762338dSopenharmony_ci 4489762338dSopenharmony_ci include_dirs = [ 4499762338dSopenharmony_ci "src", 4509762338dSopenharmony_ci ... 4519762338dSopenharmony_ci ] 4529762338dSopenharmony_ci deps = [ 4539762338dSopenharmony_ci ... 4549762338dSopenharmony_ci ] 4559762338dSopenharmony_ci cflags = [ "-Wno-error" ] 4569762338dSopenharmony_ci } 4579762338dSopenharmony_ci ``` 4589762338dSopenharmony_ci 4599762338dSopenharmony_ci4. Add build options to the **BUILD.gn** file in the **hats** directory. 4609762338dSopenharmony_ci 4619762338dSopenharmony_ci Add the test module to the **test/xts/hats/build\_lite/BUILD.gn** script in the **hats** directory. 4629762338dSopenharmony_ci 4639762338dSopenharmony_ci ``` 4649762338dSopenharmony_ci lite_component("hats") { 4659762338dSopenharmony_ci ... 4669762338dSopenharmony_ci else if(board_name == "liteos_a") { 4679762338dSopenharmony_ci features += [ 4689762338dSopenharmony_ci ... 4699762338dSopenharmony_ci "//xts/hats/subsystem_lite/module_posix:HatsDemoTest" 4709762338dSopenharmony_ci ] 4719762338dSopenharmony_ci } 4729762338dSopenharmony_ci } 4739762338dSopenharmony_ci ``` 4749762338dSopenharmony_ci 4759762338dSopenharmony_ci5. Run build commands. 4769762338dSopenharmony_ci 4779762338dSopenharmony_ci Test suites are built along with the version build. The HATS is built together with the debug version. 4789762338dSopenharmony_ci 4799762338dSopenharmony_ci > **NOTE:** 4809762338dSopenharmony_ci >The HATS for the small system is independently built to an executable file \(.bin\) and archived in the **suites\\hats** directory of the build result. 4819762338dSopenharmony_ci 4829762338dSopenharmony_ci 4839762338dSopenharmony_ci### C++-based Test Case Execution \(for Standard and Small Systems\)<a name="section128222336544"></a> 4849762338dSopenharmony_ci 4859762338dSopenharmony_ci**Executing test cases for the small system** 4869762338dSopenharmony_ci 4879762338dSopenharmony_ciCurrently, test cases are shared by the NFS and mounted to the development board for execution. 4889762338dSopenharmony_ci 4899762338dSopenharmony_ci**Setting up the environment** 4909762338dSopenharmony_ci 4919762338dSopenharmony_ci1. Use a network cable or wireless network to connect the development board to your PC. 4929762338dSopenharmony_ci2. 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. 4939762338dSopenharmony_ci3. Install and register the NFS server on the PC and start the NFS service. 4949762338dSopenharmony_ci4. Run the **mount** command for the development board to ensure that the development board can access NFS shared files on the PC. 4959762338dSopenharmony_ci 4969762338dSopenharmony_ci Format: **mount** _NFS server IP address_**:/**_NFS shared directory_ **/**_development board directory_ **nfs** 4979762338dSopenharmony_ci 4989762338dSopenharmony_ci Example: 4999762338dSopenharmony_ci 5009762338dSopenharmony_ci ``` 5019762338dSopenharmony_ci mount 192.168.1.10:/nfs /nfs nfs 5029762338dSopenharmony_ci ``` 5039762338dSopenharmony_ci 5049762338dSopenharmony_ci 5059762338dSopenharmony_ci**Executing test cases** 5069762338dSopenharmony_ci 5079762338dSopenharmony_ciExecute **HatsDemoTest.bin** to trigger test case execution, and analyze serial port logs generated after the execution is complete. 508