将valgrind集成到持续集成工作流中的工具。
ValgrindC的Python项目详细描述
与Valgrind的持续整合
{a1}提供了一个连续集成到vali}包中的Python工作流。在
Valgrind有时会产生大量的发现,而且很难从这些数据中提取所需的信息。ValgrindCI最基本的功能是,如果valgrind的结果满足用户定义的某些标准,例如,valgrind报告了一个单一错误,则终止作业。ValgrindCI还可以帮助您更好地了解ValgrindCI报告的错误:
- 可以对错误进行分组或筛选(例如,仅限泄漏错误)。在
- 可在《瓦尔克历险记》上找到。在
- ValgrindCI可以生成一个HTML报告来直接在代码中调查错误。在
安装
从源安装
先决条件
ValgrindCI使用Python包^{pip
安装这些依赖项。在
> pip install -r requirements.txt
构建并安装软件包
ValgrindCI使用setuptools
构建其包,然后由pip
安装
使用pip
下载并安装
ValgrindCI是一个用Python编写的工具,可以从pip
安装。在
> pip install ValgrindCI
如何使用
ValgrindCI是一个命令工具,设计用于在您喜欢的持续集成平台的作业中执行。它解析valgrind的XML输出以提供其服务。在
首先,Valgrind必须使用选项--xml=yes
和{
> valgrind --tool=memcheck --xml=yes --xml-file==/path/to/output_file.xml my_executable --options-of-my-executable
获取基本信息
现在,可以调用ValgrindCI来解析XML输出文件并报告ValgrindCI发现的错误总数。在
> valgrind-ci /path/to/output_file.xml --number-of-errors
出错时中止
当使用非零值调用系统命令exit()
时,大多数CI平台都会检测到作业失败。此功能允许ValgrindCI在valgrind报告错误时立即报告故障:
> valgrind-ci /path/to/output_file.xml --abort-on-errors
错误汇总报告
您可以请求ValgrindCI打印ValgrindCI发现的错误的摘要报告。在
> valgrind-ci /path/to/output_file.xml --summary
输出示例如下:
src/models/FGAtmosphere.cpp:
9 errors
line 125: UninitCondition (1 errors)
line 129: UninitCondition (6 errors)
UninitValue (2 errors)
src/models/FGMassBalance.cpp:
13 errors
line 207: UninitCondition (11 errors)
line 472: SyscallParam (1 errors)
UninitCondition (1 errors)
因为一个函数可以从不同的地方调用,所以valgrind可以多次将一行代码报告为有问题的行。在上面的例子中,文件src/models/FGMassBalance.cpp
的第207行被报告了11次,每次都使用不同的调用堆栈。显然,ValgrindCI在这种情况下的附加值是按源文件和行号对错误进行分组。通过这个简单的过程,对于上面说明的特定情况,错误的数量已经从2147缩小到185!在
HTML报告
ValgrindCI可以生成一个HTML报告,在代码中显示Valgrind报告的错误。下面的命令在目录html
中生成一个HTML报告。参数--source-dir
用于构建相对于该目录的路径,而不是绝对路径。在
> valgrind-ci /path/to/output_file.xml --source-dir=/path/to/source/code --output-dir=html
如果打开文档html/index.html
,则可以使用web浏览器查看报告,错误及其相应的调用堆栈将显示在源代码中。在
其他选项
ValgrindCI命令行工具有许多参数可用于调整工具以满足您的特定需要:
usage: valgrind-ci [-h] [--version] [--source-dir SOURCE_DIR]
[--output-dir OUTPUT_DIR] [--summary] [--number-of-errors]
[--lines-before LINES_BEFORE] [--lines-after LINES_AFTER]
[--abort-on-errors]
xml_file
positional arguments:
xml_file Valgrind XML file name
optional arguments:
-h, --help show this help message and exit
--version show program's version number and exit
--source-dir SOURCE_DIR
specifies the source directory
--output-dir OUTPUT_DIR
directory where the HTML report will be generated
--summary print a summary of errors
--number-of-errors print the total number of errors found by Valgrind
--lines-before LINES_BEFORE
number of code lines to display in the HTML report
before the error line (default to 3)
--lines-after LINES_AFTER
number of code lines to display in the HTML report
after the error line (default to 3)
--abort-on-errors call exit(1) if errors have been reported by Valgrind
高级用法
ValgrindCI还可以用作Python库,帮助您以编程方式筛选和选择错误。在
错误过滤
Valgrind会产生大量的错误,并不是所有的错误都与您的项目相关。在这种情况下,ValgrindCI可以过滤数据,只报告您感兴趣的错误。在
例如,如果您只需要则可以使用方法filter_error_kind()
过滤数据以报告此类错误:
fromValgrindCI.parseimportValgrindDatadata=ValgrindData()data.parse('/path/to/output_file.xml')# Output the number of errors for leaks definitely lost.print(data.filter_error_kind('Leak_DefinitelyLost').get_num_errors())
还有一些其他过滤器可用于选择源文件的子集或特定的代码行。在
HTML报告
根据需要过滤错误后,可以从实例data
生成一个HTML报告:
fromValgrindCI.renderimportHTMLRendererrenderer=HTMLRenderer(data)renderer.render('html',lines_before=3,lines_after=3)
总结报告
或者,您可以在控制台中打印摘要报告:
fromValgrindCI.reportimportReportreport=Report(data)print(report.summary())
释放
v0.1.1
:错误修复- 修复了问题1(无法识别用于泄漏错误的标记
<xwhat>
)。在 - 修正了未指定可选参数
--source-dir
时报告错误数的问题。在
- 修复了问题1(无法识别用于泄漏错误的标记
v0.1.0
:初始版本
- 项目
标签: