Key Difference between Manual Testing and Model Checking

Slides:



Advertisements
Similar presentations
The Towers of Hanoi or Apocalypse When?.
Advertisements

Towers of Hanoi Move n (4) disks from pole A to pole C such that a disk is never put on a smaller disk A BC ABC.
CSC 205 Programming II Lecture 10 Towers of Hanoi.
HW4:Royal Garden’s Puzzle as a Model Checking Problem Pictures from UbiSoft.
Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Array_strcpy void array_strcpy(char dest[], char src[]) { int i = 0; while (src[i] != '\0') { dest[i] = src[i]; i++; } dest[i] = '\0'; }
COSO 1030 Section 4 Recursion. What is about Towers of Hanoi Divide and Conquer Strategy Recursion and Induction Thinking Recursively Recursion Pitfalls.
COSC 2006 Data Structures I Recursion III
Factorial Recursion stack Binary Search Towers of Hanoi
Recursion. Idea: Some problems can be broken down into smaller versions of the same problem Example: n! 1*2*3*…*(n-1)*n n*factorial of (n-1)
1 CSCD 300 Data Structures Recursion. 2 Proof by Induction Introduction only - topic will be covered in detail in CS 320 Prove: N   i = N ( N + 1.
Algorithms: Selected Exercises Goals Introduce the concept & basic properties of an algorithm.
Data Structures - Queues
 2003 Prentice Hall, Inc. All rights reserved. 1 Functions and Recursion Outline Function Templates Recursion Example Using Recursion: The Fibonacci Series.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Chapter 14 Recursion. Chapter Objectives Learn about recursive definitions Explore the base case and the general case of a recursive definition Learn.
Chapter 5 Recursion. Basically, a method is recursive if it includes a call to itself.
HW6: Due Dec 8th 23:59 1.Describe test cases to reach full path coverage of the triangle program by completing the path condition table below. Also, draw.
The Queue Data Structure Mugurel Ionu Andreica Spring 2012.
HW#3: Due Nov 9 NOTE. Submit both hardcopy and softcopy. 1. Formal verification of a flash memory reading unit (70 pts) – Show the correctness of the flash_read()
Ex2. Tower of Hanio 1/11 Write down a C program to solve the Tower of Hanoi ga me (3 poles and 4 disks) by using CBMC – Hint: you may non-deterministically.
UNIT 17 Recursion: Towers of Hanoi.
HW #5 Due Nov 14 23:59 1. Write down a C program and a Promela model to solve the Tower of Hanoi game (3 poles and 4 disks) by using CBMC and Spin Hint:
24 September 2002© Willem Visser Program Model Checking Enabling Technology Abstraction void add(Object o) { buffer[head] = o; head = (head+1)%size;
1 Towers of Hanoi Three pegs, one with n disks of decreasing diameter; two other pegs are empty Task: move all disks to the third peg under the following.
Lecture 11 Recursion. A recursive function is a function that calls itself either directly, or indirectly through another function; it is an alternative.
1 Data Structures CSCI 132, Spring 2016 Notes 16 Tail Recursion.
Recursion.
CS212: Data Structures and Algorithms
Algorithm Analysis 1.
Recursion.
COMP 51 Week Fourteen Recursion.
Recursion CENG 707.
Queues.
Recursion what is it? how to build recursive algorithms
Recursion A problem solving technique where an algorithm is defined in terms of itself A recursive method is a method that calls itself A recursive algorithm.
Chapter 17 Recursion.
Towers of Hanoi Move n (4) disks from pole A to pole C
Number guessing game Pick a random number between 1 and 10
Lecture 13 & 14.
A First Book of ANSI C Fourth Edition
Specifications What? Not how!.
Queues Chapter 8 Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved
Java Programming: Program Design Including Data Structures
Stack and Queue.
Data Structures 1 1.
HW-6 Deadline Extended to April 27th
Basic Data Types Queues
Key Difference between Manual Testing and Model Checking
HW#2: Due Oct 18 NOTE. Submit both hardcopy and softcopy.
Functions: Declaration, Definition, Call and return, Scope of variables, Storage classes, Recursive functions, Recursion vs Iteration.
Recursion Data Structures.
A function with one argument
Automatic Test Generation SymCrete
The Hanoi Tower Problem
Chapter 17 Recursion.
Recursion Definition: A method that calls itself. Examples
FLIPPED CLASSROOM ACTIVITY CONSTRUCTOR – USING EXISTING CONTENT
REPETITION STATEMENTS
CS210- Lecture 5 Jun 9, 2005 Agenda Queues
Recursion.
1. (50 pts) Concolic testing the sort function
Key Difference between Manual Testing and Concolic/Symbolic Testing
FLIPPED CLASSROOM ACTIVITY CONSTRUCTOR – USING EXISTING CONTENT
Recursive Thinking.
Q1:Royal Garden’s Puzzle as a Model Checking Problem
Stacks and Linked Lists
Presentation transcript:

Key Difference between Manual Testing and Model Checking Manual testing (unit testing) A user should test one concrete execution scenario by checking a pair of concrete input values and the expected concrete output values Model checking (concolic testing) A user should imagine all possible execution scenarios and model a general environment that can enable all possible executions A user should describe general invariants on input values and output values

Ex1. Circular Queue of Positive Integers #include<stdio.h> #define SIZE 12 #define EMPTY 0 // We assume that q[] is // empty if head==tail unsigned int q[SIZE],head,tail; void enqueue(unsigned int x) { q[tail]=x; tail=(++tail)%SIZE; } unsigned int dequeue() { unsigned int ret; ret = q[head]; q[head]=0; head= (++head)%SIZE; return ret;} Step 1) 1 2 3 4 5 6 7 8 9 10 11 15 6 9 8 4 head=6 tail=11 Step 2) 3 5 15 6 9 8 4 17 tail=2 head=6 Step 3) 3 5 6 9 8 4 17 tail=2 head=7

void enqueue_verify() { unsigned int x, old_head, old_tail; unsigned int old_q[SIZE], i; __CPROVER_assume(x>0); for(i=0; i < SIZE; i++) old_q[i]=q[i]; old_head=head; old_tail=tail; enqueue(x); assert(q[old_tail]==x); assert(tail== ((old_tail +1) % SIZE)); assert(head==old_head); for(i=0; i < old_tail; i++) assert(old_q[i]==q[i]); for(i=old_tail+1; i < SIZE; i++) assert(old_q[i]==q[i]); } void dequeue_verify() { unsigned int ret, old_head, old_tail; unsigned int old_q[SIZE], i; for(i=0; i < SIZE; i++) old_q[i]=q[i]; old_head=head; old_tail=tail; __CPROVER_assume(head!=tail); ret=dequeue(); assert(ret==old_q[old_head]); assert(q[old_head]== EMPTY); assert(head==(old_head+1)%SIZE); assert(tail==old_tail); for(i=0; i < old_head; i++) assert(old_q[i]==q[i]); for(i=old_head+1; i < SIZE; i++) assert(old_q[i]==q[i]);} int main() {// cbmc q.c –unwind SIZE+2 environment_setup(); enqueue_verify();} int main() {// cbmc q.c –unwind SIZE+2 environment_setup(); dequeue_verify();}

#include<stdio.h> #define SIZE 12 #define EMPTY 0 // Initial random queue setting following the script void environment_setup() { int i; for(i=0;i<SIZE;i++) { q[i]=EMPTY;} head=non_det(); __CPROVER_assume(0<= head && head < SIZE); tail=non_det(); __CPROVER_assume(0<= tail && tail < SIZE); if( head < tail) for(i=head; i < tail; i++) { q[i]=non_det(); __CPROVER_assume(0< q[i]); } else if(head > tail) { for(i=0; i < tail; i++) { for(i=head; i < SIZE; i++) { } // We assume that q[] is empty if head==tail #include<stdio.h> #define SIZE 12 #define EMPTY 0 unsigned int q[SIZE],head,tail; void enqueue(unsigned int x) { q[tail]=x; tail=(++tail)%SIZE; } unsigned int dequeue() { unsigned int ret; ret = q[head]; q[head]=0; head= (++head)%SIZE; return ret;

Model checking v.s. random sequence of method calls You may try to test the circular queue code by calling enqueue and dequeuer randomly Ex. void test1(){e(10);r=d();assert(r==10);) void test2(){e(10);e(20);d();e(30);r=d(); assert(r =20);) void test3(){...} … Note that model checking covers all test scenarios of the above random method sequence calls Note that a random sequence of method calls just provide ONE input instance/state to the circular queue MC provides ALL input instances/states through environment/input space modeling

Ex2. Tower of Hanio Write down a C program to solve the Tower of Hanoi game (3 poles and 4 disks) by using CBMC Hint: you may non-deterministically select the disk to move Find the shortest solution by analyzing counter examples. Also explain why your solution is the shortest one. Use non-determinism and __CPROVER_assume() properly for the moving choice Use assert statement to detect when all the disks are moved to the destination

Top[3] 0 1 2 2 -1 2 1 1 2 3 // cbmc hanoi3.c –unwind 7 –no-unwinding-assertions // Increase n from 1 to 10 in –unwind [n] to find the shortest solution 1:signed char disk[3][3] = {{3,2,1},{0,0,0},{0,0,0}}; 2:char top[3]={2,-1,-1};// The position where the top disk is located at. 3: // If the pole does not have any disk, top is -1 4:int main() { 5: unsigned char dest, src; 14: while(1) { 15: src = non_det(); 16: __CPROVER_assume(src==0 || src==1 || src==2); 17: __CPROVER_assume(top[src] != -1); 18: 19: dest= non_det(); 20: __CPROVER_assume((dest==0 || dest==1 || dest==2) && (dest != src)); 21: __CPROVER_assume(top[dest]==-1 || (disk[src][top[src]] < disk[dest][top[dest]]) ); 22: 25: top[dest]++; 26: disk[dest][top[dest]]=disk[src][top[src]]; 27: 28: disk[src][top[src]]=0; 29: top[src]--; 30: 31: assert( !(disk[2][0]==3 && disk[2][1]==2 && disk[2][2]==1 )); } } 0 1 2 2 1 1 2 3