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 -I, --screenshot get screenshot(only in random input) 118 # wukong special -help //wukong专项测试帮助菜单 119 usage: wukong special [<arguments>] 120 These are wukong special arguments list: 121 -h, --help special test help 122 -t, --touch[x,y] touch event 123 -c, --count total count of test 124 -i, --interval interval 125 -S, --swap[option] swap event 126 option is -s| -e| -b 127 -s, --start: the start point of swap 128 -e, --end: the end point of swap 129 -b, --bilateral: swap go and back 130 -k, --spec_insomnia power on/off event 131 -T, --time total time of test 132 -C, --component component event 133 -p, --screenshot get screenshot(only in componment input) 134 -r, --record record user operation 135 -R, --replay replay user operation 136 -u, --uitest uitest dumpLayout 137 ``` 138 139## 随机测试 140 141### 命令参数 142 143| 命令 | 功能 | 必选 | 说明 | 144| --------------- | ------------------------------------ | ---- | ---------------------------------------- | 145| -h,--help | 获取当前测试的帮助信息。 | 否 | - | 146| -c,--count | 设置执行次数,与测试总时间-T冲突。二者取其一。 | 否 | 单位次数,默认10次。 | 147| -i,--interval | 设置执行间隔。 | 否 | 单位ms,默认1500ms。 | 148| -s,--seed | 设置随机种子。 | 否 | 配置相同随机种子,会生成相同随机事件序列。 | 149| -b,--bundle[bundlename,……,bundlename] | 设置本次测试的允许应用名单,与-p冲突。 | 否 | 默认测试当前设备所有应用(应用名称用英文逗号隔开)。 | 150| -p,--prohibit[bundlename,……,bundlename] | 设置本次测试的禁止应用名单,与-b冲突。 | 否 | 默认不禁止任何应用(应用名称用英文逗号隔开)。 | 151| -d,--page[page,……,page] | 设置本次测试的禁止页面名单。 | 否 | 系统默认禁止pages/system页面(页面名称用逗号隔开)。 | 152| -a,--appswitch | 设置应用随机拉起测试比例。 | 否 | 默认10%。 | 153| -t,--touch | 设置屏幕随机触摸测试比例。 | 否 | 默认10%。 | 154| -S,--swap | 设置屏幕随机移动测试比例。 | 否 | 默认3%。 | 155| -m,--mouse | 设置屏幕随机鼠标测试比例。 | 否 | 默认1%。 | 156| -k,--keyboard | 设置屏幕随机键盘操作测试比例。 | 否 | 默认2%。 | 157| -H,--hardkey | 设置随机物理按键测试比例。 | 否 | 默认2%。 | 158| -r,--rotate | 设置随机屏幕旋转测试比例。 | 否 | 默认2%。 | 159| -C, --component | 设置随机控件测试比例。 | 否 | 默认70%。 | 160| -I, --screenshot | 控件测试截图。 | 否 | - | 161| -T,--time | 设置测试总时间,与设置执行次数-c冲突。二者取其一。 | 否 | 单位分钟,默认10分钟。 | 162| -e, --allow ability | 设置允许测试的ability | 否 | - | 163| -E, --block ability | 设置禁止测试的ability | 否 | - | 164| -Y, --blockCompId | 设置不进行注入的CompId | 否 | - | 165| -y, --blockCompType | 设置不进行注入的CompType | 否 | - | 166| -B, --checkBWScreen | 设置启用黑白屏检测 | 否 | - | 167| -U, -uri | 设置应用拉起页面uri | 否 | - | 168| -x, -uriType | 设置应用拉起页面uriType | 否 | - | 169 170### 使用示例 171 172- 设置100次事件注入 173 174 ```bash 175 # wukong exec -s 10 -i 1000 -a 0.28 -t 0.72 -c 100 176 ``` 177 178 命令中各参数含义: 179 | 命令 | 参数值 |说明 | 180 | -------------- | -------------- | -------------- | 181 | wukong exec | - | 主命令。 | 182 | -s | 10 | 参数设置随机种子,10为种子值。 | 183 | -i | 1000 | 参数设置应用拉起间隔为1000ms。 | 184 | -a | 0.28 | 参数设置应用随机拉起测试比例28%。 | 185 | -t | 0.72 | 参数设置屏幕随机touch测试比例为72%。 | 186 | -c | 100 | 参数设置执行次数为100次。 | 187 188- 指定页面压测 189 190 ```bash 191 > 显示启动 192 > hdc_std shell 193 # wukong exec -b bundlename -a abilityname -U uri 194 195 > 隐式启动 196 > hdc_std shell 197 # wukong exec -b bundlename -U uri -x uriType 198 ``` 199 200- 设置允许测试和禁止测试的ability 201 ```bash 202 # wukong exec -b com.ohos.settings -e com.ohos.settings.MainAbility -E com.ohos.settings.AppInfoAbility 203 ``` 204 > **说明** 205 > 206 > 若配置-e、-E则须配置-b来指定应用。 207 208## 专项测试 209 210### 命令参数 211 212| 命令 | 功能 | 必选 | 说明 | 213| :------------------ | ---------------------- | ---- | :------------------ | 214| -h, --help | 获取当前专项测试的帮助信息。 | 否 | - | 215| -k, --spec_insomnia | 休眠唤醒专项测试。 | 否 | - | 216| -c, --count | 设置执行次数。 | 否 | 单位次数,默认10次。 | 217| -i, --interval | 设置执行间隔。 | 否 | 单位ms,默认1500ms。 | 218| -S, --swap | 滑动测试。 | 否 | - | 219| -s, --start[x,y] | 设置滑动测试起点坐标。 | 否 | 坐标均为正值。 | 220| -e, --end[x,y] | 设置滑动测试终点坐标。 | 否 | 坐标均为正值。 | 221| -b, --bilateral | 设置往返滑动。 | 否 | 默认不往返滑动。 | 222| -t, --touch[x,y] | 点击测试。 | 否 | - | 223| -T, --time | 设置测试总时间。 | 否 | 单位分钟,默认10分钟。 | 224| -C, --component | 控件顺序遍历测试。 | 否 | 需要设置测试应用名称。 | 225| -r, --record | 录制。 | 否 | 需要指定录制文件。 | 226| -R, --replay | 回放。 | 否 | 需要指定回放文件。 | 227| -p, --screenshot | 控件测试截图。 | 否 | - | 228 229### 测试命令 230 231```bash 232# wukong special -C [bundlename] -p 233``` 234 235## 专注测试 236 237### 命令参数 238 239| 命令 | 功能 | 必选 | 说明 | 240| --------------- | ------------------------------------ | ---- | ---------------------------------------- | 241| -n,--numberfocus | 设置每个控件注入的次数。 | 否 | 单位次数。 | 242| -f, --focustypes | 设置需要专注的控件类型。 | 否 | 以英文逗号隔开。 | 243| -h,--help | 获取当前测试的帮助信息。 | 否 | | 244| -c,--count | 设置执行次数,与设置执行时间-T冲突。二者取其一。 | 否 | 单位次数,默认10次。 | 245| -i,--interval | 设置执行间隔。 | 否 | 单位ms,默认1500ms。 | 246| -s,--seed | 设置随机种子。 | 否 | 配置相同随机种子,会生成相同随机事件序列。 | 247| -b,--bundle[bundlename,……,bundlename] | 设置本次测试的允许应用名单,与-p冲突。 | 否 | 默认测试当前设备所有应用(应用名称用英文逗号隔开)。 | 248| -p,--prohibit[bundlename,……,bundlename] | 设置本次测试的禁止应用名单,与-b冲突。 | 否 | 默认不禁止任何应用(应用名称用英文逗号隔开)。 | 249| -d,--page[page,……,page] | 设置本次测试的禁止页面名单。 | 否 | 系统默认禁止pages/system页面(页面名称用逗号隔开)。 | 250| -a,--appswitch | 设置应用随机拉起测试比例。 | 否 | 默认10%。 | 251| -t,--touch | 设置屏幕随机触摸测试比例。 | 否 | 默认10%。 | 252| -S,--swap | 设置屏幕随机移动测试比例。 | 否 | 默认3%。 | 253| -m,--mouse | 设置屏幕随机鼠标测试比例。 | 否 | 默认1%。 | 254| -k,--keyboard | 设置屏幕随机键盘操作测试比例。 | 否 | 默认2%。 | 255| -H,--hardkey | 设置随机物理按键测试比例。 | 否 | 默认2%。 | 256| -r,--rotate | 设置随机屏幕旋转测试比例。 | 否 | 默认2%。 | 257| -C, --component | 设置随机控件测试比例。 | 否 | 默认70%。 | 258| -I, --screenshot | 控件测试截图。 | 否 | - | 259| -T,--time | 设置测试总时间,与设置执行次数-c冲突。二者取其一。 | 否 | 单位分钟,默认10分钟。 | 260| -e, --allow ability | 设置允许测试的ability | 否 | - | 261| -E, --block ability | 设置禁止测试的ability | 否 | - | 262| -Y, --blockCompId | 设置不进行注入的CompId | 否 | - | 263| -y, --blockCompType | 设置不进行注入的CompType | 否 | - | 264| -B, --checkBWScreen | 设置启用黑白屏检测 | 否 | - | 265 266### 使用示例 267 268```bash 269# wukong focus -s 10 -i 1000 -a 0.28 -t 0.72 -c 100 270``` 271 272命令中各参数含义: 273| 命令 | 参数值 |说明 | 274| -------------- | -------------- | -------------- | 275| wukong exec | - | 主命令。 | 276| -s | 10 | 参数设置随机种子,10为种子值。 | 277| -i | 1000 | 参数设置应用拉起间隔为1000ms。 | 278| -a | 0.28 | 参数设置应用随机拉起测试比例28%。 | 279| -t | 0.72 | 参数设置屏幕随机touch测试比例为72%。 | 280| -c | 100 | 参数设置执行次数为100次。 | 281 282 283## 查看测试结果 284 285### 测试结果输出路径 286 287执行完测试指令后,会自动生成测试结果,测试结果输出根路径如下: 288 289- 2022/9/22之前的IDE版本,结果存放路径为:/data/local/wukong/report/xxxxxxxx_xxxxxx/ 290- 2022/9/22之后的IDE版本,结果存放路径为:/data/local/tmp/wukong/report/xxxxxxxx_xxxxxx/ 291 292### 测试报告文件目录 293 294| 类型 | 描述 | 295| ------------------------------------ | ------------------ | 296| exception/ | 存放本次测试产生的异常文件。 | 297| screenshot/ | 存放测试遍历的截图。 | 298| wukong_report.csv | 测试报告统计汇总。 | 299| wukong.log | 测试操作历程。 | 300 301### 查看操作日志 302 303wukong支持通过hdc命令将日志获取到本地,查看操作历程。 304 305```bash 306// wukong.log文件对应路径如下 307/data/local/tmp/wukong/report/xxxxxxxx_xxxxxx/wukong.log 308 309// 查看wukong测试报告文件目录操作如下 310# cd /data/local/tmp/wukong/report/20170805_170053 311# ls 312data.js exception wukong.log wukong_report.csv 313 314// 开启shell窗口,用hdc file recv获取wukong日志 315C:\Users\xxx>hdc file recv /data/local/tmp/wukong/report/20170805_170053/wukong.log C:\Users\xxx\Desktop\log 316[I][2024-01-03 20:08:02] HdcFile::TransferSummary success 317FileTransfer finish, Size:76492, File count = 1, time:16ms rate:4780.75kB/s 318```