1# XTS 2 3## Introduction 4 5The X test suite \(XTS\) subsystem contains a set of OpenHarmony compatibility 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. 6 7This subsystem contains the ACTS and **tools** software package. 8 9- 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 with OpenHarmony during the entire development process. 10- The **tools** software package stores the test case development framework related to **acts**. 11 12## System Types 13 14OpenHarmony supports the following system types: 15 16- Mini system 17 18 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. Typical boards include Multi-modalV200Z-R. 19 20- Small system 21 22 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. Typical boards include Hispark_Taurus. 23 24- Standard system 25 26 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. Typical boards include HopeRun DAYU200. 27 28 29## Directory Structure 30 31``` 32/test/xts 33├── acts # Test code 34│ └── subsystem # Source code of subsystem test cases for the standard system 35│ └── subsystem_lite # Source code of subsystems test cases for mini and small systems 36│ └── BUILD.gn # Build configuration of test cases for the standard system 37│ └── build_lite 38│ └── BUILD.gn # Build configuration of test cases for mini and small systems 39└── tools # Test tool code 40``` 41 42## Constraints 43 44Test cases for the mini system must be developed based on C, and those for the small system must be developed based on C++. 45 46## Usage Guidelines 47 48**Table 1** Test case levels 49 50| Level | Definition | Scope | 51| ----- | ---------- | ----- | 52| Level0 | Smoke | Verifies basic functionalities of key features and basic DFX attributes with the most common input. The pass result indicates that the features are runnable. | 53| Level1 | Basic | Verifies basic functionalities of key features and basic DFX attributes with common input. The pass result indicates that the features are testable. | 54| Level2 | Major | 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. | 55| Level3 | Regular | Verifies functionalities of all key features, and all DFX attributes with common and uncommon input combinations or normal and abnormal preset conditions. | 56| Level4 | Rare | Verifies functionalities of key features under extremely abnormal presets and uncommon input combinations. | 57 58**Table 2** Test case granularities 59 60| Test Scale | Test Objects | Test Environment | 61| ---------- | ------------ | ---------------- | 62| LargeTest | Service functionalities, all-scenario features, and mechanical power environment (MPE) and scenario-level DFX | Devices close to real devices. | 63| MediumTest | Modules, subsystem functionalities after module integration, and DFX | Single device that is actually used. You can perform message simulation, but do not mock functions. | 64| SmallTest | Modules, classes, and functions | Local PC. Use a large number of mocks to replace dependencies with other modules. | 65 66**Table 3** Test types 67 68| Type | Definition | 69| ---------- | ------------ | 70| Function | Tests the correctness of both service and platform functionalities provided by the tested object for end users or developers. | 71| Performance | 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. | 72| Power | Tests the power consumption of the tested object in a certain period of time under specific preset conditions and load models. 73| Reliability | 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. | 74| Security | - 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.<br>- Tests the privacy protection capability to ensure that the collection, use, retention, disclosure, and disposal of users' private data comply with laws and regulations.<br>- 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). | 75| Global | 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. | 76| Compatibility | - 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.<br>- Tests system backward compatibility with its own data and the compatibility of common applications in the ecosystem.<br>- Tests software compatibility with related hardware. | 77| User | 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. | 78| Standard | 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. | 79| Safety | Tests the safety property of the tested object to avoid possible hazards to personal safety, health, and the object itself. | 80| Resilience | 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. | 81 82 83## Test Case Development Guidelines 84 85You should select the appropriate programming language and your target test framework to develop test cases. 86 87**Table 4** Test frameworks and test case languages for different systems 88 89| System | Test Framework | Language | 90| ---------- | ------------ | ---------------- | 91| Mini | HCTest | C | 92| Small | HCPPTest | C++ | 93| Standard | HJSUnit and HCPPTest | JavaScript and C++ | 94 95### C-based Test Case Development and Compilation \(for the Mini System\) 96 97**Developing test cases for the mini system** 98 99The 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. 100 1011. Access the **test/xts/acts** repository where the test cases will be stored. 102 103 ``` 104 ├── acts 105 │ └──subsystem_lite 106 │ │ └── module_hal 107 │ │ │ └── BUILD.gn 108 │ │ │ └── src 109 │ └──build_lite 110 │ │ └── BUILD.gn 111 ``` 112 1132. Write the test case in the **src** directory. 114 115 1. Import the test framework header file. 116 117 ``` 118 #include "hctest.h" 119 ``` 120 121 122 123 2. Use the **LITE\_TEST\_SUIT** macro to define names of the subsystem, module, and test suite. 124 125 ``` 126 /** 127 * @brief Registers a test suite named IntTestSuite. 128 * @param test Subsystem name 129 * @param example Module name 130 * @param IntTestSuite Test suite name 131 */ 132 LITE_TEST_SUIT(test, example, IntTestSuite); 133 ``` 134 135 3. Define Setup and TearDown. 136 137 Format: Test suite name+Setup, Test suite name+TearDown. 138 139 The Setup and TearDown functions must exist, but function bodies can be empty. 140 141 4. Use the **LITE\_TEST\_CASE** macro to write the test case. 142 143 Three parameters are involved: test suite name, test case name, and test case properties \(including type, granularity, and level\). 144 145 ``` 146 LITE_TEST_CASE(IntTestSuite, TestCase001, Function | MediumTest | Level1) 147 { 148 // Do something 149 }; 150 ``` 151 152 153 154 5. Use the **RUN\_TEST\_SUITE** macro to register the test suite. 155 156 ``` 157 RUN_TEST_SUITE(IntTestSuite); 158 ``` 159 160 161 1623. Create the configuration file \(**BUILD.gn**\) of the test module. 163 164 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: 165 166 ``` 167 import("//test/xts/tools/lite/build/suite_lite.gni") 168 hctest_suite("ActsDemoTest") { 169 suite_name = "acts" 170 sources = [ 171 "src/test_demo.c", 172 ] 173 include_dirs = [ ] 174 cflags = [ "-Wno-error" ] 175 } 176 ``` 177 1784. Add build options to the **BUILD.gn** file in the **acts** directory. 179 180 You need to add the test module to the **test/xts/acts/build\_lite/BUILD.gn** script in the **acts** directory. 181 182 ``` 183 lite_component("acts") { 184 ... 185 if(board_name == "liteos_m") { 186 features += [ 187 ... 188 "//xts/acts/subsystem_lite/module_hal:ActsDemoTest" 189 ] 190 } 191 } 192 ``` 193 1945. Run build commands. 195 196 Test suites are built along with version build. The ACTS is built together with the debug version. 197 198 > **NOTE** 199 > 200 > The ACTS build middleware is a static library, which will be linked to the image. 201 202 203### C-based Test Case Execution \(for the Mini System\) 204 205**Executing test cases for the mini system** 206 207Burn the image into the development board. 208 209**Executing the test** 210 2111. Use a serial port tool to log in to the development board and save information about the serial port. 2122. Restart the device and view serial port logs. 213 214**Analyzing the test result** 215 216View the serial port logs, whose format is as follows: 217 218The log for each test suite starts with **Start to run test suite:** and ends with **xx Tests xx Failures xx Ignored**. 219 220### C++-based Test Case Development and Compilation \(for Standard and Small Systems\) 221 222**Developing test cases for small-system devices** \(For examples of the standard system, go to the **global/i18n\_standard directory**.\) 223 224The HCPPTest framework is enhanced and adapted based on the open-source framework Googletest. 225 2261. Access the **test/xts/acts** repository where the test cases will be stored. 227 228 ``` 229 ├── acts 230 │ └──subsystem_lite 231 │ │ └── module_posix 232 │ │ │ └── BUILD.gn 233 │ │ │ └── src 234 │ └──build_lite 235 │ │ └── BUILD.gn 236 ``` 237 2382. Write the test case in the **src** directory. 239 240 1. Import the test framework header file. 241 242 The following statement includes **gtest.h**. 243 244 ``` 245 #include "gtest/gtest.h" 246 ``` 247 248 249 250 2. Define Setup and TearDown. 251 252 ``` 253 using namespace std; 254 using namespace testing::ext; 255 class TestSuite: public testing::Test { 256 protected: 257 // Preset action of the test suite, which is executed before the first test case 258 static void SetUpTestCase(void){ 259 } 260 // Test suite cleanup action, which is executed after the last test case 261 static void TearDownTestCase(void){ 262 } 263 // Preset action of the test case 264 virtual void SetUp() 265 { 266 } 267 // Cleanup action of the test case 268 virtual void TearDown() 269 { 270 } 271 }; 272 ``` 273 274 275 276 3. Use the **HWTEST** or **HWTEST\_F** macro to write the test case. 277 278 **HWTEST**: definition of common test cases, including the test suite name, test case name, and case annotation. 279 280 **HWTEST\_F**: definition of SetUp and TearDown test cases, including the test suite name, test case name, and case annotation. 281 282 Three parameters are involved: test suite name, test case name, and test case properties \(including type, granularity, and level\). 283 284 ``` 285 HWTEST_F(TestSuite, TestCase_0001, Function | MediumTest | Level1) { 286 // Do something 287 } 288 ``` 289 290 291 2923. Create a configuration file \(**BUILD.gn**\) of the test module. 293 294 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. 295 296 Example: 297 298 ``` 299 import("//test/xts/tools/lite/build/suite_lite.gni") 300 hcpptest_suite("ActsDemoTest") { 301 suite_name = "acts" 302 sources = [ 303 "src/TestDemo.cpp" 304 ] 305 306 include_dirs = [ 307 "src", 308 ... 309 ] 310 deps = [ 311 ... 312 ] 313 cflags = [ "-Wno-error" ] 314 } 315 ``` 316 3174. Add build options to the **BUILD.gn** file in the **acts** directory. 318 319 Add the test module to the **test/xts/acts/build\_lite/BUILD.gn** script in the **acts** directory. 320 321 ``` 322 lite_component("acts") { 323 ... 324 else if(board_name == "liteos_a") { 325 features += [ 326 ... 327 "//xts/acts/subsystem_lite/module_posix:ActsDemoTest" 328 ] 329 } 330 } 331 ``` 332 3335. Run build commands. 334 335 Test suites are built along with the version build. The ACTS is built together with the debug version. 336 337 > **NOTE** 338 > 339 > 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. 340 341 342### C++-based Test Case Execution \(for Standard and Small Systems\) 343 344**Executing test cases for the small system** 345 346Currently, test cases are shared by the NFS and mounted to the development board for execution. 347 348**Setting up the environment** 349 3501. Use a network cable or wireless network to connect the development board to your PC. 3512. 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. 3523. Install and register the NFS server on the PC and start the NFS service. 3534. Run the **mount** command for the development board to ensure that the development board can access NFS shared files on the PC. 354 355 Format: **mount** _NFS server IP address_**:/**_NFS shared directory_ **/**_development board directory_ **nfs** 356 357 Example: 358 359 ``` 360 mount 192.168.1.10:/nfs /nfs nfs 361 ``` 362 363 364**Executing test cases** 365 366Execute **ActsDemoTest.bin** to trigger test case execution, and analyze serial port logs generated after the execution is complete. 367 368### JavaScript-based Test Case Development \(for the Standard System\) 369 370The HJSUnit framework is used to support automated test of OpenHarmony apps that are developed using the JavaScript language based on the JS application framework. 371 372**Basic syntax of test cases** 373 374The test cases are developed with the JavaScript language and must meet the programming specifications of the language. 375 376**Table 5** Basic syntax 377 378| Syntax | Description | Mandatory | 379| ------ | ----------- | --------- | 380| beforeAll | 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. | No | 381| afterAll | 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. | No | 382| beforeEach | 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 it. You can pass the action function as the only parameter. | No | 383| afterEach | 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 it. You can pass the clear function as the only parameter. | No | 384| describe | Defines a test suite. You can pass two parameters: test suite name and test suite function. The describe statement supports nesting. You can use beforeall, beforeEach, afterEach, and afterAll in each describe statement. | Yes | 385| it | Defines a test case. You can pass three parameters: test case name, filter parameter, and test case function.<br>**Usage of the filter parameter**:<br>The value of the filter parameter is a 32-bit integer. Setting different bits to 1 means different configurations:<br><ul><li>bit 0: whether the filter parameter takes effect. **1** 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>**Test case categories**: 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.<br>**Test case scales**: Bits 16-18 indicate SMALL (small-scale test), MEDIUM (medium-scale test), and LARGE (large-scale test), respectively.<br>**Test levels**: 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. | Yes | 386 387Use the standard syntax of Jasmine to write test cases. The ES6 specification is supported. 388 3891. Store the test cases in the **entry/src/main/js/test** directory, whose structure is as follows: 390 391 ``` 392 ├── BUILD.gn 393 │ └──entry 394 │ │ └──src 395 │ │ │ └──main 396 │ │ │ │ └──js 397 │ │ │ │ │ └──default 398 │ │ │ │ │ │ └──pages 399 │ │ │ │ │ │ │ └──index 400 │ │ │ │ │ │ │ │ └──index.js # Entry file 401 │ │ │ │ │ └──test # Test code 402 │ │ │ └── resources # HAP resources 403 │ │ │ └── config.json # HAP configuration file 404 ``` 405 4062. Start the JS test framework and load test cases. The following is an example for **index.js**. 407 408 ``` 409 // Start the JS test framework and load test cases. 410 import {Core, ExpectExtend} from 'deccjsunit/index' 411 412 export default { 413 data: { 414 title: "" 415 }, 416 onInit() { 417 this.title = this.$t('strings.world'); 418 }, 419 onShow() { 420 console.info('onShow finish') 421 const core = Core.getInstance() 422 const expectExtend = new ExpectExtend({ 423 'id': 'extend' 424 }) 425 core.addService('expect', expectExtend) 426 core.init() 427 const configService = core.getDefaultService('config') 428 configService.setConfig(this) 429 require('../../../test/List.test') 430 core.execute() 431 }, 432 onReady() { 433 }, 434 } 435 ``` 436 4373. Write a unit test case by referring to the following example: 438 439 ``` 440 // Use HJSUnit to perform the unit test. 441 describe('appInfoTest', function () { 442 it('app_info_test_001', 0, function () { 443 var info = app.getInfo() 444 expect(info.versionName).assertEqual('1.0') 445 expect(info.versionCode).assertEqual('3') 446 }) 447 }) 448 ``` 449 450 451### JavaScript-based Test Case Packaging \(for the Standard System\) 452 453For 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). 454 455 456## Repositories Involved 457 458[xts\_acts](https://gitee.com/openharmony/xts_acts) 459 460[xts\_tools](https://gitee.com/openharmony/xts_tools)