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