1e41f4b71Sopenharmony_ci# wukong稳定性工具使用指导 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci## 功能介绍 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ciwukong是系统自带的一种命令行工具,支持Ability的随机事件注入、控件注入、异常捕获、报告生成和对Ability数据遍历截图等特性。通过模拟用户行为,对系统或应用进行稳定性压力测试。 6e41f4b71Sopenharmony_ciwukong分为随机测试和专项测试。随机测试是指随机测试界面内容,支持的能力包括:shell启动、拉起整机应用、多种注入方式、设置随机种子、打印运行日志和生成报告。专项测试主要提供对指定应用控件进行测试,支持的能力包括:shell启动、顺序遍历及截图、测试休眠睡醒、录制回放、打印运行日志和生成报告。 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ci## 实现原理 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ciwukong部件架构图以及部件内子模块职责如下所述。 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci- 命令行解析:支持命令行获取参数并解析命令行参数。 14e41f4b71Sopenharmony_ci- 运行环境管理:根据命令行初始化wukong整体运行环境。 15e41f4b71Sopenharmony_ci- 系统接口管理:检查并获取指定的mgr,注册controller和dfx的faultlog的回调函数。 16e41f4b71Sopenharmony_ci- 随机事件生成:通过random函数生成指定种子数的随机序列,生成事件。 17e41f4b71Sopenharmony_ci- 事件注入:根据支持的事件类型向系统注入事件,依赖窗口、多模、安全等子系统。 18e41f4b71Sopenharmony_ci- 异常捕获处理/报告生成:通过DFX子系统获取运行中的异常信息并记录log,生成报告。 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci## 约束与限制 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci1. wukong测试工具在API 9版本开始预置使用。 23e41f4b71Sopenharmony_ci2. 在低于API 9版本,不能随版本编译,使用时需自行编译后推送至被检测设备,具体步骤如下。 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci ```bash 26e41f4b71Sopenharmony_ci // 构建方式 27e41f4b71Sopenharmony_ci ./build.sh --product-name rk3568 --build-target wukong 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci // 推送方式 30e41f4b71Sopenharmony_ci hdc shell mount -o rw,remount / 31e41f4b71Sopenharmony_ci hdc file send wukong / 32e41f4b71Sopenharmony_ci hdc shell chmod a+x /wukong 33e41f4b71Sopenharmony_ci hdc shell mv /wukong /bin/ 34e41f4b71Sopenharmony_ci ``` 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci3. PC被检测设备连接后,才可执行命令行,支持单个和多个设备。 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci## 功能特性及命令说明 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci| 命令 | 说明 | 备注 | 41e41f4b71Sopenharmony_ci| -------------- | ---------------------------------------------- | ------------- | 42e41f4b71Sopenharmony_ci| version | 获取wukong版本信息。 | -v, --version。 | 43e41f4b71Sopenharmony_ci| help | 获取wukong帮助信息。 | | 44e41f4b71Sopenharmony_ci| appinfo | 查询支持拉起应用bundleName和对应的mainAbility名。 | | 45e41f4b71Sopenharmony_ci| special | wukong专项测试。 | | 46e41f4b71Sopenharmony_ci| exec | wukong随机测试。 | | 47e41f4b71Sopenharmony_ci| focus | wukong专注测试。 | | 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci## 随机测试 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci### wukong随机测试命令参数 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci| 命令 | 功能 | 必选 | 备注 | 54e41f4b71Sopenharmony_ci| --------------- | ------------------------------------ | ---- | ---------------------------------------- | 55e41f4b71Sopenharmony_ci| -h,--help | 获取当前测试的帮助信息。 | 否 | | 56e41f4b71Sopenharmony_ci| -c,--count | 设置执行次数,与设置执行时间-T冲突。二者取其一。 | 否 | 单位次数,默认10次。 | 57e41f4b71Sopenharmony_ci| -i,--interval | 设置执行间隔。 | 否 | 单位ms,默认1500ms。 | 58e41f4b71Sopenharmony_ci| -s,--seed | 设置随机种子。 | 否 | 配置相同随机种子,会生成相同随机事件序列。 | 59e41f4b71Sopenharmony_ci| -b,--bundle[bundlename,……,bundlename] | 设置本次测试的允许应用名单,与-p冲突。 | 否 | 默认测试当前设备所有应用(应用名称用英文逗号隔开)。 | 60e41f4b71Sopenharmony_ci| -p,--prohibit[bundlename,……,bundlename] | 设置本次测试的禁止应用名单,与-b冲突。 | 否 | 默认不禁止任何应用(应用名称用英文逗号隔开)。 | 61e41f4b71Sopenharmony_ci| -d,--page[page,……,page] | 设置本次测试的禁止页面名单。 | 否 | 系统默认禁止pages/system页面(页面名称用逗号隔开)。 | 62e41f4b71Sopenharmony_ci| -a,--appswitch | 设置应用随机拉起测试比例。 | 否 | 默认10%。 | 63e41f4b71Sopenharmony_ci| -t,--touch | 设置屏幕随机touch测试比例。 | 否 | 默认10%。 | 64e41f4b71Sopenharmony_ci| -S,--swap | 设置屏幕随机swap测试比例。 | 否 | 默认3%。 | 65e41f4b71Sopenharmony_ci| -m,--mouse | 设置屏幕随机mouse测试比例。 | 否 | 默认1%。 | 66e41f4b71Sopenharmony_ci| -k,--keyboard | 设置屏幕随机keyboard测试比例。 | 否 | 默认2%。 | 67e41f4b71Sopenharmony_ci| -H,--hardkey | 设置随机hardkey测试比例。 | 否 | 默认2%。 | 68e41f4b71Sopenharmony_ci| -r,--rotate | 设置随机rotate测试比例。 | 否 | 默认2%。 | 69e41f4b71Sopenharmony_ci| -C, --component | 设置随机控件测试比例。 | 否 | 默认70%。 | 70e41f4b71Sopenharmony_ci| -I, --screenshot | 控件测试截图。 | 否 | - | 71e41f4b71Sopenharmony_ci| -T,--time | 设置测试总时间,与设置执行次数-c冲突。二者取其一。 | 否 | 单位分钟,默认10分钟。 | 72e41f4b71Sopenharmony_ci| -e, --allow ability | 设置压测ability白名单 | 否 | - | 73e41f4b71Sopenharmony_ci| -E, --block ability | 设置压测ability白名单 | 否 | - | 74e41f4b71Sopenharmony_ci| -Y, --blockCompId | 设置不进行注入的CompId | 否 | - | 75e41f4b71Sopenharmony_ci| -y, --blockCompType | 设置不进行注入的CompType | 否 | - | 76e41f4b71Sopenharmony_ci| -B, --checkBWScreen | 设置启用黑白屏检测 | 否 | - | 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci## 专项测试 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci### wukong专项测试命令参数 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ci| 命令 | 功能 | 必选 | 备注 | 83e41f4b71Sopenharmony_ci| :------------------ | ---------------------- | ---- | :------------------ | 84e41f4b71Sopenharmony_ci| -h, --help | 获取当前专项测试的帮助信息。 | 否 | | 85e41f4b71Sopenharmony_ci| -k, --spec_insomnia | 休眠唤醒专项测试。 | 否 | - | 86e41f4b71Sopenharmony_ci| -c, --count | 设置执行次数。 | 否 | 单位次数,默认10次。 | 87e41f4b71Sopenharmony_ci| -i, --interval | 设置执行间隔。 | 否 | 单位ms,默认1500ms。 | 88e41f4b71Sopenharmony_ci| -S, --swap | 滑动测试。 | 否 | - | 89e41f4b71Sopenharmony_ci| -s, --start[x,y] | 设置滑动测试起点坐标。 | 否 | 坐标均为正值。 | 90e41f4b71Sopenharmony_ci| -e, --end[x,y] | 设置滑动测试终点坐标。 | 否 | 坐标均为正值。 | 91e41f4b71Sopenharmony_ci| -b, --bilateral | 设置往返滑动。 | 否 | 默认不往返滑动。 | 92e41f4b71Sopenharmony_ci| -t, --touch[x,y] | 点击测试。 | 否 | - | 93e41f4b71Sopenharmony_ci| -T, --time | 设置测试总时间。 | 否 | 单位分钟,默认10分钟。 | 94e41f4b71Sopenharmony_ci| -C, --component | 控件顺序遍历测试。 | 否 | 需要设置测试应用名称。 | 95e41f4b71Sopenharmony_ci| -r, --record | 录制。 | 否 | 需要指定录制文件。 | 96e41f4b71Sopenharmony_ci| -R, --replay | 回放。 | 否 | 需要指定回放文件。 | 97e41f4b71Sopenharmony_ci| -p, --screenshot | 控件测试截图。 | 否 | - | 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_ci## 专注测试 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ci### wukong专注测试命令参数 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_ci| 命令 | 功能 | 必选 | 备注 | 104e41f4b71Sopenharmony_ci| --------------- | ------------------------------------ | ---- | ---------------------------------------- | 105e41f4b71Sopenharmony_ci| -n,--numberfocus | 设置每个控件注入的次数。 | 否 | 单位次数。 | 106e41f4b71Sopenharmony_ci| -f, --focustypes | 设置需要专注的控件类型。 | 否 | 以英文逗号隔开。 | 107e41f4b71Sopenharmony_ci其余参数继承自随机测试命令参数。 108e41f4b71Sopenharmony_ci 109e41f4b71Sopenharmony_ci## 命令行使用示例 110e41f4b71Sopenharmony_ci 111e41f4b71Sopenharmony_ci> 以下操作需要先进入shell模式 112e41f4b71Sopenharmony_ci 113e41f4b71Sopenharmony_ci```bash 114e41f4b71Sopenharmony_ci#若为单设备,则直接输入如下命令进入shell模式 115e41f4b71Sopenharmony_ciC:\Users>hdc shell 116e41f4b71Sopenharmony_ci# 117e41f4b71Sopenharmony_ci 118e41f4b71Sopenharmony_ci#若为多设备,则需先获取sn号,先输入hdc list targets获取sn号,然后进入shell模式 119e41f4b71Sopenharmony_ciC:\Users>hdc list targets 120e41f4b71Sopenharmony_ci15xxx424axxxx345209d94xxxx8fxx900 121e41f4b71Sopenharmony_ciC:\Users>hdc -t 15xxx424axxxx345209d94xxxx8fxx900 shell 122e41f4b71Sopenharmony_ci# 123e41f4b71Sopenharmony_ci``` 124e41f4b71Sopenharmony_ci 125e41f4b71Sopenharmony_ci### 1.获取应用的bundle name和ability name 126e41f4b71Sopenharmony_ci 127e41f4b71Sopenharmony_ci```bash 128e41f4b71Sopenharmony_ci# wukong appinfo 129e41f4b71Sopenharmony_ciBundleName: com.ohos.adminprovisioning 130e41f4b71Sopenharmony_ciAbilityName: com.ohos.adminprovisioning.MainAbility 131e41f4b71Sopenharmony_ciBundleName: com.ohos.callui 132e41f4b71Sopenharmony_ciAbilityName: com.ohos.callui.MainAbility 133e41f4b71Sopenharmony_ci``` 134e41f4b71Sopenharmony_ci 135e41f4b71Sopenharmony_ci### 2.执行随机测试命令 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ci```bash 138e41f4b71Sopenharmony_ci# wukong exec -s 10 -i 1000 -a 0.28 -t 0.72 -c 100 139e41f4b71Sopenharmony_ci``` 140e41f4b71Sopenharmony_ci 141e41f4b71Sopenharmony_ci命令中各参数含义: 142e41f4b71Sopenharmony_ci| 命令 | 参数值 |说明 | 143e41f4b71Sopenharmony_ci| -------------- | -------------- | -------------- | 144e41f4b71Sopenharmony_ci| wukong exec | - | 主命令。 | 145e41f4b71Sopenharmony_ci| -s | 10 | 参数设置随机种子,10为种子值。 | 146e41f4b71Sopenharmony_ci| -i | 1000 | 参数设置应用拉起间隔为1000ms。 | 147e41f4b71Sopenharmony_ci| -a | 0.28 | 参数设置应用随机拉起测试比例28%。 | 148e41f4b71Sopenharmony_ci| -t | 0.72 | 参数设置屏幕随机touch测试比例为72%。 | 149e41f4b71Sopenharmony_ci| -c | 100 | 参数设置执行次数为100次。 | 150e41f4b71Sopenharmony_ci 151e41f4b71Sopenharmony_ci### 3.执行专项测试命令 152e41f4b71Sopenharmony_ci 153e41f4b71Sopenharmony_ci```bash 154e41f4b71Sopenharmony_ci# wukong special -C [bundlename] -p 155e41f4b71Sopenharmony_ci``` 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_ci 命令中各参数含义: 158e41f4b71Sopenharmony_ci | 命令 | 参数值 | 说明 | 159e41f4b71Sopenharmony_ci | -------------- |-------------- | ---------------------------------------------- | 160e41f4b71Sopenharmony_ci | wukong special | - | 主命令。 | 161e41f4b71Sopenharmony_ci | -C [bundlename] |[bundlename] | 控件顺序遍历测试参数设置,bundlename为测试应用名称。 | 162e41f4b71Sopenharmony_ci | -p | p | 表示截图。 | 163e41f4b71Sopenharmony_ci 164e41f4b71Sopenharmony_ci### 4.执行查看帮助命令 165e41f4b71Sopenharmony_ci 166e41f4b71Sopenharmony_ci```bash 167e41f4b71Sopenharmony_ciC:\Users>hdc shell 168e41f4b71Sopenharmony_ci# wukong --help //wukong帮助菜单 169e41f4b71Sopenharmony_ciwukong: '--help' is not a valid wukong command. See 'wukong help'. 170e41f4b71Sopenharmony_ciusage: wukong <command> [<arguments>] 171e41f4b71Sopenharmony_ciThese are common wukong command list: 172e41f4b71Sopenharmony_ci help wukong help information 173e41f4b71Sopenharmony_ci -v/--version wukong version 174e41f4b71Sopenharmony_ci exec run random test 175e41f4b71Sopenharmony_ci special run special test 176e41f4b71Sopenharmony_ci focus run focus test 177e41f4b71Sopenharmony_ci appinfo show all app information 178e41f4b71Sopenharmony_ci# wukong exec -help //wukong随机测试帮助菜单 179e41f4b71Sopenharmony_ciusage: wukong exec [<arguments>] 180e41f4b71Sopenharmony_ciThese are wukong exec arguments list: 181e41f4b71Sopenharmony_ci -h, --help random test help 182e41f4b71Sopenharmony_ci -a, --appswitch appswitch event percent 183e41f4b71Sopenharmony_ci -b, --bundle the bundle name of allowlist 184e41f4b71Sopenharmony_ci -p, --prohibit the bundle name of blocklist 185e41f4b71Sopenharmony_ci -d, --page block page list 186e41f4b71Sopenharmony_ci -t, --touch touch event percent 187e41f4b71Sopenharmony_ci -c, --count test count 188e41f4b71Sopenharmony_ci -i, --interval interval 189e41f4b71Sopenharmony_ci -s, --seed random seed 190e41f4b71Sopenharmony_ci -m, --mouse mouse event percent 191e41f4b71Sopenharmony_ci -k, --keyboard keyboard event percent 192e41f4b71Sopenharmony_ci -H, --hardkey hardkey event percent 193e41f4b71Sopenharmony_ci -S, --swap swap event percent 194e41f4b71Sopenharmony_ci -T, --time test time 195e41f4b71Sopenharmony_ci -C, --component component event percent 196e41f4b71Sopenharmony_ci -r, --rotate rotate event percent 197e41f4b71Sopenharmony_ci -e, --allow ability the ability name of allowlist 198e41f4b71Sopenharmony_ci -E, --block ability the ability name of blocklist 199e41f4b71Sopenharmony_ci -I, --screenshot get screenshot(only in random input) 200e41f4b71Sopenharmony_ci# wukong special -help //wukong专项测试帮助菜单 201e41f4b71Sopenharmony_ciusage: wukong special [<arguments>] 202e41f4b71Sopenharmony_ciThese are wukong special arguments list: 203e41f4b71Sopenharmony_ci -h, --help special test help 204e41f4b71Sopenharmony_ci -t, --touch[x,y] touch event 205e41f4b71Sopenharmony_ci -c, --count total count of test 206e41f4b71Sopenharmony_ci -i, --interval interval 207e41f4b71Sopenharmony_ci -S, --swap[option] swap event 208e41f4b71Sopenharmony_ci option is -s| -e| -b 209e41f4b71Sopenharmony_ci -s, --start: the start point of swap 210e41f4b71Sopenharmony_ci -e, --end: the end point of swap 211e41f4b71Sopenharmony_ci -b, --bilateral: swap go and back 212e41f4b71Sopenharmony_ci -k, --spec_insomnia power on/off event 213e41f4b71Sopenharmony_ci -T, --time total time of test 214e41f4b71Sopenharmony_ci -C, --component component event 215e41f4b71Sopenharmony_ci -p, --screenshot get screenshot(only in componment input) 216e41f4b71Sopenharmony_ci -r, --record record user operation 217e41f4b71Sopenharmony_ci -R, --replay replay user operation 218e41f4b71Sopenharmony_ci -u, --uitest uitest dumpLayout 219e41f4b71Sopenharmony_ci``` 220e41f4b71Sopenharmony_ci 221e41f4b71Sopenharmony_ci## 查看测试结果 222e41f4b71Sopenharmony_ci 223e41f4b71Sopenharmony_ci### 测试结果输出路径 224e41f4b71Sopenharmony_ci 225e41f4b71Sopenharmony_ci执行完测试指令后,会自动生成测试结果,测试结果输出根路径如下: 226e41f4b71Sopenharmony_ci 227e41f4b71Sopenharmony_ci- 2022/9/22之前的IDE版本,结果存放路径为:/data/local/wukong/report/xxxxxxxx_xxxxxx/ 228e41f4b71Sopenharmony_ci- 2022/9/22之后的IDE版本,结果存放路径为:/data/local/tmp/wukong/report/xxxxxxxx_xxxxxx/ 229e41f4b71Sopenharmony_ci 230e41f4b71Sopenharmony_ci### 测试报告文件目录 231e41f4b71Sopenharmony_ci 232e41f4b71Sopenharmony_ci| 类型 | 描述 | 233e41f4b71Sopenharmony_ci| ------------------------------------ | ------------------ | 234e41f4b71Sopenharmony_ci| exception/ | 存放本次测试产生的异常文件。 | 235e41f4b71Sopenharmony_ci| screenshot/ | 存放测试遍历的截图。 | 236e41f4b71Sopenharmony_ci| wukong_report.csv | 测试报告统计汇总。 | 237e41f4b71Sopenharmony_ci| wukong.log | 测试操作历程。 | 238e41f4b71Sopenharmony_ci 239e41f4b71Sopenharmony_ci### 查看操作日志 240e41f4b71Sopenharmony_ci 241e41f4b71Sopenharmony_ciwukong支持通过hdc命令将日志获取到本地,查看操作历程。 242e41f4b71Sopenharmony_ci 243e41f4b71Sopenharmony_ci```bash 244e41f4b71Sopenharmony_ci// wukong.log文件对应路径如下 245e41f4b71Sopenharmony_ci/data/local/tmp/wukong/report/xxxxxxxx_xxxxxx/wukong.log 246e41f4b71Sopenharmony_ci 247e41f4b71Sopenharmony_ci// 查看wukong测试报告文件目录操作如下 248e41f4b71Sopenharmony_ci# cd /data/local/tmp/wukong/report/20170805_170053 249e41f4b71Sopenharmony_ci# ls 250e41f4b71Sopenharmony_cidata.js exception wukong.log wukong_report.csv 251e41f4b71Sopenharmony_ci 252e41f4b71Sopenharmony_ci// 开启shell窗口,用hdc file recv获取wukong日志 253e41f4b71Sopenharmony_ciC:\Users\xxx>hdc file recv /data/local/tmp/wukong/report/20170805_170053/wukong.log C:\Users\xxx\Desktop\log 254e41f4b71Sopenharmony_ci[I][2024-01-03 20:08:02] HdcFile::TransferSummary success 255e41f4b71Sopenharmony_ciFileTransfer finish, Size:76492, File count = 1, time:16ms rate:4780.75kB/s 256e41f4b71Sopenharmony_ci``` 257