From b6e2b5d4b8a0a0672e73d6198bd7ce600bd0933a Mon Sep 17 00:00:00 2001 From: alex__hold Date: Thu, 28 Oct 2021 14:39:17 +0800 Subject: [PATCH] merge xts_tools and xts_tools_full Signed-off-by: alex__hold --- LICENSE | 0 README.md | 250 ++++++--- README_zh.md | 237 ++++++-- build/ohos.build | 49 ++ build/suite.gni | 454 +++++++++++++++ build/suite.py | 442 +++++++++------ build/test_package_select.py | 60 ++ build/utils.py | 268 +++------ BUILD.gn => lite/BUILD.gn | 0 lite/LICENSE | 177 ++++++ lite/OAT.xml | 62 ++ lite/README.md | 530 ++++++++++++++++++ lite/README_zh.md | 530 ++++++++++++++++++ build.sh => lite/build.sh | 0 {build => lite/build}/common.gni | 0 lite/build/suite.py | 273 +++++++++ {build => lite/build}/suite_lite.gni | 0 lite/build/utils.py | 388 +++++++++++++ {checksum => lite/checksum}/BUILD.gn | 0 .../checksum}/include/checksum_file.h | 0 .../checksum}/include/checksum_sha256.h | 0 .../checksum}/src/checksum_file.c | 0 .../checksum}/src/checksum_sha256.c | 0 {checksum => lite/checksum}/src/main.c | 0 lite/figures/icon-caution.gif | Bin 0 -> 580 bytes lite/figures/icon-danger.gif | Bin 0 -> 580 bytes lite/figures/icon-note.gif | Bin 0 -> 394 bytes lite/figures/icon-notice.gif | Bin 0 -> 406 bytes lite/figures/icon-tip.gif | Bin 0 -> 253 bytes lite/figures/icon-warning.gif | Bin 0 -> 580 bytes {hcpptest => lite/hcpptest}/BUILD.gn | 0 {hctest => lite/hctest}/BUILD.gn | 0 {hctest => lite/hctest}/include/hctest.h | 0 .../hctest}/include/hctest_internal.h | 0 .../hctest}/include/unity_config.h | 0 {hctest => lite/hctest}/src/hctest.c | 0 {hctest => lite/hctest}/src/hctest_service.c | 0 {others => lite/others}/query/BUILD.gn | 0 .../others}/query/src/QueryMain.cpp | 0 .../reliability}/JSPressTest.js | 0 .../reliability}/NativePressTest.py | 0 .../reliability}/RebootPressTest.py | 0 {reliability => lite/reliability}/readme.md | 0 {reliability => lite/reliability}/utils.py | 0 {repackage => lite/repackage}/auto_jffs2.sh | 0 runtest.sh => lite/runtest.sh | 0 46 files changed, 3240 insertions(+), 480 deletions(-) mode change 100755 => 100644 LICENSE create mode 100644 build/ohos.build create mode 100755 build/suite.gni mode change 100644 => 100755 build/suite.py create mode 100755 build/test_package_select.py rename BUILD.gn => lite/BUILD.gn (100%) create mode 100755 lite/LICENSE create mode 100644 lite/OAT.xml create mode 100755 lite/README.md create mode 100755 lite/README_zh.md rename build.sh => lite/build.sh (100%) rename {build => lite/build}/common.gni (100%) create mode 100644 lite/build/suite.py rename {build => lite/build}/suite_lite.gni (100%) create mode 100755 lite/build/utils.py rename {checksum => lite/checksum}/BUILD.gn (100%) rename {checksum => lite/checksum}/include/checksum_file.h (100%) rename {checksum => lite/checksum}/include/checksum_sha256.h (100%) rename {checksum => lite/checksum}/src/checksum_file.c (100%) rename {checksum => lite/checksum}/src/checksum_sha256.c (100%) rename {checksum => lite/checksum}/src/main.c (100%) create mode 100644 lite/figures/icon-caution.gif create mode 100644 lite/figures/icon-danger.gif create mode 100755 lite/figures/icon-note.gif create mode 100644 lite/figures/icon-notice.gif create mode 100644 lite/figures/icon-tip.gif create mode 100644 lite/figures/icon-warning.gif rename {hcpptest => lite/hcpptest}/BUILD.gn (100%) rename {hctest => lite/hctest}/BUILD.gn (100%) rename {hctest => lite/hctest}/include/hctest.h (100%) rename {hctest => lite/hctest}/include/hctest_internal.h (100%) rename {hctest => lite/hctest}/include/unity_config.h (100%) rename {hctest => lite/hctest}/src/hctest.c (100%) rename {hctest => lite/hctest}/src/hctest_service.c (100%) rename {others => lite/others}/query/BUILD.gn (100%) rename {others => lite/others}/query/src/QueryMain.cpp (100%) rename {reliability => lite/reliability}/JSPressTest.js (100%) rename {reliability => lite/reliability}/NativePressTest.py (100%) rename {reliability => lite/reliability}/RebootPressTest.py (100%) rename {reliability => lite/reliability}/readme.md (100%) rename {reliability => lite/reliability}/utils.py (100%) rename {repackage => lite/repackage}/auto_jffs2.sh (100%) rename runtest.sh => lite/runtest.sh (100%) diff --git a/LICENSE b/LICENSE old mode 100755 new mode 100644 diff --git a/README.md b/README.md index 5e6d11b..5777900 100755 --- a/README.md +++ b/README.md @@ -1,17 +1,18 @@ -# X Test Suite +# XTS - [Introduction](#section465982318513) -- [Devices](#section125090457443) +- [System Types](#section125090457443) - [Directory Structure](#section161941989596) - [Constraints](#section119744591305) - [Usage Guidelines](#section137768191623) - [Test Case Development Guidelines](#section3695134065513) - - [C-based Test Case Development and Compilation \(for Mini-System Devices\)](#section1551164914237) - - [C-based Test Case Execution \(for Mini-System Devices\)](#section10100701294) - - [C++-based Test Case Development and Compilation \(for Small-, Standard-, and Large-System Devices\)](#section5714177113113) - - [C++-based Test Case Execution \(for Small-, Standard-, and Large-System Devices\)](#section42281924184) + - [C-based Test Case Development and Compilation \(for the Mini System\)](#section198193336544) + - [C-based Test Case Execution \(for the Mini System\)](#section13820233175418) + - [C++-based Test Case Development and Compilation \(for Standard and Small Systems\)](#section3822123311540) + - [C++-based Test Case Execution \(for Standard and Small Systems\)](#section128222336544) + - [JavaScript-based Test Case Development \(for the Standard System\)](#section159801435165220) + - [JavaScript-based Test Case Packaging \(for the Standard System\)](#section445519106559) -- [Repositories Involved](#section1371113476307) ## Introduction @@ -22,44 +23,39 @@ This subsystem contains the ACTS and **tools** software package. - The **acts** directory stores the source code and configuration files of ACTS test cases. The ACTS helps device vendors detect the software incompatibility as early as possible and ensures that the software is compatible to OpenHarmony during the entire development process. - The **tools** software package stores the test case development framework related to **acts**. -## Devices +## System Types -OpenHarmony supports the following device types: +OpenHarmony supports the following system types: -- **Mini-System Devices \(reference memory ≥ 128 KB\)** +- Mini system - Such devices are equipped with MCU processors such as ARM Cortex-M and 32-bit RISC-V. They provide rich short-distance connection and peripheral bus access capabilities. Typical products include LinkIoT module devices and sensors in the smart home field. The LinkIoT module is usually used for smart Internet of Things \(IoT\) devices as the hardware module that implements connectivity functions. In the smart home field, the LinkIoT module is integrated into devices by vendors. For example, a LinkIoT module provides WLAN/Bluetooth access and data connection, and it usually communicates with the chip of smart home devices via a universal asynchronous receiver-transmitter \(UART\) or general-purpose input/output \(GPIO\) interface. + A mini system runs on the devices whose memory is greater than or equal to 128 KiB and that are equipped with MCU processors such as ARM Cortex-M and 32-bit RISC-V. This system provides multiple lightweight network protocols and graphics frameworks, and a wide range of read/write components for the IoT bus. Typical products include connection modules, sensors, and wearables for smart home. -- **Small-System Devices \(reference memory ≥ 1 MB\)** +- Small system - Such devices are equipped with application processors such as ARM Cortex-A. They provide higher security capabilities, standard graphics framework, and multimedia capabilities for video encoding and decoding. Typical products include IP cameras, electronic cat eyes, and routers in the smart home field, as well as event data recorders \(EDRs\) in the smart travel field. + A small system runs on the devices whose memory is greater than or equal to 1 MiB and that are equipped with application processors such as ARM Cortex-A. This system provides higher security capabilities, standard graphics frameworks, and video encoding and decoding capabilities. Typical products include smart home IP cameras, electronic cat eyes, and routers, and event data recorders \(EDRs\) for smart travel. +- Standard system -- **Standard-System Devices \(reference memory ≥ 128 MB\)** - - Such devices are equipped with application processors such as ARM Cortex-A. They provide a complete application framework supporting enhanced interaction, 3D GPU, hardware composer, diverse components, and rich animations. Typical products include high-end refrigerator displays. - -- **Large-System Devices \(reference memory ≥ 1 GB\)** - - Such devices are equipped with application processors such as ARM Cortex-A and provide a complete compatible application framework. Typical products include smart TVs and smart watches. + A standard system runs on the devices whose memory is greater than or equal to 128 MiB and that are equipped with application processors such as ARM Cortex-A. This system provides a complete application framework supporting the enhanced interaction, 3D GPU, hardware composer, diverse components, and rich animations. This system applies to high-end refrigerator displays. ## Directory Structure ``` /test/xts -├── acts # Test code -│ └── subsystem # Source code of subsystem test cases for large-system devices -│ └── subsystem_lite # Source code of subsystems test cases for mini- and small-system devices -│ └── BUILD.gn # Build configuration of test cases for large-system devices -│ └── build_lite # Build configuration of test cases for mini-and small-system devices -│ └── build_lite # Build configuration -└── tools # Test tool code +├── acts # Test code +│ └── subsystem # Source code of subsystem test cases for the standard system +│ └── subsystem_lite # Source code of subsystems test cases for mini and small systems +│ └── BUILD.gn # Build configuration of test cases for the standard system +│ └── build_lite +│ └── BUILD.gn # Build configuration of test cases for mini and small systems +└── tools # Test tool code ``` ## Constraints -Test cases for mini system devices must be developed based on C, and those for small system devices must be developed based on C++. +Test cases for the mini system must be developed based on C, and those for the small system must be developed based on C++. ## Usage Guidelines @@ -216,12 +212,12 @@ Test cases for mini system devices must be developed based on C, and those for s ## Test Case Development Guidelines -You should select the appropriate programming language and your target test framework to develop test cases for the devices to test. +You should select the appropriate programming language and your target test framework to develop test cases. -**Table 4** Test frameworks and test case languages for different devices +**Table 4** Test frameworks and test case languages for different systems -

Device Type

+ @@ -229,40 +225,33 @@ You should select the appropriate programming language and your target test fram - - - - - - - - -

System

Test Framework

Mini-system devices

+

Mini

HCTest

C

Small-system devices

+

Small

HCPPTest

C++

Standard-system devices

+

Standard

HJUnit and HCPPTest

+

HJSUnit and HCPPTest

Java and C++

-

Large-system devices

-

HJUnit and HCPPTest

-

Java and C++

+

JavaScript and C++

-### C-based Test Case Development and Compilation \(for Mini-System Devices\) +### C-based Test Case Development and Compilation \(for the Mini System\) -**Developing test cases for mini-system devices** +**Developing test cases for the mini system** The HCTest framework is used to support test cases developed with the C language. HCTest is enhanced and adapted based on the open-source test framework Unity. @@ -323,7 +312,7 @@ The HCTest framework is used to support test cases developed with the C language 3. Create the configuration file \(**BUILD.gn**\) of the test module. - Create a **BUILD.gn** \(example\) compilation file in each test module directory. Specify the name of the compiled static library and its dependent header file and library in the compilation file. The format is as follows: + Create a **BUILD.gn** \(example\) build file in each test module directory. Specify the name of the built static library and its dependent header file and library in the build file. The format is as follows: ``` import("//test/xts/tools/lite/build/suite_lite.gni") @@ -337,7 +326,7 @@ The HCTest framework is used to support test cases developed with the C language } ``` -4. Add compilation options to the **BUILD.gn** file in the **acts** directory. +4. Add build options to the **BUILD.gn** file in the **acts** directory. You need to add the test module to the **test/xts/acts/build\_lite/BUILD.gn** script in the **acts** directory. @@ -353,17 +342,17 @@ The HCTest framework is used to support test cases developed with the C language } ``` -5. Run compilation commands. +5. Run build commands. - Test suites are compiled along with version compilation. The ACTS is compiled together with the debug version. + Test suites are built along with version build. The ACTS is built together with the debug version. >![](figures/icon-note.gif) **NOTE:** - >The ACTS compiles middleware as a static library, which will be linked to the image. + >The ACTS build middleware is a static library, which will be linked to the image. -### C-based Test Case Execution \(for Mini-System Devices\) +### C-based Test Case Execution \(for the Mini System\) -**Executing test cases for mini-system devices** +**Executing test cases for the mini system** Burn the image into the development board. @@ -378,9 +367,9 @@ View the serial port logs, whose format is as follows: The log for each test suite starts with **Start to run test suite:** and ends with **xx Tests xx Failures xx Ignored**. -### C++-based Test Case Development and Compilation \(for Small-, Standard-, and Large-System Devices\) +### C++-based Test Case Development and Compilation \(for Standard and Small Systems\) -**Developing test cases for small-system devices** +**Developing test cases for small-system devices** \(For examples of the standard system, go to the **global/i18n\_standard directory**.\) The HCPPTest framework is enhanced and adapted based on the open-source framework Googletest. @@ -446,7 +435,7 @@ The HCPPTest framework is enhanced and adapted based on the open-source framewor 3. Create a configuration file \(**BUILD.gn**\) of the test module. - Create a **BUILD.gn** compilation file in each test module directory. Specify the name of the compiled static library and its dependent header file and library in the compilation file. Each test module is independently compiled into a **.bin** executable file, which can be directly mounted to the development board for testing. + Create a **BUILD.gn** build file in each test module directory. Specify the name of the built static library and its dependent header file and library in the build file. Each test module is independently built into a **.bin** executable file, which can be directly pushed to the development board for testing. Example: @@ -467,10 +456,9 @@ The HCPPTest framework is enhanced and adapted based on the open-source framewor ] cflags = [ "-Wno-error" ] } - ``` -4. Add compilation options to the **BUILD.gn** file in the **acts** directory. +4. Add build options to the **BUILD.gn** file in the **acts** directory. Add the test module to the **test/xts/acts/build\_lite/BUILD.gn** script in the **acts** directory. @@ -486,17 +474,17 @@ The HCPPTest framework is enhanced and adapted based on the open-source framewor } ``` -5. Run compilation commands. +5. Run build commands. - Test suites are compiled along with the version compilation. The ACTS is compiled together with the debug version. + Test suites are built along with the version build. The ACTS is built together with the debug version. >![](figures/icon-note.gif) **NOTE:** - >The ACTS for a small system device is independently compiled to an executable file \(.bin\) and archived in the **suites\\acts** directory of the compilation result. + >The ACTS for the small system is independently built to an executable file \(.bin\) and archived in the **suites\\acts** directory of the build result. -### C++-based Test Case Execution \(for Small-, Standard-, and Large-System Devices\) +### C++-based Test Case Execution \(for Standard and Small Systems\) -**Executing test cases for small-system devices** +**Executing test cases for the small system** Currently, test cases are shared by the NFS and mounted to the development board for execution. @@ -520,11 +508,141 @@ Currently, test cases are shared by the NFS and mounted to the development board Execute **ActsDemoTest.bin** to trigger test case execution, and analyze serial port logs generated after the execution is complete. -## Repositories Involved +### JavaScript-based Test Case Development \(for the Standard System\) -[X Test Suite](https://gitee.com/openharmony/docs/blob/master/en/readme/x-test-suite.md) +The HJSUnit framework is used to support automated test of OpenHarmony apps that are developed using the JavaScript language based on the JS application framework. -[xts\_acts](https://gitee.com/openharmony/xts_acts/blob/master/README.md) +**Basic syntax of test cases** -**xts\_tools** +The test cases are developed with the JavaScript language and must meet the programming specifications of the language. + +**Table 5** + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Syntax

+

Description

+

Mandatory

+

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

+

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

+

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

+

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

+

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

+

it

+

Defines a test case. You can pass three parameters: test case name, filter parameter, and test case function.

+

Usage of the filter parameter:

+

The value of the filter parameter is a 32-bit integer. Setting different bits to 1 means different configurations:

+
  • 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.
  • Bits 0-10: test case categories
  • Bits 16-18: test case scales
  • Bits 24-28: test levels
