• Home
Name Date Size #Lines LOC

..--

config/12-May-2024-10691

figures/12-May-2024-

lite/12-May-2024-1816

plugins/12-May-2024-11,1599,397

src/xdevice/12-May-2024-11,7719,380

.gitattributesD12-May-2024631 1615

.gitignoreD12-May-20246 21

BUILD.gnD12-May-2024720 1816

LICENSED12-May-20249.9 KiB178150

OAT.xmlD12-May-20243.8 KiB6310

README.mdD12-May-202410.3 KiB227175

README_zh.mdD12-May-20248.7 KiB225173

run.batD12-May-20241.7 KiB6859

run.shD12-May-20241.7 KiB6439

setup.pyD12-May-20241.8 KiB6036

README.md

1# XDevice<a name="EN-US_TOPIC_0000001083129731"></a>
2
3-   [Introduction](#section15701932113019)
4-   [Directory Structure](#section1791423143211)
5-   [Constraints](#section118067583303)
6-   [Usage](#section2036431583)
7-   [Repositories Involved](#section260848241)
8
9## Introduction<a name="section15701932113019"></a>
10
11XDevice, a core module of the OpenHarmony test framework, provides services on which test case execution depends.
12
13XDevice consists of the following sub-modules:
14
15-   **command**: enables command-based interactions between users and the test platform. It parses and processes user commands.
16-   **config**: sets test framework configurations and provides different configuration options for the serial port connection and USB connection modes.
17-   **driver**: functions as a test case executor, which defines main test steps, such as test case distribution, execution, and result collection.
18-   **report**: parses test results and generates test reports.
19-   **scheduler**: schedules various test case executors in the test framework.
20-   **environment**: configures the test framework environment, enabling device discovery and device management.
21-   **testkit**: provides test tools to implement JSON parsing, network file mounting, etc.
22-   **resource**: provides the device connection configuration file and report template definitions.
23
24## Directory Structure<a name="section1791423143211"></a>
25
26```
27xdevice
28├── config                        # XDevice configuration
29│     ├── user_config.xml         # XDevice environment configuration
30├── src                           # Source code
31│     ├── xdevice
32├── plugins                       # XDevice plugins
33│     ├── ohos                    # OpenHarmony plugins
34|          ├── src                # OpenHarmony plugins source code
35│          └── setup.py           # Installation script of the plugins
36```
37
38## Constraints<a name="section118067583303"></a>
39
40The environment requirements for using this module are as follows:
41
42-   Python version: 3.7.5 or later
43-   pySerial version: 3.3 or later
44-   Paramiko version: 2.7.1 or later
45-   RSA version: 4.0 or later
46
47## Usage<a name="section2036431583"></a>
48
49-   **Installing XDevice**
50    1.  Go to the installation directory of XDevice.
51    2.  Open the console window and run the following command:
52
53        ```
54        python setup.py install
55        ```
56
57
58-   **Installing the extension**
59    1.  Go to the installation directory of the XDevice extension.
60    2.  Open the console and run the following command:
61
62        ```
63        python setup.py install
64        ```
65
66
67-   **Modifying the user\_config.xml file**
68
69    Configure information about your environment in the  **user\_config.xml**  file.
70
71    **1. Configure the environment.**
72
73    -   For devices that support hdc connection, refer to the following note to configure the environment.
74
75        >![](figures/icon-note.gif) **NOTE:**
76        >**ip/port**: IP address and port of a remote device. By default, the parameter is left blank, indicating that the local device \(IP address: 127.0.0.1; port: the one used for hdc startup\) is used as the test device.
77        >**sn**: SN of the test devices specified for command execution. If this parameter is set to  **SN1**, only device SN1 can execute the subsequent  **run**  commands. In this case, other devices are set as  **Ignored**  and not involved in the command execution. You can run the  **list devices**  command and check the value of  **Allocation**  to view the  **sn**  values. You can set multiple SNs and separate each two of them with a semicolon \(;\).
78
79    -   For devices that support serial port connection, refer to the following note to configure the environment.
80
81        >![](figures/icon-note.gif) **NOTE:**
82        >**type**: device connection mode. The  **com**  mode indicates that the device is connected through the serial port.
83        >**label**: device type, for example,  **wifiiot**
84        >**serial**: serial port
85        >-   **serial/com**: serial port for local connection, for example,  **COM20**
86        >-   **serial/type**: serial port type. The value can be  **cmd**  \(serial port for test case execution\) or  **deploy**  \(serial port for system upgrade\).
87        >    For the open-source project, the  **cmd**  and  **deploy**  serial ports are the same, and their  **com**  values are the same too.
88        >   **serial/baud\_rate, data\_bits, stop\_bits**  and  **timeout**: serial port parameters. You can use the default values.
89
90
91    **2. Set the test case directory.**
92
93    **dir**: test case directory
94
95    **3. Mount the NFS.**
96
97    >![](figures/icon-note.gif) **NOTE:**
98    >**server**: NFS mounting configuration. Set the value to  **NfsServer**.
99    >**server/ip**: IP address of the mounting environment
100    >**server/port**: port number of the mounting environment
101    >**server/username**: user name for logging in to the server
102    >**server/password**: password for logging in to the server
103    >**server/dir**: external mount path
104    >**server/remote**: whether the NFS server and the XDevice executor are deployed on different devices. If yes, set this parameter to  **true**. Otherwise, set it to  **false**.
105
106-   **Specify the task type.**
107-   **Start the test framework.**
108-   **Execute test commands.**
109
110    Test framework commands can be classified into three groups:  **help**,  **list**, and  **run**. Among them,  **run**  commands are most commonly used in the instruction sequence.
111
112    **help**
113
114    Queries help information about test framework commands.
115
116    ```
117    help:
118         use help to get information.
119    usage:
120         run:  Display a list of supported run command.
121         list: Display a list of supported device and task record.
122    Examples:
123         help run
124         help list
125    ```
126
127    >![](figures/icon-note.gif) **NOTE:**
128    >**help run**: displays the description of  **run**  commands.
129    >**help list**: displays the description of  **list**  commands.
130
131    **list**
132
133    Displays device information and related task information.
134
135    ```
136    list:
137         This command is used to display device list and task record.
138    usage:
139          list
140          list history
141          list <id>
142    Introduction:
143         list:         display device list
144         list history: display history record of a serial of tasks
145         list <id>:    display history record about task what contains specific id
146    Examples:
147         list
148         list history
149         list 6e****90
150    ```
151
152    >![](figures/icon-note.gif) **NOTE:**
153    >**list**: displays device information.
154    >**list history**: displays historical task information.
155    >**list <id\>**: displays historical information about tasks with specified IDs.
156
157    **run**
158
159    Executes test tasks.
160
161    ```
162    run:
163         This command is used to execute the selected testcases.
164         It includes a series of processes such as use case compilation, execution, and result collection.
165    usage: run [-l TESTLIST [TESTLIST ...] | -tf TESTFILE
166                [TESTFILE ...]] [-tc TESTCASE] [-c CONFIG] [-sn DEVICE_SN]
167                [-rp REPORT_PATH [REPORT_PATH ...]]
168                [-respath RESOURCE_PATH [RESOURCE_PATH ...]]
169                [-tcpath TESTCASES_PATH [TESTCASES_PATH ...]]
170                [-ta TESTARGS [TESTARGS ...]] [-pt]
171                [-env TEST_ENVIRONMENT [TEST_ENVIRONMENT ...]]
172                [-e EXECTYPE] [-t [TESTTYPE [TESTTYPE ...]]]
173                [-td TESTDRIVER] [-tl TESTLEVEL] [-bv BUILD_VARIANT]
174                [-cov COVERAGE] [--retry RETRY] [--session SESSION]
175                [--dryrun] [--reboot-per-module] [--check-device]
176                [--repeat REPEAT]
177                action task
178    Specify tests to run.
179      positional arguments:
180       action                Specify action
181       task                  Specify task name,such as "ssts", "acts", "hits"
182    ```
183
184    >![](figures/icon-note.gif) **NOTE:**
185    >The structure of a basic  **run**  command is as follows:
186    >```
187    >run [task name] -l module1;moudle2
188    >```
189    >**task name**: task type. This parameter is optional. Generally, the value is  **ssts**,  **acts**, or  **hits**.
190    >**-l**: test cases to execute. Use semicolons \(;\) to separate each two test cases.
191    >**module**: module to test. Generally, there is a  **.json**  file of the module in the  **testcases**  directory.
192    >In addition, other parameters can be attached to this command as constraints. Common parameters are as follows:
193    >**-sn**: specifies the devices for test case execution. If this parameter is set to  **SN1**, only device SN1 executes the test cases.
194    >**-c**: specifies a new  **user\_config.xml**  file.
195    >**-rp**: indicates the path where the report is generated. The default directory is  **xxx/xdevice/reports**. Priority of a specified directory is higher than that of the default one.
196    >**-tcpath**: indicates the environment directory, which is  **xxx/xdevice/testcases**  by default. Priority of a specified directory is higher than that of the default one.
197    >**-respath**: indicates the test suite directory, which is  **xxx/xdevice/resource**  by default. Priority of a specified directory is higher than that of the default one.
198    >**--reboot-per-module**: restarts the device before test case execution.
199
200-   **View the execution result.**
201
202    After executing the  **run**  commands, the test framework displays the corresponding logs on the console, and generates the execution report in the directory specified by the  **-rp**  parameter. If the parameter is not set, the report will be generated in the default directory.
203
204    ```
205    Structure of the report directory (the default or the specified one)
206         ├── result # Test case execution results of the module
207         │     ├── module name.xml
208         │     ├──  ... ...
209210         ├── log # Running logs of devices and tasks
211         │     ├── device 1.log
212         │     ├── ... ...
213         │     ├── task.log
214         ├── summary_report.html # Visual report
215         ├── summary_report.html # Statistical report
216         └── ... ...
217    ```
218
219
220## Repositories Involved<a name="section260848241"></a>
221
222[testing subsystem](https://gitee.com/openharmony/docs/blob/master/en/readme/test.md)
223
224**test\_xdevice**
225
226[test\_developertest](https://gitee.com/openharmony/test_developertest/blob/master/README.md)
227

README_zh.md

1# xdevice组件<a name="ZH-CN_TOPIC_0000001083129731"></a>
2
3-   [简介](#section15701932113019)
4-   [目录](#section1791423143211)
5-   [约束](#section118067583303)
6-   [使用](#section2036431583)
7-   [相关仓](#section260848241)
8
9## 简介<a name="section15701932113019"></a>
10
11xdevice是OpenHarmony中为测试框架的核心组件,提供用例执行所依赖的相关服务。
12
13xdevice主要包括以下几个主要模块:
14
15-   command,用户与测试平台命令行交互模块,提供用户输入命令解析,命令处理。
16-   config,测试框架配置模块,提供测试平台串口连接方式和USB连接方式的不同配置选项。
17-   driver,测试用例执行器,提供测试用例分发,执行,结果收集等主要测试步骤定义。
18-   report,测试报告模块,提供测试结果解析和测试报告生成。
19-   scheduler,测试框架调度模块,提供不同类型的测试执行器调度的调度功能。
20-   environment,测试框架的环境配置模块,提供设备发现,设备管理的功能。
21-   testkit,测试框架工具模块,提供json解析,网络文件挂载等操作。
22-   resource,测试框架资源模块,提供设备连接配置文件和报告模板定义。
23
24## 目录<a name="section1791423143211"></a>
25
26```
27xdevice
28├── config                    # xdevice组件配置
29│     ├── user_config.xml     # xdevice环境配置
30├── src                       # 组件源码目录
31│     ├── xdevice
32├── plugins                   # xdevice扩展模块
33|     |—— ohos                # openharmony测试驱动插件
34│           ├── src           # 扩展模块源码
35│           └── setup.py      # ohos扩展模块安装脚本
36```
37
38## 约束<a name="section118067583303"></a>
39
40运行环境要求:
41
42-   python版本\>=3.7.5
43-   pyserial\>=3.3
44-   paramiko\>=2.7.1
45-   rsa\>=4.0
46
47## 使用<a name="section2036431583"></a>
48
49-   **安装xdevice**
50    1.  打开xdevice安装目录。
51    2.  打开控制台,执行如下命令:
52
53        ```
54        python setup.py install
55        ```
56
57
58-   **安装extension**
59    1.  打开extension安装目录。
60    2.  打开控制台,执行如下命令:
61
62        ```
63        python setup.py install
64        ```
65
66
67-   **修改user\_config.xml**
68
69    user\_config.xml是框架提供的用户配置文件,用户可以根据自身环境信息配置相关内容,具体介绍如下:
70
71    **1、environment环境相关配置:**
72
73    -   设备类型一
74
75        >![](figures/icon-note.gif) **说明:**
76        >ip/port: 表示远程设备地址,默认情况为空,表示使用本地设备,ip地址为127.0.0.1,port为本机hdc启动端口号;
77        >​sn: 过滤执行测试设备,若设置为SN1,则表示只有设备SN1能够支持后续run命令执行,其他设备分配状态设置为Ignored,不参与命令执行,可通过list devices命令中Allocation字段来查看sn设置,可配置多个sn,中间以;隔开;
78
79    -   设备类型二
80
81        >![](figures/icon-note.gif) **说明:**
82        >type: 设备连接方式,com表示连接方式是串口
83        >label: 表示设备种类,如wifiiot
84        >serial: 表示一个串口定义
85        >serial/com 表示本地连接的串口,如COM20 serial/type 表示串口类型,cmd是命令串口,deploy是刷机串口,社区版本cmd和deploy使用同一个串口,com值相同
86        >serial/baud\_rate、data\_bits、stop\_bits、timeout: 为串口波特率等串口参数 ,一般采用默认值即可。
87
88
89    **2、测试用例目录设置**
90
91    dir: 指定测试用例目录。
92
93    **3、nfs挂载**
94
95    >![](figures/icon-note.gif) **说明:**
96    >server: nfs挂载配置,label取值为NfsServer。
97    >server/ip: 挂载环境IP地址。
98    >server/port: 挂载环境端口。
99    >server/username: 登录用户名。
100    >server/password: 登录用户密码。
101    >server/dir: 对应挂载的外部路径。
102    >server/remote: nfs服务器与xDevice执行机不在同一台机器时,remote配置为true,否则为false。
103
104-   **选定任务类型**
105-   **启动框架**
106-   **执行指令**
107
108    框架指令可以分为三组:help、list、run。在指令序列中,以run为最常用的执行指令。
109
110    **1、help**
111
112    输入help指令可以查询框架指令帮助信息。
113
114    ```
115    help:
116         use help to get information.
117    usage:
118         run:  Display a list of supported run command.
119         list: Display a list of supported device and task record.
120    Examples:
121         help run
122         help list
123    ```
124
125    >![](figures/icon-note.gif) **说明:**
126    >help run:展示run指令相关说明
127    >help list:展示 list指令相关说明
128
129    **2、list**
130
131    list指令用来展示设备和相关的任务信息
132
133    ```
134    list:
135         This command is used to display device list and task record.
136    usage:
137          list
138          list history
139          list <id>
140    Introduction:
141         list:         display device list
142         list history: display history record of a serial of tasks
143         list <id>:    display history record about task what contains specific id
144    Examples:
145         list
146         list history
147         list 6e****90
148    ```
149
150    >![](figures/icon-note.gif) **说明:**
151    >list: 展示设备信息
152    >list history: 展示任务历史信息
153    >list <id\>: 展示特定id的任务其历史信息
154
155    **3、run**
156
157    run指令主要用于执行测试任务
158
159    ```
160    run:
161         This command is used to execute the selected testcases.
162         It includes a series of processes such as use case compilation, execution, and result collection.
163    usage: run [-l TESTLIST [TESTLIST ...] | -tf TESTFILE
164                [TESTFILE ...]] [-tc TESTCASE] [-c CONFIG] [-sn DEVICE_SN]
165                [-rp REPORT_PATH [REPORT_PATH ...]]
166                [-respath RESOURCE_PATH [RESOURCE_PATH ...]]
167                [-tcpath TESTCASES_PATH [TESTCASES_PATH ...]]
168                [-ta TESTARGS [TESTARGS ...]] [-pt]
169                [-env TEST_ENVIRONMENT [TEST_ENVIRONMENT ...]]
170                [-e EXECTYPE] [-t [TESTTYPE [TESTTYPE ...]]]
171                [-td TESTDRIVER] [-tl TESTLEVEL] [-bv BUILD_VARIANT]
172                [-cov COVERAGE] [--retry RETRY] [--session SESSION]
173                [--dryrun] [--reboot-per-module] [--check-device]
174                [--repeat REPEAT]
175                action task
176    Specify tests to run.
177      positional arguments:
178       action                Specify action
179       task                  Specify task name,such as "ssts", "acts", "hits"
180    ```
181
182    >![](figures/icon-note.gif) **说明:**
183    >一个基本的run指令结构如下:
184    >```
185    >run [task name] -l module1;moudle2
186    >```
187    >task name:任务类型。一般为ssts、acts、hits。非必选项
188    >-l :指定执行测试用例,多个测试用例,中间用;隔开
189    >module:被测试的模块。一般在testcases目录下存在对应的\\.json文件
190    >此外,其他参数可以作为约束条件,附加到这个基本指令之上使用。常用的如:
191    >-sn: 过滤执行测试设备,若设置为SN1,则表示只有设备SN1执行用例
192    >-c: 重新指定user\_config.xml193    >-rp: 报告生成路径。默认为xxx/xdevice/reports目录。指定目录后,优先级:指定目录\>xxx/xdevice/reports目录。
194    >-tcpath:环境目录,默认为xxx/xdevice/testcases目录。指定目录后,优先级:指定目录\>xxx/xdevice/testcases目录
195    >-respath:测试套目录,默认为xxx/xdevice/resource目录。指定目录后,优先级:指定目录\>xxx/xdevice/resource目录
196    >--reboot-per-module: 执行前先重启设备
197
198-   **查看执行结果**
199
200    框架执行run指令,控制台会输出对应的log打印,还会生成对应的执行结果报告。如果使用了-rp参数指定报告路径,那么报告就会生成在指定的路径下。否则报告会存放在默认目录。
201
202    ```
203    当前报告目录(默认目录/指定目录)
204         ├── result(模块执行结果存放目录)
205         │     ├── <模块名>.xml
206         │     ├──  ... ...
207208         ├── log (设备和任务运行log存放目录)
209         │     ├── <设备1>.log
210         │     ├── ... ...
211         │     ├── <任务>.log
212         ├── summary_report.html(测试任务可视化报告)
213         ├── summary_report.html(测试任务数据化报告)
214         └── ... ...
215    ```
216
217
218## 相关仓<a name="section260848241"></a>
219
220[测试子系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/%E6%B5%8B%E8%AF%95%E5%AD%90%E7%B3%BB%E7%BB%9F.md)
221
222**test\_xdevice**
223
224[test\_developertest](https://gitee.com/openharmony/test_developertest/blob/master/README_zh.md)
225