[论文解读] Inputs from Hell: Generating Uncommon Inputs from Common Samples
本文提出一种方法,利用上下文无关语法和输入样本生成常见且不常见的、但语法正确的输入。通过从常见输入中挖掘产生式概率并进行反转,该方法生成‘地狱输入’——即罕见、边缘情况的输入,可暴露程序中未测试的代码路径,从而有效实现鲁棒性测试,并覆盖处理结构化输入(如 JSON、JavaScript 和 CSS)的程序中此前未被发现的行为。
Generating structured input files to test programs can be performed by techniques that produce them from a grammar that serves as the specification for syntactically correct input files. Two interesting scenarios then arise for effective testing. In the first scenario, software engineers would like to generate inputs that are as similar as possible to the inputs in common usage of the program, to test the reliability of the program. More interesting is the second scenario where inputs should be as dissimilar as possible from normal usage. This is useful for robustness testing and exploring yet uncovered behavior. To provide test cases for both scenarios, we leverage a context-free grammar to parse a set of sample input files that represent the program's common usage, and determine probabilities for individual grammar production as they occur during parsing the inputs. Replicating these probabilities during grammar-based test input generation, we obtain inputs that are close to the samples. Inverting these probabilities yields inputs that are strongly dissimilar to common inputs, yet still valid with respect to the grammar. Our evaluation on three common input formats (JSON, JavaScript, CSS) shows the effectiveness of these approaches in obtaining instances from both sets of inputs.
研究动机与目标
- 为解决生成语法正确但不常见的输入以压力测试软件中极少执行的代码路径的挑战。
- 提供一种利用现有输入样本和形式化语法生成与常见使用模式相似的输入的方法,以支持回归测试。
- 通过反转从常见输入中挖掘出的概率,生成‘地狱输入’——即不常见但语法正确的输入,以探索未被测试的程序行为。
- 提供一种成本低、通用性强的技术,以超越标准模糊测试和基于语法的生成,增强软件测试能力。
提出的方法
- 使用上下文无关语法定位一组常见输入样本,提取产生式规则的频率。
- 基于输入样本中观察到的频率,为语法规则分配概率,构建概率语法。
- 通过使用挖掘出的概率从概率语法中采样,生成与样本相似的输入。
- 反转语法规则的概率,创建第二个概率语法,使其倾向于选择罕见、不常见的产生式选择。
- 通过从反转的概率语法中采样生成‘地狱输入’,在确保语法正确性的同时,最大化与常见输入的差异性。
- 在三种输入格式(JSON、JavaScript 和 CSS)上评估该方法,测量代码覆盖率和错误发现情况。
实验结果
研究问题
- RQ1从常见输入样本中挖掘出的概率语法能否有效生成与典型使用模式相似的输入?
- RQ2反转语法规则的概率能否生成在语法上正确但与常见输入显著不同的输入?
- RQ3通过反转概率发现的‘地狱输入’在多大程度上能触发目标程序中此前未被覆盖的代码路径?
- RQ4与标准模糊测试或基于语法的生成相比,该方法在代码覆盖率和错误发现方面表现如何?
主要发现
- 该方法成功生成了覆盖与原始样本输入相同代码区域的输入,验证了其在回归测试和基于相似性的测试中的有效性。
- 反转的概率语法始终生成了能触发原始样本未覆盖的新代码路径的输入,证明了其在鲁棒性测试中的成功。
- 在 JSON、JavaScript 和 CSS 的评估中,该方法反复发现了新的代码覆盖率,尤其在使用频率较低的语言结构(如解构赋值和复杂嵌套表达式)方面表现突出。
- 与标准基于语法的生成相比,该方法通过聚焦于罕见但高影响力的输入模式,弥补了传统模糊测试的盲区,表现更优。
- 该方法展示了实际可行性:当存在形式化语法时,工程成本较低,并且可扩展至真实世界输入格式。
阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。