README.md
1# XTS<a name="EN-US_TOPIC_0000001126156429"></a>
2
3- [Introduction](#section465982318513)
4- [System Types](#section125090457443)
5- [Directory Structure](#section161941989596)
6- [Constraints](#section119744591305)
7- [Usage Guidelines](#section137768191623)
8- [Test Case Development Guidelines](#section3695134065513)
9 - [C-based Test Case Development and Compilation \(for the Mini System\)](#section198193336544)
10 - [C-based Test Case Execution \(for the Mini System\)](#section13820233175418)
11 - [C++-based Test Case Development and Compilation \(for Standard and Small Systems\)](#section3822123311540)
12 - [C++-based Test Case Execution \(for Standard and Small Systems\)](#section128222336544)
13
14
15## Introduction<a name="section465982318513"></a>
16
17The X test suite \(XTS\) subsystem contains a set of OpenHarmony certification test suites, including the currently supported distributed compatibility test suite \(DCTS\).
18
19This subsystem contains the DCTS and **tools** software package.
20
21- The **dcts** directory stores the source code and configuration files of DCTS test cases. The DCTS helps device vendors detect the distributed scenario incompatibility as early as possible and ensures that the software is compatible to OpenHarmony during the entire development process.
22- The **tools** software package stores the test case development framework related to **dcts**.
23
24## System Types<a name="section125090457443"></a>
25
26OpenHarmony supports the following system types:
27
28- Mini system
29
30 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.
31
32- Small system
33
34 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.
35
36- Standard system
37
38 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.
39
40
41## Directory Structure<a name="section161941989596"></a>
42
43```
44/test/xts
45├── dcts # Test code
46│ └── subsystem # Source code of subsystem test cases for the standard system
47│ └── subsystem_lite # Source code of subsystems test cases for mini and small systems
48│ └── common # Source code of Test cases rely on shared memory for mini and small systems
49│ └── BUILD.gn # Build configuration of test cases for the standard system
50│ └── build_lite
51│ └── BUILD.gn # Build configuration of test cases for mini and small systems
52└── tools # Test tool code
53```
54
55## Constraints<a name="section119744591305"></a>
56
57Test cases for the mini system must be developed based on C, the small system must be developed based on C++, and the standard system must be developed based on C++ or js.
581. Currently the DCTS supports the standard system.
592. Screenless devices do not support PIN authentication networking and do not support DCTS test。
60
61## Usage Guidelines<a name="section137768191623"></a>
62
63**Table 1** Test case levels
64
65<a name="table12856113719456"></a>
66<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>
67</th>
68<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>
69</th>
70<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>
71</th>
72</tr>
73</thead>
74<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>
75</td>
76<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>
77</td>
78<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>
79</td>
80</tr>
81<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>
82</td>
83<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>
84</td>
85<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>
86</td>
87</tr>
88<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>
89</td>
90<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>
91</td>
92<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>
93</td>
94</tr>
95<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>
96</td>
97<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>
98</td>
99<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>
100</td>
101</tr>
102<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>
103</td>
104<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>
105</td>
106<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>
107</td>
108</tr>
109</tbody>
110</table>
111
112**Table 2** Test case granularities
113
114<a name="table1690733521014"></a>
115<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>
116</th>
117<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>
118</th>
119<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>
120</th>
121</tr>
122</thead>
123<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>
124</td>
125<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>
126</td>
127<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>
128</td>
129</tr>
130<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>
131</td>
132<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>
133</td>
134<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>
135</td>
136</tr>
137<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>
138</td>
139<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>
140</td>
141<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>
142</td>
143</tr>
144</tbody>
145</table>
146
147**Table 3** Test types
148
149<a name="table18811230124619"></a>
150<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>
151</th>
152<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>
153</th>
154</tr>
155</thead>
156<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>
157</td>
158<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>
159</td>
160</tr>
161<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>
162</td>
163<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>
164</td>
165</tr>
166<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>
167</td>
168<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>
169</td>
170</tr>
171<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>
172</td>
173<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>
174</td>
175</tr>
176<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>
177</td>
178<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>
179</td>
180</tr>
181<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>
182</td>
183<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>
184</td>
185</tr>
186<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>
187</td>
188<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>
189</td>
190</tr>
191<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>
192</td>
193<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>
194</td>
195</tr>
196<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>
197</td>
198<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>
199</td>
200</tr>
201<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>
202</td>
203<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>
204</td>
205</tr>
206<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>
207</td>
208<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>
209</td>
210</tr>
211</tbody>
212</table>
213
214## Test Case Development Guidelines<a name="section3695134065513"></a>
215
216You should select the appropriate programming language and your target test framework to develop test cases.
217
218**Table 4** Test frameworks and test case languages for different systems
219
220<a name="table4418343171415"></a>
221<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>
222</th>
223<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>
224</th>
225<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>
226</th>
227</tr>
228</thead>
229<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>
230</td>
231<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>
232</td>
233<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>
234</td>
235</tr>
236<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>
237</td>
238<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>
239</td>
240<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>
241</td>
242</tr>
243<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>
244</td>
245<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>
246</td>
247<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>
248</td>
249</tr>
250</tbody>
251</table>
252
253### C-based Test Case Development and Compilation \(for the Mini System\)<a name="section198193336544"></a>
254
255**Developing test cases for the mini system**
256
257The 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.
258
2591. Access the **test/xts/dcts** repository where the test cases will be stored.
260
261 ```
262 ├── dcts
263 │ └──subsystem_lite
264 │ │ └── module_hal
265 │ │ │ └── BUILD.gn
266 │ │ │ └── src
267 │ └──build_lite
268 │ │ └── BUILD.gn
269 ```
270
2712. Write the test case in the **src** directory.
272
273 1 Import the test framework header file.
274
275 ```
276 #include "hctest.h"
277 ```
278
279 2. Use the **LITE\_TEST\_SUIT** macro to define names of the subsystem, module, and test suite.
280
281 ```
282 /**
283 * @brief Registers a test suite named IntTestSuite.
284 * @param test Subsystem name
285 * @param example Module name
286 * @param IntTestSuite Test suite name
287 */
288 LITE_TEST_SUIT(test, example, IntTestSuite);
289 ```
290
291 3. Define Setup and TearDown.
292
293 Format: Test suite name+Setup, Test suite name+TearDown.
294
295 The Setup and TearDown functions must exist, but function bodies can be empty.
296
297 4. Use the **LITE\_TEST\_CASE** macro to write the test case.
298
299 Three parameters are involved: test suite name, test case name, and test case properties \(including type, granularity, and level\).
300
301 ```
302 LITE_TEST_CASE(IntTestSuite, TestCase001, Function | MediumTest | Level1)
303 {
304 // Do something
305 };
306 ```
307
308 5. Use the **RUN\_TEST\_SUITE** macro to register the test suite.
309
310 ```
311 RUN_TEST_SUITE(IntTestSuite);
312 ```
313
3143. Create the configuration file \(**BUILD.gn**\) of the test module.
315
316 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:
317
318 ```
319 import("//test/xts/tools/lite/build/suite_lite.gni")
320 hctest_suite("DctsDemoTest") {
321 suite_name = "dcts"
322 sources = [
323 "src/test_demo.c",
324 ]
325 include_dirs = [ ]
326 cflags = [ "-Wno-error" ]
327 }
328 ```
329
3304. Add build options to the **BUILD.gn** file in the **dcts** directory.
331
332 You need to add the test module to the **test/xts/dcts/build\_lite/BUILD.gn** script in the **dcts** directory.
333
334 ```
335 lite_component("dcts") {
336 ...
337 if(board_name == "liteos_m") {
338 features += [
339 ...
340 "//xts/dcts/subsystem_lite/module_hal:DctsDemoTest"
341 ]
342 }
343 }
344 ```
345
3465. Run build commands.
347
348 Test suites are built along with version build. The DCTS is built together with the debug version.
349
350 >![](figures/icon-note.gif) **NOTE:**
351 >The DCTS build middleware is a static library, which will be linked to the image.
352
353
354### C-based Test Case Execution \(for the Mini System\)<a name="section13820233175418"></a>
355
356**Executing test cases for the mini system**
357
358Burn the image into the development board.
359
360**Executing the test**
361
3621. Use a serial port tool to log in to the development board and save information about the serial port.
3632. Restart the device and view serial port logs.
364
365**Analyzing the test result**
366
367View the serial port logs, whose format is as follows:
368
369The log for each test suite starts with **Start to run test suite:** and ends with **xx Tests xx Failures xx Ignored**.
370
371### C++-based Test Case Development and Compilation \(for Standard and Small Systems\)<a name="section3822123311540"></a>
372
373**Developing test cases for small-system devices** \(For examples of the standard system, go to the **global/i18n\_standard directory**.\)
374
375The HCPPTest framework is enhanced and adapted based on the open-source framework Googletest.
376
3771. Access the **test/xts/dcts** repository where the test cases will be stored.
378
379 ```
380 ├── dcts
381 │ └──subsystem_lite
382 │ │ └── module_posix
383 │ │ │ └── BUILD.gn
384 │ │ │ └── src
385 │ └──build_lite
386 │ │ └── BUILD.gn
387 ```
388
3892. Write the test case in the **src** directory.
390
391 1. Import the test framework header file.
392
393 The following statement includes **gtest.h**.
394
395 ```
396 #include "gtest/gtest.h"
397 ```
398
399 2. Define Setup and TearDown.
400
401 ```
402 using namespace std;
403 using namespace testing::ext;
404 class TestSuite: public testing::Test {
405 protected:
406 // Preset action of the test suite, which is executed before the first test case
407 static void SetUpTestCase(void){
408 }
409 // Test suite cleanup action, which is executed after the last test case
410 static void TearDownTestCase(void){
411 }
412 // Preset action of the test case
413 virtual void SetUp()
414 {
415 }
416 // Cleanup action of the test case
417 virtual void TearDown()
418 {
419 }
420 };
421 ```
422
423 3. Use the **HWTEST** or **HWTEST\_F** macro to write the test case.
424
425 **HWTEST**: definition of common test cases, including the test suite name, test case name, and case annotation.
426
427 **HWTEST\_F**: definition of SetUp and TearDown test cases, including the test suite name, test case name, and case annotation.
428
429 Three parameters are involved: test suite name, test case name, and test case properties \(including type, granularity, and level\).
430
431 ```
432 HWTEST_F(TestSuite, TestCase_0001, Function | MediumTest | Level1) {
433 // Do something
434 }
435 ```
436
4373. Create a configuration file \(**BUILD.gn**\) of the test module.
438
439 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.
440
441 Example:
442
443 ```
444 import("//test/xts/tools/lite/build/suite_lite.gni")
445 hcpptest_suite("DctsDemoTest") {
446 suite_name = "dcts"
447 sources = [
448 "src/TestDemo.cpp"
449 ]
450
451 include_dirs = [
452 "src",
453 ...
454 ]
455 deps = [
456 ...
457 ]
458 cflags = [ "-Wno-error" ]
459 }
460 ```
461
4624. Add build options to the **BUILD.gn** file in the **dcts** directory.
463
464 Add the test module to the **test/xts/dcts/build\_lite/BUILD.gn** script in the **dcts** directory.
465
466 ```
467 lite_component("dcts") {
468 ...
469 else if(board_name == "liteos_a") {
470 features += [
471 ...
472 "//xts/dcts/subsystem_lite/module_posix:DctsDemoTest"
473 ]
474 }
475 }
476 ```
477
4785. Run build commands.
479
480 Test suites are built along with the version build. The DCTS is built together with the debug version.
481
482 >![](figures/icon-note.gif) **NOTE:**
483 >The DCTS for the small system is independently built to an executable file \(.bin\) and archived in the **suites\\dcts** directory of the build result.
484
485
486### C++-based Test Case Execution \(for Standard and Small Systems\)<a name="section128222336544"></a>
487
488**Executing test cases for the small system**
489
490Currently, test cases are shared by the NFS and mounted to the development board for execution.
491
492**Setting up the environment**
493
4941. Use a network cable or wireless network to connect the development board to your PC.
4952. 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.
4963. Install and register the NFS server on the PC and start the NFS service.
4974. Run the **mount** command for the development board to ensure that the development board can access NFS shared files on the PC.
498
499 Format: **mount** _NFS server IP address_**:/**_NFS shared directory_ **/**_development board directory_ **nfs**
500
501 Example:
502
503 ```
504 mount 192.168.1.10:/nfs /nfs nfs
505 ```
506
507
508**Executing test cases**
509
510Execute **DctsDemoTest.bin** to trigger test case execution, and analyze serial port logs generated after the execution is complete.
511