Automated Test Case Generation: Metaheuristic Search

Similar documents
What is Evolutionary Computation? Genetic Algorithms. Components of Evolutionary Computing. The Argument. When changes occur...

Evolutionary Computation. Lecture 3. Evolutionary Computation. X 2 example: crossover. x 2 example: selection

Evolutionary Algorithms

The Metaphor. Individuals living in that environment Individual s degree of adaptation to its surrounding environment

9/17/14 LOCAL SEARCH. Today. Reading. Read AIMA Ch Objectives. Simulated Annealing Genetic algorithms Gradient ascent

The Genetic Algorithm CSC 301, Analysis of Algorithms Department of Computer Science Grinnell College December 5, 2016

Genetic Algorithm: An Optimization Technique Concept

Metaheuristics and Cognitive Models for Autonomous Robot Navigation

Evolutionary Algorithms

GENETIC ALGORITHMS. Narra Priyanka. K.Naga Sowjanya. Vasavi College of Engineering. Ibrahimbahg,Hyderabad.

Foundations of Artificial Intelligence

Use of Genetic Algorithms in Discrete Optimalization Problems

Part 1: Motivation, Basic Concepts, Algorithms

Optimisation and Operations Research

Generational and steady state genetic algorithms for generator maintenance scheduling problems

CHAPTER 3 RESEARCH METHODOLOGY

Machine Learning: Algorithms and Applications

Logistics. Final exam date. Project Presentation. Plan for this week. Evolutionary Algorithms. Crossover and Mutation

Genetic Algorithms for Optimizations

PARALLEL LINE AND MACHINE JOB SCHEDULING USING GENETIC ALGORITHM

EFFECT OF CROSS OVER OPERATOR IN GENETIC ALGORITHMS ON ANTICIPATORY SCHEDULING

Introduction to Artificial Intelligence. Prof. Inkyu Moon Dept. of Robotics Engineering, DGIST

Comp215: Genetic Algorithms - Part 1

Machine Learning. Genetic Algorithms

Machine Learning. Genetic Algorithms

Design and Implementation of Genetic Algorithm as a Stimulus Generator for Memory Verification

Introduction To Genetic Algorithms

Evolutionary Algorithms - Population management and popular algorithms Kai Olav Ellefsen

Functional Testing. CSCE Lecture 4-01/21/2016

IMPLEMENTATION OF AN OPTIMIZATION TECHNIQUE: GENETIC ALGORITHM

Metaheuristics. Approximate. Metaheuristics used for. Math programming LP, IP, NLP, DP. Heuristics

College of information technology Department of software

Plan for today GENETIC ALGORITHMS. Randomised search. Terminology: The GA cycle. Decoding genotypes

Testing Close to and Post-Release: System, Acceptance, and Regression Testing

Intelligent Techniques Lesson 4 (Examples about Genetic Algorithm)

Genetic Algorithms and Genetic Programming Lecture 13

Artificial Evolution. FIT3094 AI, A-Life and Virtual Environments Alan Dorin

What is an Evolutionary Algorithm? Presented by: Faramarz Safi (Ph.D.) Faculty of Computer Engineering Islamic Azad University, Najafabad Branch

CSE /CSE6602E - Soft Computing Winter Lecture 9. Genetic Algorithms & Evolution Strategies. Guest lecturer: Xiangdong An

2. Genetic Algorithms - An Overview

Evolutionary Computation

Optimal Capacitor Placement for Loss Reduction in Distribution Systems Using Fuzzy and Hybrid Genetic Algorithm

10. Lecture Stochastic Optimization

Genetic Algorithm and Application in training Multilayer Perceptron Model

Genetic Programming for Symbolic Regression

Genetically Evolved Solution to Timetable Scheduling Problem

Structural Bioinformatics (C3210) Conformational Analysis Protein Folding Protein Structure Prediction

Software Next Release Planning Approach through Exact Optimization

Introduction To Genetic Algorithms

CapSel GA Genetic Algorithms.

Genetic Algorithm. Presented by Shi Yong Feb. 1, 2007 Music McGill University

Genetic Algorithms. Part 3: The Component of Genetic Algorithms. Spring 2009 Instructor: Dr. Masoud Yaghini

Introduction to Genetic Algorithm (GA) Presented By: Rabiya Khalid Department of Computer Science

