25 Star 116 Fork 178

OpenHarmony / testfwk_xdevice

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

xdevice

简介

xdevice是OpenHarmony中为测试框架的核心组件,提供用例执行所依赖的相关服务。

xdevice主要包括以下几个主要模块:

  • command,用户与测试平台命令行交互模块,提供用户输入命令解析,命令处理。
  • config,测试框架配置模块,提供测试平台串口连接方式和USB连接方式的不同配置选项。
  • driver,测试用例执行器,提供测试用例分发,执行,结果收集等主要测试步骤定义。
  • report,测试报告模块,提供测试结果解析和测试报告生成。
  • scheduler,测试框架调度模块,提供不同类型的测试执行器调度的调度功能。
  • environment,测试框架的环境配置模块,提供设备发现,设备管理的功能。
  • testkit,测试框架工具模块,提供json解析,网络文件挂载等操作。
  • resource,测试框架资源模块,提供设备连接配置文件和报告模板定义。

目录

xdevice
├── config                    # xdevice组件配置
│     ├── user_config.xml     # xdevice环境配置
├── src                       # 组件源码目录
│     ├── xdevice
├── plugins                   # xdevice扩展模块
|     |—— ohos                # openharmony测试驱动插件
│           ├── src           # 扩展模块源码
│           └── setup.py      # ohos扩展模块安装脚本
|     |--devicetest           # devicetest测试驱动插件
|           └── setup.py      # deviectest扩展模块安装脚本

约束

运行环境要求:

  • python版本>=3.7.5
  • pyserial>=3.3
  • paramiko>=2.7.1
  • rsa>=4.0

