176e6818aSopenharmony_ci# XDevice<a name="EN-US_TOPIC_0000001083129731"></a>
276e6818aSopenharmony_ci
376e6818aSopenharmony_ci-   [Introduction](#section15701932113019)
476e6818aSopenharmony_ci-   [Directory Structure](#section1791423143211)
576e6818aSopenharmony_ci-   [Constraints](#section118067583303)
676e6818aSopenharmony_ci-   [Usage](#section2036431583)
776e6818aSopenharmony_ci-   [Repositories Involved](#section260848241)
876e6818aSopenharmony_ci
976e6818aSopenharmony_ci## Introduction<a name="section15701932113019"></a>
1076e6818aSopenharmony_ci
1176e6818aSopenharmony_ciXDevice, a core module of the OpenHarmony test framework, provides services on which test case execution depends.
1276e6818aSopenharmony_ci
1376e6818aSopenharmony_ciXDevice consists of the following sub-modules:
1476e6818aSopenharmony_ci
1576e6818aSopenharmony_ci-   **command**: enables command-based interactions between users and the test platform. It parses and processes user commands.
1676e6818aSopenharmony_ci-   **config**: sets test framework configurations and provides different configuration options for the serial port connection and USB connection modes.
1776e6818aSopenharmony_ci-   **driver**: functions as a test case executor, which defines main test steps, such as test case distribution, execution, and result collection.
1876e6818aSopenharmony_ci-   **report**: parses test results and generates test reports.
1976e6818aSopenharmony_ci-   **scheduler**: schedules various test case executors in the test framework.
2076e6818aSopenharmony_ci-   **environment**: configures the test framework environment, enabling device discovery and device management.
2176e6818aSopenharmony_ci-   **testkit**: provides test tools to implement JSON parsing, network file mounting, etc.
2276e6818aSopenharmony_ci-   **resource**: provides the device connection configuration file and report template definitions.
2376e6818aSopenharmony_ci
2476e6818aSopenharmony_ci## Directory Structure<a name="section1791423143211"></a>
2576e6818aSopenharmony_ci
2676e6818aSopenharmony_ci```
2776e6818aSopenharmony_cixdevice
2876e6818aSopenharmony_ci├── config                            # XDevice configuration
2976e6818aSopenharmony_ci│     ├── user_config.xml             # XDevice environment configuration
3076e6818aSopenharmony_ci├── src                               # Source code
3176e6818aSopenharmony_ci│     ├── xdevice
3276e6818aSopenharmony_ci├── plugins                           # XDevice plugins
3376e6818aSopenharmony_ci│     ├── ohos                        # OpenHarmony plugins
3476e6818aSopenharmony_ci|          ├── src                    # OpenHarmony plugins source code
3576e6818aSopenharmony_ci│          └── setup.py               # Installation script of the plugins
3676e6818aSopenharmony_ci```
3776e6818aSopenharmony_ci
3876e6818aSopenharmony_ci## Constraints<a name="section118067583303"></a>
3976e6818aSopenharmony_ci
4076e6818aSopenharmony_ciThe environment requirements for using this module are as follows:
4176e6818aSopenharmony_ci
4276e6818aSopenharmony_ci-   Python version: 3.7.5 or later
4376e6818aSopenharmony_ci-   pySerial version: 3.3 or later
4476e6818aSopenharmony_ci-   Paramiko version: 2.7.1 or later
4576e6818aSopenharmony_ci-   RSA version: 4.0 or later
4676e6818aSopenharmony_ci
4776e6818aSopenharmony_ci## Usage<a name="section2036431583"></a>
4876e6818aSopenharmony_ci
4976e6818aSopenharmony_ci-   **Installing XDevice**
5076e6818aSopenharmony_ci    1.  Go to the installation directory of XDevice.
5176e6818aSopenharmony_ci    2.  Open the console window and run the following command:
5276e6818aSopenharmony_ci
5376e6818aSopenharmony_ci        ```
5476e6818aSopenharmony_ci        python setup.py install
5576e6818aSopenharmony_ci        ```
5676e6818aSopenharmony_ci
5776e6818aSopenharmony_ci
5876e6818aSopenharmony_ci-   **Installing the extension**
5976e6818aSopenharmony_ci    1.  Go to the installation directory of the XDevice extension.
6076e6818aSopenharmony_ci    2.  Open the console and run the following command:
6176e6818aSopenharmony_ci
6276e6818aSopenharmony_ci        ```
6376e6818aSopenharmony_ci        python setup.py install
6476e6818aSopenharmony_ci        ```
6576e6818aSopenharmony_ci
6676e6818aSopenharmony_ci
6776e6818aSopenharmony_ci-   **Modifying the user\_config.xml file**
6876e6818aSopenharmony_ci
6976e6818aSopenharmony_ci    Configure information about your environment in the  **user\_config.xml**  file.
7076e6818aSopenharmony_ci
7176e6818aSopenharmony_ci    **1. Configure the environment.**
7276e6818aSopenharmony_ci
7376e6818aSopenharmony_ci    -   For devices that support hdc connection, refer to the following note to configure the environment.
7476e6818aSopenharmony_ci
7576e6818aSopenharmony_ci        >![](figures/icon-note.gif) **NOTE:** 
7676e6818aSopenharmony_ci        >**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.
7776e6818aSopenharmony_ci        >**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 \(;\).
7876e6818aSopenharmony_ci
7976e6818aSopenharmony_ci    -   For devices that support serial port connection, refer to the following note to configure the environment.
8076e6818aSopenharmony_ci
8176e6818aSopenharmony_ci        >![](figures/icon-note.gif) **NOTE:** 
8276e6818aSopenharmony_ci        >**type**: device connection mode. The  **com**  mode indicates that the device is connected through the serial port.
8376e6818aSopenharmony_ci        >**label**: device type, for example,  **wifiiot**
8476e6818aSopenharmony_ci        >**serial**: serial port
8576e6818aSopenharmony_ci        >-   **serial/com**: serial port for local connection, for example,  **COM20**
8676e6818aSopenharmony_ci        >-   **serial/type**: serial port type. The value can be  **cmd**  \(serial port for test case execution\) or  **deploy**  \(serial port for system upgrade\).
8776e6818aSopenharmony_ci        >    For the open-source project, the  **cmd**  and  **deploy**  serial ports are the same, and their  **com**  values are the same too.
8876e6818aSopenharmony_ci        >   **serial/baud\_rate, data\_bits, stop\_bits**  and  **timeout**: serial port parameters. You can use the default values.
8976e6818aSopenharmony_ci
9076e6818aSopenharmony_ci
9176e6818aSopenharmony_ci    **2. Set the test case directory.**
9276e6818aSopenharmony_ci    
9376e6818aSopenharmony_ci    **dir**: test case directory
9476e6818aSopenharmony_ci    
9576e6818aSopenharmony_ci    **3. Mount the NFS.**
9676e6818aSopenharmony_ci    
9776e6818aSopenharmony_ci    >![](figures/icon-note.gif) **NOTE:** 
9876e6818aSopenharmony_ci    >**server**: NFS mounting configuration. Set the value to  **NfsServer**.
9976e6818aSopenharmony_ci    >**server/ip**: IP address of the mounting environment
10076e6818aSopenharmony_ci    >**server/port**: port number of the mounting environment
10176e6818aSopenharmony_ci    >**server/username**: user name for logging in to the server
10276e6818aSopenharmony_ci    >**server/password**: password for logging in to the server
10376e6818aSopenharmony_ci    >**server/dir**: external mount path
10476e6818aSopenharmony_ci    >**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**.
10576e6818aSopenharmony_ci
10676e6818aSopenharmony_ci-   **Specify the task type.**
10776e6818aSopenharmony_ci-   **Start the test framework.**
10876e6818aSopenharmony_ci-   **Execute test commands.**
10976e6818aSopenharmony_ci
11076e6818aSopenharmony_ci    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.
11176e6818aSopenharmony_ci
11276e6818aSopenharmony_ci    **help**
11376e6818aSopenharmony_ci
11476e6818aSopenharmony_ci    Queries help information about test framework commands.
11576e6818aSopenharmony_ci
11676e6818aSopenharmony_ci    ```
11776e6818aSopenharmony_ci    help:
11876e6818aSopenharmony_ci         use help to get information.  
11976e6818aSopenharmony_ci    usage:
12076e6818aSopenharmony_ci         run:  Display a list of supported run command.
12176e6818aSopenharmony_ci         list: Display a list of supported device and task record.  
12276e6818aSopenharmony_ci    Examples:
12376e6818aSopenharmony_ci         help run
12476e6818aSopenharmony_ci         help list
12576e6818aSopenharmony_ci    ```
12676e6818aSopenharmony_ci
12776e6818aSopenharmony_ci    >![](figures/icon-note.gif) **NOTE:** 
12876e6818aSopenharmony_ci    >**help run**: displays the description of  **run**  commands.
12976e6818aSopenharmony_ci    >**help list**: displays the description of  **list**  commands.
13076e6818aSopenharmony_ci
13176e6818aSopenharmony_ci    **list**
13276e6818aSopenharmony_ci
13376e6818aSopenharmony_ci    Displays device information and related task information.
13476e6818aSopenharmony_ci
13576e6818aSopenharmony_ci    ```
13676e6818aSopenharmony_ci    list:
13776e6818aSopenharmony_ci         This command is used to display device list and task record.  
13876e6818aSopenharmony_ci    usage:
13976e6818aSopenharmony_ci          list
14076e6818aSopenharmony_ci          list history
14176e6818aSopenharmony_ci          list <id>  
14276e6818aSopenharmony_ci    Introduction:
14376e6818aSopenharmony_ci         list:         display device list
14476e6818aSopenharmony_ci         list history: display history record of a serial of tasks
14576e6818aSopenharmony_ci         list <id>:    display history record about task what contains specific id  
14676e6818aSopenharmony_ci    Examples:
14776e6818aSopenharmony_ci         list
14876e6818aSopenharmony_ci         list history
14976e6818aSopenharmony_ci         list 6e****90
15076e6818aSopenharmony_ci    ```
15176e6818aSopenharmony_ci
15276e6818aSopenharmony_ci    >![](figures/icon-note.gif) **NOTE:** 
15376e6818aSopenharmony_ci    >**list**: displays device information.
15476e6818aSopenharmony_ci    >**list history**: displays historical task information.
15576e6818aSopenharmony_ci    >**list <id\>**: displays historical information about tasks with specified IDs.
15676e6818aSopenharmony_ci
15776e6818aSopenharmony_ci    **run**
15876e6818aSopenharmony_ci
15976e6818aSopenharmony_ci    Executes test tasks.
16076e6818aSopenharmony_ci
16176e6818aSopenharmony_ci    ```
16276e6818aSopenharmony_ci    run:
16376e6818aSopenharmony_ci         This command is used to execute the selected testcases.
16476e6818aSopenharmony_ci         It includes a series of processes such as use case compilation, execution, and result collection.  
16576e6818aSopenharmony_ci    usage: run [-l TESTLIST [TESTLIST ...] | -tf TESTFILE
16676e6818aSopenharmony_ci                [TESTFILE ...]] [-tc TESTCASE] [-c CONFIG] [-sn DEVICE_SN]
16776e6818aSopenharmony_ci                [-rp REPORT_PATH [REPORT_PATH ...]]
16876e6818aSopenharmony_ci                [-respath RESOURCE_PATH [RESOURCE_PATH ...]]
16976e6818aSopenharmony_ci                [-tcpath TESTCASES_PATH [TESTCASES_PATH ...]]
17076e6818aSopenharmony_ci                [-ta TESTARGS [TESTARGS ...]] [-pt]
17176e6818aSopenharmony_ci                [-env TEST_ENVIRONMENT [TEST_ENVIRONMENT ...]]
17276e6818aSopenharmony_ci                [-e EXECTYPE] [-t [TESTTYPE [TESTTYPE ...]]]
17376e6818aSopenharmony_ci                [-td TESTDRIVER] [-tl TESTLEVEL] [-bv BUILD_VARIANT]
17476e6818aSopenharmony_ci                [-cov COVERAGE] [--retry RETRY] [--session SESSION]
17576e6818aSopenharmony_ci                [--dryrun] [--reboot-per-module] [--check-device]
17676e6818aSopenharmony_ci                [--repeat REPEAT]
17776e6818aSopenharmony_ci                action task  
17876e6818aSopenharmony_ci    Specify tests to run.
17976e6818aSopenharmony_ci      positional arguments:
18076e6818aSopenharmony_ci       action                Specify action
18176e6818aSopenharmony_ci       task                  Specify task name,such as "ssts", "acts", "hits"
18276e6818aSopenharmony_ci    ```
18376e6818aSopenharmony_ci
18476e6818aSopenharmony_ci    >![](figures/icon-note.gif) **NOTE:** 
18576e6818aSopenharmony_ci    >The structure of a basic  **run**  command is as follows:
18676e6818aSopenharmony_ci    >```
18776e6818aSopenharmony_ci    >run [task name] -l module1;moudle2
18876e6818aSopenharmony_ci    >```
18976e6818aSopenharmony_ci    >**task name**: task type. This parameter is optional. Generally, the value is  **ssts**,  **acts**, or  **hits**.
19076e6818aSopenharmony_ci    >**-l**: test cases to execute. Use semicolons \(;\) to separate each two test cases.
19176e6818aSopenharmony_ci    >**module**: module to test. Generally, there is a  **.json**  file of the module in the  **testcases**  directory.
19276e6818aSopenharmony_ci    >In addition, other parameters can be attached to this command as constraints. Common parameters are as follows:
19376e6818aSopenharmony_ci    >**-sn**: specifies the devices for test case execution. If this parameter is set to  **SN1**, only device SN1 executes the test cases.
19476e6818aSopenharmony_ci    >**-c**: specifies a new  **user\_config.xml**  file.
19576e6818aSopenharmony_ci    >**-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.
19676e6818aSopenharmony_ci    >**-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.
19776e6818aSopenharmony_ci    >**-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.
19876e6818aSopenharmony_ci    >**--reboot-per-module**: restarts the device before test case execution.
19976e6818aSopenharmony_ci
20076e6818aSopenharmony_ci-   **View the execution result.**
20176e6818aSopenharmony_ci
20276e6818aSopenharmony_ci    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.
20376e6818aSopenharmony_ci
20476e6818aSopenharmony_ci    ```
20576e6818aSopenharmony_ci    Structure of the report directory (the default or the specified one)
20676e6818aSopenharmony_ci         ├── result # Test case execution results of the module
20776e6818aSopenharmony_ci         │     ├── module name.xml
20876e6818aSopenharmony_ci         │     ├──  ... ... 
20976e6818aSopenharmony_ci21076e6818aSopenharmony_ci         ├── log # Running logs of devices and tasks
21176e6818aSopenharmony_ci         │     ├── device 1.log
21276e6818aSopenharmony_ci         │     ├── ... ...
21376e6818aSopenharmony_ci         │     ├── task.log
21476e6818aSopenharmony_ci         ├── summary_report.html # Visual report
21576e6818aSopenharmony_ci         ├── summary_report.html # Statistical report
21676e6818aSopenharmony_ci         └── ... ...
21776e6818aSopenharmony_ci    ```
21876e6818aSopenharmony_ci
21976e6818aSopenharmony_ci
22076e6818aSopenharmony_ci## Repositories Involved<a name="section260848241"></a>
22176e6818aSopenharmony_ci
22276e6818aSopenharmony_ci[testing subsystem](https://gitee.com/openharmony/docs/blob/master/en/readme/test.md)
22376e6818aSopenharmony_ci
22476e6818aSopenharmony_ci**test\_xdevice**
22576e6818aSopenharmony_ci
22676e6818aSopenharmony_ci[test\_developertest](https://gitee.com/openharmony/test_developertest/blob/master/README.md)
227