Analysis of Statement Branch and Loop Coverage in Software Testing With Genetic Algorithm

Evolutionary Computation. Lecture 1 January, 2007 Ivan Garibay

Optimal Design of Laminated Composite Plates by Using Advanced Genetic Algorithm

A Comprehensive Study of Forest Fire Behavior as Cellular Automata Model

The Impact of Search Algorithms in Automated Program Repair

Processor Scheduling Algorithms in Environment of Genetics

EVOLUTIONARY ALGORITHMS AT CHOICE: FROM GA TO GP EVOLŪCIJAS ALGORITMI PĒC IZVĒLES: NO GA UZ GP

An introduction to evolutionary computation

Genetic Algorithms. Moreno Marzolla Dip. di Informatica Scienza e Ingegneria (DISI) Università di Bologna.

Automatic Software Structural Testing by Using Evolutionary Algorithms for Test Data Generations

Introduction Evolutionary Algorithm Implementation

Lecture 8 Testability Measures

TIMETABLING EXPERIMENTS USING GENETIC ALGORITHMS. Liviu Lalescu, Costin Badica

Assoc. Prof. Rustem Popa, PhD

Genetic Algorithms and Genetic Programming. Lecture 1: Introduction (25/9/09)

Genetic Algorithms and Genetic Programming Lecture 14

Intro. ANN & Fuzzy Systems. Lecture 36 GENETIC ALGORITHM (1)

A Study of Crossover Operators for Genetic Algorithms to Solve VRP and its Variants and New Sinusoidal Motion Crossover Operator

Timetabling with Genetic Algorithms

DEVELOPMENT OF MULTI-OBJECTIVE SIMULATION-BASED GENETIC ALGORITHM FOR SUPPLY CHAIN CYCLIC PLANNING AND OPTIMISATION

Genetic Algorithm for Predicting Protein Folding in the 2D HP Model

Research and Applications of Shop Scheduling Based on Genetic Algorithms

GENETIC ALGORITHM BASED APPROACH FOR THE SELECTION OF PROJECTS IN PUBLIC R&D INSTITUTIONS

VISHVESHWARAIAH TECHNOLOGICAL UNIVERSITY S.D.M COLLEGE OF ENGINEERING AND TECHNOLOGY. A seminar report on GENETIC ALGORITHMS.

Implementation of CSP Cross Over in Solving Travelling Salesman Problem Using Genetic Algorithms

A PRACTICAL APPROACH TO PRIORITIZE THE TEST CASES OF REGRESSION TESTING USING GENETIC ALGORITHM

A Viral Systems Algorithm for the Traveling Salesman Problem

Deterministic Crowding, Recombination And Self-Similarity

A Genetic Algorithm for Order Picking in Automated Storage and Retrieval Systems with Multiple Stock Locations

Model-Based Testing. CSCE Lecture 10-02/11/2016

Evolutionary Algorithms for Fire and Rescue Service Decision Making

initial set of random solutions called population satisfying boundary and/or system

Designing High Thermal Conductive Materials Using Artificial Evolution MICHAEL DAVIES, BASKAR GANAPATHYSUBRAMANIAN, GANESH BALASUBRAMANIAN

Genetic algorithms. History

Minimizing Makespan for Machine Scheduling and Worker Assignment Problem in Identical Parallel Machine Models Using GA

Fundamentals of Dynamic Testing. Inaccuracy in Dynamic Testing

Genetic Algorithm: A Search of Complex Spaces

SCOAP circuit topological analysis CC0 CC1 SC0 SC1

Getting Started with OptQuest

SWARM-BASED OPTIMISATION

GENETIC ALGORITHM A NOBLE APPROACH FOR ECONOMIC LOAD DISPATCH

The two-stage recombination operator and its application to the multiobjective 0/1 knapsack problem: a comparative study

PCG: Search Revisited, Evolution, and More

Improving Differential Evolution Algorithm with Activation Strategy

Genetic Algorithm to Dry Dock Block Placement Arrangement Considering Subsequent Ships

A Genetic Algorithm on Inventory Routing Problem

[Sharma* et al., 5(6): June, 2016] ISSN: IC Value: 3.00 Impact Factor: 4.116

Transcription:

Automated Test Case Generation: Metaheuristic Search CSCE 747 - Lecture 21-03/29/2016

Testing as a Search Problem Do you have a goal in mind when testing? Can that goal be measured? Then you are searching for a test suite that achieves that goal. Out of the near-infinite set of inputs, I would like a set of inputs that obey those properties. cover all branches. try all 2-way pairs of representative values. (etc) Gregory Gay CSCE 747 - Spring 2016 2

Testing as a Search Problem I want to find all faults cannot be checked. However, almost all testing goals can. Boolean: Property Satisfied/Not Satisfied Numeric: % Coverage Obtained If we can take a candidate solution and check whether it meets our goal, then computers can search for a solution. Many search techniques for automated test case generation. Gregory Gay CSCE 747 - Spring 2016 3

Search Process Choose a solution. If it does not accomplish the goal, try another. Keep trying new solutions until goal is achieved or all solutions are tried. The order that solutions are tried is key to efficiently finding a solution. A search follows some defined strategy. Called a heuristic. Heuristics are used to choose solutions and to ignore solutions known to be unviable. Gregory Gay CSCE 747 - Spring 2016 5

Search Budget Exhaustive Search - try all solutions. Most software has near-infinite number of inputs. We generally cannot try all solutions without constraining the problem. Search can be bound by a search budget. Number of attempts made. Time allotted to the search. Optimization problem: Search for the best solution possible given the search budget. Gregory Gay CSCE 747 - Spring 2016 5

Search Heuristics Simple strategy: randomly generate input. Fast, easy to understand, very bad at finding faults. Adaptive random testing applies strategies to control the distribution of random test generation. Retains benefits of RT, more likely to find faults. Dynamic symbolic execution extracts logical expressions describing program paths, and generates input from those expressions. Gregory Gay CSCE 747 - Spring 2016 6

Search Heuristics Highly Applicable, Low Chance of Efficacy RT ART DSE SE Less Applicable, High Chance of Efficacy Random Testing: Very fast, easy to implement, requires no information about the system. Unlikely to satisfy goals. Adaptive Random Testing: Almost as efficient as RT, same other benefits, far more likely to satisfy goals. Still based on random chance. (Dynamic) Symbolic Execution: Will find an exact solution if possible. Many restrictions on complexity and data structures of the programs supported. Gregory Gay CSCE 747 - Spring 2016 7

Optimization Problem Often too many restrictions to make exhaustive search feasible. No way to try all inputs or abstract complex systems. Instead, need a strategy to sample from the input space. But not in a purely random manner. How can we find the best solution possible given a limited search budget? Can apply optimization algorithms. Called metaheuristic search techniques. Gregory Gay CSCE 747 - Spring 2016 8

Metaheuristic Search

Optimization Problem If we can calculate a score related to attainment of a testing goal, then we have an optimization target. Test generation as an optimization problem: Generate a test (or set of tests). Score each of them using a fitness function. Manipulate the solution according to a search strategy (the metaheuristic ). Gregory Gay CSCE 747 - Spring 2016 10

Metaheuristic Search Choose a smart strategy to sample from the search space. Not purely random - fitness function guides the search towards better solutions. The metaheuristic changes its approach based on past attempts. No guarantee of an optimal solution but if we re smart, we ll hit something close enough. Computationally feasible, and often more effective than random search. Gregory Gay CSCE 747 - Spring 2016 11

Local Search Generate a potential solution. Score it using your fitness function. Attempt to improve it by looking at its local neighborhood. Test cases minorly different from the current choice. Keep making small, incremental improvements. Very fast and efficient if you make a good initial guess. Can get stuck in local maxima if not. Reset strategies help. Gregory Gay CSCE 747 - Spring 2016 12

Generating Neighbors Neighbors are tests created by making a small change to the current test. Single method call: Switch value of boolean, other values from an enumerated set, bounded range of numeric choices. Multiple method calls: Insert a new method call. Delete or replace an existing call. Can replace by changing the method called or the parameters. Important to control size of a neighborhood. Gregory Gay CSCE 747 - Spring 2016 13

Hill Climbing Pick a initial solution at random. Examine the local neighborhood. Choose the best neighbor and move to it. Repeat until no better solution can be found. Climbs mountains in fitness function landscape. Strategies: Steepest Ascent - examine all neighbors, take the one with the highest improvement. Random Ascent - examine neighbors at random, and choose the first to show any improvement. Gregory Gay CSCE 747 - Spring 2016 14

