[Paper Review] On the Generation of Test Data for Prolog by Partial Evaluation
This paper proposes a novel approach to test data generation (TDG) for Prolog programs using partial evaluation (PE), overcoming the challenge of handling failing derivations—common in logic programming—by transforming Prolog code to explicitly represent failure. The method enables the generation of both test cases and test-case generators via two-phase PE: first, a Prolog interpreter is specialized to capture failing paths, and second, constraint solving yields concrete test inputs, extending the benefits of PE-based TDG to declarative languages.
In recent work, we have proposed an approach to Test Data Generation (TDG) of imperative bytecode by partial evaluation (PE) of CLP which consists in two phases: (1) the bytecode program is first transformed into an equivalent CLP program by means of interpretive compilation by PE, (2) a second PE is performed in order to supervise the generation of test-cases by execution of the CLP decompiled program. The main advantages of TDG by PE include flexibility to handle new coverage criteria, the possibility to obtain test-case generators and its simplicity to be implemented. The approach in principle can be directly applied for TDG of any imperative language. However, when one tries to apply it to a declarative language like Prolog, we have found as a main difficulty the generation of test-cases which cover the more complex control flow of Prolog. Essentially, the problem is that an intrinsic feature of PE is that it only computes non-failing derivations while in TDG for Prolog it is essential to generate test-cases associated to failing computations. Basically, we propose to transform the original Prolog program into an equivalent Prolog program with explicit failure by partially evaluating a Prolog interpreter which captures failing derivations w.r.t. the input program. Another issue that we discuss in the paper is that, while in the case of bytecode the underlying constraint domain only manipulates integers, in Prolog it should properly handle the symbolic data manipulated by the program. The resulting scheme is of interest for bringing the advantages which are inherent in TDG by PE to the field of logic programming.
Motivation & Objective
- To address the challenge of generating test cases for Prolog that cover failing derivations, which standard partial evaluation inherently omits.
- To extend the existing PE-based TDG framework—originally designed for imperative bytecode—to declarative languages like Prolog.
- To enable the automatic synthesis of test-case generators in CLP form from Prolog programs, enhancing reusability and coverage flexibility.
- To handle symbolic data and complex unifications in Prolog, particularly negated unifications, by integrating constraint handling rules (CHR) and multi-domain constraint solvers.
- To evaluate the feasibility and effectiveness of the approach through preliminary experiments on recursive predicates like sorted/1, demonstrating coverage of paths with bounded recursion depth.
Proposed method
- Transform the original Prolog program into an equivalent version with explicit failure by partially evaluating a Prolog interpreter that tracks failing derivations.
- Use a two-phase partial evaluation process: first, specialize a bytecode interpreter to decompile Prolog into CLP; second, supervise test-case generation via PE of the CLP program.
- Integrate constraint handling rules (CHR) to manage disequality constraints arising from negated unifications, such as \+ L=[] or \+ A#>0.
- Leverage multi-domain constraint solvers (e.g., boolean and numeric) to represent and solve negative conditions as positive constraints, enabling feasibility checking.
- Apply coverage criteria like block-count to guide path enumeration and ensure test cases target specific program paths.
- Use symbolic execution principles within the PE framework to accumulate path conditions and generate test inputs via constraint solving.
Experimental results
Research questions
- RQ1Can partial evaluation be adapted to generate test cases for Prolog programs that include failing derivations, which are typically ignored in standard PE?
- RQ2How can negated unifications and symbolic data structures in Prolog be effectively modeled and solved within a PE-based TDG framework?
- RQ3To what extent can the existing PE-based TDG approach for bytecode be generalized to declarative languages like Prolog?
- RQ4Can the resulting test-case generators be expressed as CLP programs that are both executable and reusable for regression testing?
- RQ5How do coverage criteria like block-count perform in guiding the generation of diverse, path-covered test inputs in Prolog?
Key findings
- The approach successfully generates test cases for the Prolog predicate `sorted/1` that cover all paths with up to three recursive calls, as demonstrated by the block-count (2) criterion.
- A total of seven distinct test cases were generated, including both success and failure paths, such as `[[0,1,2,0|_]],[],no/first-try` for non-sorted lists.
- The method enables the automatic synthesis of CLP-based test-case generators, which can be reused to generate new test inputs without re-running the full PE pipeline.
- The integration of CHR and multi-domain constraint solvers allows effective handling of negated unifications, such as `\+ L=[]` and `\+ A#>0`, by transforming them into positive disequality constraints.
- Preliminary experiments confirm that the approach is viable and scalable for recursive predicates, though further evaluation is needed on larger programs.
- The framework supports advanced Prolog features such as cut/0 and fail/0, though full integration and empirical comparison with existing tools remain ongoing.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.