Wenhan Wang, Kaibo Liu, An Ran Chen, Ge Li, Zhi Jin, Gang Huang, Lei Ma
{"title":"Python Symbolic Execution with LLM-powered Code Generation","authors":"Wenhan Wang, Kaibo Liu, An Ran Chen, Ge Li, Zhi Jin, Gang Huang, Lei Ma","doi":"arxiv-2409.09271","DOIUrl":null,"url":null,"abstract":"Symbolic execution is a key technology in software testing, which generates\ntest cases by collecting symbolic path constraints and then solving constraints\nwith SMT solvers. Symbolic execution has been proven helpful in generating\nhigh-coverage test cases, but its limitations, e.g., the difficulties in\nsolving path constraints, prevent it from broader usage in software testing.\nMoreover, symbolic execution has encountered many difficulties when applied to\ndynamically typed languages like Python, because it is extremely challenging to\ntranslate the flexible Python grammar into rigid solvers. To overcome the main challenges of applying symbolic execution in Python, we\nproposed an LLM-empowered agent, LLM-Sym, that automatically calls an SMT\nsolver, Z3, to solve execution path constraints. Based on an introductory-level\nsymbolic execution engine, our LLM agent can extend it to supporting programs\nwith complex data type `list'. The core contribution of LLM-Sym is translating\ncomplex Python path constraints into Z3 code. To enable accurate path-to-Z3\ntranslation, we design a multiple-step code generation pipeline including type\ninference, retrieval and self-refine. Our experiments demonstrate that LLM-Sym\nis capable of solving path constraints on Leetcode problems with complicated\ncontrol flows and list data structures, which is impossible for the backbone\nsymbolic execution engine. Our approach paves the way for the combination of\nthe generation ability of LLMs with the reasoning ability of symbolic solvers,\nand opens up new opportunities in LLM-augmented test case generation.","PeriodicalId":501278,"journal":{"name":"arXiv - CS - Software Engineering","volume":null,"pages":null},"PeriodicalIF":0.0000,"publicationDate":"2024-09-14","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"0","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"arXiv - CS - Software Engineering","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/arxiv-2409.09271","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 0
Abstract
Symbolic execution is a key technology in software testing, which generates
test cases by collecting symbolic path constraints and then solving constraints
with SMT solvers. Symbolic execution has been proven helpful in generating
high-coverage test cases, but its limitations, e.g., the difficulties in
solving path constraints, prevent it from broader usage in software testing.
Moreover, symbolic execution has encountered many difficulties when applied to
dynamically typed languages like Python, because it is extremely challenging to
translate the flexible Python grammar into rigid solvers. To overcome the main challenges of applying symbolic execution in Python, we
proposed an LLM-empowered agent, LLM-Sym, that automatically calls an SMT
solver, Z3, to solve execution path constraints. Based on an introductory-level
symbolic execution engine, our LLM agent can extend it to supporting programs
with complex data type `list'. The core contribution of LLM-Sym is translating
complex Python path constraints into Z3 code. To enable accurate path-to-Z3
translation, we design a multiple-step code generation pipeline including type
inference, retrieval and self-refine. Our experiments demonstrate that LLM-Sym
is capable of solving path constraints on Leetcode problems with complicated
control flows and list data structures, which is impossible for the backbone
symbolic execution engine. Our approach paves the way for the combination of
the generation ability of LLMs with the reasoning ability of symbolic solvers,
and opens up new opportunities in LLM-augmented test case generation.