+

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.

+

Test case scales: Bits 16-18 indicate SMALL (small-scale test), MEDIUM (medium-scale test), and LARGE (large-scale test), respectively.

+

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

+
+ +Use the standard syntax of Jasmine to write test cases. The ES6 specification is supported. + +1. Store the test cases in the **entry/src/main/js/test** directory, whose structure is as follows: + + ``` + ├── BUILD.gn + │ └──entry + │ │ └──src + │ │ │ └──main + │ │ │ │ └──js + │ │ │ │ │ └──default + │ │ │ │ │ │ └──pages + │ │ │ │ │ │ │ └──index + │ │ │ │ │ │ │ │ └──index.js # Entry file + │ │ │ │ │ └──test # Test code + │ │ │ └── resources # HAP resources + │ │ │ └── config.json # HAP configuration file + ``` + +2. Start the JS test framework and load test cases. The following is an example for **index.js**. + + ``` + // Start the JS test framework and load test cases. + import {Core, ExpectExtend} from 'deccjsunit/index' + + export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + core.addService('expect', expectExtend) + core.init() + const configService = core.getDefaultService('config') + configService.setConfig(this) + require('../../../test/List.test') + core.execute() + }, + onReady() { + }, + } + ``` + +3. Write a unit test case by referring to the following example: + + ``` + // Use HJSUnit to perform the unit test. + describe('appInfoTest', function () { + it('app_info_test_001', 0, function () { + var info = app.getInfo() + expect(info.versionName).assertEqual('1.0') + expect(info.versionCode).assertEqual('3') + }) + }) + ``` + + +### JavaScript-based Test Case Packaging \(for the Standard System\) + +For details about how to build a HAP, see the JS application development guide of the standard system [Building and Creating HAPs](https://developer.harmonyos.com/en/docs/documentation/doc-guides/build_overview-0000001055075201). diff --git a/README_zh.md b/README_zh.md index 16f93bb..82392f1 100755 --- a/README_zh.md +++ b/README_zh.md @@ -1,15 +1,17 @@ -# XTS认证子系统开发指南 +# XTS子系统 - [简介](#section465982318513) -- [设备类型](#section125090457443) +- [系统类型](#section125090457443) - [目录](#section161941989596) - [约束](#section119744591305) - [使用说明](#section137768191623) - [用例开发指导](#section3695134065513) - - [C语言用例开发编译指导(适用于轻量系统类设备产品用例开发)](#section1551164914237) - - [C语言用例执行指导(适用于轻量系统类设备产品用例开发)](#section10100701294) - - [C++语言用例开发编译指导(适用于小型系统类设备、标准系统类设备、大型系统类设备用例开发)](#section5714177113113) - - [C++语言用例执行指导(适用于小型系统类设备、标准系统类设备、大型系统类设备用例开发)](#section42281924184) + - [C语言用例开发编译指导(适用于轻量系统产品用例开发)](#section198193336544) + - [C语言用例执行指导(适用于轻量系统产品用例开发)](#section13820233175418) + - [C++语言用例开发编译指导(适用于小型系统、标准系统用例开发)](#section3822123311540) + - [C++语言用例执行指导(适用于小型系统、标准系统用例开发)](#section128222336544) + - [JS语言用例开发指导(适用于标准系统)](#section159801435165220) + - [JS语言用例编译打包指导(适用于标准系统)](#section445519106559) - [相关仓](#section1371113476307) @@ -22,44 +24,39 @@ XTS子系统当前包括acts与tools软件包: - acts,存放acts相关测试用例源码与配置文件,其目的是帮助终端设备厂商尽早发现软件与OpenHarmony的不兼容性,确保软件在整个开发过程中满足OpenHarmony的兼容性要求。 - tools,存放acts相关测试用例开发框架。 -## 设备类型 +## 系统类型 -OpenHarmony支持如下几种设备类型: +OpenHarmony支持如下几种系统类型: -- **轻量系统类设备(参考内存≥128KB)** +- 轻量系统(mini system) - 面向MCU类处理器,例如Arm Cortex-M、RISC-V 32位的设备,资源极其有限,参考内存≥128KB,提供丰富的近距连接能力以及丰富的外设总线访问能力。典型产品有智能家居领域的联接类模组、传感器设备等。联接类模组通常应用在智能物联网设备中,负责实现联接部分的硬件模块,在智能家居领域由厂家集成到其设备中。例如:联接类模组提供WLAN/Bluetooth的接入和数据的联接,模组与厂家家居的芯片通常通过UART或GPIO等总线接口进行通信。 + 面向MCU类处理器例如Arm Cortex-M、RISC-V 32位的设备,硬件资源极其有限,支持的设备最小内存为128KiB,可以提供多种轻量级网络协议,轻量级的图形框架,以及丰富的IOT总线读写部件等。可支撑的产品如智能家居领域的连接类模组、传感器设备、穿戴类设备等。 -- **小型系统类设备(参考内存≥1MB)** +- 小型系统(small system) - 面向应用处理器,例如Arm Cortex-A的设备,参考内存≥1MB,提供更高的安全能力,提供标准的图形框架,提供视频编解码的多媒体能力。典型产品有智能家居领域的IPCamera、电子猫眼、路由器以及智慧出行域的行车记录仪等。 + 面向应用处理器例如Arm Cortex-A的设备,支持的设备最小内存为1MiB,可以提供更高的安全能力、标准的图形框架、视频编解码的多媒体能力。可支撑的产品如智能家居领域的IP Camera、电子猫眼、路由器以及智慧出行域的行车记录仪等。 +- 标准系统(standard system) -- **标准系统类设备(参考内存≥128MB)** - - 面向应用处理器,例如Arm Cortex-A的设备,参考内存≥128MB,提供增强的交互能力,提供3D GPU以及硬件合成能力,提供更多控件以及动效更丰富的图形能力,提供完整的应用框架。典型产品有高端的冰箱显示屏等。 - -- **大型系统类设备(参考内存≥1GB)** - - 面向应用处理器,例如Arm Cortex-A的设备,参考内存≥1GB,提供完整的兼容应用框架。典型的产品有智慧屏、智能手表等。 + 面向应用处理器例如Arm Cortex-A的设备,支持的设备最小内存为128MiB,可以提供增强的交互能力、3D GPU以及硬件合成能力、更多控件以及动效更丰富的图形能力、完整的应用框架。可支撑的产品如高端的冰箱显示屏。 ## 目录 ``` /test/xts -├── acts # 测试代码存放目录 -│ └── subsystem # 大型系统类设备子系统测试用例源码存放目录 -│ └── subsystem_lite # 轻量系统类设备、小型系统类设备子系统测试用例源码存放目录 -│ └── BUILD.gn # 大型系统类设备测试用例编译配置 -│ └── build_lite # 轻量系统类设备、小型系统类设备测试用例编译配置存放目录 -│ └── BUILD.gn # 轻量系统类设备、小型系统类设备测试用例编译配置 -└── tools # 测试工具代码存放目录 +├── acts # 测试代码存放目录 +│ └── subsystem # 标准系统子系统测试用例源码存放目录 +│ └── subsystem_lite # 轻量系统、小型系统子系统测试用例源码存放目录 +│ └── BUILD.gn # 标准系统测试用例编译配置 +│ └── build_lite # 轻量系统、小型系统测试用例编译配置存放目录 +│ └── BUILD.gn # 轻量系统、小型系统测试用例编译配置 +└── tools # 测试工具代码存放目录 ``` ## 约束 -轻量系统类设备用例开发语言是C,小型系统类设备用例开发语言是C++。 +轻量系统用例开发语言是C,小型系统用例开发语言是C++。 ## 使用说明 @@ -216,12 +213,12 @@ OpenHarmony支持如下几种设备类型: ## 用例开发指导 -根据测试设备选择测试框架和对应测试用例语言。 +根据测试系统选择测试框架和对应测试用例语言。 -**表 4** 设备和测试框架、开发语言对应关系 +**表 4** 系统和测试框架、开发语言对应关系 -

设备

+ @@ -229,40 +226,33 @@ OpenHarmony支持如下几种设备类型: - - - - - - - - -

系统

测试框架

轻量系统类设备

+

轻量系统

hctest

c

小型系统类设备

+

小型系统

hcpptest

c++

标准系统类设备

+

标准系统

HJUnit、hcpptest

+

HJSUnit、hcpptest

java、c++

-

大型系统类设备

-

HJUnit、hcpptest

-

java、c++

+

js、c++

-### C语言用例开发编译指导(适用于轻量系统类设备产品用例开发) +### C语言用例开发编译指导(适用于轻量系统产品用例开发) -**示例:轻量系统类设备测试用例开发** +**示例:轻量系统测试用例开发** 当前使用的测试框架是hctest,hctest测试框架支持使用C语言编写测试用例,是在开源测试框架unity的基础上进行增强和适配。 @@ -361,9 +351,9 @@ OpenHarmony支持如下几种设备类型: >acts测试套件编译中间件为静态库,最终链接到版本镜像中 。 -### C语言用例执行指导(适用于轻量系统类设备产品用例开发) +### C语言用例执行指导(适用于轻量系统产品用例开发) -**示例:轻量系统类设备测试用例执行** +**示例:轻量系统测试用例执行** 将版本镜像烧录进开发板。 @@ -378,9 +368,9 @@ OpenHarmony支持如下几种设备类型: 每个测试套件执行以Start to run test suite开始,以xx Tests xx Failures xx Ignored结束。 -### C++语言用例开发编译指导(适用于小型系统类设备、标准系统类设备、大型系统类设备用例开发) +### C++语言用例开发编译指导(适用于小型系统、标准系统用例开发) -**示例:小型系统类设备测试用例开发** +**示例:小型系统测试用例开发**(标准系统参考具体样例目录:global/i18n\_standard) 当前使用的测试框架是hcpptest,hcpptest测试框架是在开源的googletest测试框架的基础上进行的增强和适配。 @@ -446,7 +436,7 @@ OpenHarmony支持如下几种设备类型: 3. 测试模块下用例配置文件(BUILD.gn)样例: - 每个测试模块目录下新建BUILD.gn编译文件,用于指定编译后可执行文件的名称、依赖的头文件、依赖的库等;具体写法如下。每个测试模块将独立编译成.bin可执行文件, 该文件可直接mount到单板上进行测试。 + 每个测试模块目录下新建BUILD.gn编译文件,用于指定编译后可执行文件的名称、依赖的头文件、依赖的库等;具体写法如下。每个测试模块将独立编译成.bin可执行文件, 该文件可直接push到单板上进行测试。 举例: @@ -491,12 +481,12 @@ OpenHarmony支持如下几种设备类型: 随版本编译,debug版本编译时会同步编译acts测试套件 >![](figures/icon-note.gif) **说明:** - >小型系统类设备acts独立编译成可执行文件(bin格式), 在编译产物的suites\\acts目录下归档。 + >小型系统acts独立编译成可执行文件(bin格式), 在编译产物的suites\\acts目录下归档。 -### C++语言用例执行指导(适用于小型系统类设备、标准系统类设备、大型系统类设备用例开发) +### C++语言用例执行指导(适用于小型系统、标准系统用例开发) -**示例:小型系统类设备测试用例执行** +**示例:小型系统测试用例执行** 目前的用例执行采用nfs共享的方式,mount到单板去执行。 @@ -520,11 +510,146 @@ OpenHarmony支持如下几种设备类型: 测试套件执行 ActsDemoTest.bin 触发用例执行,基于串口打印日志进行分析。 +### JS语言用例开发指导(适用于标准系统) + +当前使用的测试框架是HJSUnit,用于支撑OpenHarmony application测试(特指基于JS应用框架使用 Javascript 语言开发的 APP)进行自动化测试。 + +**用例编写基础语法** + +测试用例为 js 语言,必须满足 JavaScript 语言编程规范: + +**表 5** + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

用例语法

+

描述

+

要求

+

beforeAll

+

测试套级别的预置条件,在所有测试用例开始前执行且仅执行一次,支持一个参数:预置动作函数

+

可选

+

afterAll

+

测试套级别的清理条件,在所有测试用例结束后执行且仅执行一次,支持一个参数:清理动作函数

+

可选

+

beforeEach

+

测试用例级别的预置条件,在每条测试用例开始前执行,执行次数与 it 定义的测试用例数一致,支持一个参数:预置动作函数

+

可选

+

afterEach

+

测试用例级别的清理条件,在每条测试用例结束后执行,执行次数与 it 定义的测试用例数一致,支持一个参数:清理动作函数

+

可选

+

describe

+

定义一个测试套,支持两个参数:测试套名称和测试套函数; describe 支持嵌套,每个 describe 内均可以定义 beforeAll 、beforeEach 、afterEach 和 afterAll

+

必选

+

it

+

定义一条测试用例,支持三个参数:用例名称,过滤参数和用例函数

+

备注:

+

过滤参数:过滤参数为一个 32 位的 Int 类型参数,0 位 置1表示不筛选、默认执行;0-10 位 置1表示测试用例类型;16-18 位 置1表示测试用例规模;24-28 位 置1表示测试层级

+

测试用例类型。置位0-10分别表示:FUNCTION 方法类测试、PERFORMANCE 性能类测试、POWER 功耗类测试、RELIABILITY 可靠性测试、SECURITY 安全合规测试、GLOBAL 整体性测试、COMPATIBILITY 兼容性测试、USER 用户测试、STANDARD 标准测试、SAFETY 安全特性测试,RESILIENCE 压力测试。

+

测试用例规模。置位16-18分别表示:SMALL 小型测试、MEDIUM 中型测试、LARGE 大型测试。

+

测试层级。置位24-28分别表示:LEVEL0-0 级测试、LEVEL1-1 级测试、LEVEL2-2 级测试、LEVEL3-3 级测试、LEVEL4-4 级测试。

+

必选

