A Test Case + Mock Class Generator for Coding Against Interfaces Mainul Islam, Christoph Csallner Software Engineering Research Center (SERC) Computer.

Slides:



Advertisements
Similar presentations
Leonardo de Moura Microsoft Research. Z3 is a new solver developed at Microsoft Research. Development/Research driven by internal customers. Free for.
Advertisements

Satisfiability Modulo Theories (An introduction)
PLDI’2005Page 1June 2005 Example (C code) int double(int x) { return 2 * x; } void test_me(int x, int y) { int z = double(x); if (z==y) { if (y == x+10)
Automatic test case generation for programs that are coded against interfaces and annotations or use native code Mainul Islam Supervisor: Dr. Christoph.
Technology of Test Case Generation Levi Lúcio University of Geneva Marko Samer Vienna University of Technology.
Problem Solving 5 Using Java API for Searching and Sorting Applications ICS-201 Introduction to Computing II Semester 071.
1 Symbolic Execution for Model Checking and Testing Corina Păsăreanu (Kestrel) Joint work with Sarfraz Khurshid (MIT) and Willem Visser (RIACS)
1/20 Generalized Symbolic Execution for Model Checking and Testing Charngki PSWLAB Generalized Symbolic Execution for Model Checking and Testing.
Kai Pan, Xintao Wu University of North Carolina at Charlotte Generating Program Inputs for Database Application Testing Tao Xie North Carolina State University.
Hybrid Concolic Testing Rupak Majumdar Koushik Sen UC Los Angeles UC Berkeley.
Dynamic Symbolic Execution CS 8803 FPL Oct 31, 2012 (Slides adapted from Koushik Sen) 1.
CSE503: SOFTWARE ENGINEERING SYMBOLIC TESTING, AUTOMATED TEST GENERATION … AND MORE! David Notkin Spring 2011.
Homework Any Questions?. Statements / Blocks, Section 3.1 An expression becomes a statement when it is followed by a semicolon x = 0; Braces are used.
Pexxxx White Box Test Generation for
Synergy: A New Algorithm for Property Checking
DART Directed Automated Random Testing Patrice Godefroid, Nils Klarlund, and Koushik Sen Syed Nabeel.
1 Advanced Material The following slides contain advanced material and are optional.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Engr 691 Special Topics in Engineering Science Software Architecture Spring Semester 2004 Lecture Notes.
Tao Xie North Carolina State University Supported by CACC/NSA Related projects supported in part by ARO, NSF, SOSI.
DART: Directed Automated Random Testing Koushik Sen University of Illinois Urbana-Champaign Joint work with Patrice Godefroid and Nils Klarlund.
Tao Xie (North Carolina State University) Nikolai Tillmann, Jonathan de Halleux, Wolfram Schulte (Microsoft Research, Redmond WA, USA)
Symbolic Execution with Mixed Concrete-Symbolic Solving (SymCrete Execution) Jonathan Manos.
CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.
DySy: Dynamic Symbolic Execution for Invariant Inference.
Software Engineering Prof. Dr. Bertrand Meyer March 2007 – June 2007 Chair of Software Engineering Static program checking and verification Slides: Based.
Tao Xie Automated Software Engineering Group Department of Computer Science North Carolina State University
Teaching and Learning Programming and Software Engineering via Interactive Gaming Tao Xie University of Illinois at Urbana-Champaign In collaboration with.
Computer Science and Engineering College of Engineering The Ohio State University Interfaces The credit for these slides goes to Professor Paul Sivilotti.
Introduction Algorithms and Conventions The design and analysis of algorithms is the core subject matter of Computer Science. Given a problem, we want.
1 Conditions Logical Expressions Selection Control Structures Chapter 5.
Advance Data Structure 1 College Of Mathematic & Computer Sciences 1 Computer Sciences Department م. م علي عبد الكريم حبيب.
Tao Xie North Carolina State University Nikolai Tillmann, Peli de Halleux, Wolfram Schulte Microsoft Research.
Parameterized Unit Tests By Nikolai Tillmann and Wolfram Schulte Proc. of ESEC/FSE 2005 Presented by Yunho Kim Provable Software Lab, KAIST TexPoint fonts.
Working with arrays (we will use an array of double as example)
IDENTIFYING SEMANTIC DIFFERENCES IN ASPECTJ PROGRAMS Martin Görg and Jianjun Zhao Computer Science Department, Shanghai Jiao Tong University.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Introduction to branching.
Xusheng Xiao North Carolina State University CSC 720 Project Presentation 1.
jFuzz – Java based Whitebox Fuzzing
Proving Non-Termination Gupta, Henzinger, Majumdar, Rybalchenko, Ru-Gang Xu presentation by erkan.
Learning Symbolic Interfaces of Software Components Zvonimir Rakamarić.
Cooperative Developer Testing: Tao Xie North Carolina State University In collaboration with Xusheng ASE and Nikolai Tillmann, Peli de
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Comparison of Tarry’s Algorithm and Awerbuch’s Algorithm CS 6/73201 Advanced Operating System Presentation by: Sanjitkumar Patel.
Improving Structural Testing of Object-Oriented Programs via Integrating Evolutionary Testing and Symbolic Execution Kobi Inkumsah Tao Xie Dept. of Computer.
CUTE: A Concolic Unit Testing Engine for C Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.
Extended Static Checking for Java Cormac Flanagan Joint work with: Rustan Leino, Mark Lillibridge, Greg Nelson, Jim Saxe, and Raymie Stata Compaq Systems.
( = “unknown yet”) Our novel symbolic execution framework: - extends model checking to programs that have complex inputs with unbounded (very large) data.
Lazy Annotation for Program Testing and Verification (Supplementary Materials) Speaker: Chen-Hsuan Adonis Lin Advisor: Jie-Hong Roland Jiang December 3,
Random Test Generation of Unit Tests: Randoop Experience
Symbolic Execution in Software Engineering By Xusheng Xiao Xi Ge Dayoung Lee Towards Partial fulfillment for Course 707.
CSE 331 SOFTWARE DESIGN & IMPLEMENTATION SYMBOLIC TESTING Autumn 2011.
Symstra: A Framework for Generating Object-Oriented Unit Tests using Symbolic Execution Tao Xie, Darko Marinov, Wolfram Schulte, and David Notkin University.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
CS223: Software Engineering Lecture 26: Software Testing.
Dynamic Symbolic Execution
Chapter 5 Decisions. Chapter 5 Decisions ssential uestion: How are Boolean expressions or operators used in everyday life?
A Test Case + Mock Class Generator for Coding Against Interfaces
RDE: Replay DEbugging for Diagnosing Production Site Failures
Microsoft Visual Basic 2005 BASICS
White-Box Testing Using Pex
New Ideas Track: Testing MapReduce-Style Programs Christoph Csallner, Leonidas Fegaras, Chengkai Li Computer.
Dynamic Symbolic Data Structure Repair
null, true, and false are also reserved.
Chapter 1: Computer Systems
Automatic Test Generation SymCrete
Example (C code) int double(int x) { return 2 * x; }
Diagnostic Evaluation
CUTE: A Concolic Unit Testing Engine for C
Outline Software Development Activities
Presentation transcript:

A Test Case + Mock Class Generator for Coding Against Interfaces Mainul Islam, Christoph Csallner Software Engineering Research Center (SERC) Computer Science and Engineering Department University of Texas at Arlington, USA February 07, Published at: 8th International Workshop on Dynamic Analysis (WODA), 2010

Test case generation Dynamic Symbolic Execution Mock Class Motivating examples to generate Mock Class Algorithm to generate Mock Class Results Demonstration Mock Class Generator for Coding Against Interfaces 1 Talk Outline

What is the goal behind testing ? Mock Class Generator for Coding Against Interfaces 2 Test Case Generation public void Test(int x) { if (x > 0) { if (x == ) { throw new Exception(“Bug”); } What can be a good test case to test this method ? Probability to reach the bug (with a random test input) is: ½ * 1/2^31

Explore all feasible execution paths Initialize the input with symbolic values and execute the program over symbolic values At conditional statements check if either of the branches can be taken (using a constraint solver) For each path we get an accumulated path condition Mock Class Generator for Coding Against Interfaces 3 Symbolic Execution If (s) then … else … C falsetrue C` = C ⋀ sC` = C ⋀⌝ s s Dynamic symbolic execution: Combine Concrete and Symbolic execution

void TestMe (int a[]) { if (a == null) return; if (a.length > 0) if (a[0] == 123) throw new Exception(“Error”); } This example is taken from the slides of Nikolai Tillman (with permission) 4 Dynamic Symbolic Execution by Example a == null a.length > 0 a[0] == 123 T T T F F F Constraints to SolveInput Observed Constraints null {} {0} {123} a != null && !(a.length > 0) a == null a != null && a.length > 0 && a[0] != 123 a != null && a.length > 0 && a[0] == 123 a != null a != null && a.length > 0 a != null && a.length > 0 && a[0] == 123 SolveExecute Choose Next Path a == null Done: No path left

public interface A { // … } public class C { public void foo (A a, int x) { // … } Mock Class Generator for Coding Against Interfaces 5 Introduction to Mock Class

When we might need to generate mock-classes ? At the initial stage of any development Mock Class Generator for Coding Against Interfaces 6

Test case generation is important Interfaces are very important Existing techniques are not very good at this Pex - can generate an instance of a class that implements an interface that is used in the code * * Mock Class Generator for Coding Against Interfaces 7 Why is this important ?

Goal: Support interfaces in test case generation for object-oriented programs Mock Class Generator for Coding Against Interfaces 8

Motivating Example 1 public class C { public void foo (A a, int x) { int y = a.m1(x); if (a instanceof B) { B b = (B) a; int z = b.m2(x); } Mock Class Generator for Coding Against Interfaces 9 To reach this block of code, ‘a’ must be an instance of A, as well as an instance of B public interface A { int m1(int x); } public interface B { int m2(int x); }

Motivating Example 2 public class K implements A, B { // … } public class C { public void bar (A a, int x) { if (a == null) return; if ( !(a instanceof B) ) { B b = (B) a; int z = b.m2(x); } Mock Class Generator for Coding Against Interfaces 10 K implements all of the interfaces referred by the bar method, but fails reach the code block public interface A { int m1 (int x); } public interface B { int m2 (int x); }

Framework DSC – Dynamic Symbolic Execution Engine (for Java) Z3 – Constraint Solver Mock Class Generator for Coding Against Interfaces 11

Our approach to generate Mock Class Determining the type of the Mock Class Generate meaningful method body if needed Mock Class Generator for Coding Against Interfaces 12

Sub-/Supertype relation in Java Java defines a binary subtype relation If type B implements/extends type A then, - A is a direct super type of B - B is a direct sub type of A Reflexive: A is also a subtype of itself Transitive: if B is a subtype of A and C is a subtype of B then C is also a subtype of A Mock Class Generator for Coding Against Interfaces 13

Sub-/Supertype relation in Java (Cont.) A class has one direct class super type and arbitrarily many interface super types. Exceptions: type object – has no direct super type type null – has no direct sub type Mock Class Generator for Coding Against Interfaces 14

Subtype constraints Mock Class Generator for Coding Against Interfaces 15 Object ABC null Object ABC M null Initial types in the system A desired solution: with new type M public interface A { int m1 (int x); } public interface B { int m2(int x); } public class C { public void foo (A a, int x) { int y = a.m1(x); if (a instanceof B) { B b = (B) a; int z = b.m2(x); } type(a) subtypeof A type(a) != null type type(a) subtypeof B Constraints:

Subtype Relation Matrix public interface A { int m1 (int x); } public interface B { int m2(int x); } public class C { public void foo (A a, int x) { int y = a.m1(x); if (a instanceof B) { B b = (B) a; int z = b.m2(x); } Mock Class Generator for Coding Against Interfaces 16 NullObjectABCM 0Nullxxxxxx 1Objectx 2Axx 3Bxx 4Cxx 5MxMAMBMCx NullObject 0Nullxx 1Objectx NullObjectABC 0Nullxxxxx 1Objectx 2Axx 3Bxx 4Cxx NullObjectABCM 0Nullxxxxxx 1Objectx 2Axx 3Bxx 4Cxx 5Mxxxx Solution: MA = true MB = true MC = false

Program execution Found Solution? No Yes Algorithm: Generating Mock Class Dynamic Symbolic Data Structure Repair 17 Build Subtype Relation matrix (Generate the constraints) NO_MC < MAX_MC Generate Test Case Introduce a new Mock Class, N0_MC++ Encode the Mock Class in the type system No Yes Solution not found Yes Initialization: NO_MC = 0 MAX_MC = 2

Generating Method Body: for Example 1 Mock Class Generator for Coding Against Interfaces 18 public class M implements A, B { int m1 (int x){ return 0; } int m2(int x){ return 0; } Outline of the source code for Mock Class M public interface A { int m1 (int x); } public interface B { int m2(int x); } public class C { public void foo (A a, int x) { int y = a.m1(x); if (a instanceof B) { B b = (B) a; int z = b.m2(x); if (z >= 10) { //… } return 10;

Results We have run our solution on JMS (Java messaging system) These are all hand-written test cases Mock Class Generator for Coding Against Interfaces 19 Interfaces used from JMS Number of goals Number of goals reached w/o mock- classes Number of goals reached with mock- classes Message 606 ByteMessage 505 MapMessage 404 StreamMessage 404 TextMessage 505 ObjectMessage 404

Comparison with Pex: Motivating Example 1 public class C { public void foo (A a, int x) { int y = a.m1(x); if (a instanceof B) { B b = (B) a; int z = b.m2(x); } Mock Class Generator for Coding Against Interfaces 20 public interface A { int m1(int x); } public interface B { int m2(int x); } Goal 1 Goal 2 PEX reaches 1/2 goal(s) DSC reaches 2/2 goal(s)

Future Work Extend the solution to support more types, e.g. ‘Array’ Determine a upper bound to the number of mock classes needed to solve a system Evaluation Mock Class Generator for Coding Against Interfaces 21

Future Work (Cont.) Mock Class Generator for Coding Against Interfaces 22 public class M implements A, B { int m1 (int x){ return 0; } int m2(int x){ return 0; } Outline of the source code for Mock Class M public class C { public void foo (A a, int x) { int y = a.m1(x); if (a instanceof B) { B b = (B) a; int z = b.m2(x); if (z >= 10) { //… } return 10; Extend method body generation for complex types

Mock Class Generator for Coding Against Interfaces 23 Demo

Mock Class Generator for Coding Against Interfaces 24 Thank you !