使用

  • 安装xdevice

    1. 打开xdevice安装目录。

    2. 打开控制台,执行如下命令:

    python setup.py install
  • 安装ohos扩展模块

    1. 打开plugins\ohos安装目录。

    2. 打开控制台,执行如下命令:

    python setup.py install
  • 修改user_config.xml

    user_config.xml是框架提供的用户配置文件,用户可以根据自身环境信息配置相关内容,具体介绍如下:

    1. environment环境相关配置

      以下列出三种device配置。

      <environment>
          <!-- 标准系统设备配置>
          <device type="usb-hdc"> <!-- type: 设备连接方式,usb-hdc表示使用hdc命令控制设备(默认) -->
              <ip></ip> <!-- ip: 远端设备地址,ip和port为空时使用本地设备,非空时使用远端设备 -->
              <port></port> <!-- port: 远端设备端口号 -->
              <sn></sn> <!-- sn: 设备串口号列表,串口号之间用分号;分隔,sn为空时使用所有本地设备,非空时使用指定的sn设备 -->
          </device>
      
          <!-- 轻量系统设备配置(轻量系统设备进行测试时,需要刷入已经集成好测试用例的系统,所以需要配置两个串口进行通信,如设备支持,可以将两个serial标签的com口设置为一致),可配置多个 -->
          <device type="com" label="wifiiot"> <!-- type: 设备连接方式,com表示连接方式为串口;label:设备种类,如wifiiot -->
              <serial> <!-- serial:表示一个串口定义 -->
                  <com></com> <!-- serial:表示本地连接的串口,如COM4 -->
                  <type>cmd</type> <!-- type:表示串口类型,cmd为命令串口 -->
                  <baud_rate>115200</baud_rate> <!-- baud_rate、data_bits、stop_bits、timeout:为串口波特率等串口参数,一般采用默认值即可 -->
                  <data_bits>8</data_bits>
                  <stop_bits>1</stop_bits>
                  <timeout>20</timeout>
              </serial>
              <serial>
                  <com></com>
                  <type>deploy</type> <!-- type:表示串口类型,cmd为刷机串口 -->
                  <baud_rate>115200</baud_rate>
              </serial>
          </device>
      
          <!-- 小型系统设备配置,可配置多个 -->
          <device type="com" label="ipcamera">
              <serial>
                  <com></com>
                  <type>cmd</type>
                  <baud_rate>115200</baud_rate>
                  <data_bits>8</data_bits>
                  <stop_bits>1</stop_bits>
                  <timeout>1</timeout>
              </serial>
          </device>
          <device type="com" label="ipcamera">
              <ip></ip>
              <port></port>
          </device>
      </environment>
    2. 测试用例目录设置

      以下为testcase标签内容及作用。

      <testcases>
          <!-- dir标签和server标签同时配置时只有一个会起作用 -->
          <!-- 指定测试用例目录,为空则默认设置为当前项目下的testcase文件夹 -->
          <dir></dir>
          <!-- nfs挂载配置,label取值为NfsServer -->
          <server label="NfsServer">
              <ip></ip>   <!-- 挂载环境IP地址 -->
              <port></port>  <!-- 挂载环境端口 -->
              <dir></dir>  <!-- 对应挂载的外部路径 -->
              <username></username>  <!-- 登录用户名(remote为false时,可不填或删除) -->
              <password></password> <!-- 登录密码(remote为false时,可不填或删除) -->
              <remote></remote> <!-- nfs服务器与xDevice执行机不在同一机器时,remote配置为true,否则为false -->
          </server>
      </testcases>
    3. 资源目录设置

      以下为resource标签内容及作用。

      <resource>
          <!-- 指定资源目录,为空则默认设置为当前项目下的resource文件夹 -->
          <dir></dir>
          <!-- 下载OpenHarmony官网测试资源 -->
          <web_resource>
               <!-- 是否开启功能,TRUE开启/FALSE不开启,默认配置为FALSE -->
               <enable>FALSE</enable>
               <!-- 下载接口地址 -->
               <url></url>
           </web_resource>>
      </resource>
    4. 日志打印等级设置

      以下为loglevel标签内容及作用。

      <!-- 默认为INFO,如需更详细信息可设置为DEBUG -->
      <loglevel>INFO</loglevel>
  • 选定任务类型

    设备执行的测试支撑套件是由测试配置文件所指定。

    每类XTS测试套都有一个json格式的测试配置文件,主要配置了需要使用的kits(测试支撑套件)等信息,执行预制和清理操作。

    以下为某个测试支撑套件的json配置文件样例。

    {
        //测试支撑套件描述
        "description":"Configuration for acecshi Tests",
    
        //指定执行当前测试支撑套件的设备
        //environment设置为可选,如不设置,将从框架中注册的设备中选择一个符合的空闲设备执行用例
        "environment":{
              "type":"device",
              "label":"wifiiot"
        },
    
        //指定设备执行的驱动
        "driver":{
            "type":"OHJSUnitTest",
            "test-timeout":"700000",
            "bundle-name":"com.open.harmony.acetestfive",
            "package-name":"com.open.harmony.acetestfive",
            "shell-timeout":"700000",
        },
    
        //kit的作用是为了支撑测试执行活动
        "kits":[
            {
              "type":"ShellKit",
              "run-command":[
                "remount",
                "mkdir /data/data/resource"
              ],
              "teardown-command":[
                "remount",
                "rm -rf /data/data/resource"
              ]
            }
        ]
    }
  • 启动框架

    可以通过以下几种方式启动框架

    • Linux系统可以运行根目录下的run.sh文件
    • Windows系统可以运行根目录下的run.bat文件
    • Linux和Windows系统皆可运行项目目录下的src\xdevice\__main__.py文件
  • 执行指令

    框架指令可以分为三组:help、list、run。在指令序列中,以run为最常用的执行指令。

    1. help

      输入help指令可以查询框架指令帮助信息。

      help:
          use help to get information.  
      usage:
          run:  Display a list of supported run command.
          list: Display a list of supported device and task record.  
      Examples:
          help run
          help list

      说明: help run:展示run指令相关说明 help list:展示 list指令相关说明。

    2. list

      list指令用来展示设备和相关的任务信息。

      list:
          This command is used to display device list and task record.  
      usage:
            list
            list history
            list <id>  
      Introduction:
          list:         display device list
          list history: display history record of a serial of tasks
          list <id>:    display history record about task what contains specific id  
      Examples:
          list
          list history
          list 6e****90

      说明: list: 展示设备信息 list history: 展示任务历史信息 list : 展示特定id的任务其历史信息。

    3. run

      run指令主要用于执行测试任务。

      run:
          This command is used to execute the selected testcases.
          It includes a series of processes such as use case compilation, execution, and result collection.  
      usage: run [-l TESTLIST [TESTLIST ...] | -tf TESTFILE
                  [TESTFILE ...]] [-tc TESTCASE] [-c CONFIG] [-sn DEVICE_SN]
                  [-rp REPORT_PATH [REPORT_PATH ...]]
                  [-respath RESOURCE_PATH [RESOURCE_PATH ...]]
                  [-tcpath TESTCASES_PATH [TESTCASES_PATH ...]]
                  [-ta TESTARGS [TESTARGS ...]] [-pt]
                  [-env TEST_ENVIRONMENT [TEST_ENVIRONMENT ...]]
                  [-e EXECTYPE] [-t [TESTTYPE [TESTTYPE ...]]]
                  [-td TESTDRIVER] [-tl TESTLEVEL] [-bv BUILD_VARIANT]
                  [-cov COVERAGE] [--retry RETRY] [--session SESSION]
                  [--dryrun] [--reboot-per-module] [--check-device]
                  [--repeat REPEAT]
                  action task  
      Specify tests to run.
        positional arguments:
        action                Specify action
        task                  Specify task name,such as "ssts", "acts", "hits"

      run常用指令基本使用方式如下。

      xDevice命令 功能 示例
      run xts 运行所有指定类型的xts模块,如acts,hits,ssts等 run acts
      run -l XXX 运行指定测试套。如有多个测试套,测试套之间以分号分隔 run -l ActsWifiServiceTest;ActsLwipTest(testcase目录下的测试套名称)
      run -sn 指定运行设备sn号,多个sn号之间以分号分隔 run acts -sn 10.11.133.22:12345
      run acts -sn 2222122;22321321
      run -rp 指定报告生成路径,默认报告生成在项目根目录下的reports文件夹,以时间戳或任务id建立子目录 run acts -rp /XXXX/XXX
      run -respath 指定测试资源路径,默认为项目根目录下的resource文件夹 run -respath /XXX/XXX/XXX
      run -tcpath 指定测试用例路径,默认为项目根目录下的testcases文件夹 run -tcpath /XXX/XXX/XXX
      run - ta 指定模块运行参数,可以指定运行测试套中的某个用例,多个用例之间以逗号分隔,目前只支持hits run hits -ta size:large
      run hits -l XXXTest -ta class:XXXX(类名)#XXXXX(方法名)
      run --retry 重新运行上次失败的测试用例 run --retry --session 2022-12-13-12-21-11(report任务报告目录)
      run --reboot-per-module 执行前先重启设备 run --reboot-per-module -l XXXX
  • 查看执行结果

    框架执行run指令,控制台会输出对应的log打印,还会生成对应的执行结果报告。如果使用了-rp参数指定报告路径,那么报告就会生成在指定的路径下。否则报告会存放在默认目录。

    当前报告目录(默认目录/指定目录)
        ├── result(模块执行结果存放目录)
        │     ├── <模块名>.xml
        │     ├──  ... ... 
    
        ├── log (设备和任务运行log存放目录)
        │     ├── <设备1>.log
        │     ├── ... ...
        │     ├── <任务>.log
        ├── summary_report.html(测试任务可视化报告)
        ├── summary_report.html(测试任务数据化报告)
        ├── detail_report.html(详细执行用例结果可视化报告)
        ├── failures_report.html(失败用例可视化报告,无失败用例时不生成)
        ├── summary.ini(记录测试类型,使用的设备,开始时间和结束时间等信息)
        ├── task_info.record(记录执行命令,失败用例等清单信息)
        ├── XXX.zip(对上述文件进行压缩得到的文件)
        ├── summary_report.hash(对压缩文件进行SHA256加密得到的文件)
        └── ... ...

相关仓

测试子系统

test_xdevice

test_developertest

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

简介

Development self-test and the base library of XTS certification testing | 开发自测试与XTS认证测试基础库 展开 收起
Python 等 4 种语言
Apache-2.0
取消

发行版 (1)

全部

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/openharmony/testfwk_xdevice.git
git@gitee.com:openharmony/testfwk_xdevice.git
openharmony
testfwk_xdevice
testfwk_xdevice
master

搜索帮助