Simulated Annealing Choose a neighboring test case. If it is a better solution, select it. If not, select it at probability: ((score - newscore) * (time / temp)) prob(score, newscore, time, temp) = e Governed by temperature function: temp(time, maxtime) = (maxtime - time) / maxtime Repeat until search budget expires and return best solution. Initially, large random jumps around the search space. Over time, search stabilizes. Gregory Gay CSCE 747 - Spring 2016 15

Global Search Generate a set of solutions. Score them. At a certain probability, sample from other regions of the space. Strategies typically based on natural processes - swarm attack patterns, ant colony behavior, species evolution. Models of how populations interact and change. Gregory Gay CSCE 747 - Spring 2016 16

Genetic Algorithms Over multiple generations, evolve a population - favoring good solutions and filtering out bad solutions. Diversity is introduced to the population each generation by: Keeping some of the best solutions. Randomly generating some population members. Creating offspring through mutation and gene crossover. Gregory Gay CSCE 747 - Spring 2016 17

Genetic Algorithms - Mutation Create a copy of a highscoring test. Impose a small change to that test. Follow the rules for determining the neighbors of a test. Choose a mutation from that set. A good test could be improved by checking one of its neighbors. Gregory Gay CSCE 747 - Spring 2016 18

Genetic Algorithms - Crossover Take two high-scoring tests, and attempt to combine aspects of them into one. Choose one element, sample from a probability distribution to decide which parent to inherit from. By combining features from two good tests, we may produce a better test. Gregory Gay CSCE 747 - Spring 2016 19

Genetic Algorithms - Crossover One Point Crossover Splice at a randomly chosen crossover point. A B C D 1 2 3 4 A B 3 4 1 2 C D Uniform Crossover Each point is a potential crossover point. A B C D 1 2 3 4 A 2 3 1 B C D 4 Discrete Recombination Instead of sampling once per index for both children, it is done for for every child. A B C D 1 2 3 4 A A 2 B C 4 3 4 Gregory Gay CSCE 747 - Spring 2016 20

Particle Swarm Optimization A swarm of agents each attempt to search for good test cases. When another agent finds a better solution than the best known worldwide, they tell everybody. Each agent mutates their solution based on their knowledge of the best local solution and the best global solution. Over time, the agents converge on the best solutions. Gregory Gay CSCE 747 - Spring 2016 21

Particle Swarm Optimization Each agent i has velocity v i and position p i. Position: Their current solution. Velocity: The amount of change to be made to the solution. Bound by a maximum velocity. Vectors along all dimensions in the solution. (i.e., method parameters) Each round, velocity and position are updated based on current local and global knowledge. Gregory Gay CSCE 747 - Spring 2016 22

Particle Swarm Optimization Update Rules: v i d = v i d + (best g - p i d ) + (best l - p i d ) is an inertial weight. = max - ( max - min ) time / maxtime Decreases linearly over time and are user-set acceleration coefficients. and are random numbers best g is the global best score. best l is the local best score. Guide the velocity and position of the agent. d d d p i = p i + v i Gregory Gay CSCE 747 - Spring 2016 23

Fitness Functions Solutions are judged by a fitness function that takes in the solution and calculates a score. Distance from the current solution to the ideal solution. How close are you to covering a testing goal? Smaller scores are typically better. Must offer information to guide the search. Must be cheap to calculate - performed 100s-1000s of times per generation. Gregory Gay CSCE 747 - Spring 2016 24

Structural Coverage Normally measured as proportion of test obligations covered to total obligations. This serves as a score - how good are current testing efforts. However, this is not an ideal fitness function. Does not inform the search process. Instead - can we score a test such that we can learn from the attempt? Not just is this good, but how close is this to ideal? Gregory Gay CSCE 747 - Spring 2016 25

Branch Coverage Fitness Function Instead of raw coverage, use the branch distance and approach level: fitness(s,b) = AL(s,b) + normalize(bd(s,b)) Approach level - count of the branch s control-dependent nodes not yet executed. Branch distance - if the other branch is taken, measure how close the target branch was from being taken. Gregory Gay CSCE 747 - Spring 2016 26

