HCCL_VM单元测试脚本
HCCL_VM UT Test Execution Script
【免费下载链接】hcommHCOMM(Huawei Communication)是HCCL的通信基础库,提供通信域以及通信资源的管理能力。项目地址: https://gitcode.com/cann/hcomm
Overview
run_ut.shis the unit test execution script for the HCCL_VM project, used to automate the compilation and execution of test cases.
Three-Step Process
The script automatically completes the following steps during execution:
| Step | Description | Log Output |
|---|---|---|
| Step 1 | CMake configuration + make compilation | build.log |
| Step 2 | Generate executable files | Lists all binaries with size/time |
| Step 3 | Execute test cases and display results | run.log+summary.log |
| Step 4 | Generate gcov/lcov coverage HTML report (requires--cov) | coverage.log |
Usage
cd {HCCL_VM_PATH}/test # Basic usage ./run_ut.sh # Full compilation + execute all tests ./run_ut.sh --cov # Full compilation + execution + generate gcov/lcov coverage HTML report ./run_ut.sh <directory> # Compile + execute all tests in specified directory (recursive) ./run_ut.sh <binary_name> # Compile + execute specified test binary ./run_ut.sh <test_file_name> # Compile + execute the binary corresponding to the specified test file ./run_ut.sh <file> <test_case_name> # Compile + execute a single test case in the specified file # Other commands ./run_ut.sh -l, --list # List all available tests ./run_ut.sh -h, --help # Display help informationCommand Details
1. Full Execution
./run_ut.sh- Executes all tests in the
testdirectory. - Complete three-step process: compilation → generate executables → run all tests.
- Suitable for full regression testing.
2. Coverage Report
./run_ut.sh --cov- Full compilation + execute all tests + generate gcov/lcov coverage HTML report.
- Automatically enables the
--coveragecompilation flag, generating.gcno/.gcdafiles. - Four-step process: compilation (with coverage instrumentation) → execution → collect coverage data → generate HTML report.
- Report output path:
$CODE_DIR/coverage_report/html/index.html. - Automatically filters system headers, third-party libraries, stub files, and other non-business code.
3. Directory Execution
./run_ut.sh plugin/checker ./run_ut.sh plugin/ccu_executor ./run_ut.sh store- Recursively finds all
*_test.ccfiles in the specified directory. - Compiles and executes all tests in that directory.
- Suitable for module-level testing.
4. Binary Execution
./run_ut.sh test_checker ./run_ut.sh test_allgather_semantics_checker- Compiles and executes the specified test binary.
- Binary names start with
test_.
5. File Execution
./run_ut.sh checker_test.cc ./run_ut.sh allgather_semantics_checker_test.cc- Automatically matches the corresponding binary based on the test file name.
- Compiles and executes.
6. Single Test Case Execution
./run_ut.sh checker_test.cc CheckerTest.GenAndCheckGraph_EmptyQueues ./run_ut.sh allgather_semantics_checker_test.cc AllgatherSemanticsCheckerTest.CheckBasic- Executes a single test case in the specified test file.
- Test case name format:
TestSuiteName.TestCaseName.
7. List Tests
./run_ut.sh -l ./run_ut.sh --list- Lists all available test files and their status.
- Displays the number of test cases and corresponding binary names.
Examples
# Example 1: Full test ./run_ut.sh # Example 2: Full test + coverage report ./run_ut.sh --cov # Example 3: Execute all tests in the plugin/checker directory ./run_ut.sh plugin/checker # Example 4: Compile and execute test_checker ./run_ut.sh test_checker # Example 5: Compile and execute the binary corresponding to checker_test.cc ./run_ut.sh checker_test.cc # Example 6: Execute a single test case ./run_ut.sh checker_test.cc CheckerTest.GenAndCheckGraph_EmptyQueues # Example 7: List all tests ./run_ut.sh -lLog Directory
Each execution generates log files underut_logs/<timestamp>/:
{HCCL_VM_PATH}/ut_logs/20260425_142048/ ├── build.log # Detailed compilation log (cmake + make output) ├── run.log # Detailed execution log (full output of each test) └── summary.log # Summary log (execution result of each test)Log File Description
| File | Content |
|---|---|
build.log | CMake configuration output, make compilation output, list of generated executables |
run.log | Full output of each test (including gtest details) |
summary.log | Execution status, pass/fail count, and time summary for each test |
Execution Results
After the script finishes, summary information is displayed:
======================================== Directory Test Result Summary: plugin/checker ======================================== Executed: 16 PASSED: 185 FAILED: 8 CRASHED: 0 TIMEOUT: 0Status Description
| Status | Description |
|---|---|
PASS | Test passed |
FAIL | Test failed (assertion failure) |
CRASH | Test crashed (core dump) |
TIMEOUT | Test timed out (default 60 seconds) |
Directory Structure
test/ ├── run_ut.sh # This script ├── cmd/ # Command-related tests │ ├── base/ │ ├── subcmds/ │ └── utils/ ├── device_arm/ # Device-related tests ├── device_vir/ ├── ipc/ # IPC-related tests │ └── shm/ ├── log/ # Log-related tests ├── plugin/ # Plugin-related tests │ ├── ccu_executor/ │ │ ├── control_type/ │ │ ├── load_type/ │ │ ├── reduce_type/ │ │ └── trans_type/ │ └── checker/ │ └── framework/ │ ├── mem_conflict_check/ │ ├── semantics_check/ │ └── singletask_check/ ├── proxy/ # Proxy-related tests │ ├── level1/ │ └── level2/ ├── runnerdb/ # Database-related tests ├── store/ # Storage-related tests │ └── hccl_shm/ └── src_root/ # Source root directory testsEnvironment Requirements
Before executing the script, you must modify the following environment variables inrun_ut.shto use the actual paths:
# The following are example paths. Modify them according to your actual environment. export HCOMM_CODE_HOME=/home/q30033976/checker/hcomm # hcomm source code path export HCCL_CODE_HOME=/home/q30033976/checker/hccl # hccl source code path (required for AIV/AICPU mode) source /home/q30033976/checker/Ascend/cann/set_env.sh # CANN environment script pathExample: If your working directory is/home/workspace, modify the settings to:
export HCOMM_CODE_HOME=/home/workspace/hcomm export HCCL_CODE_HOME=/home/workspace/hccl source /home/workspace/Ascend/cann/set_env.shThe script will automatically load these environment variables. Failure to modify them will result in compilation errors.
Configuration Parameters
The script has the following built-in configuration (can be modified at the beginning of the script):
| Parameter | Default Value | Description |
|---|---|---|
CMAKE_BUILD_TYPE | Debug | CMake build type |
MAKE_JOBS | 8 | Number of parallel make jobs |
LOG_DIR | $CODE_DIR/ut_logs | Log output directory |
Notes
- First execution: The first execution will perform a complete CMake configuration, which takes a longer time.
- Compilation failure: If compilation fails, check
build.logfor detailed error information. - Test failure: If tests fail, check
run.logfor the specific failing test cases. - Log cleanup: Log directories are named by timestamp. Clean up old logs periodically to save space.
Frequently Asked Questions
Q: How to compile without executing?
A: The current script integrates compilation and execution. To compile only, use cmake and make directly:
cd {HCCL_VM_PATH}/build cmake .. && make -j8 test_checkerQ: How to view detailed output of a specific test?
A: Check therun.logfile, which contains the complete gtest output for each test.
Q: What to do if a test times out?
A: The default timeout is 60 seconds. You can modify thetimeout_secparameter in the script.
Q: How to add new tests?
A: Create a*_test.ccfile in the corresponding directory and add the build target to the correspondingCMakeLists.txt.
Viewing Coverage Reports
After generating the HTML coverage report on Linux, start an HTTP server to view it:
cd <coverage_report/html directory> python3 -m http.server 8080- Access via local browser:
http://localhost:8080. - For remote servers, use SSH port forwarding to access locally:
ssh -L 8080:localhost:8080 <user>@<server_ip> # Then open http://localhost:8080 in your local browserPress^Cto stop the server.
Version History
- v1.0 - Initial version, supports full/directory/file/test-case-level test execution.
- v2.0 - Optimized command-line parameters, supports automatic path derivation, three-step process logging.
- v2.1 - Added
--covparameter, supports gcov/lcov coverage HTML report generation.
【免费下载链接】hcommHCOMM(Huawei Communication)是HCCL的通信基础库,提供通信域以及通信资源的管理能力。项目地址: https://gitcode.com/cann/hcomm
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
