We use cookies to improve your experience with our site.

使用规则导向的符号执行进行面向C语言的单元测试数据生成

Unit Test Data Generation for C Using Rule-Directed Symbolic Execution

  • 摘要: 单元测试广泛应用于软件开发过程中。自动化测试数据生成是单元测试中的一个重要环节。基于约束的测试数据生成是用于自动化的生成测试数据的技术,其使用符号执行来生成约束。单元测试只对函数进行测试而不是对整个程序进行测试,单个函数常常对其输入设置前置条件。传统的符号执行无法检测到这些前置条件,更不必说将这些前置条件转换为约束。为了解决这一问题,我们提出了一种新的单元测试数据生成方法,该方法使用规则导向的符号执行来处理缺少输入前置条件的函数。规则导向的符号执行使用预定义的规则来检测单个函数中的前置条件,并基于前置条件为输入生成约束。我们引入隐性约束来表示前置条件,并将隐性约束和程序约束统一为完整约束。基于完整约束生成的测试数据可以覆盖以前无法覆盖的代码,帮助开发人员发现更多功能故障和逻辑故障。我们在工具CTS-IC中实现了我们的方法,并使用实际工程进行了实验。实验结果表明,规则导向的符号执行可以自动的从单个函数中找到前置条件(隐性约束)。除此之外,我们的方法生成的单元测试数据可以获得比类似工具更高的覆盖率,并能有效地缓解由单元测试中缺少输入前置条件所引发的问题。

     

    Abstract: Unit testing is widely used in software development. One important activity in unit testing is automatic test data generation. Constraint-based test data generation is a technique for automatic generation of test data, which uses symbolic execution to generate constraints. Unit testing only tests functions instead of the whole program, where individual functions typically have preconditions imposed on their inputs. Conventional symbolic execution cannot detect these preconditions, let alone converting these preconditions into constraints. To overcome these limitations, we propose a novel unit test data generation approach using rule-directed symbolic execution for dealing with functions with missing input preconditions. Rule-directed symbolic execution uses predefined rules to detect preconditions in the individual function, and generates constraints for inputs based on preconditions. We introduce implicit constraints to represent preconditions, and unify implicit constraints and program constraints into integrated constraints. Test data generated based on integrated constraints can explore previously unreachable code and help developers find more functional faults and logical faults. We have implemented our approach in a tool called CTS-IC, and applied it to real-world projects. The experimental results show that rule-directed symbolic execution can find preconditions (implicit constraints) automatically from an individual function. Moreover, the unit test data generated by our approach achieves higher coverage than similar tools and efficiently mitigates missing input preconditions problems in unit testing for individual functions.

     

/

返回文章
返回