Detailed Design and Verification with JML Curt Clifton Rose-Hulman - - PowerPoint PPT Presentation

detailed design and verification with jml
SMART_READER_LITE
LIVE PREVIEW

Detailed Design and Verification with JML Curt Clifton Rose-Hulman - - PowerPoint PPT Presentation

Detailed Design and Verification with JML Curt Clifton Rose-Hulman Institute of Technology And now for something completely different And now for something completely different Course Topics DETAILED DESIGN AND VERIFICATION (JML)


slide-1
SLIDE 1

Detailed Design and Verification with JML

Curt Clifton Rose-Hulman Institute of Technology

slide-2
SLIDE 2

And now for something completely different

slide-3
SLIDE 3

And now for something completely different

slide-4
SLIDE 4

Course Topics

2 4 6 8 10 Week

ABSTRACTIONS (ALLOY) DETAILED DESIGN AND VERIFICATION (JML) REACTIVE SYSTEMS (STATE CHARTS)

HW 7 due Thursday, 6am

slide-5
SLIDE 5

Formal Verification

Formal reasoning about actual code Application: Design-by-contract Weakest pre-condition calculation Proving program correctness

slide-6
SLIDE 6

First, learn basic reasoning techniques Working by hand Using same notation that we’ll automate later Then, experiment with prototype tools for automated reasoning

The Plan

slide-7
SLIDE 7

JML: Notation and Tools

slide-8
SLIDE 8

What’s JML?

JML stands for “Java Modeling Language” A Behavioral Interface Specification Language A “BISL” specifies the signatures of functions, methods, and classes—the interface Conditions that must hold—the behavior JML extends Java with special annotations for behavioral specifications

Q1,2

slide-9
SLIDE 9

JML Annotations

Annotations in JML are just Java comments JML tools recognize comments using ‘@’ symbol //@ starts a single line annotation //@ requires x > 0; /*@ … */ defines a multi-line comment Common mistake—adding a space: // @

NOT VALID! BEGIN Q3

slide-10
SLIDE 10

POSTCONDITION: WHAT METHOD MUST ENSURE PRECONDITION: WHAT CALLER MUST GUARANTEE

Example

/*@ requires x > 0; @ ensures \result * \result <= x && @ x < (\result + 1) * (\result + 1); @*/ public static int iroot(int x) { … }

FINISH Q3

slide-11
SLIDE 11

One use for JML: Design by Contract

A software development methodology Engineer specifies a contract for each method: A precondition and A postcondition Programmer implements the methods

Q4

slide-12
SLIDE 12

WHAT’S THE USE?

THE FAMILY OF JML TOOLS

Java Annotated With JML HTML Documentation Unit Tests Executable Java with Runtime Checks Model Checking Proofs of Correctness Static Warnings Runtime Data Traces jmlc4 JMLUnitNG bogor JACK, Jive, Krakatoa, KeY, LOOP jmldoc Daikon OpenJML 7

slide-13
SLIDE 13

Techniques for Formal Verification, or …

slide-14
SLIDE 14

How Do You Eat an Elephant?

ONE BITE AT A TIME

slide-15
SLIDE 15

First Bites

Assignment Sequencing

slide-16
SLIDE 16

Detailed Notation

Low-level verification: use JML’s assert Pre-condition: before a statement or block Post-condition: after a statement or block … //@ assert n == 0; i = 0; //@ assert n == i; …

WHY NOT JUST USE JAVA’S ASSERT STATEMENT? Q5

slide-17
SLIDE 17

TOTAL CORRECTNESS PARTIAL CORRECTNESS

Proving Program Properties

Specify the program with pre- and post-conditions Use “inference rules” to annotate the program proving that from the pre-condition we can reach the post-condition Show that loops and recursive functions terminate

slide-18
SLIDE 18

Assignment Rule

//@ assert P(e); v = e; //@ assert P(v); WHATEVER IS TRUE ABOUT e BEFORE IS TRUE ABOUT v AFTER WHAT MUST BE TRUE ABOUT e BEFORE IF WE WANT SOME PROPERTY TO BE TRUE ABOUT v AFTER?

slide-19
SLIDE 19

The Weakest Precondition is…

THE LEAST RESTRICTIVE PRE-CONDITION SUCH THAT THE POST-CONDITION MUST HOLD.

Q6

slide-20
SLIDE 20

Examples…

//@ assert P(e); v = e; //@ assert P(v);

Q7,8

slide-21
SLIDE 21

Examples

2: //@ assert 11 == y; 1: //@ assert 14 - 3 == y; x = 3; //@ assert 14 - x == y; 2: //@ assert 100 <= n * 3 && n * 3 < p; 1: n’ = n * 3; // tick trick //@ assert 100 <= n’ && n’ < p;

slide-22
SLIDE 22

Composition Rule

IF:

//@ assert P1; S1; //@ assert Q1;

AND

//@ assert P2; S2; //@ assert Q2;

AND

Q1 ==> P2

THEN:

//@ assert P1; S1; //@ assert Q1; //@ assert P2; S2; //@ assert Q2;

IMPORTANT: IMPLICATIONS GO DOWN Q9

slide-23
SLIDE 23

Composition Example

3: //@ assert 3 * (x + y) > 10; 2: x’ = x + y; // tick trick 1: //@ assert 3 * x’ > 10; y = 3 * x; //@ assert y > 10;