FilesLast commitLast update
7 months ago
4 months ago
2 months ago
4 months ago
2 months ago
9 months ago
2 months ago
25 days ago
25 days ago
16 days ago
3 months ago
2 months ago
4 months ago
1 month ago
4 months ago
1 month ago
1 month ago
1 month ago
1 month ago
25 days ago
7 months ago
README

libmcpp 顶层测试

概述

tests/ 根目录与若干子目录共同构成 libmcpp 集成/公共 API 测试。本文件覆盖根目录 test_*.cpp(含 timer);子目录各自有 README。

对应生产代码:libraries/mcbase/src/timer.cpp、libraries/mcbase/include/mc/timer.h 等。类型为 UT。

目录结构

tests/
├── meson.build
├── README.md
├── test_timer.cpp
├── test_validate.cpp
├── test_validator.cpp
├── test_json_wrapper.cpp   # 仅 enable_conan_compile
├── crypto/ README.md
├── dbus/ README.md
├── json_wrapper/ README.md
├── log/ README.md
├── variant/ README.md
└── ...

测试文件说明

test_timer.cpp

周期 timer 的 stop / 重装 / 无死锁:

  • stop_prevents_pending_timeout:未到期即 stop,回调不触发
  • stop_waits_for_running_timeout:回调执行中 stop 会等待返回
  • stop_once_prevents_periodic_rearm_after_timeout:回调执行中 stop,timeout 返回后被 generation 挡住
  • stop_once_bails_out_internal_rearm:timeout 已返回、即将 start(..., false) 时 stop,命中内部重装 bail-out
  • stop_from_timeout_does_not_deadlock:回调内 stop
  • stop_on_worker_polls_runtime_while_waiting_for_timeout:worker 上 stop 等待时仍能 poll

mc::timer_testing::set_before_periodic_rearm 声明在 libraries/mcbase/tests/test_utilities/timer_testing.h(不安装),仅 tests=true 时编进 libmcbase;生产头 mc/timer.h 不含测试符号。

测试统计

文件 用例数
test_timer.cpp 6
test_validate.cpp / test_validator.cpp 见源文件

被测模块功能说明

生产符号 职责
mc::timer::start/stop 启动/停止;周期 timeout 后内部 start(..., false) 不得清取消标志
timer_impl::m_mutex 重装与 stop 同一临界区
m_generation async_wait 完成路径上的迟到到期兜底

构建和运行

cd /path/to/libmcpp
./scripts/smart_build.sh
meson test -C builddir --print-errorlogs --test-args="--gtest_filter=timer_test.*"

过滤 timer 也可对 mcbase_test / libmcpp_test 使用 --gtest_filter=timer_test.*(目标名以 meson test -C builddir --list 为准)。

注意事项

  • 回调中 stop 会在 run_callback 的 is_cancelled(generation) 处返回,不会进入 start(..., false)。要覆盖内部重装 bail-out 必须用 set_before_periodic_rearm。
  • 用户回调结束后才内部重装,所以 stop_once_bails_out_internal_rearm 里 stop() 不必等探针;测完靠 scoped_periodic_rearm_probe 析构清 hook。
  • ./scripts/smart_build.sh 若同时有 FAIL 与 TIMEOUT,不会整包 timeout-multiplier=3 重试。看到 ninja: no work to do 后长时间无输出,通常是 meson 正在跑 mcbase unit tests(timeout 300s),不是脚本卡死。
  • 不要并行跑两个 smart_build.sh(尤其是一个 -X 清 builddir、另一个还在 gcc-ar)。会表现为 xxx.cpp.o: No such file or directory。脚本用 .smart_build.lock 互斥。