arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2504.01294cs.SE
收藏

使用大语言模型从文档中提取形式化规约以进行自动化测试

Extracting Formal Specifications from Documents Using LLMs for Automated Testing

Hui Li, Zhen Dong, Siao Wang, Hui Zhang, Liwei Shen, Xin Peng, Dongdong She

AI总结:

针对从软件文档中人工提取形式化规约耗时易错的问题,本研究评估了GPT-4o等LLMs的端到端提取能力,并提出“先标注后转换”的两阶段方法,使正确提取数量增加29.2%,最高准确率达71.6%。

摘要:

自动化测试在确保软件安全性方面发挥着至关重要的作用。它严重依赖形式化规约来验证系统行为的正确性。然而,定义这些形式化规约的主要方法是通过人工分析软件文档,这需要经验丰富的研究人员和工程师投入大量工程精力。同时,系统更新进一步增加了维护相应形式化规约的人力成本,使得人工分析方法成为一项耗时且容易出错的任务。大语言模型(LLMs)的最新进展展示了在自然语言理解方面的良好能力。然而,使用LLMs从软件文档中自动提取形式化规约的可行性仍未被探索。我们通过构建一个包含来自三个代表性开源软件的37份文档中603条规约的综合数据集来进行实证研究。然后,我们评估了最新LLMs以端到端方式从文档中提取形式化规约的能力,包括GPT-4o、Claude和Llama。我们的研究展示了LLMs在形式化规约提取任务中的应用,同时发现了两个主要局限性:规约过度简化和规约捏造。我们将这些缺陷归因于LLMs在处理和表达能力方面的固有局限性,以及它们捏造虚构信息的倾向。受人类认知过程的启发,我们提出了一种两阶段方法,即先标注后转换(annotation-then-conversion),以应对这些挑战。我们的方法相比端到端方法展现出显著改进,正确提取的规约数量增加了29.2%,平均准确率提高了14.0%。特别是,我们表现最好的LLM达到了71.6%的准确率。

英文摘要:

Automated testing plays a crucial role in ensuring software security. It heavily relies on formal specifications to validate the correctness of the system behavior. However, the main approach to defining these formal specifications is through manual analysis of software documents, which requires a significant amount of engineering effort from experienced researchers and engineers. Meanwhile, system update further increases the human labor cost to maintain a corresponding formal specification, making the manual analysis approach a time-consuming and error-prone task. Recent advances in Large Language Models (LLMs) have demonstrated promising capabilities in natural language understanding. Yet, the feasibility of using LLMs to automate the extraction of formal specifications from software documents remains unexplored. We conduct an empirical study by constructing a comprehensive dataset comprising 603 specifications from 37 documents across three representative open-source software. We then evaluate the most recent LLMs' capabilities in extracting formal specifications from documents in an end-to-end fashion, including GPT-4o, Claude, and Llama. Our study demonstrates the application of LLMs in formal specification extraction tasks while identifying two major limitations: specification oversimplification and specification fabrication. We attribute these deficiencies to the LLMs' inherent limitations in processing and expressive capabilities, as well as their tendency to fabricate fictional information. Inspired by human cognitive processes, we propose a two-stage method, annotation-then-conversion, to address these challenges. Our method demonstrates significant improvements over the end-to-end method, with a 29.2% increase in the number of correctly extracted specifications and a 14.0% improvement in average accuracy. In particular, our best-performing LLM achieves an accuracy of 71.6%.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