+
+ +用例编写语法采用 jasmine 的标准语法,格式支持ES6格式。 + +1. 规范用例目录:测试用例存储到entry/src/main/js/test目录。 + + ``` + ├── BUILD.gn + │ └──entry + │ │ └──src + │ │ │ └──main + │ │ │ │ └──js + │ │ │ │ │ └──default + │ │ │ │ │ │ └──pages + │ │ │ │ │ │ │ └──index + │ │ │ │ │ │ │ │ └──index.js # 入口文件 + │ │ │ │ │ └──test # 测试代码存放目录 + │ │ │ └── resources # hap资源存放目录 + │ │ │ └── config.json # hap配置文件 + ``` + +2. index.js示例 + + ``` + // 拉起js测试框架,加载测试用例 + import {Core, ExpectExtend} from 'deccjsunit/index' + + export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + core.addService('expect', expectExtend) + core.init() + const configService = core.getDefaultService('config') + configService.setConfig(this) + require('../../../test/List.test') + core.execute() + }, + onReady() { + }, + } + ``` + +3. 单元测试用例示例 + + ``` + // Example1: 使用HJSUnit进行单元测试 + describe('appInfoTest', function () { + it('app_info_test_001', 0, function () { + var info = app.getInfo() + expect(info.versionName).assertEqual('1.0') + expect(info.versionCode).assertEqual('3') + }) + }) + ``` + + +### JS语言用例编译打包指导(适用于标准系统) + +hap包编译请参考[标准系统js应用开发指导](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/build_overview-0000001055075201)。 + ## 相关仓 -[XTS认证子系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/XTS%E8%AE%A4%E8%AF%81%E5%AD%90%E7%B3%BB%E7%BB%9F.md) +xts\_acts -[xts\_acts](https://gitee.com/openharmony/xts_acts/blob/master/README_zh.md) - -**xts\_tools** +xts\_tools diff --git a/build/ohos.build b/build/ohos.build new file mode 100644 index 0000000..f80901b --- /dev/null +++ b/build/ohos.build @@ -0,0 +1,49 @@ +{ + "subsystem": "xts", +"parts":{ + "phone_tests": { + "variants": [ + "phone" + ], + "module_list": [], + "inner_kits": [], + "system_kits": [], + "test_list": [ + "//test/xts/acts:acts" + ] + }, + "ivi_tests": { + "variants": [ + "ivi" + ], + "module_list": [], + "inner_kits": [], + "system_kits": [], + "test_list": [ + "//test/xts/acts:acts_ivi" + ] + }, + "intellitv_tests": { + "variants": [ + "intellitv" + ], + "module_list": [], + "inner_kits": [], + "system_kits": [], + "test_list": [ + "//test/xts/acts:acts_intellitv" + ] + }, + "wearable_tests": { + "variants": [ + "wearable" + ], + "module_list": [], + "inner_kits": [], + "system_kits": [], + "test_list": [ + "//test/xts/acts:acts_wearable" + ] + } + } +} diff --git a/build/suite.gni b/build/suite.gni new file mode 100755 index 0000000..0a565d7 --- /dev/null +++ b/build/suite.gni @@ -0,0 +1,454 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/test.gni") + +declare_args() { + SUITES_OUTPUT_ROOT = "$root_out_dir/suites" + SUITE_ARCHIVE_DIR = "$root_out_dir/suites/archives" + TESTCONFIG_FILENAME = "Test.xml" + XTS_ROOT = "//test/xts" + ACTS_ROOT = "//test/xts/acts" + + # create testsuite archive is time-consuming, do it only if necessary + make_archive = false + XTS_SUITENAME = getenv("XTS_SUITENAME") +} + +template("ohos_testsuite_base") { + assert(defined(invoker.project_type), + "project_type is required in target ${target_name}") + + _project_type = invoker.project_type + _subsystem_name = "" + if (defined(invoker.subsystem_name)) { + _subsystem_name = invoker.subsystem_name + } + + _test_files = "" + if (defined(invoker.generated_testfiles)) { + foreach(file, invoker.generated_testfiles) { + _test_files = + _test_files + "," + rebase_path("$root_gen_dir") + "/" + file + } + } + + _is_testbundle = defined(invoker.is_testbundle) && invoker.is_testbundle + + if (defined(invoker.sub_output_dir)) { + _output_file_dir = + rebase_path("$root_out_dir/tests/moduletest/${invoker.sub_output_dir}") + } else if (defined(invoker.module_out_path)) { + _output_file_dir = + rebase_path("$root_out_dir/tests/moduletest/${invoker.module_out_path}") + } else { + _output_file_dir = rebase_path("$root_out_dir/tests/moduletest") + } + _output_file = "${_output_file_dir}/module_${target_name}" + + if (_project_type == "gtest" || _project_type == "ctestbundle") { + _output_file = "${_output_file_dir}/${target_name}" + _archive_filename = "${target_name}" + + target("ohos_moduletest", "module_${target_name}") { + forward_variables_from(invoker, "*") + testonly = true + } + } else if (_project_type == "zunit" || _project_type == "javatestbundle") { + _output_file = "${_output_file_dir}/module_${target_name}.dex" + _archive_filename = "${target_name}.dex" + + target("ohos_java_moduletest", "module_${target_name}") { + forward_variables_from(invoker, "*") + testonly = true + } + } else if (_project_type == "hostjunit") { + _output_file = "${_output_file_dir}/module_${target_name}.jar" + if (defined(invoker.final_jar_path)) { + _output_file = invoker.final_jar_path + } + _archive_filename = "${target_name}.jar" + + target("java_library", "module_${target_name}") { + forward_variables_from(invoker, "*") + is_host_library = true + } + } else if (_project_type == "testhap" || _project_type == "haptestbundle") { + assert(defined(invoker.hap_name), + "hap_name is required in target ${target_name}") + assert(!defined(invoker.final_hap_path), + "please use hap_name instead of final_hap_path") + + _hap_name = invoker.hap_name + _final_hap_path = "${SUITES_OUTPUT_ROOT}/haps/${_hap_name}.hap" + _output_file = _final_hap_path + _archive_filename = "${_hap_name}.hap" + + target("ohos_hap", "module_${target_name}") { + forward_variables_from(invoker, "*") + subsystem_name = XTS_SUITENAME + final_hap_path = _final_hap_path + testonly = true + } + } else if (_project_type == "pythontest") { + if (defined(invoker.outputs_dir)) { + _out_put_dir = invoker.outputs_dir + _archive_filename = "${_subsystem_name}/${_out_put_dir}" + } else { + _archive_filename = "${_subsystem_name}" + } + _test_files = invoker.output_file + _deps = [] + if (defined(invoker.deps)) { + _deps = invoker.deps + } + } + + _apilibrary_deps = "" + if (_is_testbundle && defined(invoker.deps)) { + foreach(dep, invoker.deps) { + _apilibrary_deps = _apilibrary_deps + "," + dep + } + } + + if (_project_type != "pythontest") { + _deps = [ ":module_${target_name}" ] + } else { + _deps = [] + } + _suite_out_dir = "${SUITES_OUTPUT_ROOT}/${XTS_SUITENAME}" + _archive_testfile = "${_suite_out_dir}/testcases/${_archive_filename}" + _arguments = [ + "build_module_with_testbundle", + "--build_gen_dir", + rebase_path("$root_gen_dir"), + "--build_target_name", + target_name, + "--buildgen_testfile", + rebase_path(_output_file), + "--project_path", + rebase_path("."), + "--test_xml", + rebase_path(TESTCONFIG_FILENAME), + "--project_type", + _project_type, + "--suite_out_dir", + rebase_path("${_suite_out_dir}"), + "--archive_testfile", + rebase_path("${_archive_testfile}"), + ] + + if (_subsystem_name != "") { + _arguments += [ + "--subsystem_name", + _subsystem_name, + ] + } + + if (_apilibrary_deps != "") { + _arguments += [ + "--apilibrary_deps", + _apilibrary_deps, + ] + } + + if (_test_files != "") { + _arguments += [ + "--test_files", + _test_files, + ] + } + + action(target_name) { + deps = _deps + script = rebase_path("//test/xts/tools/build/suite.py") + args = _arguments + outputs = [ _archive_testfile ] + testonly = true + } +} + +template("ohos_moduletest_suite") { + target("ohos_testsuite_base", "${target_name}") { + forward_variables_from(invoker, "*") + if (!defined(module_out_path)) { + module_out_path = "xts/modules" + } + project_type = "gtest" + } +} + +template("ohos_hap_suite") { + target("ohos_testsuite_base", "${target_name}") { + forward_variables_from(invoker, "*") + + # auto add HJUnitRunner entry ability and test-framework + if (defined(hap_profile)) { + # NOTE:: the GN tool disallow source files located in the ${out_dir} + # so we put the generated files in the xts dir. remember to REMOVE these. + _profile_relative_path = rebase_path(hap_profile, rebase_path(XTS_ROOT)) + _fixed_profile_path = + "${XTS_ROOT}/autogen_apiobjs/${_profile_relative_path}" + _fixer_script = rebase_path( + "//test/xts/tools/build/adapter/haptest_manifest_fixer.py") + exec_script(_fixer_script, + [ + "add_entryability", + "--raw_file=" + rebase_path(hap_profile), + "--dest_file=" + rebase_path(_fixed_profile_path), + ]) + hap_profile = _fixed_profile_path + } + + if (defined(deps)) { + deps += [ "//test/xts/tools/hjunit:testkit_harmonyjunitrunner_java" ] + } else { + deps = [ "//test/xts/tools/hjunit:testkit_harmonyjunitrunner_java" ] + } + + project_type = "testhap" + } +} + +template("ohos_js_hap_suite") { + target("ohos_testsuite_base", "${target_name}") { + forward_variables_from(invoker, "*") + project_type = "testhap" + js_build_mode = "debug" + } +} + +template("ohos_shell_app_suite") { + target("ohos_adapter_shell_app_suite", "${target_name}") { + forward_variables_from(invoker, "*") + } +} + +template("ohos_prebuilt_suite") { + assert(!defined(invoker.source_files) || !defined(invoker.jar_path) || + !defined(invoker.source_dir), + "source_files, jar_path or source_dir must be specified one.") + assert(!defined(invoker.final_jar_path), + "final_jar_path is not allowed in target ${target_name}") + + if (defined(invoker.jar_path)) { + _output_name = "${target_name}.jar" + if (defined(invoker.output_name)) { + _output_name = "${invoker.output_name}.jar" + } + + _output_type = "tools" + if (defined(invoker.output_type)) { + _output_type = invoker.output_type + } + + _final_jar_path = + "${SUITES_OUTPUT_ROOT}/${XTS_SUITENAME}/${_output_type}/${_output_name}" + + target("java_prebuilt", "${target_name}") { + forward_variables_from(invoker, "*") + final_jar_path = _final_jar_path + is_host_library = true + } + } else { + assert(defined(invoker.output_dir), + "output_dir is require in target ${target_name}") + _outputs = [] + _copy_args = [ + "--method_name", + "copy_file", + ] + _deps = [] + _output_dir = "${SUITES_OUTPUT_ROOT}/${XTS_SUITENAME}/${invoker.output_dir}" + if (defined(invoker.source_dir)) { + _copy_args += [ + "--arguments", + "output=" + rebase_path(_output_dir) + "#source_dirs=" + + rebase_path(invoker.source_dir) + "#to_dir=True", + ] + _outputs = [ _output_dir ] + } else if (defined(invoker.source_files)) { + _sources = "" + foreach(src, invoker.source_files) { + _sources = _sources + rebase_path(src) + "," + } + _copy_args += [ + "--arguments", + "output=" + rebase_path(_output_dir) + "#sources=" + _sources + + "#to_dir=True", + ] + _outputs = [ _output_dir ] + } + if (defined(invoker.deps)) { + _deps = invoker.deps + } + action(target_name) { + script = rebase_path("//test/xts/tools/build/utils.py") + deps = _deps + args = _copy_args + outputs = _outputs + } + } +} + +template("ohos_deploy_xdevice") { + _suite_out_dir = "${SUITES_OUTPUT_ROOT}/${XTS_SUITENAME}" + + _args = [ + "build_xdevice", + "--source_dir", + rebase_path("//test/xdevice"), + "--suite_out_dir", + rebase_path(_suite_out_dir), + ] + + if (defined(invoker.configs_dir)) { + _args += [ + "--configs_dir", + rebase_path(rebase_path(invoker.configs_dir)), + ] + } + + if (defined(invoker.resources_dir)) { + _args += [ + "--resources_dir", + rebase_path(rebase_path(invoker.resources_dir)), + ] + } + + action(target_name) { + testonly = true + script = rebase_path("//test/xts/tools/build/suite.py") + args = _args + outputs = [ + "${_suite_out_dir}/tools/xdevice-extension-0.0.0.tar.gz", + "${_suite_out_dir}/tools/xdevice-0.0.0.tar.gz", + "${_suite_out_dir}/tools/run.sh", + "${_suite_out_dir}/tools/run.bat", + ] + } +} + +template("ohos_test_suite") { + _output = "${SUITES_OUTPUT_ROOT}/${target_name}.zip" + _suite_path = rebase_path("${SUITES_OUTPUT_ROOT}/${XTS_SUITENAME}") + _suite_archive_dir = rebase_path("${SUITE_ARCHIVE_DIR}") + _prebuilts_files = rebase_path("//xts/resource") + _gen_args = [ + "archive_suite", + "--suite_path", + _suite_path, + "--prebuilts_resource", + _prebuilts_files, + "--suite_archive_dir", + _suite_archive_dir, + "--make_archive", + "${make_archive}", + ] + + _deps = [] + if (defined(invoker.deps)) { + _deps += invoker.deps + } + + action(target_name) { + testonly = true + script = rebase_path("//test/xts/tools/build/suite.py") + deps = _deps + args = _gen_args + outputs = [ _output ] + } +} + +template("pythontest_suite") { + assert(defined(invoker.script), "script is required in target ${target_name}") + + _subsystem_name = "" + if (defined(invoker.subsystem_name)) { + _subsystem_name = invoker.subsystem_name + } else { + _local_path = rebase_path(".") + _args1 = [ + "--method_name", + "get_subsystem_name", + "--arguments", + "path=${_local_path}", + ] + _subsystem_name = + exec_script(rebase_path("//test/xts/tools/build/utils.py"), + _args1, + "trim string") + } + _deps = [] + if (defined(invoker.deps)) { + _deps = invoker.deps + _deps + } + _outputs_dir = "" + if (defined(invoker.outputs_dir)) { + _outputs_dir = invoker.outputs_dir + } + _output_file = rebase_path("${invoker.script}") + + target("ohos_testsuite_base", "${target_name}") { + project_type = "pythontest" + subsystem_name = _subsystem_name + output_file = _output_file + deps = _deps + outputs_dir = _outputs_dir + } +} + +template("executable_suite") { + assert(defined(invoker.suite_name), + "suite_name is required in target ${target_name}") + _suite_name = invoker.suite_name + _local_path = rebase_path(".") + _args1 = [ + "--method_name", + "get_subsystem_name", + "--arguments", + "path=${_local_path}", + ] + _subsystem_name = exec_script(rebase_path("//test/xts/tools/build/utils.py"), + _args1, + "trim string") + + _outputs_dir = "" + if (defined(invoker.outputs_dir)) { + _outputs_dir = "${invoker.outputs_dir}" + } + ohos_executable(target_name) { + forward_variables_from(invoker, + "*", + [ + "test_type", + "module_out_path", + "visibility", + ]) + forward_variables_from(invoker, [ "visibility" ]) + if (!defined(deps)) { + deps = [] + } + + subsystem_name = "tests" + part_name = "ssts" + ohos_test = true + testonly = true + output_name = "$target_name" + test_output_dir = "$SUITES_OUTPUT_ROOT/${_suite_name}/testcases/${_subsystem_name}/${_outputs_dir}" + if (defined(invoker.output_extension)) { + output_extension = invoker.output_extension + } + } +} diff --git a/build/suite.py b/build/suite.py old mode 100644 new mode 100755 index 3cf556e..2b3a875 --- a/build/suite.py +++ b/build/suite.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- """ -Copyright (c) 2021 Huawei Device Co., Ltd. +Copyright (c) 2020-2021 Huawei Device Co., Ltd. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at @@ -27,150 +27,48 @@ from string import Template import utils import json import shutil -import platform +import glob +import stat -class SuiteModuleBuilder: - """ - To Build Suite Module - @arguments(build_target_name, target_file...) - """ - - def __init__(self, arguments): - self.arguments = arguments - self.args = None - - def build_module(self): - """ - build_target_name='wifiaware_test', - javalib_file=None, - project_path='xxx/communication_lite/wifiaware', - project_type='hctest', - source_path='xxx/x.c,xxx/x.c - subsystem_name='communication', - suite_filename='libwifiaware_test.a', - suite_out_paths='out/x/suites/acts/testcases/communication,' - target_file='xxxx/libs/libmodule_wifiaware_test.a', - test_xml='xxx/Test.json' - :return: - """ - - parser = argparse.ArgumentParser() - parser.add_argument('--build_target_name', help='', required=False) - parser.add_argument('--target_file', help='', required=False) - parser.add_argument('--hap_name', help='', required=False) - parser.add_argument('--project_path', help='', required=True) - parser.add_argument('--test_xml', help='', required=False) - parser.add_argument('--project_type', help='', required=True) - parser.add_argument('--suite_out_paths', help='', required=True) - parser.add_argument('--suite_filename', help='', required=True) - parser.add_argument('--subsystem_name', help='', required=False) - parser.add_argument('--build_root_path', help='', required=False) - parser.add_argument('--hap_sign', help='', required=False) - self.args = parser.parse_args(self.arguments) +XTS_RESOURCE_ROOT = 'ivbxfj`qspqsjfubsz0sftpvsdf' - for _suite_out_file in self.args.suite_out_paths.split(","): - if not _suite_out_file: - continue - if self.args.project_type == "pythontest": - _out_file = _suite_out_file - else: - _out_file = os.path.join(_suite_out_file, - self.args.suite_filename) - if self.args.project_type == "pythontest": - utils.copy_file(output=_out_file, - source_dirs=self.args.target_file, - to_dir=True) - elif self.args.project_type == "open_source_test": - utils.copy_file(output=_out_file, - sources=self.args.target_file, - to_dir=True) - elif self.args.project_type == "hjsunit": - utils.build_js_hap(self.args.project_path, self.args. - suite_out_paths, self.args.hap_name) - elif self.args.project_type != "hctest": - utils.copy_file(output=_out_file, - sources=self.args.target_file, - to_dir=False) +def _get_xts_rootpath(project_path): + if project_path is not None: + return project_path[0:project_path.find('/xts/') + len('/xts/')] + raise ValueError('Illegal xts project path ' + project_path) - _testsuite_name = self.args.suite_filename - _matcher = re.match(r"(lib|libmodule_)?(\S+)\.\S+", - _testsuite_name) - if _matcher: - _testsuite_name = _matcher.group(2) - if self.args.project_type != "open_source_test": - _config_file = os.path.join(_suite_out_file, - _testsuite_name + ".json") - else: - _config_file = os.path.join(_out_file, - _testsuite_name + ".json") - utils.record_testmodule_info(self.args.build_target_name, - _testsuite_name, - self.args.subsystem_name, - _suite_out_file) - _test_xml = self.args.test_xml - if _test_xml and os.path.exists(_test_xml): - utils.copy_file(output=_config_file, sources=_test_xml, - to_dir=False) - else: - self._generate_xml_by_template(_test_xml, _testsuite_name, - _config_file) - @staticmethod - def _record_testmodule_info(build_target_name, module_name, - subsystem_name, suite_out_dir): - if not build_target_name or not subsystem_name: - print( - 'build_target_name or subsystem_name of testmodule "%s" ' - 'is invalid!' % module_name) - return - module_info_dir = os.path.dirname(suite_out_dir) - module_info_list_file = os.path.join(module_info_dir, - 'module_info.json') - module_info_data = {} - if os.path.exists(module_info_list_file): - try: - with open(module_info_list_file, 'r') as module_file: - module_info_data = json.load(module_file) - except ValueError: - print("NO json object could be decoded but continue") - module_info = {'subsystem': subsystem_name, - 'build_target_name': build_target_name} - module_info_data[module_name] = module_info - with open(module_info_list_file, 'w') as out_file: - json.dump(module_info_data, out_file) +def _get_subsystem_name(project_path): + if '/hits/' in project_path: + index0 = project_path.find('/hits/') + len('/hits/') + elif '/acts/' in project_path: + index0 = project_path.find('/acts/') + len('/acts/') + else: + raise ValueError('Illegal xts project path ' + project_path) + index1 = project_path.find('/', index0) + return project_path[index0:index1] - def _generate_xml_by_template(self, test_xml, module_name, - config_file): - index = test_xml.rfind(".json") - tmpl_file = test_xml[:index] + ".tmpl" - if not os.path.exists(tmpl_file): - raise Exception( - "Can't find the Test.json or Test.tmpl in the " - "path %s " % os.path.dirname( - test_xml)) - tmpl_content = utils.read_file(tmpl_file) - values = {"module": module_name, "subsystem": self.args.subsystem_name} - xml_content = Template(tmpl_content).substitute(values) - utils.write_file(config_file, xml_content, False) - @staticmethod - def _check_file_exist(file_path): - if not os.path.exists(file_path): - raise Exception("File [%s] does not exist!" % file_path) +def _get_resource_rootpath(project_path): + xts_root = _get_xts_rootpath(project_path) + resource_reldir = ''.join(chr(ord(ch) - 1) for ch in XTS_RESOURCE_ROOT) + return os.path.join(xts_root, resource_reldir) class XDeviceBuilder: """ - To build XTS as a egg package + To build XTS as an egg package @arguments(project_dir, output_dirs) """ def __init__(self, arguments): parser = argparse.ArgumentParser() - parser.add_argument('--project_dir', help='', required=True) - parser.add_argument('--output_dirs', help='', required=True) + parser.add_argument('--source_dir', help='', required=True) + parser.add_argument('--configs_dir', help='', required=False) + parser.add_argument('--resources_dir', help='', required=False) + parser.add_argument('--suite_out_dir', help='', required=True) self.args = parser.parse_args(arguments) def build_xdevice(self): @@ -178,39 +76,41 @@ class XDeviceBuilder: build xdevice package :return: """ - command = [utils.get_python_cmd(), "setup.py", "install", "--user"] - factory_script = os.path.join(self.args.project_dir, "factory.sh") - if os.path.exists(factory_script): - os.chmod(factory_script, 0o775) - command = factory_script + extension_dir = os.path.join(self.args.source_dir, 'extension') + gen_dir0 = os.path.join(self.args.source_dir, 'dist') + gen_dir1 = os.path.join(extension_dir, 'dist') + shutil.rmtree(gen_dir0, ignore_errors=True) + shutil.rmtree(gen_dir1, ignore_errors=True) + command0 = ["python", "setup.py", "sdist"] + command1 = ["python", "setup.py", "sdist"] try: - subprocess.check_call(command, cwd=self.args.project_dir) + subprocess.check_call(command0, cwd=self.args.source_dir) + subprocess.check_call(command1, cwd=extension_dir) except subprocess.CalledProcessError as exc: print('returncode: {} cmd: {} output: {}'.format( - exc.returncode, exc.cmd, exc.output)) + exc.returncode, exc.cmd, exc.output)) - dist_dir = os.path.join(self.args.project_dir, 'dist') run_scripts = ",".join( - [os.path.join(self.args.project_dir, "run.bat"), - os.path.join(self.args.project_dir, "run.sh")]) - config_dir = os.path.join(self.args.project_dir, "config") - res_dir = os.path.join(self.args.project_dir, "resource") - for tool_dir in self.args.output_dirs.split(","): - if tool_dir: - utils.copy_file(output=tool_dir, source_dirs=dist_dir, - to_dir=True) - root_dir = os.path.dirname(tool_dir) - utils.copy_file(output=root_dir, sources=run_scripts, - to_dir=True) - to_dir = os.path.join(root_dir, "config") - utils.copy_file(output=to_dir, source_dirs=config_dir, - to_dir=True) - utils.copy_file(os.path.join(root_dir, "resource"), - source_dirs=res_dir) - if not os.path.exists(os.path.join( - root_dir, "resource", "tools")): - os.mkdir(os.path.join(root_dir, "resource", "tools")) - return 0 + [os.path.join(self.args.source_dir, "run.bat"), + os.path.join(self.args.source_dir, "run.sh")]) + + dist_tools_dir = os.path.join(self.args.suite_out_dir, 'tools') + utils.copy_file(output=dist_tools_dir, source_dirs=gen_dir0, + to_dir=True) + utils.copy_file(output=dist_tools_dir, source_dirs=gen_dir1, + to_dir=True) + utils.copy_file(output=self.args.suite_out_dir, sources=run_scripts, + to_dir=True) + + if self.args.configs_dir: + dist_configs_dir = os.path.join(self.args.suite_out_dir, 'config') + utils.copy_file(output=dist_configs_dir, + source_dirs=self.args.configs_dir, to_dir=True) + if self.args.resources_dir: + dist_resources_dir = os.path.join(self.args.suite_out_dir, + 'resource') + utils.copy_file(output=dist_resources_dir, + source_dirs=self.args.resources_dir, to_dir=True) class SuiteArchiveBuilder: @@ -221,26 +121,240 @@ class SuiteArchiveBuilder: def archive_suite(self): parser = argparse.ArgumentParser() parser.add_argument('--suite_path', help='', required=True) - parser.add_argument('--build_enabled', help='', required=True) + parser.add_argument('--prebuilts_resource', help='', required=True) + parser.add_argument('--suite_archive_dir', help='', required=True) + parser.add_argument('--make_archive', help='', required=True) args = parser.parse_args(self.arguments) - if not args.build_enabled.lower() == 'true': - print('build hit not enabled, skip making archive') + + if not args.make_archive.lower() == 'true': + print('make archive disabled') return 0 - + suite_path = args.suite_path if not os.path.isdir(suite_path): raise Exception("[%s] does not exist" % suite_path) - + + copyfiles = args.prebuilts_resource.split(",") + for file_path in copyfiles: + subprocess.call(["cp", "-rf", file_path, suite_path]) + archive_name = os.path.basename(suite_path) - suite_root_path = os.path.dirname(suite_path) - shutil.make_archive(suite_path, "zip", suite_root_path, archive_name) + archive_root_path = args.suite_archive_dir + if not os.path.isdir(archive_root_path): + os.mkdir(archive_root_path) + # remove the extra output of target "java_prebuilt" + # such as ztest-tradefed-common.interface.jar + subprocess.call(["find", suite_path, "-name", "*.interface.jar", + "-exec", "rm", "{}", "+"]) + shutil.make_archive(os.path.join(archive_root_path, archive_name), + "zip", suite_path) return 0 +class SuiteModuleWithTestbundleBuilder: + + def __init__(self, arguments): + self.arguments = arguments + self.args = None + + def build_module_with_testbundle(self): + parser = argparse.ArgumentParser() + parser.add_argument('--build_gen_dir', help='', required=True) + parser.add_argument('--build_target_name', help='', required=True) + parser.add_argument('--subsystem_name', help='', + required=False) + parser.add_argument('--buildgen_testfile', help='', required=True) + parser.add_argument('--project_path', help='', required=True) + parser.add_argument('--test_xml', help='', required=False) + parser.add_argument('--project_type', help='', required=True) + parser.add_argument('--suite_out_dir', help='', required=True) + parser.add_argument('--archive_testfile', help='', required=True) + parser.add_argument('--apilibrary_deps', help='', required=False) + parser.add_argument('--test_files', help='', required=False) + + self.args = parser.parse_args(self.arguments) + + self._create_testsuite(self.args) + return 0 + + def _create_testsuite(self, args): + _test_xml = args.test_xml + _testcases_dir = os.path.dirname(args.archive_testfile) + _testsuite_name = os.path.basename(args.archive_testfile)\ + .replace('.hap', '').replace('module_', '') + _testcase_xml = os.path.join(_testcases_dir, _testsuite_name + ".xml") + _config_file = os.path.join(_testcases_dir, + _testsuite_name + ".config") + _json_file = os.path.join(_testcases_dir, _testsuite_name + ".json") + + if args.project_type == "js_test_hap": + self._generate_json_by_template(_test_xml.replace(".xml", ".json"), + _testsuite_name, _json_file) + dest_file = os.path.join( + _testcases_dir, "{}.hap".format(_testsuite_name)) + self._copy_file(args.buildgen_testfile, dest_file) + os.chmod(dest_file, stat.S_IRWXU|stat.S_IRWXG|stat.S_IRWXO) + return + if args.project_type == "pythontest": + self._generate_json_by_template(_test_xml.replace(".xml", ".json"), + _testsuite_name, os.path.join( + args.archive_testfile, _testsuite_name + ".json")) + utils.copy_file(output=self.args.archive_testfile, + source_dirs=self.args.test_files) + return + self._check_file_exist(args.buildgen_testfile) + self._copy_file(args.buildgen_testfile, args.archive_testfile) + if args.project_type == "app": + return + self._record_testmodule_info(args.build_target_name, + _testsuite_name, + _testcases_dir) + if _test_xml and os.path.exists(_test_xml): + self._copy_file(_test_xml, _config_file) + elif _test_xml.replace(".xml", ".json") and \ + os.path.exists(_test_xml.replace(".xml", ".json")): + self._generate_json_by_template(_test_xml.replace(".xml", ".json"), + _testsuite_name, _json_file) + else: + self._generate_xml_by_template(_test_xml, _testsuite_name, + _config_file) + #self._generate_testcase_xml(args) + _resource_srcroot = _get_resource_rootpath(args.project_path) + try: + self._archive_test_resource(_config_file, _resource_srcroot, + args.suite_out_dir) + except Exception as error: + print("Archive resource error: %s" % error, file=sys.stderr) + self._archive_test_file_to_testcase(_testcases_dir) + + @staticmethod + def _record_testmodule_info(build_target_name, module_name, testcases_dir): + if not build_target_name or not module_name: + raise ValueError( + 'Ethire build_target_name or module_name is invalid') + + module_info_list_file = os.path.join(testcases_dir, 'module_info.list') + lines = [] + if os.path.isfile(module_info_list_file): + with open(module_info_list_file, 'r') as file_read: + for line in file_read: + lines.append(line.strip()) + + new_lines = ['%s %s' % (build_target_name, module_name)] + for line in lines: + arr = line.strip().split(' ') + if len(arr) == 0 or arr[0] == build_target_name: + continue + new_lines.append(line) + + # add module info + with open(module_info_list_file, 'w') as file_write: + file_write.write('\n'.join(new_lines) + '\n') + + + @staticmethod + def _generate_json_by_template(source_file, module_name, dest_file): + source_content = utils.read_file(source_file) + values = {"module": module_name} + xml_content = Template(source_content).substitute(values) + utils.write_file(dest_file, xml_content, False) + + @staticmethod + def _generate_xml_by_template(test_xml, module_name, + config_file): + # find the template file + index = test_xml.rfind(".xml") + tmpl_file = test_xml[:index] + ".tmpl" + if not os.path.exists(tmpl_file): + raise Exception("Can't find the Test.xml or " + "Test.tmpl in the path %s " % + os.path.dirname(test_xml)) + tmpl_content = utils.read_file(tmpl_file) + values = {"module": module_name} + xml_content = Template(tmpl_content).substitute(values) + utils.write_file(config_file, xml_content, False) + + def _copy_file(self, source, target): + if not os.path.exists(os.path.dirname(target)): + os.makedirs(os.path.dirname(target)) + if not os.path.exists(target) or ( + os.path.exists(target) and + (os.stat(target).st_mtime != os.stat(source).st_mtime)): + print('Trying to copy "%s" to "%s"' % (source, target)) + subprocess.call(["rm", "-rf", target]) + subprocess.call(["cp", "-rf", source, target]) + + def _copy_file_to_target(self, source_file, dest_file): + if not os.path.exists(source_file): + print("[ERROR] source_file is not exist. %s" % source_file, + file=sys.stderr) + return + else: + self._copy_file(source_file, dest_file) + + def _archive_test_resource(self, xml_file, root_dir, resource_dir): + _pattern = re.compile("[-=]>") + if os.path.exists(xml_file): + try: + dom = xml.dom.minidom.parse(xml_file) + childroot = dom.getElementsByTagName("target_preparer") + for child in childroot: + for child_atrr in child.getElementsByTagName("option"): + name = child_atrr.getAttribute("name") + attr_value = child_atrr.getAttribute("value") + value = _pattern.split(attr_value)[0].strip() + if name != "" or value != "": + if name == "push" and \ + value.startswith("resource/"): + self._copy_file_to_target( + os.path.join(root_dir, "../", value), + os.path.join(resource_dir, value)) + else: + raise Exception("Test.xml node name and " + "value not is null") + except IOError as error: + print("IO Error: %s" % error, file=sys.stderr) + except ExpatError as error: + print("ExpatError Error: %s" % error, file=sys.stderr) + finally: + pass + else: + with open(xml_file.replace(".config", ".json"), + "r", encoding="UTF-8") as json_file: + json_str = json.load(json_file) + kits = json_str["kits"] + for kit in kits: + types = kit["type"] + if types == "PushKit": + push_resources = kit["push"] + for resource in push_resources: + value = _pattern.split(resource)[0].strip() + if value.startswith("resource/"): + self._copy_file_to_target( + os.path.join(root_dir, "../", value), + os.path.join(resource_dir, value)) + + def _archive_test_file_to_testcase(self, cases_dir): + if self.args.test_files is None: + return + arr_test_files = self.args.test_files.split(',') + for file in arr_test_files: + if file == "": + continue + self._copy_file_to_target(file, + os.path.join(cases_dir, + os.path.basename(file))) + + def _check_file_exist(self, file_path): + if not os.path.exists(file_path): + raise Exception("File [%s] does not exist!" % file_path) + + ACTION_MAP = {"build_module": "SuiteModuleBuilder", "build_xdevice": "XDeviceBuilder", "archive_suite": "SuiteArchiveBuilder", - } + "build_module_with_testbundle": + "SuiteModuleWithTestbundleBuilder"} def _find_action(action, arguments): diff --git a/build/test_package_select.py b/build/test_package_select.py new file mode 100755 index 0000000..ff8abb4 --- /dev/null +++ b/build/test_package_select.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" +Copyright (c) 2021 Huawei Device Co., Ltd. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +import json +import sys + + +def filter_modules(subsystem_data_file, test_packages): + subsystems = set() + with open(subsystem_data_file) as fd: + subsystem_data = json.load(fd) + subsystems = set(subsystem_data) + subsystems.add("demo") + subsystems.add("storage") + selected_packages = [] + for dep in test_packages: + if 'selected_subsystem=' in dep: + selected_subsystem = dep.split('=')[1] + init_subsystems = subsystems.copy() + subsystems.clear() + for item in selected_subsystem.split(','): + if item in init_subsystems: + subsystems.add(item) + break + for dep in test_packages: + rslash_index = dep.find('/hits') + if rslash_index < 0: + rslash_index = dep.find('/acts') + colon_index = dep.find(':') + if rslash_index < 0 or colon_index < 0: + continue + rslash_index += 5 + subsystem_name = dep[rslash_index + 1:colon_index] + if subsystem_name in subsystems: + selected_packages.append(dep) + else: + pass + return selected_packages + + +if __name__ == "__main__": + main_subsystem_data_file = sys.argv[1] + main_test_packages = sys.argv[2:] + main_selected_packages = filter_modules(main_subsystem_data_file, + main_test_packages) + sys.stdout.write('\n'.join(main_selected_packages)) diff --git a/build/utils.py b/build/utils.py index 5f3bf25..7a890ef 100755 --- a/build/utils.py +++ b/build/utils.py @@ -1,7 +1,7 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python # -*- coding: utf-8 -*- """ -Copyright (c) 2021 Huawei Device Co., Ltd. +Copyright (c) 2020-2021 Huawei Device Co., Ltd. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at @@ -19,14 +19,10 @@ import os import fnmatch import sys import argparse -import json -import platform -import subprocess - import distutils.dir_util as dir_util import distutils.file_util as file_util -from distutils.errors import DistutilsError - +import json +import subprocess # all sub system list, must be lowercase. _SUB_SYSTEM_LIST = [ @@ -34,43 +30,25 @@ _SUB_SYSTEM_LIST = [ "hiviewdfx", "communication", "security", - "update", + "updater", "sstsutils", "utils", + "uikit", "multimedia", "hdf", - "aafwk", - "appexecfwk", - "distributed_schedule", + "appexecfwk", + "distributedschedule", "startup", "sensors", "sample", - "iot_hardware", + "iothardware", "open_posix_testsuite", - "graphic", - "ace", - "applications", - "ai", - "global", - "telephony", - "dcts" ] +_GRADLE_PARAMS = ["SIGN_USER_NAME", "SIGN_PWD", "SIGN_MATERIAL_PATH", + "SIGN_PROFILE", "SIGN_CERT_FILE"] -_NO_FILTE_SUB_SYSTEM_LIST = [ - "applications", - "kernel", - "open_posix_testsuite", - "sample", - "telephony", - "dcts", - "hiviewdfx", - "communication", - "security", - "update", - "sstsutils", - "hdf", - "distributed_schedule" -] +_DEFAULT_USER_NAME = "user" +_DEFAULT_PWD = "decrypt_pwd" def main(): @@ -85,9 +63,7 @@ def main(): for argument in args.arguments.split("#"): key_value = argument.strip().split("=") if len(key_value) != 2: - raise ValueError( - "The arguments' format is 'key=value#key=value'. Wrong format:" - " " + argument) + raise ValueError("Wrong format : '%s' % argument") arguments.setdefault(key_value[0].strip(), key_value[1].strip()) method(**arguments) return 0 @@ -138,32 +114,20 @@ def copy_file(output, sources="", source_dirs="", to_dir=True): except OSError: if not os.path.isdir(_output): raise - try: - if _sources: - _copy_files(_sources.split(","), _output) + if _sources: + _copy_files(_sources.split(","), _output) + + if _source_dirs: + _copy_dir(_source_dirs.split(","), _output) - if _source_dirs: - _copy_dir(_source_dirs.split(","), _output) - except DistutilsError: - print("ignore file exist error") return 0 def _copy_files(sources, output): - copy_set = set() for source_file in sources: source_file = source_file.strip() - if os.path.isfile(source_file) and os.path.exists(source_file): - # if same file name exist, add dir path - if os.path.basename(source_file) in copy_set: - new_output = os.path.join(output, os.path.dirname(source_file). - split(os.sep)[-1]) - if not os.path.exists(new_output): - os.makedirs(new_output) - file_util.copy_file(source_file, new_output) - else: - file_util.copy_file(source_file, output) - copy_set.add(os.path.basename(source_file)) + if os.path.isfile(source_file): + file_util.copy_file(source_file, output) def _copy_dir(sources, output): @@ -188,12 +152,12 @@ def gen_suite_out(suite_output_prefix, suite_names, out_suffix): def get_subsystem_name(path): subsystem_name = "" for subsystem in _SUB_SYSTEM_LIST: - subsystem_path = "/" + subsystem + "/" + subsystem_path = "/%s/" % (subsystem) _path = path.lower() if subsystem_path in _path: subsystem_name = subsystem break - subsystem_path = "/" + subsystem + "_lite/" + subsystem_path = "/%s/_lite" % (subsystem) if subsystem_path in _path: subsystem_name = subsystem break @@ -204,6 +168,7 @@ def get_subsystem_name(path): def get_modulename_by_buildtarget(module_list_file, build_target): if not os.path.exists(module_list_file): return "" + module_info_data = {} with open(module_list_file, "r") as module_file: module_info_data = json.load(module_file) for module in module_info_data: @@ -221,128 +186,6 @@ def glob(path, filename_pattern): return files -def filter_by_subsystem(testsuites, product_json): - product_info = {} - filtered_features = [] - subs_comps = {} - # parses product json to obtain all the subsystem name - if os.path.exists(product_json): - try: - with open(product_json, 'r') as product_info: - product_info = json.load(product_info) - except ValueError: - print("NO json object could be decoded.") - subsystem_info = product_info.get("subsystems") - for subsystem in subsystem_info: - subs_comps[subsystem.get("subsystem")] = \ - subsystem.get("components", []) - - feature_list = testsuites.split(",") - for feature in feature_list: - # if subsytem name match - subsystem = get_subsystem_name_no_output(feature) - if subsystem in _NO_FILTE_SUB_SYSTEM_LIST: - filtered_features.append(feature) - print(feature) - elif subsystem in subs_comps: - components = subs_comps.get(subsystem, []) - if check_component(feature, components): - filtered_features.append(feature) - print(feature) - return filtered_features - - -def get_subsystem_name_no_output(path): - subsystem_name = "" - for subsystem in _SUB_SYSTEM_LIST: - subsystem_path = "/" + subsystem - _path = path.lower() - if subsystem_path in _path: - subsystem_name = subsystem - break - subsystem_path = "/" + subsystem + "_lite" - if subsystem_path in _path: - subsystem_name = subsystem - break - return subsystem_name - - -def check_component(path, components): - for component in components: - component_name = component.get("component", "") - component_name = component_name.replace("_lite", "") - if component_name in path or "{}_hal".format(component_name) in path \ - or "{}_posix".format(component_name) in path: - return True - return False - - -def get_python_cmd(): - major, _, _ = platform.python_version_tuple() - if major == "3": - return "python" - else: - return "python3" - - -def record_testmodule_info(build_target_name, module_name, - subsystem_name, suite_out_dir, same_file=False): - if not build_target_name or not subsystem_name: - print( - 'build_target_name or subsystem_name of testmodule "%s" ' - 'is invalid!' % module_name) - return - if same_file: - module_info_list_file = os.path.join(suite_out_dir, 'module_info.json') - else: - module_info_list_file = os.path.join(suite_out_dir, - '{}_module_info.json'.format - (build_target_name)) - module_info_data = {} - if os.path.exists(module_info_list_file): - try: - with open(module_info_list_file, 'r') as module_file: - module_info_data = json.load(module_file) - except ValueError: - print("NO json object could be decoded but continue") - module_info = {'subsystem': subsystem_name, - 'build_target_name': build_target_name} - module_info_data[module_name] = module_info - with open(module_info_list_file, 'w') as out_file: - json.dump(module_info_data, out_file) - - -def record_test_component_info(out_dir, version): - if not os.path.exists(out_dir): - os.makedirs(out_dir) - all_module_file = os.path.join(out_dir, 'module_info.json') - all_module_data = {} - for root, dirs, files in os.walk(out_dir): - for file in files: - if file.endswith("module_info.json"): - with open(os.path.join(root, file), 'r') as json_data: - module_data = json.load(json_data) - all_module_data.update(module_data) - os.remove(os.path.join(root, file)) - with open(all_module_file, 'w') as out_file: - json.dump(all_module_data, out_file) - - test_component_file = os.path.join(out_dir, 'test_component.json') - test_component_data = {'version': version, } - with open(test_component_file, 'w') as out_file: - json.dump(test_component_data, out_file) - - -def get_target_modules(all_features): - feature_list = [] - if all_features: - for feature in all_features.split(","): - if feature: - feature_list.append(feature) - print(feature) - return feature_list - - def cmd_popen(cmd): proc = subprocess.Popen(cmd) proc.wait() @@ -351,25 +194,60 @@ def cmd_popen(cmd): raise Exception("{} failed, return code is {}".format(cmd, ret_code)) -def build_js_hap(project_path, out_put_dir, hap_name): +def build_js_hap(**kwargs): if not check_env(): return + if "project_path" not in kwargs or "out_put_dir" not in kwargs: + return + project_path = kwargs.get("project_path") gradle_dir = os.path.join(project_path, "gradle") os.chdir(gradle_dir) build_clean = ["gradle", "clean"] cmd_popen(build_clean) - build_cmd = ["gradle", "entry:packageDebugHap"] - cmd_popen(build_cmd) - gralde_output_dir = os.path.join(gradle_dir, "entry", "build", "outputs") - if os.path.exists(gralde_output_dir): - for root, _, files in os.walk(gralde_output_dir): - for file in files: - if file.endswith(".hap"): - file_util.copy_file(os.path.join(root, file), - os.path.join(out_put_dir.rstrip(','), - hap_name)) - return + if "SIGN_USER_NAME" not in kwargs: + pass + gradle_parm_cmd = get_gradle_cmd(**kwargs) + # build sign debug hap + build_hap_cmd = ["gradle"] + build_hap_cmd.extend(gradle_parm_cmd) + build_hap_cmd.append("entry:aD") + cmd_popen(build_hap_cmd) + + # build sign ohos test hap + build_test_hap_cmd = ["gradle"] + build_test_hap_cmd.extend(gradle_parm_cmd) + build_test_hap_cmd.append("entry:aDOT") + cmd_popen(build_test_hap_cmd) + + gradle_output_dir = os.path.join(gradle_dir, "entry", "build", "outputs") + if not os.path.exists(gradle_output_dir): + return + out_put_dir = kwargs.get("out_put_dir") + if not os.path.exists(out_put_dir): + os.makedirs(out_put_dir) + hap_name = kwargs.get("hap_name") + for root, _, files in os.walk(gradle_output_dir): + for file in files: + if file.endswith(".hap") and "unsigned" not in file: + if "debugOhosTest" in root: + target_file = "{}_OhosTest.hap".format(hap_name) + else: + target_file = "{}.hap".format(hap_name) + file_util.copy_file(os.path.join(root, file), + os.path.join(out_put_dir.rstrip(','), + target_file)) + + +def get_gradle_cmd(**kwargs): + cmd = [] + if kwargs: + kwargs.setdefault("SIGN_USER_NAME", _DEFAULT_USER_NAME) + kwargs.setdefault("SIGN_PWD", _DEFAULT_PWD) + for param in _GRADLE_PARAMS: + if param in kwargs: + cmd.append("-P{}={}".format(param, kwargs.get(param))) + return cmd def check_env(): @@ -377,12 +255,14 @@ def check_env(): check all the env for js hap build return: return true if all env ready, otherwise return false """ - env_list = ['OHOS_SDK_HOME', 'NODE_HOME', 'GRADLE_HOME'] + env_list = ['OHOS_SDK_HOME'] for env in env_list: if not os.environ.get(env): print("the env {} not set, skip build!".format(env)) return False else: return True + + if __name__ == '__main__': sys.exit(main()) diff --git a/BUILD.gn b/lite/BUILD.gn similarity index 100% rename from BUILD.gn rename to lite/BUILD.gn diff --git a/lite/LICENSE b/lite/LICENSE new file mode 100755 index 0000000..4a45986 --- /dev/null +++ b/lite/LICENSE @@ -0,0 +1,177 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS \ No newline at end of file diff --git a/lite/OAT.xml b/lite/OAT.xml new file mode 100644 index 0000000..e21e6aa --- /dev/null +++ b/lite/OAT.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + diff --git a/lite/README.md b/lite/README.md new file mode 100755 index 0000000..5e6d11b --- /dev/null +++ b/lite/README.md @@ -0,0 +1,530 @@ +# X Test Suite + +- [Introduction](#section465982318513) +- [Devices](#section125090457443) +- [Directory Structure](#section161941989596) +- [Constraints](#section119744591305) +- [Usage Guidelines](#section137768191623) +- [Test Case Development Guidelines](#section3695134065513) + - [C-based Test Case Development and Compilation \(for Mini-System Devices\)](#section1551164914237) + - [C-based Test Case Execution \(for Mini-System Devices\)](#section10100701294) + - [C++-based Test Case Development and Compilation \(for Small-, Standard-, and Large-System Devices\)](#section5714177113113) + - [C++-based Test Case Execution \(for Small-, Standard-, and Large-System Devices\)](#section42281924184) + +- [Repositories Involved](#section1371113476307) + +## Introduction + +The X test suite \(XTS\) subsystem contains a set of OpenHarmony certification test suites, including the currently supported application compatibility test suite \(ACTS\) and the device compatibility test suite \(DCTS\) that will be supported in the future. + +This subsystem contains the ACTS and **tools** software package. + +- The **acts** directory stores the source code and configuration files of ACTS test cases. The ACTS helps device vendors detect the software incompatibility as early as possible and ensures that the software is compatible to OpenHarmony during the entire development process. +- The **tools** software package stores the test case development framework related to **acts**. + +## Devices + +OpenHarmony supports the following device types: + +- **Mini-System Devices \(reference memory ≥ 128 KB\)** + + Such devices are equipped with MCU processors such as ARM Cortex-M and 32-bit RISC-V. They provide rich short-distance connection and peripheral bus access capabilities. Typical products include LinkIoT module devices and sensors in the smart home field. The LinkIoT module is usually used for smart Internet of Things \(IoT\) devices as the hardware module that implements connectivity functions. In the smart home field, the LinkIoT module is integrated into devices by vendors. For example, a LinkIoT module provides WLAN/Bluetooth access and data connection, and it usually communicates with the chip of smart home devices via a universal asynchronous receiver-transmitter \(UART\) or general-purpose input/output \(GPIO\) interface. + +- **Small-System Devices \(reference memory ≥ 1 MB\)** + + Such devices are equipped with application processors such as ARM Cortex-A. They provide higher security capabilities, standard graphics framework, and multimedia capabilities for video encoding and decoding. Typical products include IP cameras, electronic cat eyes, and routers in the smart home field, as well as event data recorders \(EDRs\) in the smart travel field. + + +- **Standard-System Devices \(reference memory ≥ 128 MB\)** + + Such devices are equipped with application processors such as ARM Cortex-A. They provide a complete application framework supporting enhanced interaction, 3D GPU, hardware composer, diverse components, and rich animations. Typical products include high-end refrigerator displays. + +- **Large-System Devices \(reference memory ≥ 1 GB\)** + + Such devices are equipped with application processors such as ARM Cortex-A and provide a complete compatible application framework. Typical products include smart TVs and smart watches. + + +## Directory Structure + +``` +/test/xts +├── acts # Test code +│ └── subsystem # Source code of subsystem test cases for large-system devices +│ └── subsystem_lite # Source code of subsystems test cases for mini- and small-system devices +│ └── BUILD.gn # Build configuration of test cases for large-system devices +│ └── build_lite # Build configuration of test cases for mini-and small-system devices +│ └── build_lite # Build configuration +└── tools # Test tool code +``` + +## Constraints + +Test cases for mini system devices must be developed based on C, and those for small system devices must be developed based on C++. + +## Usage Guidelines + +**Table 1** Test case levels + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Level

