SuperAPI AI Directory

ohos-ut-test-coverage-report-generation

Testing & quality

View repository

Updated 10-16 03:11

About this skill

OpenHarmony - Code Coverage Analysis

Documentation Navigation

  • 🚀 Quick Start: See references/quick-start.md - Environment configuration, device connection, execution examples
  • ⚡ Performance Notes: See references/performance-guide.md - Expected duration, resource usage, optimization suggestions
  • 📚 Usage Examples: See references/usage-examples.md - Full/incremental scenarios, parameter matching rules
  • 📖 Parameter Guide: See references/parameter-guide.md - Detailed explanation of parameter parsing rules, validation rules, and matching rules
  • 💡 Best Practices: See references/best-practices.md - Scenario selection, optimization suggestions, security suggestions
  • 🔧 Troubleshooting: See references/troubleshooting.md - Common troubleshooting steps, error recovery strategies

Quick Start

Must Configure: {SKILL_DIR}/config/user-config.json(must include the code_root field)

Execution Examples:

  • Full: "Generate a full code coverage report for the ability_base component"
  • Incremental: "Generate an incremental code coverage report for the ability_base component"

📖 See references/quick-start.md(environment configuration, device connection)


Anti-Patterns - Absolutely Prohibited Actions

NEVER do the following, otherwise the test will fail to compile or run:

Prohibited Item Reason Correct Practice
NEVER modify source code We are only responsible for compiling and running to generate reports, and do not modify source code or test case content Modification of all C/C++ code and skill content is prohibited
NEVER deviate from the preset process Operations outside the preset process are prohibited to prevent the use of incorrect commands and coverage tools Follow the execution process and only load the md involved in the current process and the error handling process md
NEVER check status during command execution Synchronous blocking commands must be waited for completion Checking logs, processes, etc. during command execution is prohibited; you must wait for the command to return naturally or time out
NEVER interrupt or poll long-running commands You must use timeout and wait for natural completion Actively interrupting or polling to check command status is prohibited; let the timeout mechanism handle timeouts
NEVER retry directly after a compilation interruption The compilation cache must be cleaned first Execute rm -rf out/ before retrying
NEVER use the same output directory when running multiple components in parallel It will cause report conflicts Use an independent output directory for each component
NEVER modify the lcov branch coverage parameter without recompiling The gcno file will not match You must recompile after modifying the parameter

Pre-Execution Decision Checklist

Before starting execution, first ask yourself:

💭 Thinking Framework

  • Goal: What does the user want to evaluate? (The entire component, the changed part, a specific module?)
  • Scope: What parameters did the user provide? (subsystem, part, module, testsuite, testcase?)
  • Scenario: Is full or incremental suitable? (Use incremental for daily development, use full for periodic checks)
  • Resources: Do the disk space and device status meet the requirements?

✅ 3 key questions that must be confirmed:

  1. Target scope correctness

    • Is it full (subsystem/part/module supported) or incremental (only part supported)?
    • If it is incremental, confirm that no subsystem was passed in (an error will occur INCREMENTAL_NOT_SUPPORT_SUBSYSTEM)
  2. Input completeness

    • Full: at least one of subsystem, part, module must be provided
    • Incremental: part must be provided (cannot be empty)
  3. Resource availability

    • Is there sufficient disk space? (Full requires 50GB+, incremental requires 20GB+, see references/performance-guide.md)
    • Is the device connected? (hdc list targets can verify)

Full vs Incremental Decision Table

Scenario Recommended Type Expected Duration Resource Requirements See
Verification before PR merge Incremental 30 min-2 hours 20GB disk references/best-practices.md
Weekly quality check Full 3-5 hours 50GB disk references/performance-guide.md
Verification after refactoring Full 3-5 hours 50GB disk references/best-practices.md
Daily development and debugging Incremental 30 min-2 hours 20GB disk references/best-practices.md

Execution Flow

用户输入
    ↓
[1] 主入口 (SKILL.md)
    - 解析关键词和参数
    - 确认覆盖率类型 (全量/增量)
    ↓
[2] 配置检查 ⚠️ **MANDATORY - READ ENTIRE FILE**
在进入此步骤前,你必须完整读取 `references/01-config-checker.md` 
的所有内容(约414行),不要设置任何行数限制。
**DO NOT Load**: 在完成此步骤前,不要加载后续参考文档。
执行内容:
    ├──[1] 获取基础变量 (SKILL_DIR、CODE_ROOT)
    ├──[2] 检查项目结构 (developer_test、xdevice、pr_local_coverage)
    ├──[3] 检查用户输入参数 (全量/增量覆盖率参数)
    ├──[4] 检查配置文件 (user-config.json内容、/etc/lcovrc)
    ├──[5] 解析部件名称 (subsystem/part)
    ├──[6] 检查设备连接配置
    └──[7] 返回配置和参数信息
    ↓
[3] 环境检查 ⚠️ **MANDATORY - READ ENTIRE FILE**
完成配置检查后,读取 `references/02-env-checker.md` 的所有内容(约150行)。
**DO NOT Load**: 在完成此步骤前,不要加载 03-dependency-installer.md。
执行内容:
    ├──[1] 操作系统检测 (仅支持Linux)
    ├──[2] 检查Python 版本 (需要3.8+)
    ├──[3] 检查工具依赖
    ├──[4] 检查Python依赖包
    ├──[5] 检查是否存在可执行编译命令的全仓根目录 (build_system.sh)
    ├──[6] 权限检查
    ├──[7] 磁盘空间检查
    └──[8] 返回环境状态,如果出现错误进入错误处理流程
    ↓
[4] 依赖安装 ⚠️ **MANDATORY - READ ENTIRE FILE**
完成环境检查后,读取 `references/03-dependency-installer.md` 的所有内容(约100行)。
**DO NOT Load**: 在完成此步骤前,不要加载执行模块。
执行内容:
    ├──[1] 安装系统依赖 (仅支持Linux)
    ├──[2] 安装Python包依赖 (需要3.8+)
    ├──[3] 验证安装结果
    ├──[4] 返回依赖安装状态,如果出现错误进入错误处理流程
    ↓
[5] 覆盖率执行流程
    ├── 全量:⚠️ **MANDATORY - READ ENTIRE FILE**
    当 `taskType = "full_coverage"` 时,读取 `references/04-full-coverage-executor.md` 
    的所有内容(约472行)。**DO NOT Load**: 增量模式下不要加载此文档。
    │  ├── [1] 修改developer_test中的 user_config.xml 配置文件
    │  ├── [2] 执行 build_before_generate.py (如果用户已经编译完成则跳过)
    │  ├── [3] 编译用例 (检查skip_compile、预编译、构建命令、执行、验证)
    │  ├── [4] 启动框架并执行命令 (构建命令、拼接命令、执行、验证)
    │  ├── [5] 执行 after_lcov_branch.py (恢复源码)
    │  ├── [6] 移动报告到输出目录
    │  ├── [7] 解析报告
    │  └── [8] 清理环境
    └── 增量: ⚠️ **MANDATORY - READ ENTIRE FILE**
    当 `taskType = "incremental_coverage"` 时,读取 `references/05-incremental-coverage-executor.md` 
    的所有内容。**DO NOT Load**: 全量模式下不要加载此文档。
        ├── [1] 执行本地编译脚本 (script/pr_local_coverage/local_build)
        ├── [2] 执行覆盖率流程脚本 (script/pr_local_coverage/pr_coverage)
        ├── [3] 移动报告到输出结果目录
        ├── [4] 恢复环境
        └── [5] 清理临时文件
    ↓
[6] 错误处理 ❌ **DO NOT LOAD(仅在错误时触发)**
在任何步骤出现错误时,读取 `references/06-error-handler.md` 的相关错误处理部分。
在步骤 [2]-[5] 期间,不要加载此文档。
        ├──[1] 识别错误类型
        ├──[2] 查找解决方案
        ├──[3] 提供用户友好的错误信息
        └──[4] 返回错误信息

Parameter Description

Parameter Source

  • code_root: From {SKILL_DIR}/config/user-config.json in code_root field
  • Other parameters: parsed from user input

Parameter Details

📖 For detailed parameter parsing rules, validation rules, and matching rules, see: → references/parameter-guide.md - complete parameter guide

Quick Reference

  • Full coverage parameters: subsystem, part, module, testsuite, testcase (at least one must be provided)
  • Incremental coverage parameters: part (required), diff (optional, automatically generated if not provided)
  • Common parameters: output (optional, default {CODE_ROOT}/coverage_result), skip_compiler (optional, full only)

Parameter Validation Rules

📖 See: references/parameter-guide.md - Parameter Validation Rules section


Core Usage Examples

See references/usage-examples.md - full/incremental scenarios, parameter matching rules, error examples (lines 1-389)


Error Recovery Strategy

Error Type Recovery Method Whether cleanup is required See
Configuration error Modify user-config.json and retry No references/troubleshooting.md
Missing environment Run pip install / apt-get No references/quick-start.md
Compilation failed Retry after clearing the compilation cache Yes:rm -rf out/ references/troubleshooting.md
Test timeout Check device status and retry No references/troubleshooting.md
Report generation failed Check lcov data integrity Yes: regenerate gcda references/troubleshooting.md
Device connection failed Check hdc configuration and reconnect No references/quick-start.md

Module Description

All modules are located in the references/ directory:

  • 01-config-checker.md - Configuration and parameter checking module
  • 02-env-checker.md - Environment and dependency checking module
  • 03-dependency-installer.md - Dependency installation module
  • 04-full-coverage-executor.md - Full coverage execution module
  • 05-incremental-coverage-executor.md - Incremental coverage execution module
  • 06-error-handler.md - Error handling module

Scripts are located in the scripts/ directory:

  • check_gcno_files.py - gcno file checking script
  • parse_coverage_report.py - Full coverage report data parsing script
  • run_test_with_monitor.sh - Script for executing the full coverage test command in the background and monitoring the hdc connection
  • pr_local_coverage - Incremental coverage report script
  • addlcov - Backup tool

Configuration file: config/user-config.json


Variable Definitions

Obtained by 01-config-checker.md and passed to subsequent modules:

  • SKILL_DIR: The directory where the current SKILL is located (obtained by searching upward for SKILL.md)
  • CODE_ROOT: Obtained from the code_root field in {SKILL_DIR}/config/user-config.json

Inter-module Parameter Passing Information

Overall Parameter Transfer Flow

主入口
  ↓
[01] config-checker
  ├──→ [02] env-checker
  ├──→ [04] full-coverage-executor (全量模式)
  ├──→ [05] incremental-coverage-executor (增量模式)
  └──→ [06] error-handler (错误时)

[02] env-checker
  ├──→ [03] dependency-installer
  └──→ [06] error-handler (错误时)

[03] dependency-installer
  └──→ [06] error-handler (错误时)

[04/05] 执行模块
  └──→ [06] error-handler (错误时)

Parameters passed by 01-config-checker.md to subsequent modules

Passed to 02-env-checker.md:

  • skill_dir: {SKILL_DIR}
  • code_root: {CODE_ROOT}
  • output_path: {output_path}
  • taskType: Task type
  • config.deviceInfo: Device configuration information (complete)

Passed to 04-full-coverage-executor.md (full mode):

  • skill_dir: {SKILL_DIR}
  • code_root: {CODE_ROOT}
  • taskType: Task type
  • userInput.parameters: Parameter object parsed by the user
  • config.deviceInfo: Device configuration information (complete)

Passed to 05-incremental-coverage-executor.md (incremental mode):

  • skill_dir: {SKILL_DIR}
  • code_root: {CODE_ROOT}
  • taskType: Task type
  • userInput.parameters: Parameter object parsed by the user
  • config.deviceInfo: Device configuration information (complete)

Parameters passed by 02-env-checker.md to subsequent modules

Passed to 03-dependency-installer.md:

  • skill_dir: {SKILL_DIR}
  • code_root: {CODE_ROOT}
  • output_path: {output_path}
  • taskType: Task type
  • tools: Tool dependency status
  • pythonPackages: Python package dependency status
  • permissions: Permission status

Parameters passed by 03-dependency-installer.md to subsequent modules

Passed to the 04/05 execution modules:

  • isAllInstalled: Whether all dependencies are installed
  • dependencies: Dependency installation status

Module Invocation Specifications

When invoking modules under references, follow these specifications:

Invocation Order and Parameter Passing

  • 01-config-checker.md:

    • Step [2] invocation
    • Input: parsed user parameters
    • Output: complete configuration information + device information
    • Passed to: 02, 04, 05
  • 02-env-checker.md:

    • Step [3] invocation
    • Input: skill-related paths + device information
    • Output: environment check status
    • Passed to: 03
  • 03-dependency-installer.md:

    • Step [4] invocation
    • Input: check results from 02
    • Output: dependency installation status
    • Passed to: 04/05
  • 04-full-coverage-executor.md:

    • Step [5] invocation (full mode)
    • Input: complete configuration from 01
    • Output: coverage report
  • 05-incremental-coverage-executor.md:

    • Step [5] call (incremental mode)
    • Input: complete configuration from 01
    • Output: coverage report
  • 06-error-handler.md:

    • Called on any error
    • Input: error message
    • Output: user-friendly error message

Important principles

  • One-way transfer: information is only passed in process order; reverse references are prohibited
  • Completeness: 01 provides the complete configuration; 02/03 do not check it again
  • Consistency: all sequence numbers and flowcharts remain consistent