Syntax-based Testing CS 4501 / 6501 Software Testing

Slides:



Advertisements
Similar presentations
Introduction to Software Testing Chapter 5.5 Input Space Grammars Paul Ammann & Jeff Offutt
Advertisements

Introduction to Software Testing Chapter 9.5 Input Space Grammars Paul Ammann & Jeff Offutt
176 Formal Languages and Applications: We know that Pascal programming language is defined in terms of a CFG. All the other programming languages are context-free.
ParsingParsing. 2 Front-End: Parser  Checks the stream of words and their parts of speech for grammatical correctness scannerparser source code tokens.
Introduction to Software Testing Chapter 9.1 Syntax-based Testing Paul Ammann & Jeff Offutt
Chapter 2 Syntax A language that is simple to parse for the compiler is also simple to parse for the human programmer. N. Wirth.
Introduction to Software Testing Chapter 5.5 Input Space Grammars Paul Ammann & Jeff Offutt
Introduction to Software Testing Chapter 9.4 Model-Based Grammars Paul Ammann & Jeff Offutt
1 Introduction to Parsing Lecture 5. 2 Outline Regular languages revisited Parser overview Context-free grammars (CFG’s) Derivations.
CSI 3120, Grammars, page 1 Language description methods Major topics in this part of the course: –Syntax and semantics –Grammars –Axiomatic semantics (next.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 2 Syntax A language that is simple to parse.
Introduction to Software Testing Chapter 5.1 Syntax-based Testing Paul Ammann & Jeff Offutt
Syntax-Based Testing Mingzhe Du Hongying Du Dharani Chintapatla.
Copyright © Curt Hill Languages and Grammars This is not English Class. But there is a resemblance.
CPS 506 Comparative Programming Languages Syntax Specification.
Introduction to Software Testing Chapters 1-5 Coverage Summary Paul Ammann & Jeff Offutt
Software Testing Syntax-based Testing. Syntax Coverage Four Structures for Modeling Software Graphs Logic Input Space Syntax Use cases Specs Design Source.
Introduction to Software Testing Chapter 9.2 Program-based Grammars Paul Ammann & Jeff Offutt
Syntax Analysis - Parsing Compiler Design Lecture (01/28/98) Computer Science Rensselaer Polytechnic.
LECTURE 4 Syntax. SPECIFYING SYNTAX Programming languages must be very well defined – there’s no room for ambiguity. Language designers must use formal.
©SoftMoore ConsultingSlide 1 Context-Free Grammars.
Introduction to Parsing
CS 3304 Comparative Languages
Regular Expressions, Backus-Naur Form and Reverse Polish Notation
Chapter 3 – Describing Syntax
Describing Syntax and Semantics
Finite State Machines Dr K R Bond 2009
Paul Ammann & Jeff Offutt
Introduction to Parsing
CS 404 Introduction to Compiler Design
Programming Languages Translator
CS510 Compiler Lecture 4.
ISP Coverage Criteria CS 4501 / 6501 Software Testing
Introduction to Parsing (adapted from CS 164 at Berkeley)
Introduction to Software Testing Chapter 9.2 Program-based Grammars
Graph Coverage Criteria CS 4501 / 6501 Software Testing
Input Space Partition Testing CS 4501 / 6501 Software Testing
Representation, Syntax, Paradigms, Types
What does it mean? Notes from Robert Sebesta Programming Languages
Graph Coverage for Specifications CS 4501 / 6501 Software Testing
Automata and Languages What do these have in common?
Coverage-Based Test Design CS 4501 / 6501 Software Testing
Logic Coverage CS 4501 / 6501 Software Testing
Introduction to Software Testing Chapter 5.1 Syntax-based Testing
Compiler Design 4. Language Grammars
Introduction to Software Testing Chapter 9.2 Program-based Grammars
Programming Language Syntax 2
COP4020 Programming Languages
Introduction to Software Testing Chapter 5.2 Program-based Grammars
R.Rajkumar Asst.Professor CSE
Representation, Syntax, Paradigms, Types
Lecture 4: Lexical Analysis & Chomsky Hierarchy
Introduction to Parsing
Logic Coverage CS 4501 / 6501 Software Testing
ISP Coverage Criteria CS 4501 / 6501 Software Testing
Introduction to Parsing
Paul Ammann & Jeff Offutt
Representation, Syntax, Paradigms, Types
Graph Coverage Criteria CS 4501 / 6501 Software Testing
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Software Testing Syntax-based Testing.
Introduction to Software Testing Chapter 5.1 Syntax-based Testing
Representation, Syntax, Paradigms, Types
High-Level Programming Language
Chapter 10: Compilers and Language Translation
Discrete Maths 13. Grammars Objectives
Programming Languages 2nd edition Tucker and Noonan
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
COMPILER CONSTRUCTION
Faculty of Computer Science and Information System
Presentation transcript:

Syntax-based Testing CS 4501 / 6501 Software Testing

Structures for Criteria-Based Testing Four structures for modeling software Input space Graph Source Design Specs Use cases Applied to Logic Source Specs FSMs DNF Applied to Syntax Source Models Integration Inputs Applied to FSM = Finite State Machine DNF = Disjunctive Normal Form ---R R--R RI-R RIPR

Syntax-Based Testing Many software artifacts follow strict syntax rules We can use syntax to generate artifacts that are valid (correct syntax) or artifacts that are invalid (incorrect syntax) Syntactic descriptions can come from many sources: Programs Integration elements Design documents Input descriptions Tests are created with two general goals Cover the syntax in some way Violate the syntax

Grammar-Based Coverage Criteria Software engineering uses automata theory to describe software artifacts in several ways: Programming languages defined in BNF Program behavior described as finite state machines Allowable inputs defined by grammars Focus: Testing the program with valid inputs Exercise productions of the grammar according to some criterion Testing the program with invalid inputs Use grammar-based mutation to test the program with invalid input

Regular Expression (G s n | B t n)* Closure operator Choice Sequence zero or more occurrences (G s n | B t n)* Choice Either one can be used Sequence Any sequence of “G s n” and “B t n” “G” and “B” may be commands, methods, or events “s”, “t”, and “n” may be arguments, parameters, or values “s”, “t”, “and “n” may be literals or a set of values

Test Cases from Grammar A test case can be a sequence of strings that satisfies the regular expression Example (G s n | B t n)* Suppose “s”, “t”, and “n” are number G 26 08 01 90 B 22 06 27 94 G 22 11 21 94 B 13 01 09 03

Backus-Naur-Form (BNF) Grammars Although regular expressions are sometimes sufficient, a more expressive grammar is often used Start symbol Non-terminal symbols Stream ::= action* action ::= actG | actB actG ::= “G” s n actB ::= “B” t n s ::= digit1-3 t ::= digit1-3 n ::= digit2 “.” digit2 “.” digit2 digit ::= “0” | “1” | “2” | “3” | “4” | “5” | “6” | “7” | “8” | “9” Production rules Possible rewriting of a given nonterminal Terminal symbol Everything in the quotes

More Example: BNF Grammar Simple grammar for a toy language of arithmetic expressions in BNF notation expr ::= id | num | expr op expr id ::= letter | letter id num ::= digit | digit num op ::= “+” | “-” | “*” | “/” letter ::= “a” | “b” | “c” | … | “z” digit ::= “0” | “1” | “2” | “3” | … | “9”

Example: Derivations expr ::= id | num | expr op expr id ::= letter | letter id num ::= digit | digit num op ::= “+” | “-” | “*” | “/” letter ::= “a” | “b” | “c” | … | “z” digit ::= “0” | “1” | “2” | “3” | … | “9” a expr => id => letter => “a” 49 expr => num => digit num => “4” num => “4” digit => “4” “9” ab+12 expr => expr or expr => expr “+” expr => … => “a” “b” “+” “1” “2”

Grammar Coverage Criteria Terminal Symbol Coverage (TSC) TR contains each terminal in the grammar One test case per terminal Production Coverage (PDC) TR contains each production rule in the grammar One test case per production (hence PDC subsumes TSC) Derivation Coverage (DC) TR contains every possible derivation of the grammar One test case per derivation No practical – TR usually infinite When applicable, DC subsumes PDC

Example: TSC Imagine you are testing a parser or interpreter for the example toy language. Define a test set (i.e., a set of grammar derivations) that satisfies TSC expr ::= id | num | expr op expr id ::= letter | letter id num ::= digit | digit num op ::= “+” | “-” | “*” | “/” letter ::= “a” | “b” | “c” | … | “z” digit ::= “0” | “1” | “2” | “3” | … | “9” Tests for TSC Need 40 tests 26 tests: a, b, …, z 10 tests: 0, 1, ..., 9 4 tests: +, -, *, / Terminal Symbol Coverage (TSC) TR contains each terminal in the grammar One test case per terminal

Example: PDC Imagine you are testing a parser or interpreter for the example toy language. Define a test set (i.e., a set of grammar derivations) that satisfies PDC Tests for PDC Need 47 tests: 40 tests that satisfy TSC 4 for op, 26 for letter, 10 for digit Additional 7 tests expr ::=id expr ::= num expr ::= expr op expr id ::= letter id ::= letter id num ::= digit num ::= digit num expr ::= id | num | expr op expr id ::= letter | letter id num ::= digit | digit num op ::= “+” | “-” | “*” | “/” letter ::= “a” | “b” | “c” | … | “z” digit ::= “0” | “1” | “2” | “3” | … | “9” Production Coverage (PDC) TR contains each production rule in the grammar One test case per production (hence PDC subsumes TSC)

Example: DC Imagine you are testing a parser or interpreter for the example toy language. Define a test set (i.e., a set of grammar derivations) that satisfies DC Tests for DC The number of tests depends on details of the program For this example: Infinite due to id ::= letter id and num ::= digit num expr ::= expr op expr expr ::= id | num | expr op expr id ::= letter | letter id num ::= digit | digit num op ::= “+” | “-” | “*” | “/” letter ::= “a” | “b” | “c” | … | “z” digit ::= “0” | “1” | “2” | “3” | … | “9” Derivation Coverage (DC) TR contains every possible derivation of the grammar One test case per derivation

Mutation Testing Grammars describe both valid and invalid string Both types can be produced by mutating the grammar, resulting in mutants A mutant is a variation of a valid string Mutants can be valid or invalid strings Mutation is based on mutation operators and ground strings Mutations over a grammar can be viewed as purposely generating invalid derivations Invalid derivations must be recognized as errors by the software under test

Ground strings (tests or programs) What is Mutation? A process of changing the software artifact based on well defined rules Rules are defined on syntactic description We perform mutation analysis when we want to make systematic changes We can mutate the syntax or objects developed from the syntax Mutation operators Grammar Applied universally or according to empirically verified distributions Grammar Ground strings (tests or programs)

Mutation Testing Ground string Mutation operator Mutant A string in the grammar Mutation operator Rule that specifies syntactic variations of strings generated from a grammar Mutant Result of one application of a mutation operator A mutant is a string either in the grammar or very close to being in the grammar

Underlying Concept: Mutation Testing subject Run tests on subject Apply mutation operators no Distinguishable result? yes Record killed mutants Generate tests mutants Run tests on mutants

Mutants and Ground Strings Mutation operators The key to mutation testing is the design of the mutation operators. Well designed operators lead to powerful testing Sometimes mutant strings are based on ground strings Sometimes they are derived directly from the grammar Ground strings are used for valid tests Invalid tests do not need ground string

Example: Valid and Invalid Mutants Stream ::= action* action ::= actG | actB actG ::= “G” s n actB ::= “B” t n s ::= digit1-3 t ::= digit1-3 n ::= digit2 “.” digit2 “.” digit2 digit ::= “0” | “1” | “2” | “3” | “4” | “5” | “6” | “7” | “8” | “9” Valid Mutants Ground Strings Mutants G 26 08.01.90 B 26 08.01.90 B 22 06.27.94 B 45 06.27.94 Invalid Mutants 7 26 08.01.90 B 22 06.27.1

Note on Mutation Should more than one operator be applied at the same time ? Usually not – multiple mutations can interfere with each other Experience with program-based mutation indicates not Recent research is finding exceptions Should every possible application of a mutation operator be considered ? Necessary with program-based mutation Mutation operators have been defined for many languages Programming languages (Fortran, Lisp, Ada, C, C++, Java) Specification languages (SMV, Z, Object-Z, algebraic specs) Modeling languages (Statecharts, activity diagrams) Input grammars (XML, SQL, HTML) Non program (Spreadsheet, policy)

Killing Mutants When ground strings are mutated to create valid strings, the hope is to exhibit different behavior from the ground string This is normally used when the grammars are programming languages, the strings are programs, and the ground strings are pre-existing programs Killing Mutants: Given a mutant m  M for a derivation D and a test t, t is said to kill m if and only if the output of t on D is different from the output of t on m The derivation D may be represented by the list of productions or by the final string

Grammar-based Mutation Coverage Criteria Coverage is defined in terms of killing mutants Mutation score = number killed mutants / total number mutants Mutation Coverage (MC) TR contains exactly one requirement to kill each mutant Mutation Operator Coverage (MOC) For each mutation operator, TR contains exactly one requirement to create a mutant using that operator Mutation Production Coverage (MPC) For each mutation operator, TR contains several requirements to create a mutant that includes every product that can be mutated by that operator

Example Mutation Operators Terminal and nonterminal deletion Remove a terminal or nonterminal symbol from a production Terminal and nonterminal duplication Duplicate a terminal or nonterminal symbol in a production Terminal replacement Replace a terminal with another terminal Nonterminal replacement Replace a terminal with another nonterminal

Example Stream ::= action* action ::= actG | actB actG ::= “G” s n actB ::= “B” t n s ::= digit1-3 t ::= digit1-3 n ::= digit2 “.” digit2 “.” digit2 digit ::= “0” | “1” | “2” | “3” | “4” | “5” | “6” | “7” | “8” | “9” Mutation Operators Exchange actG and actB Replace digits with all other digits Ground String G 25 08.01.90 B 21 06.27.94 Mutants using MPC B 25 08.01.90 G 21 06.27.94 G 15 08.01.90 B 22 06.27.94 G 35 08.01.90 B 23 06.27.94 G 45 08.01.90 B 24 06.27.94 … … Mutants using MOC B 25 08.01.90 B 23 06.27.94

Summary The number of test requirements for mutation depends on two things The syntax of the artifact being mutated The mutation operators Mutation testing is very difficult to apply by hand Mutation testing is very effective – considered the “gold standard” of testing Mutation testing is often used to evaluate other criteria