arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2603.06107cs.SE
收藏

面向C扩展Python项目的现实世界故障检测:自动化单元测试生成

Real-World Fault Detection for C-Extended Python Projects with Automated Unit Test Generation

University of Namur(南纳穆尔大学);University of Passau(帕绍大学);JetBrains Research(JetBrains研究院);Delft University of Technology(代尔夫特理工大学)

Lucas Berg, Lukas Krodinger, Stephan Lukasczyk, Annibale Panichella, Gordon Fraser, Wim Vanhoof, Xavier Devroey

AI总结:

本研究提出通过分离测试生成过程的生成与执行阶段,利用子进程执行技术提升C扩展Python项目中故障检测的覆盖率和准确性。

摘要:

许多流行的Python库使用C扩展来实现性能关键操作,使用户能够结合Python的简单性和多功能性与C的性能。这种方法的缺点是C中引发的异常可以绕过Python的异常处理机制,导致整个解释器崩溃。如果在调用公共API时发生此类崩溃,则属于真正的故障。虽然自动化测试生成在原则上应能够检测此类故障,但原生代码中的崩溃会完全停止测试过程,阻止对底层错误的检测或重现,从而抑制对非崩溃代码部分的覆盖率。为了解决这个问题,我们提出将测试生成过程的生成和执行阶段分离。因此,我们调整Pynguin,一个专为Python设计的自动化测试用例生成工具,使其使用子进程执行。每个生成的测试用例在隔离的子进程中执行,防止崩溃停止测试生成过程本身。这使我们能够(1)检测此类故障,(2)为它们生成可重复的崩溃揭示测试用例,(3)研究底层故障,(4)对非崩溃代码部分进行测试生成。为了评估我们的方法,我们创建了一个包含来自21个流行Python库中1648个模块的数据集。子进程执行使自动化测试能够测试多达56.5%更多的模块,并发现了213个独特的崩溃原因,揭示了32个此前未知的故障。

英文摘要:

Many popular Python libraries use C-extensions for performance-critical operations allowing users to combine the best of the two worlds: The simplicity and versatility of Python and the performance of C. A drawback of this approach is that exceptions raised in C can bypass Python's exception handling and cause the entire interpreter to crash. These crashes are real faults if they occur when calling a public API. While automated test generation should, in principle, detect such faults, crashes in native code can halt the test process entirely, preventing detection or reproduction of the underlying errors and inhibiting coverage of non-crashing parts of the code. To overcome this problem, we propose separating the generation and execution stages of the test-generation process. We therefore adapt Pynguin, an automated test case generation tool for Python, to use subprocess-execution. Executing each generated test in an isolated subprocess prevents a crash from halting the test generation process itself. This allows us to (1) detect such faults, (2) generate reproducible crash-revealing test cases for them, (3) allow studying the underlying faults, and (4) enable test generation for non-crashing parts of the code. To evaluate our approach, we created a dataset consisting of 1648 modules from 21 popular Python libraries with C-extensions. Subprocess-execution allowed automated testing of up to 56.5% more modules and discovered 213 unique crash causes, revealing 32 previously unknown faults.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