openharmony 鸿蒙 wukong-guidelines

2023-02-03 浏览 (1053)

wukong User Guide

Introduction

wukong is a built-in command line tool that implements application stability test capabilities such as random event injection, component injection, exception capture, report generation, and data traversal of abilities. This tool allows you to conduct stability tests on the system or applications by simulating user behavior. wukong provides three types of testing: random testing, special testing, and focus testing.

In random testing, test inputs are generated randomly. Available features include shell startup, whole application startup, multiple injection modes, random seeds setting, run log printing, and report generation.

In special testing, specific application components are tested. Available features include shell startup, sequential traversal and screenshot, sleep and wakeup test, recording and playback, run log printing, and report generation.

In focus testing, specific components are injected. Available features include shell startup, device application startup, multiple injection modes, random seed setting, focus component type setting, component injection times setting, run log printing, and report generation.

Principles

The following figure shows the wukong component architecture and the responsibilities of sub-modules. Alternate text

  • Command line parsing: Obtain and parse parameters using commands.
  • Operating environment management: Initialize the overall operating environment of wukong using commands.
  • System API management: Check and obtain the specified mgr, and register the callback function of the Faultlogger for the controller and DFX.
  • Random event generation: Use the random function to generate a sequence of random numbers with the specified seed value to generate an event.
  • Event injection: Inject events of supported types to the system. This feature depends on the window, multi-mode, and security subsystems.
  • Exception capture and processing and report generation: Obtain exception information with the DFX subsystem during application running, record log, and generate reports.

Constraints

  1. The wukong tool is built in the system since API version 9.

  2. In API versions earlier than 9, you need to build the tool and push it to the target device. The procedure is as follows:

    // Build code.
    ./build.sh --product-name rk3568 --build-target wukong
    
    // Push code.
    hdc shell mount -o rw,remount /
    hdc file send wukong /
    hdc shell chmod a+x /wukong
    hdc shell mv /wukong /bin/
    
  3. When the PC is connected to one or more target devices, you can run test commands.

  4. Enter the shell mode before running any command.

Functions and Commands

CommandDescription
versionObtains version information.
helpObtains help information.
appinfoQueries the bundle name and the name of the corresponding mainAbility of the app that can be started.
specialRuns special testing.
execRuns random testing.
focusRuns focus testing.

Running Commands

  • Open the shell.

    #If you are testing one device, run **hdc shell**.
    C:\Users>hdc shell
    #
    
    #If you are testing multiple devices, run **hdc list targets** to obtain the SNs, and then run **hdc -t** open the shell.
    C:\Users>hdc list targets
    15xxx424axxxx345209d94xxxx8fxx900
    C:\Users>hdc -t 15xxx424axxxx345209d94xxxx8fxx900 shell
    #
    
  • Obtain the bundle name and ability name of the application.

    # wukong appinfo
    BundleName:  com.ohos.adminprovisioning
    AbilityName:  com.ohos.adminprovisioning.MainAbility
    BundleName:  com.ohos.callui
    AbilityName:  com.ohos.callui.MainAbility
    
  • View the help information.

    C:\Users>hdc shell
    # wukong --help        // wukong help menu.
    wukong: '--help' is not a valid wukong command. See 'wukong help'.
    usage: wukong <command> [<arguments>]
    These are common wukong command list:
      help                       wukong help information
      -v/--version               wukong version
      exec                       run random test
      special                    run special test
      focus                      run focus test
      appinfo                    show all app information
    # wukong exec -help   // Help menu for wukong random testing.
    usage: wukong exec [<arguments>]
    These are wukong exec arguments list:
      -h, --help                 random test help
      -a, --appswitch            appswitch event percent
      -b, --bundle               the bundle name of allowlist
      -p, --prohibit             the bundle name of blocklist
      -d, --page                 block page list
      -t, --touch                touch event percent
      -c, --count                test count
      -i, --interval             interval
      -s, --seed                 random seed
      -m, --mouse                mouse event percent
      -k, --keyboard             keyboard event percent
      -H, --hardkey              hardkey event percent
      -S, --swap                 swap event percent
      -T, --time                 test time
      -C, --component            component event percent
      -r, --rotate               rotate event percent
      -e, --allow ability        the ability name of allowlist
      -E, --block ability        the ability name of blocklist
      -Y, --blockCompId          the id list of block component
      -y, --blockCompType        the type list of block component
      -I, --screenshot           get screenshot(only in random input)
      -B, --checkBWScreen        black and white screen detection
      -U, --Uri                  set Uri pages
      -x, --Uri-type             set Uri-type
    # wukong special -help    // Help menu for wukong special testing.
    usage: wukong special [<arguments>]
    These are wukong special arguments list:
      -h, --help                 special test help
      -t, --touch[x,y]           touch event
      -c, --count                total count of test
      -i, --interval             interval
      -S, --swap[option]         swap event
                                  option is -s|-e|-b
                                  -s, --start: the start point of swap
                                  -e, --end: the end point of swap
                                  -b, --bilateral: swap go and back
      -k, --spec_insomnia        power on/off event
      -T, --time                 total time of test
      -C, --component            component event
      -p, --screenshot           get screenshot(only in componment input)
      -r, --record               record user operation
      -R, --replay               replay user operation
      -u, --uitest               uitest dumpLayout
    

