一句话:提出基于进化算法的工具 EvoSpex,从测试用例自动推断 Java 方法的后置条件。
后置条件刻画程序终止时的状态性质,能提升多种软件可靠性分析,但源码中往往缺失。针对这一问题,本文以工具演示形式提出 EvoSpex:给定目标 Java 方法及其测试套件,先执行测试获得有效的前/后状态对,再对这些状态对进行变异以得到(假定的)无效状态对;随后用经典遗传算法在类 JML 规约语言空间中搜索候选后置条件断言,使其接受有效状态对、排除无效状态对。适应度函数同时衡量对有效状态对的精确刻画、对无效状态对的拒绝能力,并偏好更简洁的断言。该工具实现了后置条件的自动推断,可辅助开发者编写规约。
Postconditions are predicates that specify the intended behavior of a program by capturing properties about the program state when the program finishes its execution. Although postconditions can help to improve many software reliability analyses, they are seldom found accompanying source code. Thus, tools that assist developers in specifying postconditions are useful. This tool demo paper presents EvoSpex, a tool based on evolutionary computation that automatically infers postconditions of Java methods. Given a target Java method and a test suite for it, our tool executes the test suite to obtain valid pre/post state pairs for the method under analysis. Then, these pairs are mutated to obtain (allegedly) invalid ones, and finally a postcondition assertion characterizing the current method behavior is produced, by using an evolutionary algorithm that searches for an assertion that is satisfied by the valid pre/post state pairs and leaves out the invalid ones. EvoSpex implements a classic genetic algorithm that explores the space of candidate postconditions over a JML-like specification language. The algorithm is guided by a fitness function that aims at precisely capturing the valid state pairs, rejecting the invalid ones, and that also favors more succinct assertions.