+

Definition

+

Scope

+

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.

+

Level1

+

Basic

+

Verifies basic functionalities of key features and basic DFX attributes with common input. The pass result indicates that the features are testable.

+

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.

+

Level3

+

Regular

+

Verifies functionalities of all key features, and all DFX attributes with common and uncommon input combinations or normal and abnormal preset conditions.

+

Level4

+

Rare

+

Verifies functionalities of key features under extremely abnormal presets and uncommon input combinations.

+
+ +**Table 2** Test case granularities + + + + + + + + + + + + + + + + + + + + +

Test Scale

+

Test Objects

+

Test Environment

+

LargeTest

+

Service functionalities, all-scenario features, and mechanical power environment (MPE) and scenario-level DFX

+

Devices close to real devices

+

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.

+

SmallTest

+

Modules, classes, and functions

+

Local PC. Use a large number of mocks to replace dependencies with other modules.

+
+ +**Table 3** Test types + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Type

+

Definition

+

Function

+

Tests the correctness of both service and platform functionalities provided by the tested object for end users or developers.

+

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.

+

Power

+

Tests the power consumption of the tested object in a certain period of time under specific preset conditions and load models.

+

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.

+

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.
  • Tests the privacy protection capability to ensure that the collection, use, retention, disclosure, and disposal of users' private data comply with laws and regulations.
  • 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).