Random Testing

Commands

CommandDescriptionMandatoryDescription
-h,--helpObtains the help information about the test.No-
-c,--countSets the number of execution times. This command conflicts with the -T command. Set either of them.NoThe default value is 10, in times.
-i,--intervalSets the test interval.NoThe default value is 1500, in millisecond.
-s,--seedSets the random seed.NoIf the same random seed is set, the same random event sequence is generated.
-b,--bundle[bundlename, ......, bundlename]Sets allowed bundles for the test. This command conflicts with the -p command.NoBy default, all bundles on the device are allowed. Use commas (,) to separate bundle names.
-p,--prohibit[bundlename, ......, bundlename]Sets blocked bundles for the test. This command conflicts with the -b command.NoBy default, no bundle is blocked. Use commas (,) to separate bundle names.
-d,--page[page, ......, page]Sets blocked pages for the test.NoBy default, the pages/system pages are blocked. Use commas (,) to separate page names.
-a,--appswitchSets the proportion of the random application startup event test.NoThe default value is 10%.
-t,--touchSets the proportion of the random touch event test.NoThe default value is 10%.
-S,--swapSets the proportion of the random swipe event test.NoThe default value is 3%.
-m,--mouseSets the proportion of the random mouse event test.NoThe default value is 1%.
-k,--keyboardSets the proportion of the random keyboard event test.NoThe default value is 2%.
-H,--hardkeySets the proportion of the random hardkey test.NoThe default value is 2%.
-r,--rotateSets the proportion of the random rotate event test.NoThe default value is 2%.
-C, --componentSets the proportion of random component test.NoThe default value is 70%.
-I, --screenshotTakes a screenshot for the component test.No-
-T,--timeSets the total test time. This command conflicts with the -c command. Set either of them.NoThe default value is 10, in minute.
-e, --allow abilitySets the ability that allows testing.No-
-E, --block abilitySets the ability that blocks testing.No-
-Y, --blockCompIdSets the blocked CompId.No-
-y, --blockCompTypeSets the blocked CompType.No-
-B, --checkBWScreenEnables black and white screen check.No-
-U, -uriSets the URI of the application startup page.No-
-x, -uriTypeSets the URI type of the application startup page.No-

Samples

  • Set 100 event injections.

    # wukong exec -s 10 -i 1000 -a 0.28 -t 0.72 -c 100
    

    The parameters in the command are described as follows. |Command |Value |Description | |--------------|--------------|--------------| |wukong exec|- |Works as the main command. | |-s |10 |Sets the random seed. The seed value is 10.| |-i|1000 |Sets the application startup interval to 1000 ms.| |-a|0.28 |Sets the proportion of the random application startup test to 28%. | |-t|0.72 |Sets the proportion of the random touch test to 72%. | |-c|100 |Sets the number of execution times to 100. |

  • Specify a page to perform a pressure test.

    > Explicit start
    > hdc_std shell
    # wukong exec -b bundlename -a abilityname -U uri
    
    > Implicit start
    > hdc_std shell
    # wukong exec -b bundlename -U uri -x uriType
    
  • Set the ability that allows and blocks testing.

    # wukong exec -b com.ohos.settings -e com.ohos.settings.MainAbility -E com.ohos.settings.AppInfoAbility
    

    NOTE

    If -e and -E are set, you must set -b to specify an application.

Special Testing

Commands

CommandDescriptionMandatoryDescription
-h, --helpObtains the help information about the special testing.No-
-k, --spec_insomniaPowers on/off the special testing.No-
-c, --countSets the number of test times.NoThe default value is 10, in times.
-i, --intervalSets the test interval.NoThe default value is 1500, in millisecond.
-S, --swapSets a swipe event for the test.No-
-s, --start[x,y]Sets the coordinates of the start point of the swipe event.NoThe values of coordinates are positive.
-e, --end[x,y]Sets the coordinates of the end point of the swipe event.NoThe values of coordinates are positive.
-b, --bilateralSets a back and forth swipe event.NoBy default, the back and forth swipe event is disabled.
-t, --touch[x,y]Sets a touch event for the test.No-
-T, --timeSets the total test time.NoThe default value is 10, in minute.
-C, --componentSets the sequential traversal test for components.NoYou need to set the name of the test application.
-r, --recordRecords user operation.NoYou need to specify the recording file.
-R, --replayReplays user operation.NoYou need to specify the playback file.
-p, --screenshotTakes a screenshot for the component test.No-

Samples

# wukong special -C [bundlename] -p

Focus Testing

Commands

