Skip to main content
QUICK REVIEW

[论文解读] Predicting Code Coverage without Execution

Michele Tufano, Shubham Chandel|arXiv (Cornell University)|Jul 25, 2023
Software Engineering Research被引用 4
一句话总结

本文提出代码覆盖率预测作为一项新颖的基准任务,用于评估大语言模型(LLMs)对代码执行的理解能力。通过从HumanEval中收集实际代码覆盖率标注,构建了CoverageEval数据集,对当前最先进的LLMs——GPT-4、GPT-3.5、BARD和Claude进行评估,结果显示即使GPT-4在少样本提示下也仅达到24.48%的准确率,表明LLMs在理解代码执行动态方面仍有巨大提升空间。

ABSTRACT

Code coverage is a widely used metric for quantifying the extent to which program elements, such as statements or branches, are executed during testing. Calculating code coverage is resource-intensive, requiring code building and execution with additional overhead for the instrumentation. Furthermore, computing coverage of any snippet of code requires the whole program context. Using Machine Learning to amortize this expensive process could lower the cost of code coverage by requiring only the source code context, and the task of code coverage prediction can be a novel benchmark for judging the ability of models to understand code. We propose a novel benchmark task called Code Coverage Prediction for Large Language Models (LLMs). We formalize this task to evaluate the capability of LLMs in understanding code execution by determining which lines of a method are executed by a given test case and inputs. We curate and release a dataset we call COVERAGEEVAL by executing tests and code from the HumanEval dataset and collecting code coverage information. We report the performance of four state-of-the-art LLMs used for code-related tasks, including OpenAI's GPT-4 and GPT-3.5-Turbo, Google's BARD, and Anthropic's Claude, on the Code Coverage Prediction task. Finally, we argue that code coverage as a metric and pre-training data source are valuable for overall LLM performance on software engineering tasks.

研究动机与目标

  • 将代码覆盖率预测形式化为一项新基准任务,以评估LLMs对代码执行的理解能力。
  • 解决传统代码覆盖率测量中计算成本高且依赖上下文的问题,特别是针对代码片段或部分程序的情况。
  • 评估LLMs是否能在不实际执行代码的情况下,预测给定测试用例所执行的代码行。
  • 提供一种新的预训练或微调目标,以增强LLMs对不同输入下代码行为的推理能力。
  • 在构建成本高昂、代码可用性有限或IDE中需要实时反馈的场景中实现实际应用。

提出的方法

  • 通过执行HumanEval基准中的测试用例并使用插桩技术收集实际代码覆盖率,构建CoverageEval数据集。
  • 为每个方法-测试用例对标注覆盖率标签:已执行(‘>’)、未执行(‘!’)或不可达(‘-’),形成结构化的预测任务。
  • 将该任务形式化为序列到序列的预测问题,输入为方法和测试用例,输出为带覆盖率标注的方法。
  • 使用零样本和少样本提示,在覆盖率预测任务上评估四种SOTA LLMs——GPT-4、GPT-3.5-Turbo、BARD和Claude。
  • 以精确匹配准确率为主要评估指标,衡量模型正确预测完整覆盖率标注的频率。
  • 探索了昂贵构建、代码可用性有限和实时单元测试等用例,以证明基于预测的覆盖率的实用价值。

实验结果

研究问题

  • RQ1LLMs能否在不运行代码的情况下,准确预测给定测试用例所执行的代码行?
  • RQ2在不同少样本提示策略下,当前SOTA LLMs在预测代码覆盖率方面的性能表现如何?
  • RQ3LLMs在多大程度上理解了代码在不同输入和测试条件下的动态行为?
  • RQ4代码覆盖率预测能否作为有意义的预训练或微调目标,以提升LLMs对代码执行的推理能力?
  • RQ5在哪些现实世界软件工程场景中,基于LLM的代码覆盖率预测相比传统执行方法具有实际优势?

主要发现

  • GPT-4在所评估模型中表现最佳,零样本提示下达到10.46%的精确匹配准确率,少样本提示下提升至24.48%。
  • 无一模型达到高准确率——即使GPT-4也仅对少于四分之一的方法-测试用例对预测了正确的覆盖率,表明其对代码执行的理解仍有限。
  • 各模型间的性能差距表明,当前LLMs在推理代码控制流和条件执行方面仍存在困难。
  • CoverageEval数据集使LLMs在代码执行理解方面的系统性评估成为可能,为未来研究提供了新基准。
  • 该任务在构建成本高昂、代码部分传输或实时单元测试等场景中具有实际价值,此时执行不可行或成本过高。
  • 代码覆盖率预测可作为有价值的训练目标,以提升LLMs生成和测试代码的有效性。

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。