13f4cbf05Sopenharmony_ci# Benchmark测试
23f4cbf05Sopenharmony_ci
33f4cbf05Sopenharmony_ci基准测试(benchmarking)是一种测量和评估软件性能指标的活动,可以在某个时候通过基准测试建立一个已知的性能水平(称为基准线),
43f4cbf05Sopenharmony_ci当系统的软硬件环境发生变化之后再进行一次基准测试以确定那些变化对性能的影响。这是基准测试最常见的用途,其他用途包括测定某种负载水平下的性能极限、
53f4cbf05Sopenharmony_ci管理系统或环境的变化、发现可能导致性能问题的条件等。
63f4cbf05Sopenharmony_ci
73f4cbf05Sopenharmony_ci## 目录结构
83f4cbf05Sopenharmony_ci
93f4cbf05Sopenharmony_ci```
103f4cbf05Sopenharmony_cicommonlibrary/c_utils/base/test
113f4cbf05Sopenharmony_ci├─ benchmarktest
123f4cbf05Sopenharmony_ci│   ├── ashemem_benchmark_test                      # 匿名共享内存接口性能测试
133f4cbf05Sopenharmony_ci│   ├── datetime_benchmark_test                     # 日期与时间接口性能测试
143f4cbf05Sopenharmony_ci│   ├── directory_benchmark_test                    # 文件与目录接口性能测试
153f4cbf05Sopenharmony_ci│   ├── event_benchmark_test                        # 事件处理系统接口性能测试
163f4cbf05Sopenharmony_ci│   ├── file_benchmark_test                         # 读写文件接口性能测试
173f4cbf05Sopenharmony_ci│   ├── mapped_benchmark_test                       # 文件映射接口性能测试
183f4cbf05Sopenharmony_ci│   ├── observer_benchmark_test                     # 观察者模式接口性能测试
193f4cbf05Sopenharmony_ci│   ├── parcel_benchmark_test                       # 使用Parcel作为数据容器接口性能测试
203f4cbf05Sopenharmony_ci│   ├── refbase_benchmark_test                      # 智能指针管理动态分配内存对象接口性能测试
213f4cbf05Sopenharmony_ci│   ├── rwlock_benchmark_test                       # 读写锁接口性能测试
223f4cbf05Sopenharmony_ci│   ├── safe_block_queue_benchmark_test             # 线程安全阻塞队列接口性能测试
233f4cbf05Sopenharmony_ci│   ├── safe_block_queue_tracking_benchmark_test
243f4cbf05Sopenharmony_ci│   ├── safe_map_benchmark_test                     # 线程安全Map接口性能测试
253f4cbf05Sopenharmony_ci│   ├── safe_queue_benchmark_test                   # 线程安全栈与队列接口性能测试
263f4cbf05Sopenharmony_ci│   ├── singleton_benchmark_test                    # 单例模式接口性能测试
273f4cbf05Sopenharmony_ci│   ├── sorted_vector_benchmark_test                # 有序Vector接口性能测试
283f4cbf05Sopenharmony_ci│   ├── string_benchmark_test                       # 字符串处理接口性能测试
293f4cbf05Sopenharmony_ci│   ├── thread_benchmark_test                       # 强化线程能力接口性能测试
303f4cbf05Sopenharmony_ci│   ├── thread_pool_benchmark_test                  # 线程池接口性能测试
313f4cbf05Sopenharmony_ci│   ├── timer_benchmark_test                        # 定时器接口性能测试
323f4cbf05Sopenharmony_ci│   ├── unique_fd_benchmark_test                    # 管理、传递文件描述符接口性能测试
333f4cbf05Sopenharmony_ci│   ├── benchmark_assert.h
343f4cbf05Sopenharmony_ci│   ├── BUILD.gn
353f4cbf05Sopenharmony_ci│   └── benchmark_log.h 
363f4cbf05Sopenharmony_ci```
373f4cbf05Sopenharmony_ci
383f4cbf05Sopenharmony_ci## 编译构建
393f4cbf05Sopenharmony_ci### 编译部件
403f4cbf05Sopenharmony_ci```
413f4cbf05Sopenharmony_ci./build.sh --product-name rk3568 --build-target c_utils
423f4cbf05Sopenharmony_ci```
433f4cbf05Sopenharmony_ci
443f4cbf05Sopenharmony_ci### 测试套编译
453f4cbf05Sopenharmony_ci```
463f4cbf05Sopenharmony_ci./build.sh --product-name rk3568 --build-target commonlibrary/c_utils/base/test/benchmarktest/
473f4cbf05Sopenharmony_ci```
483f4cbf05Sopenharmony_ci
493f4cbf05Sopenharmony_ci### 测试套生成路径
503f4cbf05Sopenharmony_ci```
513f4cbf05Sopenharmony_ci/out/rk3568/tests/benchmark
523f4cbf05Sopenharmony_ci```
533f4cbf05Sopenharmony_ci
543f4cbf05Sopenharmony_ci### 编译静态库
553f4cbf05Sopenharmony_ci```
563f4cbf05Sopenharmony_ci./build.sh --product-name rk3568 --build-target commonlibrary/c_utils/base:utilsbase
573f4cbf05Sopenharmony_ci```
583f4cbf05Sopenharmony_ci
593f4cbf05Sopenharmony_ci## 测试环境构建(windows)
603f4cbf05Sopenharmony_ci### 测试目录构建
613f4cbf05Sopenharmony_ci
623f4cbf05Sopenharmony_ci```
633f4cbf05Sopenharmony_ci
643f4cbf05Sopenharmony_ciTest
653f4cbf05Sopenharmony_ci├── developer_test                 # 开发者自测试框架 git clone https://gitee.com/openharmony/testfwk_developer_test.git
663f4cbf05Sopenharmony_ci│   ├── aw
673f4cbf05Sopenharmony_ci│   ├── config  # 测试框架配置
683f4cbf05Sopenharmony_ci│   │   ├── framework_config.xml   #配置benchmark timeout字段为"900"
693f4cbf05Sopenharmony_ci│   │   └── user_config.xml        #sn字段需要配置开发板序列号  test_cases字段需要配置编译生成的测试用例目录
703f4cbf05Sopenharmony_ci│   ├── examples
713f4cbf05Sopenharmony_ci│   ├── src
723f4cbf05Sopenharmony_ci│   ├── third_party
733f4cbf05Sopenharmony_ci│   ├── reports                    # 测试结果报告
743f4cbf05Sopenharmony_ci│   ├── BUILD.gn
753f4cbf05Sopenharmony_ci│   ├── start.bat                  # Windows
763f4cbf05Sopenharmony_ci│   └── start.sh                   # Linux
773f4cbf05Sopenharmony_ci├── testcase                       # cp -r /out/rk3568/tests/benchmark/ XXX/testcase/
783f4cbf05Sopenharmony_ci└── xdevice                        # git clone https://gitee.com/openharmony/testfwk_xdevice.git
793f4cbf05Sopenharmony_ci
803f4cbf05Sopenharmony_ci```
813f4cbf05Sopenharmony_ci## 执行测试用例(windows)
823f4cbf05Sopenharmony_ci### 启动测试框架
833f4cbf05Sopenharmony_ci	执行start.bat
843f4cbf05Sopenharmony_ci
853f4cbf05Sopenharmony_ci### 选择产品形态
863f4cbf05Sopenharmony_ci	默认选择为rk3568
873f4cbf05Sopenharmony_ci
883f4cbf05Sopenharmony_ci
893f4cbf05Sopenharmony_ci### 执行测试用例(以parcel为例)
903f4cbf05Sopenharmony_ci	eg:run -t BENCHMARK -ts ParcelTest
913f4cbf05Sopenharmony_ci
923f4cbf05Sopenharmony_ci  	执行命令参数说明:
933f4cbf05Sopenharmony_ci    ```
943f4cbf05Sopenharmony_ci    -t [TESTTYPE]: 指定测试用例类型,有UT,MST,ST,PERF,FUZZ,BENCHMARK等。(必选参数)
953f4cbf05Sopenharmony_ci    -ts [TESTSUITE]: 指定测试套,可独立使用。
963f4cbf05Sopenharmony_ci    ```
973f4cbf05Sopenharmony_ci
983f4cbf05Sopenharmony_ci### 测试报告日志
993f4cbf05Sopenharmony_ci当执行完测试指令,控制台会自动生成测试结果,若需要详细测试报告您可在相应的数据文档中进行查找。
1003f4cbf05Sopenharmony_ci
1013f4cbf05Sopenharmony_ci#### 测试结果
1023f4cbf05Sopenharmony_ci测试结果输出根路径如下:
1033f4cbf05Sopenharmony_ci```
1043f4cbf05Sopenharmony_ciTest/developer_test/reports/xxxx_xx_xx_xx_xx_xx
1053f4cbf05Sopenharmony_ci
106