+

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.

+

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.
  • Tests system backward compatibility with its own data and the compatibility of common applications in the ecosystem.
  • Tests software compatibility with related hardware.
+

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.

+

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.

+

Safety

+

Tests the safety property of the tested object to avoid possible hazards to personal safety, health, and the object itself.

+

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.

+
+ +## Test Case Development Guidelines + +You should select the appropriate programming language and your target test framework to develop test cases for the devices to test. + +**Table 4** Test frameworks and test case languages for different devices + + + + + + + + + + + + + + + + + + + + + + + + +

Device Type

+

Test Framework

+

Language

+

Mini-system devices

+

HCTest

+

C

+

Small-system devices

+

HCPPTest

+

C++

+

Standard-system devices

+

HJUnit and HCPPTest

+

Java and C++

+

Large-system devices

+

HJUnit and HCPPTest

+

Java and C++

+
+ +### C-based Test Case Development and Compilation \(for Mini-System Devices\) + +**Developing test cases for mini-system devices** + +The HCTest framework is used to support test cases developed with the C language. HCTest is enhanced and adapted based on the open-source test framework Unity. + +1. Access the **test/xts/acts** repository where the test cases will be stored. + + ``` + ├── acts + │ └──subsystem_lite + │ │ └── module_hal + │ │ │ └── BUILD.gn + │ │ │ └── src + │ └──build_lite + │ │ └── BUILD.gn + ``` + +2. Write the test case in the **src** directory. + + 1 Import the test framework header file. + + ``` + #include "hctest.h" + ``` + + 2. Use the **LITE\_TEST\_SUIT** macro to define names of the subsystem, module, and test suite. + + ``` + /** + * @brief Registers a test suite named IntTestSuite. + * @param test Subsystem name + * @param example Module name + * @param IntTestSuite Test suite name + */ + LITE_TEST_SUIT(test, example, IntTestSuite); + ``` + + 3. Define Setup and TearDown. + + Format: Test suite name+Setup, Test suite name+TearDown. + + The Setup and TearDown functions must exist, but function bodies can be empty. + + 4. Use the **LITE\_TEST\_CASE** macro to write the test case. + + Three parameters are involved: test suite name, test case name, and test case properties \(including type, granularity, and level\). + + ``` + LITE_TEST_CASE(IntTestSuite, TestCase001, Function | MediumTest | Level1) + { + // Do something + }; + ``` + + 5. Use the **RUN\_TEST\_SUITE** macro to register the test suite. + + ``` + RUN_TEST_SUITE(IntTestSuite); + ``` + +3. Create the configuration file \(**BUILD.gn**\) of the test module. + + Create a **BUILD.gn** \(example\) compilation file in each test module directory. Specify the name of the compiled static library and its dependent header file and library in the compilation file. The format is as follows: + + ``` + import("//test/xts/tools/lite/build/suite_lite.gni") + hctest_suite("ActsDemoTest") { + suite_name = "acts" + sources = [ + "src/test_demo.c", + ] + include_dirs = [ ] + cflags = [ "-Wno-error" ] + } + ``` + +4. Add compilation options to the **BUILD.gn** file in the **acts** directory. + + You need to add the test module to the **test/xts/acts/build\_lite/BUILD.gn** script in the **acts** directory. + + ``` + lite_component("acts") { + ... + if(board_name == "liteos_m") { + features += [ + ... + "//xts/acts/subsystem_lite/module_hal:ActsDemoTest" + ] + } + } + ``` + +5. Run compilation commands. + + Test suites are compiled along with version compilation. The ACTS is compiled together with the debug version. + + >![](figures/icon-note.gif) **NOTE:** + >The ACTS compiles middleware as a static library, which will be linked to the image. + + +### C-based Test Case Execution \(for Mini-System Devices\) + +**Executing test cases for mini-system devices** + +Burn the image into the development board. + +**Executing the test** + +1. Use a serial port tool to log in to the development board and save information about the serial port. +2. Restart the device and view serial port logs. + +**Analyzing the test result** + +View the serial port logs, whose format is as follows: + +The log for each test suite starts with **Start to run test suite:** and ends with **xx Tests xx Failures xx Ignored**. + +### C++-based Test Case Development and Compilation \(for Small-, Standard-, and Large-System Devices\) + +**Developing test cases for small-system devices** + +The HCPPTest framework is enhanced and adapted based on the open-source framework Googletest. + +1. Access the **test/xts/acts** repository where the test cases will be stored. + + ``` + ├── acts + │ └──subsystem_lite + │ │ └── module_posix + │ │ │ └── BUILD.gn + │ │ │ └── src + │ └──build_lite + │ │ └── BUILD.gn + ``` + +2. Write the test case in the **src** directory. + + 1. Import the test framework header file. + + The following statement includes **gtest.h**. + + ``` + #include "gtest/gtest.h" + ``` + + 2. Define Setup and TearDown. + + ``` + using namespace std; + using namespace testing::ext; + class TestSuite: public testing::Test { + protected: + // Preset action of the test suite, which is executed before the first test case + static void SetUpTestCase(void){ + } + // Test suite cleanup action, which is executed after the last test case + static void TearDownTestCase(void){ + } + // Preset action of the test case + virtual void SetUp() + { + } + // Cleanup action of the test case + virtual void TearDown() + { + } + }; + ``` + + 3. Use the **HWTEST** or **HWTEST\_F** macro to write the test case. + + **HWTEST**: definition of common test cases, including the test suite name, test case name, and case annotation. + + **HWTEST\_F**: definition of SetUp and TearDown test cases, including the test suite name, test case name, and case annotation. + + Three parameters are involved: test suite name, test case name, and test case properties \(including type, granularity, and level\). + + ``` + HWTEST_F(TestSuite, TestCase_0001, Function | MediumTest | Level1) { + // Do something + } + ``` + +3. Create a configuration file \(**BUILD.gn**\) of the test module. + + Create a **BUILD.gn** compilation file in each test module directory. Specify the name of the compiled static library and its dependent header file and library in the compilation file. Each test module is independently compiled into a **.bin** executable file, which can be directly mounted to the development board for testing. + + Example: + + ``` + import("//test/xts/tools/lite/build/suite_lite.gni") + hcpptest_suite("ActsDemoTest") { + suite_name = "acts" + sources = [ + "src/TestDemo.cpp" + ] + + include_dirs = [ + "src", + ... + ] + deps = [ + ... + ] + cflags = [ "-Wno-error" ] + } + + ``` + +4. Add compilation options to the **BUILD.gn** file in the **acts** directory. + + Add the test module to the **test/xts/acts/build\_lite/BUILD.gn** script in the **acts** directory. + + ``` + lite_component("acts") { + ... + else if(board_name == "liteos_a") { + features += [ + ... + "//xts/acts/subsystem_lite/module_posix:ActsDemoTest" + ] + } + } + ``` + +5. Run compilation commands. + + Test suites are compiled along with the version compilation. The ACTS is compiled together with the debug version. + + >![](figures/icon-note.gif) **NOTE:** + >The ACTS for a small system device is independently compiled to an executable file \(.bin\) and archived in the **suites\\acts** directory of the compilation result. + + +### C++-based Test Case Execution \(for Small-, Standard-, and Large-System Devices\) + +**Executing test cases for small-system devices** + +Currently, test cases are shared by the NFS and mounted to the development board for execution. + +**Setting up the environment** + +1. Use a network cable or wireless network to connect the development board to your PC. +2. Configure the IP address, subnet mask, and gateway for the development board. Ensure that the development board and the PC are in the same network segment. +3. Install and register the NFS server on the PC and start the NFS service. +4. Run the **mount** command for the development board to ensure that the development board can access NFS shared files on the PC. + + Format: **mount** _NFS server IP address_**:/**_NFS shared directory_ **/**_development board directory_ **nfs** + + Example: + + ``` + mount 192.168.1.10:/nfs /nfs nfs + ``` + + +**Executing test cases** + +Execute **ActsDemoTest.bin** to trigger test case execution, and analyze serial port logs generated after the execution is complete. + +## Repositories Involved + +[X Test Suite](https://gitee.com/openharmony/docs/blob/master/en/readme/x-test-suite.md) + +[xts\_acts](https://gitee.com/openharmony/xts_acts/blob/master/README.md) + +**xts\_tools** + diff --git a/lite/README_zh.md b/lite/README_zh.md new file mode 100755 index 0000000..16f93bb --- /dev/null +++ b/lite/README_zh.md @@ -0,0 +1,530 @@ +# XTS认证子系统开发指南 + +- [简介](#section465982318513) +- [设备类型](#section125090457443) +- [目录](#section161941989596) +- [约束](#section119744591305) +- [使用说明](#section137768191623) +- [用例开发指导](#section3695134065513) + - [C语言用例开发编译指导(适用于轻量系统类设备产品用例开发)](#section1551164914237) + - [C语言用例执行指导(适用于轻量系统类设备产品用例开发)](#section10100701294) + - [C++语言用例开发编译指导(适用于小型系统类设备、标准系统类设备、大型系统类设备用例开发)](#section5714177113113) + - [C++语言用例执行指导(适用于小型系统类设备、标准系统类设备、大型系统类设备用例开发)](#section42281924184) + +- [相关仓](#section1371113476307) + +## 简介 + +XTS子系统是OpenHarmony生态认证测试套件的集合,当前包括acts(application compatibility test suite)应用兼容性测试套件,后续会拓展dcts(device compatibility test suite)设备兼容性测试套件等。 + +XTS子系统当前包括acts与tools软件包: + +- acts,存放acts相关测试用例源码与配置文件,其目的是帮助终端设备厂商尽早发现软件与OpenHarmony的不兼容性,确保软件在整个开发过程中满足OpenHarmony的兼容性要求。 +- tools,存放acts相关测试用例开发框架。 + +## 设备类型 + +OpenHarmony支持如下几种设备类型: + +- **轻量系统类设备(参考内存≥128KB)** + + 面向MCU类处理器,例如Arm Cortex-M、RISC-V 32位的设备,资源极其有限,参考内存≥128KB,提供丰富的近距连接能力以及丰富的外设总线访问能力。典型产品有智能家居领域的联接类模组、传感器设备等。联接类模组通常应用在智能物联网设备中,负责实现联接部分的硬件模块,在智能家居领域由厂家集成到其设备中。例如:联接类模组提供WLAN/Bluetooth的接入和数据的联接,模组与厂家家居的芯片通常通过UART或GPIO等总线接口进行通信。 + +- **小型系统类设备(参考内存≥1MB)** + + 面向应用处理器,例如Arm Cortex-A的设备,参考内存≥1MB,提供更高的安全能力,提供标准的图形框架,提供视频编解码的多媒体能力。典型产品有智能家居领域的IPCamera、电子猫眼、路由器以及智慧出行域的行车记录仪等。 + + +- **标准系统类设备(参考内存≥128MB)** + + 面向应用处理器,例如Arm Cortex-A的设备,参考内存≥128MB,提供增强的交互能力,提供3D GPU以及硬件合成能力,提供更多控件以及动效更丰富的图形能力,提供完整的应用框架。典型产品有高端的冰箱显示屏等。 + +- **大型系统类设备(参考内存≥1GB)** + + 面向应用处理器,例如Arm Cortex-A的设备,参考内存≥1GB,提供完整的兼容应用框架。典型的产品有智慧屏、智能手表等。 + + +## 目录 + +``` +/test/xts +├── acts # 测试代码存放目录 +│ └── subsystem # 大型系统类设备子系统测试用例源码存放目录 +│ └── subsystem_lite # 轻量系统类设备、小型系统类设备子系统测试用例源码存放目录 +│ └── BUILD.gn # 大型系统类设备测试用例编译配置 +│ └── build_lite # 轻量系统类设备、小型系统类设备测试用例编译配置存放目录 +│ └── BUILD.gn # 轻量系统类设备、小型系统类设备测试用例编译配置 +└── tools # 测试工具代码存放目录 +``` + +## 约束 + +轻量系统类设备用例开发语言是C,小型系统类设备用例开发语言是C++。 + +## 使用说明 + +**表 1** 用例级别说明 + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

