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

基于 API 知识的深度学习框架自动单元测试生成

Automatic Unit Test Generation for Deep Learning Frameworks based on API Knowledge

Arunkaleeshwaran Narayanan, Nima Shiri harzevili, Junjie Wang, Lin Shi, Moshi Wei, Song Wang

AI总结:

针对自动测试工具在深度学习框架上效果不佳的问题,提出 MUTester,利用从 API 文档和 Stack Overflow 代码片段中挖掘的 API 约束与使用模式指导测试生成,使代码覆盖率平均提升 15.7%-27.0%,并减少约 19.0% 的无效测试。

摘要:

许多能够生成对程序具有高覆盖率的单元测试用例的自动单元测试生成工具已被提出。然而,大多数这些工具在深度学习(DL)框架上效果不佳,因为许多深度学习 API 期望输入遵循特定的 API 知识。为了填补这一空白,我们提出了 MUTester,通过利用从相应 API 文档中挖掘的 API 约束和从 Stack Overflow(SO)中的代码片段挖掘的 API 使用模式,为深度学习框架的 API 生成单元测试用例。具体而言,我们首先提出了一组 18 条规则,用于从 API 文档中挖掘 API 约束。然后,我们使用频繁项集挖掘技术,从收集自 SO 的大规模机器学习 API 相关代码片段语料库中挖掘 API 使用模式。最后,我们使用上述两类 API 知识来指导现有测试生成器对深度学习框架的测试生成。为了评估 MUTester 的性能,我们首先从四个广泛使用的深度学习框架(即 Scikit-learn、PyTorch、TensorFlow 和 CNTK)中收集了 1,971 个 API,并且对于每个 API,我们进一步提取其 API 知识,即 API 约束和 API 使用。给定一个 API,MUTester 将其 API 知识与现有的测试生成器(例如,基于搜索的测试生成器 PyEvosuite 和随机测试生成器 PyRandoop)相结合,以生成测试用例来测试该 API。我们的实验结果表明,MUTester 能够显著改进相应的测试生成方法,代码覆盖率平均提升 15.7% 至 27.0%。此外,它还可以帮助减少现有测试生成器生成的约 19.0% 的无效测试。我们对 16 名开发者的用户研究进一步证明了 MUTester 在为深度学习框架生成测试用例方面的实用性。

英文摘要:

Many automatic unit test generation tools that can generate unit test cases with high coverage over a program have been proposed. However, most of these tools are ineffective on deep learning (DL) frameworks due to the fact that many of deep learning APIs expect inputs that follow specific API knowledge. To fill this gap, we propose MUTester to generate unit test cases for APIs of deep learning frameworks by leveraging the API constraints mined from the corresponding API documentation and the API usage patterns mined from code fragments in Stack Overflow (SO). Particularly, we first propose a set of 18 rules for mining API constraints from the API documents. We then use the frequent itemset mining technique to mine the API usage patterns from a large corpus of machine learning API related code fragments collected from SO. Finally, we use the above two types of API knowledge to guide the test generation of existing test generators for deep learning frameworks. To evaluate the performance of MUTester, we first collect 1,971 APIs from four widely-used deep learning frameworks (i.e., Scikit-learn, PyTorch, TensorFlow, and CNTK) and for each API, we further extract its API knowledge, i.e., API constraints and API usage. Given an API, MUTester combines its API knowledge with existing test generators (e.g., search-based test generator PyEvosuite and random test generator PyRandoop) to generate test cases to test the API. Results of our experiment show that MUTester can significantly improve the corresponding test generation methods and the improvement in code coverage is 15.7% to 27.0% on average. In addition, it can help reduce around 19.0% of invalid tests generated by the existing test generators. Our user study with 16 developers further demonstrates the practicality of MUTester in generating test cases for deep learning frameworks.

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

↑