Skip to content

test: add support builtin testing and improve runtime feedback#102

Open
yuKing123-king wants to merge 1 commit into
DKapture:mainfrom
yuKing123-king:test/add-mock-trace-exec-BUILTIN
Open

test: add support builtin testing and improve runtime feedback#102
yuKing123-king wants to merge 1 commit into
DKapture:mainfrom
yuKing123-king:test/add-mock-trace-exec-BUILTIN

Conversation

@yuKing123-king

Copy link
Copy Markdown
Contributor

对本次trace-exec工具修改的内容

  1. 补齐 BUILTIN 测试入口,改为通过返回值处理参数解析结果
  2. 增加工具启动后的运行提示

@yuKing123-king
yuKing123-king force-pushed the test/add-mock-trace-exec-BUILTIN branch from e4ead48 to 129eca4 Compare July 21, 2026 02:37

@xu-lang xu-lang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加这些为了做什么,解决什么问题

Comment thread observe/trace-exec.cpp
#include "com.h"

#ifdef BUILTIN
#define BUILTIN_LOCAL static

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

先解释下,为什么加这个,是有重名冲突了?跟谁冲突?

@yuKing123-king yuKing123-king Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 对的,有重名冲突,当多个工具各自编译成 .o 后,两个目标文件都会导出同一个全局符号。test的Makefile会把它们链接在一起,然后合成最终可执行文件时,会导致报错。
  2. 例如这种辅助函数:void Usage(const char *arg0)或者long_opt2short_opt(const option lopts[]),在当前项目中多个工具源码中都是同样命名,所以加这个的目的是,在 BUILTIN 模式下,把这些只希望在当前源文件使用的辅助函数或全局变量,变成“仅当前源文件可见”的内部符号,以防止冲突。BUILTIN模式只给测试模式用,非 BUILTIN只给正常工具运行用

@yuKing123-king
yuKing123-king force-pushed the test/add-mock-trace-exec-BUILTIN branch from 129eca4 to 86353b9 Compare July 21, 2026 07:52
@yuKing123-king

Copy link
Copy Markdown
Contributor Author

加这些为了做什么,解决什么问题

  • 加 BUILTIN 模式,本质上是在给这些 eBPF 工具补一个“测试驱动入口”,让工具逻辑和真实内核/BPF 环境解耦,因为正常运行时,这些工具依赖: 真正的 BPF skeleton open/load/attach、真正的 ring buffer、真正的内核事件、真实 stdout/文件输出、信号、线程、阻塞轮询,但是这些东西在单测里都不稳定,很多还根本没法精确构造。

  • 所以BUILTIN 模式把“参数解析、规则装载、事件过滤、日志格式化、输出行为”这些核心逻辑保留下来,同时把“事件来源”替换成测试线程可注入的 mock 事件。把原本依赖真实内核事件的 eBPF 工具,改造成“主流程仍然真实、事件来源可控替换”的测试模式,加了 BUILTIN 后,可以让测试走的是xxx_main() 主路径,与正常工具不同的,只是事件不是来自内核,而是测试自己定义事件,然后主动投递。这样才能真正验证:帮助输出、非法参数处理、默认规则、自定义规则写入 filter map、事件是否按规则被过滤、日志是否最终被输出到 stdout 或 outfile等,依据不同工具的功能去测试不同的方面。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants