Table of Contents
Fetching ...

Automatically Testing Functional Properties of Code Translation Models

Hasan Ferit Eniser, Valentin Wüstholz, Maria Christakis

TL;DR

The paper addresses the correctness of code translations produced by large language models by introducing automated, property-based testing using an extended Nomos framework that supports $k$-safety properties. It formalizes a broad suite of properties for code transpilation, generates test harnesses via metamorphic testing, and demonstrates the approach on four state-of-the-art translation models, revealing widespread property violations. It also introduces a property-guided search that mutates model parameters to produce translations that satisfy user-specified properties, improving translation quality for a given input. The work provides a rigorous evaluation framework and a practical tool to assess and potentially enhance transpilation quality, with implications for reliable multi-language software maintenance.

Abstract

Large language models are becoming increasingly practical for translating code across programming languages, a process known as $transpiling$. Even though automated transpilation significantly boosts developer productivity, a key concern is whether the generated code is correct. Existing work initially used manually crafted test suites to test the translations of a small corpus of programs; these test suites were later automated. In contrast, we devise the first approach for automated, functional, property-based testing of code translation models. Our general, user-provided specifications about the transpiled code capture a range of properties, from purely syntactic to purely semantic ones. As shown by our experiments, this approach is very effective in detecting property violations in popular code translation models, and therefore, in evaluating model quality with respect to given properties. We also go a step further and explore the usage scenario where a user simply aims to obtain a correct translation of some code with respect to certain properties without necessarily being concerned about the overall quality of the model. To this purpose, we develop the first property-guided search procedure for code translation models, where a model is repeatedly queried with slightly different parameters to produce alternative and potentially more correct translations. Our results show that this search procedure helps to obtain significantly better code translations.

Automatically Testing Functional Properties of Code Translation Models

TL;DR

The paper addresses the correctness of code translations produced by large language models by introducing automated, property-based testing using an extended Nomos framework that supports -safety properties. It formalizes a broad suite of properties for code transpilation, generates test harnesses via metamorphic testing, and demonstrates the approach on four state-of-the-art translation models, revealing widespread property violations. It also introduces a property-guided search that mutates model parameters to produce translations that satisfy user-specified properties, improving translation quality for a given input. The work provides a rigorous evaluation framework and a practical tool to assess and potentially enhance transpilation quality, with implications for reliable multi-language software maintenance.

Abstract

Large language models are becoming increasingly practical for translating code across programming languages, a process known as . Even though automated transpilation significantly boosts developer productivity, a key concern is whether the generated code is correct. Existing work initially used manually crafted test suites to test the translations of a small corpus of programs; these test suites were later automated. In contrast, we devise the first approach for automated, functional, property-based testing of code translation models. Our general, user-provided specifications about the transpiled code capture a range of properties, from purely syntactic to purely semantic ones. As shown by our experiments, this approach is very effective in detecting property violations in popular code translation models, and therefore, in evaluating model quality with respect to given properties. We also go a step further and explore the usage scenario where a user simply aims to obtain a correct translation of some code with respect to certain properties without necessarily being concerned about the overall quality of the model. To this purpose, we develop the first property-guided search procedure for code translation models, where a model is repeatedly queried with slightly different parameters to produce alternative and potentially more correct translations. Our results show that this search procedure helps to obtain significantly better code translations.
Paper Structure (11 sections, 2 figures, 3 tables, 1 algorithm)

This paper contains 11 sections, 2 figures, 3 tables, 1 algorithm.

Figures (2)

  • Figure 1: Example $k$-safety specifications for code translation models.
  • Figure 2: The number of passing programs (top) and the number of syntactic and other property violations (bottom) as the number of search iterations increases from 1 to 20.