级别名称

+

基本定义

+

测试范围

+

Level0

+

冒烟

+

验证关键功能点基本功能/最基本DFX属性在最常见输入下的表现,通过表示功能基本可运行。

+

Level1

+

基本

+

验证各功能点基本功能/基本DFX属性在常见输入下的表现,通过表示功能基本可测试。

+

Level2

+

重要

+

验证各功能点的基本功能/基本DFX属性在常规输入/常见异常情况下的表现,通过表示功能基本正常可用,可开展Beta。

+

Level3

+

一般

+

验证各功能点的全部功能/全部DFX属性在各种常规/非常规输入组合下,或各种正常/异常预置条件组合下的表现。

+

Level4

+

生僻

+

验证关键功能点在极端异常预置条件下、用户难以触及的异常输入组合下的表现。

+
+ +**表 2** 用例粒度说明 + + + + + + + + + + + + + + + + + + + + +

用例规模

+

被测试对象

+

测试环境

+

LargeTest

+

业务功能/全场景特性/整机及场景级DFX

+

尽量使用贴近真实的环境设备

+

MediumTest

+

模块/子系统集成至设备后的功能/DFX

+

使用真实的单设备进行验证,可进行消息模拟,尽量不对函数进行MOCK

+

SmallTest

+

模块/类/函数

+

在开发者个人环境进行测试,尽量不依赖其他模块,存在大量的MOCK

+
+ +**表 3** 测试类型说明 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

测试类型名称

+

测试类型定义

+

Function

+

验证被测对象提供给用户的业务功能实现正确性的测试项,这里的“用户”可以是终端用户或开发者,功能包括业务功能及平台功能

+

Performance

+

验证被测对象在特定预置条件/负载模型下的处理能力的测试项,“处理能力”一般以单位时间内可处理的业务量来衡量,如呼叫/秒,帧率/秒,事件处理量/秒等

+

Power

+

验证被测对象在特定预置条件/负载模型下在一定时间内能源消耗量的测试项

+

Reliability

+

验证被测对象在正常/异常输入情况下,或业务量压力和长时间连续运行压力情况下业务表现的测试项,含稳定性、压力、故障注入、Monkey测试项

+

Security

+

验证系统对恶意威胁的防护能力,威胁包括但不限于未授权访问、使用、泄露、破坏、修改、毁灭,以保障信息的机密性、完整性和可用性; 验证系统对用户隐私的保护能力,保障用户的隐私数据被收集、使用、保有、披露和处置符合法律规范,保障用户的隐私权; 验证对各类安全规范的遵从情况,如安全设计规范、安全红线、工信部安全认证规范等,保障安全相关法律法规的合规。

+

Global

+

验证被测对象在是否具有国际化数据支持和本地化能力的测试项,包括语言显示、输入/输出习惯、时间显示、区域特性如货币时间禁忌等等

+

Compatibility

+

当被测对象为应用时,包括被测对象对于自身数据的后向兼容性、对于系统的前后向兼容性、对于不同用户数据(如播放器之音频文件格式/智能短信之用户短信内容)的兼容性测试项; 当被测对象为系统时,包括被测系统对于系统自身数据的后向兼容性、以及对于生态中常用应用的兼容性测试项;当被测对象为软件时,包括被测系统对于相关的硬件的兼容性;

+

User

+

验证被测对象在真实用户场景下的用户体验感受的测试项,注意此种情况下没有客观的“正确”与“失败”,所有的结论及评价都应该来自于用户

+

Standard

+

验证被测对象对于行业及公司内标准/协议/规范的遵从情况的测试项,注意此处的“标准”不包含任何安全标准,针对安全标准的测试项划归为“安全测试”类型

+

Safety

+

验证被测对象的Safety属性,避免产品可能对人身安全、健康以及产品本身带来的危害。

+

Resilience

+

验证被测对象的韧性属性,确保系统受攻击时承受并保持在有定义的运行状态(包括降级)、恢复并适应攻击以保障Mission达成。

+
+ +## 用例开发指导 + +根据测试设备选择测试框架和对应测试用例语言。 + +**表 4** 设备和测试框架、开发语言对应关系 + + + + + + + + + + + + + + + + + + + + + + + + +

设备

+

测试框架

+

语言

+

轻量系统类设备

+

hctest

+

c

+

小型系统类设备

+

hcpptest

+

c++

+

标准系统类设备

+

HJUnit、hcpptest

+

java、c++

+

大型系统类设备

+

HJUnit、hcpptest

+

java、c++

