SuperAPI AI 工具集

skia-add-test

测试与质量

查看项目

更新于 10-16 05:49

技能介绍

用途:为 Skia 仓库添加新的测试。测试主要用 C++ 编写,放在 tests/ 目录。

主要能力与流程:

  1. 创建测试文件:在 tests/ 目录新建 .cpp 文件,可参考模板 assets/test_template.cpp。
  2. 更新构建系统:把新测试文件路径加入 gn/tests.gni 的 tests_sources 列表;路径应相对该目录或使用 $_tests 变量。
  3. 编译测试:编译运行测试的 dm 工具,命令为 ninja --quiet -C out/Debug dm。
  4. 运行测试:用 dm 的 --match 参数运行指定测试,命令为 out/Debug/dm --match [test_name],其中 [test_name] 替换为 DEF_TEST 等宏中提供的名称。

关键概念: 定义测试的宏包括 DEF_TEST(name, reporter)(标准 CPU 测试)、DEF_GANESH_TEST(name, reporter, options, ctsEnforcement)(Ganesh GPU 测试)、DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS(name, reporter, context, ctsEnforcement)(Graphite GPU 测试)。 CtsEnforcement 用于标记应纳入 Android 兼容性测试套件(CTS)特定里程碑或更晚版本的测试,如 CtsEnforcement::kNever 表示不纳入 CTS,CtsEnforcement::kApiLevel_U 表示 Android U 及以后必需。 断言与报告:REPORTER_ASSERT(reporter, condition, ...) 为标准断言;ERRORF(reporter, ...) 报告带格式化消息的失败;skiatest::ReporterContext 为栈分配对象,可为失败报告提供额外上下文(如子测试名),例如在其作用域内使用 REPORTER_ASSERT,失败信息会包含该子测试名。

限制:资料未提供模板具体内容、构建环境要求、支持平台及更多错误处理细节。