Initial Configuration
Important: Before performing any operation, you must first collect the user configuration information.
When using this skill for the first time, ask the user for the configuration in the following order:
1. Project root directory path
请输入 OpenHarmony 项目根目录路径
默认:/root/OpenHarmony
2. Build artifact path
请输入编译产物输出路径
默认:${项目根目录}/out/rk3568/tests
3. Build command
请输入编译命令
模板(使用 ${OH_ROOT} 和 ${TARGET} 变量)
默认:cd ${OH_ROOT} && ./build.sh --product-name=rk3568 --build-target ${TARGET}
4. Windows IP address
请输入 Windows 机器的 IP 地址(用于 hdc 连接)
格式:x.x.x.x
端口固定使用 8710
Auto-acquire option: If the current environment is WSL, you can first try to auto-acquire:
WIN_IP=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}')
echo $WIN_IP
Ask the user whether to use the auto-acquired IP or enter it manually.
5. Connection verification (⚠️ must be performed)
After configuring the IP,mustperform the following verification steps in order to ensure the device is available:
5.1 Verify IP address reachability
ping -c 3 ${WINDOWS_IP}
Criteria:
- Success: 3 replies received, no 100% packet loss
- Failure: request timed out or unreachable
Failure handling:
❌ 无法 ping 通 ${WINDOWS_IP}
请检查:
1. Windows 机器是否开机
2. 网络连接是否正常
3. IP 地址是否正确
4. Windows 防火墙是否允许 ping(ICMP)
5.2 Verify HDC port is connectable
nc -zv -w 3 ${WINDOWS_IP} 8710
Criteria:
- Success: displays
succeeded!orConnection to xxx 8710 port [tcp/*] succeeded! - Failure: displays
timed outorConnection refused
Failure handling:
❌ 无法连接到 ${WINDOWS_IP}:8710
请检查:
1. HDC 服务是否在 Windows 上启动
2. 端口 8710 是否被防火墙阻止
3. hdc_std.exe 是否在 Windows 上运行
启动 HDC 服务方法(Windows 管理员权限 PowerShell):
hdc_std start -l
5.3 Verify device list
hdc -s ${WINDOWS_IP}:8710 list targets
Criteria:
- Success: returns the device serial number, such as
xxxxx - Failure: returns
[Empty]or an error
Failure handling:
❌ 未检测到可用设备
请检查:
1. OpenHarmony 设备是否开机
2. 设备是否通过 USB 连接到 Windows 机器
3. hdc_std 是否正确识别设备
手动查看设备(Windows 上执行):
hdc_std list targets
5.4 Verify Shell connection
hdc -s ${WINDOWS_IP}:8710 shell "echo 'connection OK'"
Criteria:
- Success: returns
connection OK - Failure: displays an error or no response
Failure handling:
❌ Shell 连接失败
请检查 hdc 版本兼容性
6. Configuration variable description
The collected configuration will be stored as the following variables and used in subsequent commands:
OH_ROOT- Project root directoryOH_OUTPUT- Build artifact pathBUILD_CMD- Build command templateWINDOWS_IP- Windows IP, port fixed at 8710
Quick commands
Build and test
cd ${OH_ROOT}/ && ${BUILD_CMD} <TARGET_NAME>
Deploy to device
hdc -s ${WINDOWS_IP}:8710 shell "mkdir -p /data/test/"
hdc -s ${WINDOWS_IP}:8710 file send <TARGET_PATH> /data/test
Run tests
hdc shell -s ${WINDOWS_IP}:8710 "chmod +x /data/test/<TARGET_NAME> && /data/test/<TARGET_NAME>"
Automation workflow
Full workflow (write + run)
When the user requests "write and run" or similar that explicitly includes the intent to write, execute in the following order:
- Write - Generate test code; the name must match the build target
- Build - Execute the build command
- Deploy - Upload to device
/data/test/ - Run - Execute the test and return the results
- Fix - If it fails, fix the errors until it passes
Run-only workflow (⚠️ preferred)
When the user only says "run the test case", "run this test case", etc., without explicitly mentioning writing or modifying code:
-
First look for the build artifact - Check whether a compiled file already exists:
cd ${OH_OUTPUT}/ && find . -name <TARGET_NAME> -
If found - Skip directly to the deployment step
-
If not found - Then perform the build, and continue with deployment and running
Basis for judgment: whether the user request contains verbs such as "write", "compose", "generate", "create", etc.
Key rules
- Naming: The test name must match the BUILD.gn target (e.g.,
LnnNetBuilderFuzzTest) - Location: Place under the tests directory of the corresponding module
- Style: Follow the OpenHarmony HWTEST_F specification, do not use GoogleTest main
- No magic numbers: All constants must be named
Detailed documentation
- environment.md - Build environment architecture and path description
- test-generation.md - Test writing specification
- build-guide.md - Compilation commands and artifact description
- deployment.md - Detailed deployment steps
- execution.md - Test execution and troubleshooting