CommandDescriptionMandatoryDescription
-n,--numberfocusSets the number of injections for each component.NoUnit: times
-f, --focustypesSets the types of component for the focus testing.NoUse commas (,) to separate the types.
-h,--helpObtains the help information about the test.No
-c,--countSets the number of test times. This command conflicts with the -T command. Set either of them.NoThe default value is 10, in times.
-i,--intervalSets the test interval.NoThe default value is 1500, in millisecond.
-s,--seedSets the random seed.NoIf the same random seed is set, the same random event sequence is generated.
-b,--bundle[bundlename, ......, bundlename]Sets allowed bundles for the test. This command conflicts with the -p command.NoBy default, all bundles on the device are allowed. Use commas (,) to separate bundle names.
-p,--prohibit[bundlename, ......, bundlename]Sets blocked bundles for the test. This command conflicts with the -b command.NoBy default, no bundle is blocked. Use commas (,) to separate bundle names.
-d,--page[page, ......, page]Sets blocked pages for the test.NoBy default, the pages/system pages are blocked. Use commas (,) to separate page names.
-a,--appswitchSets the proportion of the random application startup event test.NoThe default value is 10%.
-t,--touchSets the proportion of the random touch event test.NoThe default value is 10%.
-S,--swapSets the proportion of the random swipe event test.NoThe default value is 3%.
-m,--mouseSets the proportion of the random mouse event test.NoThe default value is 1%.
-k,--keyboardSets the proportion of the random keyboard event test.NoThe default value is 2%.
-H,--hardkeySets the proportion of the random hardkey test.NoThe default value is 2%.
-r,--rotateSets the proportion of the random rotate event test.NoThe default value is 2%.
-C, --componentSets the proportion of random component test.NoThe default value is 70%.
-I, --screenshotTakes a screenshot for the component test.No-
-T,--timeSets the total test time. This command conflicts with the -c command. Set either of them.NoThe default value is 10, in minute.
-e, --allow abilitySets the ability that allows testing.No-
-E, --block abilitySets the ability that blocks testing.No-
-Y, --blockCompIdSets the blocked CompId.No-
-y, --blockCompTypeSets the blocked CompType.No-
-B, --checkBWScreenEnables black and white screen check.No-

Samples

# wukong focus -s 10 -i 1000 -a 0.28 -t 0.72 -c 100

The parameters in the command are described as follows.

CommandValueDescription
wukong focus-Works as the main command.
-s10Sets the random seed. The seed value is 10.
-i1000Sets the application startup interval to 1000 ms.
-a0.28Sets the proportion of the random application startup test to 28%.
-t0.72Sets the proportion of the random touch test to 72%.
-c100Sets the number of execution times to 100.

Viewing the Test Result

Test Result Output Path

After the test commands are executed, the test result is automatically generated. You can obtain the test result in the following directory:

  • For DevEco Studio versions earlier than September 22, 2022: /data/local/wukong/report/xxxxxxxx_xxxxxx/
  • For DevEco Studio versions later than September 22, 2022: /data/local/tmp/wukong/report/xxxxxxxx_xxxxxx/

Test Report Directories

TypeDescription
exception/Stores exception files generated during the test.
screenshot/Stores the screenshots of the test traversal.
wukong_report.csvStores the test report summary.
wukong.logIndicates the test operation history.

View operation logs

You can run the hdc command to obtain logs to the local host and view the operation history.

// The path of the wukong.log file is as follows:
/data/local/tmp/wukong/report/xxxxxxxx_xxxxxx/wukong.log

// To view the directory of the wukong test report, run the following command:
# cd /data/local/tmp/wukong/report/20170805_170053
# ls
data.js  exception  wukong.log  wukong_report.csv

// Open the shell and run hdc file recv to obtain wukong logs.
C:\Users\xxx>hdc file recv /data/local/tmp/wukong/report/20170805_170053/wukong.log C:\Users\xxx\Desktop\log
[I][2024-01-03 20:08:02] HdcFile::TransferSummary success
FileTransfer finish, Size:76492, File count = 1, time:16ms rate:4780.75kB/s

FAQs

failed to connect to AAMS

Symptom

failed to connect to AAMS.

Possible Cause

AAMS is occupied by Hypium or the UIViewer of DevEco Testing. AAMS can be connected to only one program at a time.

Solution

Stop the process that occupies AAMS or restart the device.

Errorcode:(4005)

Symptom

Errorcode:(4005).

Possible Cause

The size of the screen display area changes. As a result, the page information fails to be obtained.

Solution

This error does not affect the test process and does not need to be handled.

Errorcode:(4007)

Symptom

Errorcode:(4007).

Possible Cause

The size of the screen display area changes. As a result, the page information fails to be obtained.

Solution

This error does not affect the test process and does not need to be handled.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Test Kit

harmony 鸿蒙arkXtest User Guide

harmony 鸿蒙SmartPerf User Guide

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/c077e75766054e4ca70810f50ecf76b9