Branch Coverage Fitness Function if(x < 10){ // Node 1 // Do something. }else if (x == 10){ // Node 2 // Do something else. } Goal, true of Node 2. branch of to Node false, 2. branch distance If x<10 = is (abs(x- true, 10)+k). approach level = 1 closer the branch distance. If x==10 is reached, approach level = 0 Goal, true branch If x==10 evaluates Closer x is to 10, Gregory Gay CSCE 747 - Spring 2016 27

evosuite demonstration

Comparing Approaches Highly Applicable, Low Chance of Efficacy RT Less efficient than ART. But more likely to achieve the testing goal. Fewer restrictions than DSE. But no guarantee of optimality. Choice of fitness function is important. ART MS DSE SE Must be fast to calculate. Must quickly converge on optimal solutions. Less Applicable, High Chance of Efficacy Gregory Gay CSCE 747 - Spring 2016 29

Combining Approaches class Foo { int x = 0; void inc(){ x++; } int getx(){ return x; } } class Bar{ String x; Bar(String x){ this.x = x; } void coverme(foo f){ String y = x + f.getx(); if(y.equals( baz5 )) // target } } MS can achieve high coverage, but will not guess baz. DSE can identify baz, but will not call Foo.inc() five times. By combining the two, the target can be covered. Gregory Gay CSCE 747 - Spring 2016 30

Not Just Test Generation... Metaheuristic search can be applied to any problem with: A large search space. Fitness function and solution generation methods with low computational complexity. Approximate continuity in the fitness function. No known optimal solution. Gregory Gay CSCE 747 - Spring 2016 31

Automated Program Repair Popular projects may have hundreds of bugs reported per day. Repair techniques, like GenProg, automatically produce patches that can repair common bug types. Many bugs can be fixed with just a few changes to the source code - inserting new code, deleting or moving existing code. GenProg uses the same ideas to search for repairs automatically. Gregory Gay CSCE 747 - Spring 2016 32

GenProg Genetic programming - solutions represent sequences of edits to the source code. Each candidate patch is applied to the program to produce a new program. See if the patched program passes all tests. Fitness function: how many tests pass? Use crossover and mutation to evolve better patches. Gregory Gay CSCE 747 - Spring 2016 33

GenProg Results GenProg repaired 55 out of 105 bugs at an average cost of $8 per bug. Large projects - over 5 million lines of code, 10000 test cases. Able to patch infinite loops, segmentation faults, buffer overflows, denial of service vulnerabilities, wrong output faults, and more. Gregory Gay CSCE 747 - Spring 2016 34

Automated Code Transplantation Not just patches Many coding tasks involve reinventing the wheel - redesigning and writing code to perform a function that already exists in some other project. What if we could slice out that code ( organ ) from a donor program and transplant it to the right vein in the target software? Gregory Gay CSCE 747 - Spring 2016 35

muscalpel Uses a form of genetic programming. Initial population of 1 statement patches. Organs need very few statements from the donor. Starting with one line at a time allows muscalpel to find efficient solutions quickly. Search evolves both organs and veins. Optimize the set of code transplanted from the donor, and the optimal location to place that code in the target software. Apply tests to ensure correctness of both original code and new features. Gregory Gay CSCE 747 - Spring 2016 36

muscalpel Results Transplantation of H.264 video codec from x264 system to VLC media player. Took VLC developers 20 days to write the code manually. Took muscalpal 26 hours to transplant automatically. In 12 of 15 experiments, successful transplants that passed all tests. Gregory Gay CSCE 747 - Spring 2016 37

We Have Learned ART is often ineffective, and DSE is limited in the scope of the programs it can be applied to. Metaheuristic search strikes middle ground: Less efficient than ART, but often more effective. Able to generate tests for programs that DSE cannot address. Smart strategies for sampling from a search space. Designed to produce near-optimal solutions within a limited search budget. Gregory Gay CSCE 747 - Spring 2016 38

We Have Learned Local methods attempt to make small changes to a current solution. Hill climbers, simulated annealing. Global methods try solutions from all around the search space. Genetic algorithms, particle swarm optimization. Can also be used to automate patching and feature transplantation. Gregory Gay CSCE 747 - Spring 2016 39

Next Time Software Inspections Ch. 18 Homework: Assignment 4 - due April 5! Gregory Gay CSCE 747 - Spring 2016 40