+
+ +### C语言用例开发编译指导(适用于轻量系统类设备产品用例开发) + +**示例:轻量系统类设备测试用例开发** + +当前使用的测试框架是hctest,hctest测试框架支持使用C语言编写测试用例,是在开源测试框架unity的基础上进行增强和适配。 + +1. 用例目录规范:测试用例存储到test/xts/acts仓中 + + ``` + ├── acts + │ └──subsystem_lite + │ │ └── module_hal + │ │ │ └── BUILD.gn + │ │ │ └── src + │ └──build_lite + │ │ └── BUILD.gn + ``` + +2. src目录下用例编写样例。 + + 1.引用测试框架 + + ``` + #include "hctest.h" + ``` + + 2. 使用宏定义LITE\_TEST\_SUIT定义子系统、模块、测试套件名称 + + ``` + /** + * @brief register a test suit named "IntTestSuite" + * @param test subsystem name + * @param example module name + * @param IntTestSuite test suit name + */ + LITE_TEST_SUIT(test, example, IntTestSuite); + ``` + + 3. 定义Setup与TearDown + + 命名方式:测试套件名称+Setup,测试套件名称+TearDown。 + + Setup与TearDown必须存在,可以为空函数。 + + 4. 使用宏定义LITE\_TEST\_CASE写测试用例 + + 包括三个参数:测试套件名称,测试用例名称,用例属性(测试类型、用例粒度、用例级别)。 + + ``` + LITE_TEST_CASE(IntTestSuite, TestCase001, Function | MediumTest | Level1) + { + //do something + }; + ``` + + 5. 使用宏定义 RUN\_TEST\_SUITE注册测试套件 + + ``` + RUN_TEST_SUITE(IntTestSuite); + ``` + +3. 测试模块的配置文件(BUILD.gn)样例: + + 在每个测试模块目录下新建BUILD.gn编译文件,用于指定编译后静态库的名称、依赖的头文件、依赖的库等;具体写法如下: + + ``` + import("//test/xts/tools/lite/build/suite_lite.gni") + hctest_suite("ActsDemoTest") { + suite_name = "acts" + sources = [ + "src/test_demo.c", + ] + include_dirs = [ ] + cflags = [ "-Wno-error" ] + } + ``` + +4. acts下BUILD.gn增加编译选项。 + + 需要将测试模块加入到acts目录下的编译脚本中,编译脚本路径:test/xts/acts/build\_lite/BUILD.gn。 + + ``` + lite_component("acts") { + ... + if(board_name == "liteos_m") { + features += [ + ... + "//xts/acts/subsystem_lite/module_hal:ActsDemoTest" + ] + } + } + ``` + +5. 测试套件编译命令。 + + 随版本编译,debug版本编译时会同步编译acts测试套件 + + >![](figures/icon-note.gif) **说明:** + >acts测试套件编译中间件为静态库,最终链接到版本镜像中 。 + + +### C语言用例执行指导(适用于轻量系统类设备产品用例开发) + +**示例:轻量系统类设备测试用例执行** + +将版本镜像烧录进开发板。 + +**测试步骤** + +1. 使用串口工具登录开发板,并保存串口打印信息。 +2. 重启设备,查看串口日志。 + +**测试结果分析指导** + +基于串口打印日志进行分析; + +每个测试套件执行以Start to run test suite开始,以xx Tests xx Failures xx Ignored结束。 + +### C++语言用例开发编译指导(适用于小型系统类设备、标准系统类设备、大型系统类设备用例开发) + +**示例:小型系统类设备测试用例开发** + +当前使用的测试框架是hcpptest,hcpptest测试框架是在开源的googletest测试框架的基础上进行的增强和适配。 + +1. 规范用例目录:测试用例存储到test/xts/acts仓中。 + + ``` + ├── acts + │ └──subsystem_lite + │ │ └── module_posix + │ │ │ └── BUILD.gn + │ │ │ └── src + │ └──build_lite + │ │ └── BUILD.gn + ``` + +2. 测试模块src下用例编写样例: + + 1. 引用测试框架: + + 需要引用gtest.h 如:\#include "gtest/gtest.h" + + ``` + #include "gtest/gtest.h" + ``` + + 2. 定义Setup与TearDown + + ``` + using namespace std; + using namespace testing::ext; + class TestSuite: public testing::Test { + protected: + // Preset action of the test suite, which is executed before the first test case + static void SetUpTestCase(void){ + } + // Test suite cleanup action, which is executed after the last test case + static void TearDownTestCase(void){ + } + // Preset action of the test case + virtual void SetUp() + { + } + // Cleanup action of the test case + virtual void TearDown() + { + } + }; + ``` + + 3. 使用宏定义HWTEST或HWTEST\_F写测试用例 + + 普通测试用例的定义:HWTEST(测试套名称, 测试用例名称, 用例标注)。 + + 包含SetUp和TearDown的测试用例的定义 :HWTEST\_F(测试套名称, 测试用例名称,用例标注)。 + + 宏定义包括三个参数:测试套件名称,测试用例名称,用例属性(测试类型、用例粒度、用例级别)。 + + ``` + HWTEST_F(TestSuite, TestCase_0001, Function | MediumTest | Level1) { + // do something + } + ``` + +3. 测试模块下用例配置文件(BUILD.gn)样例: + + 每个测试模块目录下新建BUILD.gn编译文件,用于指定编译后可执行文件的名称、依赖的头文件、依赖的库等;具体写法如下。每个测试模块将独立编译成.bin可执行文件, 该文件可直接mount到单板上进行测试。 + + 举例: + + ``` + import("//test/xts/tools/lite/build/suite_lite.gni") + hcpptest_suite("ActsDemoTest") { + suite_name = "acts" + sources = [ + "src/TestDemo.cpp" + ] + + include_dirs = [ + "src", + ... + ] + deps = [ + ... + ] + cflags = [ "-Wno-error" ] + } + + ``` + +4. acts目录下增加编译选项(BUILD.gn)样例: + + 将测试模块加入到acts目录下的编译脚本中,编译脚本为:test/xts/acts/build\_lite/BUILD.gn。 + + ``` + lite_component("acts") { + ... + else if(board_name == "liteos_a") { + features += [ + ... + "//xts/acts/subsystem_lite/module_posix:ActsDemoTest" + ] + } + } + ``` + +5. 测试套件编译命令。 + + 随版本编译,debug版本编译时会同步编译acts测试套件 + + >![](figures/icon-note.gif) **说明:** + >小型系统类设备acts独立编译成可执行文件(bin格式), 在编译产物的suites\\acts目录下归档。 + + +### C++语言用例执行指导(适用于小型系统类设备、标准系统类设备、大型系统类设备用例开发) + +**示例:小型系统类设备测试用例执行** + +目前的用例执行采用nfs共享的方式,mount到单板去执行。 + +**环境搭建** + +1. 使用有限网线或无线将开发板与PC进行连接。 +2. 开发板配置IP、子网掩码、网关,确保开发板与PC处于同一个网段。 +3. PC安装nfs服务器并完成注册,启动nfs服务。 +4. 开发板配置mount命令,确保开发板可以访问PC端的nfs共享文件。 + + 格式:mount \[nfs服务器IP\]:\[/nfs共享目录\] \[/开发板目录\] nfs + + 举例: + + ``` + mount 192.168.1.10:/nfs /nfs nfs + ``` + + +**用例执行** + +测试套件执行 ActsDemoTest.bin 触发用例执行,基于串口打印日志进行分析。 + +## 相关仓 + +[XTS认证子系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/XTS%E8%AE%A4%E8%AF%81%E5%AD%90%E7%B3%BB%E7%BB%9F.md) + +[xts\_acts](https://gitee.com/openharmony/xts_acts/blob/master/README_zh.md) + +**xts\_tools** + diff --git a/build.sh b/lite/build.sh similarity index 100% rename from build.sh rename to lite/build.sh diff --git a/build/common.gni b/lite/build/common.gni similarity index 100% rename from build/common.gni rename to lite/build/common.gni diff --git a/lite/build/suite.py b/lite/build/suite.py new file mode 100644 index 0000000..3cf556e --- /dev/null +++ b/lite/build/suite.py @@ -0,0 +1,273 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" +Copyright (c) 2021 Huawei Device Co., Ltd. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + + +import os +import sys +import argparse +import re +import subprocess +import xml.dom.minidom +from xml.parsers.expat import ExpatError +from string import Template +import utils +import json +import shutil +import platform + + +class SuiteModuleBuilder: + """ + To Build Suite Module + @arguments(build_target_name, target_file...) + """ + + def __init__(self, arguments): + self.arguments = arguments + self.args = None + + def build_module(self): + """ + build_target_name='wifiaware_test', + javalib_file=None, + project_path='xxx/communication_lite/wifiaware', + project_type='hctest', + source_path='xxx/x.c,xxx/x.c + subsystem_name='communication', + suite_filename='libwifiaware_test.a', + suite_out_paths='out/x/suites/acts/testcases/communication,' + target_file='xxxx/libs/libmodule_wifiaware_test.a', + test_xml='xxx/Test.json' + :return: + """ + + parser = argparse.ArgumentParser() + parser.add_argument('--build_target_name', help='', required=False) + parser.add_argument('--target_file', help='', required=False) + parser.add_argument('--hap_name', help='', required=False) + parser.add_argument('--project_path', help='', required=True) + parser.add_argument('--test_xml', help='', required=False) + parser.add_argument('--project_type', help='', required=True) + parser.add_argument('--suite_out_paths', help='', required=True) + parser.add_argument('--suite_filename', help='', required=True) + parser.add_argument('--subsystem_name', help='', required=False) + parser.add_argument('--build_root_path', help='', required=False) + parser.add_argument('--hap_sign', help='', required=False) + self.args = parser.parse_args(self.arguments) + + + for _suite_out_file in self.args.suite_out_paths.split(","): + if not _suite_out_file: + continue + if self.args.project_type == "pythontest": + _out_file = _suite_out_file + else: + _out_file = os.path.join(_suite_out_file, + self.args.suite_filename) + if self.args.project_type == "pythontest": + utils.copy_file(output=_out_file, + source_dirs=self.args.target_file, + to_dir=True) + elif self.args.project_type == "open_source_test": + utils.copy_file(output=_out_file, + sources=self.args.target_file, + to_dir=True) + elif self.args.project_type == "hjsunit": + utils.build_js_hap(self.args.project_path, self.args. + suite_out_paths, self.args.hap_name) + elif self.args.project_type != "hctest": + utils.copy_file(output=_out_file, + sources=self.args.target_file, + to_dir=False) + + _testsuite_name = self.args.suite_filename + _matcher = re.match(r"(lib|libmodule_)?(\S+)\.\S+", + _testsuite_name) + if _matcher: + _testsuite_name = _matcher.group(2) + if self.args.project_type != "open_source_test": + _config_file = os.path.join(_suite_out_file, + _testsuite_name + ".json") + else: + _config_file = os.path.join(_out_file, + _testsuite_name + ".json") + utils.record_testmodule_info(self.args.build_target_name, + _testsuite_name, + self.args.subsystem_name, + _suite_out_file) + _test_xml = self.args.test_xml + if _test_xml and os.path.exists(_test_xml): + utils.copy_file(output=_config_file, sources=_test_xml, + to_dir=False) + else: + self._generate_xml_by_template(_test_xml, _testsuite_name, + _config_file) + + @staticmethod + def _record_testmodule_info(build_target_name, module_name, + subsystem_name, suite_out_dir): + if not build_target_name or not subsystem_name: + print( + 'build_target_name or subsystem_name of testmodule "%s" ' + 'is invalid!' % module_name) + return + module_info_dir = os.path.dirname(suite_out_dir) + module_info_list_file = os.path.join(module_info_dir, + 'module_info.json') + module_info_data = {} + if os.path.exists(module_info_list_file): + try: + with open(module_info_list_file, 'r') as module_file: + module_info_data = json.load(module_file) + except ValueError: + print("NO json object could be decoded but continue") + module_info = {'subsystem': subsystem_name, + 'build_target_name': build_target_name} + module_info_data[module_name] = module_info + with open(module_info_list_file, 'w') as out_file: + json.dump(module_info_data, out_file) + + def _generate_xml_by_template(self, test_xml, module_name, + config_file): + index = test_xml.rfind(".json") + tmpl_file = test_xml[:index] + ".tmpl" + if not os.path.exists(tmpl_file): + raise Exception( + "Can't find the Test.json or Test.tmpl in the " + "path %s " % os.path.dirname( + test_xml)) + tmpl_content = utils.read_file(tmpl_file) + values = {"module": module_name, "subsystem": self.args.subsystem_name} + xml_content = Template(tmpl_content).substitute(values) + utils.write_file(config_file, xml_content, False) + + @staticmethod + def _check_file_exist(file_path): + if not os.path.exists(file_path): + raise Exception("File [%s] does not exist!" % file_path) + + +class XDeviceBuilder: + """ + To build XTS as a egg package + @arguments(project_dir, output_dirs) + """ + + def __init__(self, arguments): + parser = argparse.ArgumentParser() + parser.add_argument('--project_dir', help='', required=True) + parser.add_argument('--output_dirs', help='', required=True) + self.args = parser.parse_args(arguments) + + def build_xdevice(self): + """ + build xdevice package + :return: + """ + command = [utils.get_python_cmd(), "setup.py", "install", "--user"] + factory_script = os.path.join(self.args.project_dir, "factory.sh") + if os.path.exists(factory_script): + os.chmod(factory_script, 0o775) + command = factory_script + try: + subprocess.check_call(command, cwd=self.args.project_dir) + except subprocess.CalledProcessError as exc: + print('returncode: {} cmd: {} output: {}'.format( + exc.returncode, exc.cmd, exc.output)) + + dist_dir = os.path.join(self.args.project_dir, 'dist') + run_scripts = ",".join( + [os.path.join(self.args.project_dir, "run.bat"), + os.path.join(self.args.project_dir, "run.sh")]) + config_dir = os.path.join(self.args.project_dir, "config") + res_dir = os.path.join(self.args.project_dir, "resource") + for tool_dir in self.args.output_dirs.split(","): + if tool_dir: + utils.copy_file(output=tool_dir, source_dirs=dist_dir, + to_dir=True) + root_dir = os.path.dirname(tool_dir) + utils.copy_file(output=root_dir, sources=run_scripts, + to_dir=True) + to_dir = os.path.join(root_dir, "config") + utils.copy_file(output=to_dir, source_dirs=config_dir, + to_dir=True) + utils.copy_file(os.path.join(root_dir, "resource"), + source_dirs=res_dir) + if not os.path.exists(os.path.join( + root_dir, "resource", "tools")): + os.mkdir(os.path.join(root_dir, "resource", "tools")) + return 0 + + +class SuiteArchiveBuilder: + def __init__(self, arguments): + self.module_info_dir = None + self.arguments = arguments + + def archive_suite(self): + parser = argparse.ArgumentParser() + parser.add_argument('--suite_path', help='', required=True) + parser.add_argument('--build_enabled', help='', required=True) + args = parser.parse_args(self.arguments) + if not args.build_enabled.lower() == 'true': + print('build hit not enabled, skip making archive') + return 0 + + suite_path = args.suite_path + if not os.path.isdir(suite_path): + raise Exception("[%s] does not exist" % suite_path) + + archive_name = os.path.basename(suite_path) + suite_root_path = os.path.dirname(suite_path) + shutil.make_archive(suite_path, "zip", suite_root_path, archive_name) + return 0 + + +ACTION_MAP = {"build_module": "SuiteModuleBuilder", + "build_xdevice": "XDeviceBuilder", + "archive_suite": "SuiteArchiveBuilder", + } + + +def _find_action(action, arguments): + class_name = ACTION_MAP[action] + if not class_name: + raise ValueError('Unsupported operation: %s' % action) + + this_module = sys.modules[__name__] + class_def = getattr(this_module, class_name, None) + if not class_def: + raise ValueError( + 'Unsupported operation(No Implementation Class): %s' % action) + class_obj = class_def(arguments) + func = getattr(class_obj, action, None) + if not func: + raise ValueError( + 'Unsupported operation(No Implementation Method): %s' % action) + return func + + +def main(arguments): + action = arguments[0] + args = arguments[1:] + func = _find_action(action, args) + func() + return 0 + + +if __name__ == '__main__': + sys.exit(main(sys.argv[1:])) diff --git a/build/suite_lite.gni b/lite/build/suite_lite.gni similarity index 100% rename from build/suite_lite.gni rename to lite/build/suite_lite.gni diff --git a/lite/build/utils.py b/lite/build/utils.py new file mode 100755 index 0000000..5f3bf25 --- /dev/null +++ b/lite/build/utils.py @@ -0,0 +1,388 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Copyright (c) 2021 Huawei Device Co., Ltd. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +import os +import fnmatch +import sys +import argparse +import json +import platform +import subprocess + +import distutils.dir_util as dir_util +import distutils.file_util as file_util +from distutils.errors import DistutilsError + + +# all sub system list, must be lowercase. +_SUB_SYSTEM_LIST = [ + "kernel", + "hiviewdfx", + "communication", + "security", + "update", + "sstsutils", + "utils", + "multimedia", + "hdf", + "aafwk", + "appexecfwk", + "distributed_schedule", + "startup", + "sensors", + "sample", + "iot_hardware", + "open_posix_testsuite", + "graphic", + "ace", + "applications", + "ai", + "global", + "telephony", + "dcts" +] + +_NO_FILTE_SUB_SYSTEM_LIST = [ + "applications", + "kernel", + "open_posix_testsuite", + "sample", + "telephony", + "dcts", + "hiviewdfx", + "communication", + "security", + "update", + "sstsutils", + "hdf", + "distributed_schedule" +] + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--method_name', help='', required=True) + parser.add_argument('--arguments', help='', + required=True) # format key=value#key=value + args = parser.parse_args() + this_module = sys.modules[__name__] + method = getattr(this_module, args.method_name) + arguments = {} + for argument in args.arguments.split("#"): + key_value = argument.strip().split("=") + if len(key_value) != 2: + raise ValueError( + "The arguments' format is 'key=value#key=value'. Wrong format:" + " " + argument) + arguments.setdefault(key_value[0].strip(), key_value[1].strip()) + method(**arguments) + return 0 + + +def read_file(input_file): + if not os.path.exists(input_file): + return "" + + with open(input_file, 'r') as input_f: + content = input_f.read().strip() + return content + + +def write_file(output_file, content, append): + file_dir = os.path.dirname(os.path.abspath(output_file)) + if not os.path.exists(file_dir): + os.makedirs(file_dir) + mode = 'a+' if append else 'w' + with open(output_file, mode) as output_f: + output_f.write("%s\n" % content) + + +def copy_file(output, sources="", source_dirs="", to_dir=True): + """ + copy source files or source dir to output. + if sources is not empty, the output can be file(will be created + automatically) + or directory(must be exist). + :param output: If source_dirs is not empty, output must be directory. + :param sources: source files is separated by dot + :param source_dirs: source directory is separated by dot + :param to_dir: output is directory or not + :return: + """ + if not sources and not source_dirs: + raise Exception( + "sources or source_dirs parameter must be specified one") + _output = output.strip() + _sources = sources.strip() + _source_dirs = source_dirs.strip() + _parent_output = os.path.dirname(_output) + try: + if to_dir and not os.path.exists(_output): + os.makedirs(_output) + if not to_dir and not os.path.exists(_parent_output): + os.makedirs(_parent_output) + except OSError: + if not os.path.isdir(_output): + raise + try: + if _sources: + _copy_files(_sources.split(","), _output) + + if _source_dirs: + _copy_dir(_source_dirs.split(","), _output) + except DistutilsError: + print("ignore file exist error") + return 0 + + +def _copy_files(sources, output): + copy_set = set() + for source_file in sources: + source_file = source_file.strip() + if os.path.isfile(source_file) and os.path.exists(source_file): + # if same file name exist, add dir path + if os.path.basename(source_file) in copy_set: + new_output = os.path.join(output, os.path.dirname(source_file). + split(os.sep)[-1]) + if not os.path.exists(new_output): + os.makedirs(new_output) + file_util.copy_file(source_file, new_output) + else: + file_util.copy_file(source_file, output) + copy_set.add(os.path.basename(source_file)) + + +def _copy_dir(sources, output): + for source_file in sources: + source_file = source_file.strip() + if os.path.isdir(source_file): + dir_util.copy_tree(source_file, output) + + +def gen_suite_out(suite_output_prefix, suite_names, out_suffix): + outputs = [] + _suite_output_prefix = suite_output_prefix.strip() + _dirname_suffix = out_suffix.strip().rstrip(os.sep) + for suite in suite_names.split(","): + path = "%s%s/%s" % ( + _suite_output_prefix, suite.strip(), _dirname_suffix) + outputs.append(path) + print(path) + return outputs + + +def get_subsystem_name(path): + subsystem_name = "" + for subsystem in _SUB_SYSTEM_LIST: + subsystem_path = "/" + subsystem + "/" + _path = path.lower() + if subsystem_path in _path: + subsystem_name = subsystem + break + subsystem_path = "/" + subsystem + "_lite/" + if subsystem_path in _path: + subsystem_name = subsystem + break + sys.stdout.write(subsystem_name) + return subsystem_name + + +def get_modulename_by_buildtarget(module_list_file, build_target): + if not os.path.exists(module_list_file): + return "" + with open(module_list_file, "r") as module_file: + module_info_data = json.load(module_file) + for module in module_info_data: + if module_info_data[module]["build_target_name"] == build_target: + sys.stdout.write(module) + return module + return "" + + +def glob(path, filename_pattern): + files = [] + for dir_path, _, files in os.walk(path): + for filename in fnmatch.filter(files, filename_pattern): + files.append(os.path.join(dir_path, filename)) + return files + + +def filter_by_subsystem(testsuites, product_json): + product_info = {} + filtered_features = [] + subs_comps = {} + # parses product json to obtain all the subsystem name + if os.path.exists(product_json): + try: + with open(product_json, 'r') as product_info: + product_info = json.load(product_info) + except ValueError: + print("NO json object could be decoded.") + subsystem_info = product_info.get("subsystems") + for subsystem in subsystem_info: + subs_comps[subsystem.get("subsystem")] = \ + subsystem.get("components", []) + + feature_list = testsuites.split(",") + for feature in feature_list: + # if subsytem name match + subsystem = get_subsystem_name_no_output(feature) + if subsystem in _NO_FILTE_SUB_SYSTEM_LIST: + filtered_features.append(feature) + print(feature) + elif subsystem in subs_comps: + components = subs_comps.get(subsystem, []) + if check_component(feature, components): + filtered_features.append(feature) + print(feature) + return filtered_features + + +def get_subsystem_name_no_output(path): + subsystem_name = "" + for subsystem in _SUB_SYSTEM_LIST: + subsystem_path = "/" + subsystem + _path = path.lower() + if subsystem_path in _path: + subsystem_name = subsystem + break + subsystem_path = "/" + subsystem + "_lite" + if subsystem_path in _path: + subsystem_name = subsystem + break + return subsystem_name + + +def check_component(path, components): + for component in components: + component_name = component.get("component", "") + component_name = component_name.replace("_lite", "") + if component_name in path or "{}_hal".format(component_name) in path \ + or "{}_posix".format(component_name) in path: + return True + return False + + +def get_python_cmd(): + major, _, _ = platform.python_version_tuple() + if major == "3": + return "python" + else: + return "python3" + + +def record_testmodule_info(build_target_name, module_name, + subsystem_name, suite_out_dir, same_file=False): + if not build_target_name or not subsystem_name: + print( + 'build_target_name or subsystem_name of testmodule "%s" ' + 'is invalid!' % module_name) + return + if same_file: + module_info_list_file = os.path.join(suite_out_dir, 'module_info.json') + else: + module_info_list_file = os.path.join(suite_out_dir, + '{}_module_info.json'.format + (build_target_name)) + module_info_data = {} + if os.path.exists(module_info_list_file): + try: + with open(module_info_list_file, 'r') as module_file: + module_info_data = json.load(module_file) + except ValueError: + print("NO json object could be decoded but continue") + module_info = {'subsystem': subsystem_name, + 'build_target_name': build_target_name} + module_info_data[module_name] = module_info + with open(module_info_list_file, 'w') as out_file: + json.dump(module_info_data, out_file) + + +def record_test_component_info(out_dir, version): + if not os.path.exists(out_dir): + os.makedirs(out_dir) + all_module_file = os.path.join(out_dir, 'module_info.json') + all_module_data = {} + for root, dirs, files in os.walk(out_dir): + for file in files: + if file.endswith("module_info.json"): + with open(os.path.join(root, file), 'r') as json_data: + module_data = json.load(json_data) + all_module_data.update(module_data) + os.remove(os.path.join(root, file)) + with open(all_module_file, 'w') as out_file: + json.dump(all_module_data, out_file) + + test_component_file = os.path.join(out_dir, 'test_component.json') + test_component_data = {'version': version, } + with open(test_component_file, 'w') as out_file: + json.dump(test_component_data, out_file) + + +def get_target_modules(all_features): + feature_list = [] + if all_features: + for feature in all_features.split(","): + if feature: + feature_list.append(feature) + print(feature) + return feature_list + + +def cmd_popen(cmd): + proc = subprocess.Popen(cmd) + proc.wait() + ret_code = proc.returncode + if ret_code != 0: + raise Exception("{} failed, return code is {}".format(cmd, ret_code)) + + +def build_js_hap(project_path, out_put_dir, hap_name): + if not check_env(): + return + gradle_dir = os.path.join(project_path, "gradle") + os.chdir(gradle_dir) + build_clean = ["gradle", "clean"] + cmd_popen(build_clean) + build_cmd = ["gradle", "entry:packageDebugHap"] + cmd_popen(build_cmd) + gralde_output_dir = os.path.join(gradle_dir, "entry", "build", "outputs") + if os.path.exists(gralde_output_dir): + for root, _, files in os.walk(gralde_output_dir): + for file in files: + if file.endswith(".hap"): + file_util.copy_file(os.path.join(root, file), + os.path.join(out_put_dir.rstrip(','), + hap_name)) + return + + + +def check_env(): + """ + check all the env for js hap build + return: return true if all env ready, otherwise return false + """ + env_list = ['OHOS_SDK_HOME', 'NODE_HOME', 'GRADLE_HOME'] + for env in env_list: + if not os.environ.get(env): + print("the env {} not set, skip build!".format(env)) + return False + else: + return True +if __name__ == '__main__': + sys.exit(main()) diff --git a/checksum/BUILD.gn b/lite/checksum/BUILD.gn similarity index 100% rename from checksum/BUILD.gn rename to lite/checksum/BUILD.gn diff --git a/checksum/include/checksum_file.h b/lite/checksum/include/checksum_file.h similarity index 100% rename from checksum/include/checksum_file.h rename to lite/checksum/include/checksum_file.h diff --git a/checksum/include/checksum_sha256.h b/lite/checksum/include/checksum_sha256.h similarity index 100% rename from checksum/include/checksum_sha256.h rename to lite/checksum/include/checksum_sha256.h diff --git a/checksum/src/checksum_file.c b/lite/checksum/src/checksum_file.c similarity index 100% rename from checksum/src/checksum_file.c rename to lite/checksum/src/checksum_file.c diff --git a/checksum/src/checksum_sha256.c b/lite/checksum/src/checksum_sha256.c similarity index 100% rename from checksum/src/checksum_sha256.c rename to lite/checksum/src/checksum_sha256.c diff --git a/checksum/src/main.c b/lite/checksum/src/main.c similarity index 100% rename from checksum/src/main.c rename to lite/checksum/src/main.c diff --git a/lite/figures/icon-caution.gif b/lite/figures/icon-caution.gif new file mode 100644 index 0000000000000000000000000000000000000000..6e90d7cfc2193e39e10bb58c38d01a23f045d571 GIT binary patch literal 580 zcmV-K0=xZ3Nk%w1VIu$?0Hp~4{QBgqmQ+MG9K51r{QB&)np^||1PlfQ%(86!{`~yv zv{XhUWKt}AZaiE{EOcHp{O-j3`t;<+eEiycJT4p@77X;(jQsMfB$R?oG%6hQ z+MMLZbQBH@)Vg&1^3?qHb(5!%>3r0+`eq=&V&E}0Dypi0000000000 z00000A^8LW000R9EC2ui03!e$000L5z=Uu}ED8YtqjJd<+B}(9bIOb$3-31_h|V>=0A{ z1Hh0#H30>fNT})^fRU_83uewx9oRr{f{Sx1Ml`t)EQ zGkHZ67&~y{W5Jpq4H_WfuLxp*3<7O}GEl;1ESe36fLNs=B0&LQM1Buf(R)qg(BRd`t1OPjI1m_q4 literal 0 HcmV?d00001 diff --git a/lite/figures/icon-danger.gif b/lite/figures/icon-danger.gif new file mode 100644 index 0000000000000000000000000000000000000000..6e90d7cfc2193e39e10bb58c38d01a23f045d571 GIT binary patch literal 580 zcmV-K0=xZ3Nk%w1VIu$?0Hp~4{QBgqmQ+MG9K51r{QB&)np^||1PlfQ%(86!{`~yv zv{XhUWKt}AZaiE{EOcHp{O-j3`t;<+eEiycJT4p@77X;(jQsMfB$R?oG%6hQ z+MMLZbQBH@)Vg&1^3?qHb(5!%>3r0+`eq=&V&E}0Dypi0000000000 z00000A^8LW000R9EC2ui03!e$000L5z=Uu}ED8YtqjJd<+B}(9bIOb$3-31_h|V>=0A{ z1Hh0#H30>fNT})^fRU_83uewx9oRr{f{Sx1Ml`t)EQ zGkHZ67&~y{W5Jpq4H_WfuLxp*3<7O}GEl;1ESe36fLNs=B0&LQM1Buf(R)qg(BRd`t1OPjI1m_q4 literal 0 HcmV?d00001 diff --git a/lite/figures/icon-note.gif b/lite/figures/icon-note.gif new file mode 100755 index 0000000000000000000000000000000000000000..6314297e45c1de184204098efd4814d6dc8b1cda GIT binary patch literal 394 zcmZ?wbhEHblx7fPSjxcg=ii?@_wH=jwxy=7CMGH-B`L+l$wfv=#>UF#$gv|VY%C^b zCQFtrnKN(Bo_%|sJbO}7RAORe!otL&qo<>yq_Sq+8Xqqo5h0P3w3Lvb5E(g{p01vl zxR@)KuDH0l^z`+-dH3eaw=XqSH7aTIx{kzVBN;X&hha0dQSgWuiw0NWUvMRmkD|> literal 0 HcmV?d00001 diff --git a/lite/figures/icon-notice.gif b/lite/figures/icon-notice.gif new file mode 100644 index 0000000000000000000000000000000000000000..86024f61b691400bea99e5b1f506d9d9aef36e27 GIT binary patch literal 406 zcmV;H0crk6Nk%w1VIu$@0J8u9|NsB@_xJDb@8;&_*4Ea}&d#;9wWXz{jEszHYim+c zQaU<1At50E0000000000A^8Le000gEEC2ui03!e%000R7038S%NU)&51O^i-Tu6`s z0)`MFE@;3YqD6xSC^kTNu_J>91{PH8XfZ(p1pp2-SU@u3#{mEUC}_}tg3+I#{z}{Ok@D_ZUDg- zt0stin4;pC8M{WLSlRH*1pzqEw1}3oOskyNN?j;7HD{BBZ*OEcv4HK!6Bk6beR+04 z&8}k>SkTusVTDmkyOz#5fCA$JTPGJVQvr3uZ?QzzPQFvD0rGf_PdrcF`pMs}p^BcF zKtKTd`0wipR%nKN&Wj+V}pX;WC3SdJV!a_8Qi zE7z`U*|Y^H0^}fB$R?oG%6hQ z+MMLZbQBH@)Vg&1^3?qHb(5!%>3r0+`eq=&V&E}0Dypi0000000000 z00000A^8LW000R9EC2ui03!e$000L5z=Uu}ED8YtqjJd<+B}(9bIOb$3-31_h|V>=0A{ z1Hh0#H30>fNT})^fRU_83uewx9oRr{f{Sx1Ml`t)EQ zGkHZ67&~y{W5Jpq4H_WfuLxp*3<7O}GEl;1ESe36fLNs=B0&LQM1Buf(R)qg(BRd`t1OPjI1m_q4 literal 0 HcmV?d00001 diff --git a/hcpptest/BUILD.gn b/lite/hcpptest/BUILD.gn similarity index 100% rename from hcpptest/BUILD.gn rename to lite/hcpptest/BUILD.gn diff --git a/hctest/BUILD.gn b/lite/hctest/BUILD.gn similarity index 100% rename from hctest/BUILD.gn rename to lite/hctest/BUILD.gn diff --git a/hctest/include/hctest.h b/lite/hctest/include/hctest.h similarity index 100% rename from hctest/include/hctest.h rename to lite/hctest/include/hctest.h diff --git a/hctest/include/hctest_internal.h b/lite/hctest/include/hctest_internal.h similarity index 100% rename from hctest/include/hctest_internal.h rename to lite/hctest/include/hctest_internal.h diff --git a/hctest/include/unity_config.h b/lite/hctest/include/unity_config.h similarity index 100% rename from hctest/include/unity_config.h rename to lite/hctest/include/unity_config.h diff --git a/hctest/src/hctest.c b/lite/hctest/src/hctest.c similarity index 100% rename from hctest/src/hctest.c rename to lite/hctest/src/hctest.c diff --git a/hctest/src/hctest_service.c b/lite/hctest/src/hctest_service.c similarity index 100% rename from hctest/src/hctest_service.c rename to lite/hctest/src/hctest_service.c diff --git a/others/query/BUILD.gn b/lite/others/query/BUILD.gn similarity index 100% rename from others/query/BUILD.gn rename to lite/others/query/BUILD.gn diff --git a/others/query/src/QueryMain.cpp b/lite/others/query/src/QueryMain.cpp similarity index 100% rename from others/query/src/QueryMain.cpp rename to lite/others/query/src/QueryMain.cpp diff --git a/reliability/JSPressTest.js b/lite/reliability/JSPressTest.js similarity index 100% rename from reliability/JSPressTest.js rename to lite/reliability/JSPressTest.js diff --git a/reliability/NativePressTest.py b/lite/reliability/NativePressTest.py similarity index 100% rename from reliability/NativePressTest.py rename to lite/reliability/NativePressTest.py diff --git a/reliability/RebootPressTest.py b/lite/reliability/RebootPressTest.py similarity index 100% rename from reliability/RebootPressTest.py rename to lite/reliability/RebootPressTest.py diff --git a/reliability/readme.md b/lite/reliability/readme.md similarity index 100% rename from reliability/readme.md rename to lite/reliability/readme.md diff --git a/reliability/utils.py b/lite/reliability/utils.py similarity index 100% rename from reliability/utils.py rename to lite/reliability/utils.py diff --git a/repackage/auto_jffs2.sh b/lite/repackage/auto_jffs2.sh similarity index 100% rename from repackage/auto_jffs2.sh rename to lite/repackage/auto_jffs2.sh diff --git a/runtest.sh b/lite/runtest.sh similarity index 100% rename from runtest.sh rename to lite/runtest.sh