Implementing ModelChecker for Bubblesort: Software Validation & Defect Detection, Assignments of Computer Graphics

Instructions for a mini-project in the cmps 290g - topics in software engineering course during winter 2004. The project involves implementing a modelchecker class to ensure that the bubblesort algorithm never yields an assertion failure. Students are required to write code for the leq() method in the modelchecker class and run the model checker multiple times to test all possible paths. The supplied code includes the bubblesort class and the myint class, which represents symbolic integers.

Typology: Assignments

Pre 2010

Uploaded on 08/19/2009

koofers-user-c4r-1
koofers-user-c4r-1 🇺🇸

9 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CMPS 290G Topics in Software Engineering
Winter 2004 Software Validation and Defect Detection
Homework 5
Due: by email to [email protected] before or on 18 March 2004
This homework is in the form of a mini-project. This project pulls together ideas from testing,
model checking, and theorem proving. Your contribution can be implemented with under 100 lines
of code. The code on the following pages provides basic infrastructure for this project. (This code
is also at http://www.soe.ucsc.edu/classes/cmps290g/Winter04/code.)
The class Bubblesort contains a bubblesort algorithm and a test harness that applies the
sorting algorithm to arrays of length 4. While we might normally sort ints, for this project
Bubblesort sorts an array of MyInts. The class MyInt represents a symbolic integer.
The supplied class ConstraintDiff expresses inequality constraints over MyInts, and the class
Prover decides satisfiability of these constraints.
Your task is to implement a class ModelChecker.
This class will contain the usual public static void main(String[] args) method, which
in turn calls Bubblesort.main() multiple times. Bubblesort.main() creates MyInts and
compares them to perform sorting, by calling ModelChecker.leq(MyInt x,MyInt y).
You need to implement the class ModelChecker so that, using a finite (and minimal) number
of test runs, it verifies that Bubblesort.main() never yields an assertion failure.
Hint: When you run your model checker, it should require 24 test runs of Bubblesort
Please include the output of running the checker in your homework submission. The rou-
tine Prover.constraintsToString() may be helpful for producing useful output.
Feel free to consult classmates and ask questions in class on this assignment.
If necessary, you can collaborate in teams of size 2 for this project.
Please let me know if you find any bugs in the supplied code.
Once you have your model checker working, you should also use it to test some other program
(a replacement for Bubblesort) for which you think your model checker would work well.
Good luck!
pf3
pf4
pf5

Partial preview of the text

Download Implementing ModelChecker for Bubblesort: Software Validation & Defect Detection and more Assignments Computer Graphics in PDF only on Docsity!

CMPS 290G – Topics in Software Engineering

Winter 2004 – Software Validation and Defect Detection

Homework 5

Due: by email to [email protected] before or on 18 March 2004

This homework is in the form of a mini-project. This project pulls together ideas from testing, model checking, and theorem proving. Your contribution can be implemented with under 100 lines of code. The code on the following pages provides basic infrastructure for this project. (This code is also at http://www.soe.ucsc.edu/classes/cmps290g/Winter04/code.)

  • The class Bubblesort contains a bubblesort algorithm and a test harness that applies the sorting algorithm to arrays of length 4. While we might normally sort ints, for this project Bubblesort sorts an array of MyInts. The class MyInt represents a symbolic integer.
  • The supplied class ConstraintDiff expresses inequality constraints over MyInts, and the class Prover decides satisfiability of these constraints.
  • Your task is to implement a class ModelChecker. This class will contain the usual public static void main(String[] args) method, which in turn calls Bubblesort.main() multiple times. Bubblesort.main() creates MyInts and compares them to perform sorting, by calling ModelChecker.leq(MyInt x,MyInt y). You need to implement the class ModelChecker so that, using a finite (and minimal) number of test runs, it verifies that Bubblesort.main() never yields an assertion failure.
  • Hint: When you run your model checker, it should require 24 test runs of Bubblesort Please include the output of running the checker in your homework submission. The rou- tine Prover.constraintsToString() may be helpful for producing useful output.
  • Feel free to consult classmates and ask questions in class on this assignment.
  • If necessary, you can collaborate in teams of size 2 for this project.
  • Please let me know if you find any bugs in the supplied code.
  • Once you have your model checker working, you should also use it to test some other program (a replacement for Bubblesort) for which you think your model checker would work well.

Good luck!

/** The model checker skeleton. What you need to do is fill out this skeleton. */

public class ModelChecker {

/** Called by Bubblesort application to compare symbolic integers. */

public static boolean leq(MyInt x,MyInt y) { ... // Your job: write something clever here }

/** Main routine: Calls Bubblesort.main() multiple times to test all possible paths. */

public static void main(String[] args) { int numruns=0; while(...) { MyInt.reset(); numruns++; Bubblesort.main(); } System.out.println("Test runs: "+numruns); }

import java.util.*;

/** Represents a symbolic integer.

  • The class ConstraintDiff expresses constraints over MyInts, and the class Prover decides
  • satisfiability of these constraints.
  • The method get() yields the same sequence of MyInts on each run of Bubblesort,
  • provided reset() is called before each run of Bubblesort. */ public class MyInt extends Object { int id; static int numMyInt;

static ArrayList myInts=new ArrayList(); static int curNdx=0;

static void reset() { curNdx=0; }

private MyInt() { id=numMyInt++; }

public String toString() { return "v"+id; }

static MyInt get() { if (curNdx==myInts.size()) { myInts.add(new MyInt()); } return (MyInt)myInts.get(curNdx++); } }

public class Assert { public static void fail(String s) { throw new RuntimeException("Assertion failure: "+s); } public static void isTrue(boolean b) { if(!b) fail(""); }

public abstract class Constraint { public abstract Constraint negate(); }

/* Expresses constraints over MyInts of the form "x <= y + c", where x and y are MyInts.

  • The class Prover decides satisfiability of these constraints.
  • */

public class ConstraintDiff extends Constraint { int c; MyInt x,y; // x <= y+c

ConstraintDiff(MyInt x, MyInt y,int c) { this.x=x; this.y=y; this.c=c; }

public Constraint negate() { return new ConstraintDiff(y,x,-c-1); }

public String toString() { return ""+x+"<="+y+(c==0? "": (c<0? ""+c : "+"+c)); }

public boolean equals(Object o) { if (!(o instanceof ConstraintDiff)) return false; ConstraintDiff d = (ConstraintDiff)o; return d.x==x && d.y==y && d.c==c; }

public int hashCode() { return x.hashCode()+y.hashCode()+c; }

return false; }

private static Iterator from(MyInt x,ArrayList constraints) { List r = new LinkedList(); for(Iterator i=constraints.iterator(); i.hasNext();) { ConstraintDiff cd=(ConstraintDiff)i.next(); if (cd.x==x) r.add(cd); } return r.iterator(); } private static Set symInts(ArrayList constraints) { Set r = new LinkedHashSet(); for(Iterator i=constraints.iterator(); i.hasNext();) { ConstraintDiff cd=(ConstraintDiff)i.next(); r.add(cd.x); r.add(cd.y); } return r; }