Advanced programming tools at Microsoft

Slides:



Advertisements
Similar presentations
Hoare-style program verification K. Rustan M. Leino Guest lecturer Rob DeLines CSE 503, Software Engineering University of Washington 26 Apr 2004.
Advertisements

Joint work with Mike Barnett, Robert DeLine, Manuel Fahndrich, and Wolfram Schulte Verifying invariants in object-oriented programs K. Rustan M. Leino.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
The Static Driver Verifier Research Platform
The Spec# programming system K. Rustan M. Leino Microsoft Research, Redmond, WA, USA Lunch seminar, Praxis Bath, UK 6 Dec 2005 joint work with Mike Barnett,
Demand-driven inference of loop invariants in a theorem prover
Object Invariants in Specification and Verification K. Rustan M. Leino Microsoft Research, Redmond, WA Joint work with: Mike Barnett, Ádám Darvas, Manuel.
Writing specifications for object-oriented programs K. Rustan M. Leino Microsoft Research, Redmond, WA, USA 21 Jan 2005 Invited talk, AIOOL 2005 Paris,
Program Verification Using the Spec# Programming System ETAPS Tutorial K. Rustan M. Leino, Microsoft Research, Redmond Rosemary Monahan, NUIM Maynooth.
Technologies for finding errors in object-oriented software K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 3 Summer school on Formal Models.
Technologies for finding errors in object-oriented software K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 0 Summer school on Formal Models.
Spec# K. Rustan M. Leino Senior Researcher Programming Languages and Methods Microsoft Research, Redmond, WA, USA Microsoft Research faculty summit, Redmond,
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Challenges in increasing tool support for programming K. Rustan M. Leino Microsoft Research, Redmond, WA, USA 23 Sep 2004 ICTAC Guiyang, Guizhou, PRC joint.
Formal Specifications on Industrial Strength Code: From Myth to Reality Manuvir Das Principal Researcher Center for Software Excellence Microsoft Corporation.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 8.
De necessariis pre condiciones consequentia sine machina P. Consobrinus, R. Consobrinus M. Aquilifer, F. Oratio.
The Dafny program verifier
K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond, WA, USA 15 January 2009 Séminaire Digiteo Orsay, France.
The Spec# programming system K. Rustan M. Leino Microsoft Research, Redmond, WA, USA Distinguished Lecture Series Max Planck Institute for Software Systems.
A Program Transformation For Faster Goal-Directed Search Akash Lal, Shaz Qadeer Microsoft Research.
Abstraction and Modular Reasoning for the Verification of Software Corina Pasareanu NASA Ames Research Center.
Data Abstraction II SWE 619 Software Construction Last Modified, Spring 2009 Paul Ammann.
1 Thorough Static Analysis of Device Drivers Byron Cook – Microsoft Research Joint work with: Tom Ball, Vladimir Levin, Jakob Lichtenberg,
Chair of Software Engineering Software Verification Stephan van Staden Lecture 10: Model Checking.
K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond, WA, USA 3 December 2008 U. Lugano Lugano, Switzerland.
Software Verification via Refinement Checking Sagar Chaki, Edmund Clarke, Alex Groce, CMU Somesh Jha, Wisconsin.
Contracts, tools, verification K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond Keynote, ASWEC 2010; Auckland, NZ;
Synergy: A New Algorithm for Property Checking
Using and Building an Automatic Program Verifier K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond Lecture 1 LASER.
Hoare-style program verification K. Rustan M. Leino Guest lecturer Rob DeLine’s CSE 503, Software Engineering University of Washington 26 Apr 2004.
CS 267: Automated Verification Lectures 14: Predicate Abstraction, Counter- Example Guided Abstraction Refinement, Abstract Interpretation Instructor:
Automatically Validating Temporal Safety Properties of Interfaces Thomas Ball and Sriram K. Rajamani Software Productivity Tools, Microsoft Research Presented.
OOP #10: Correctness Fritz Henglein. Wrap-up: Types A type is a collection of objects with common behavior (operations and properties). (Abstract) types.
K. Rustan M. Leino Microsoft Research, Redmond, WA, USA with Mike Barnett, Robert DeLine, Manuel Fahndrich, and Wolfram Schulte Toward enforceable contracts.
Well-cooked Spaghetti: Weakest-Precondition of Unstructured Programs Mike Barnett and Rustan Leino Microsoft Research Redmond, WA, USA.
K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond Caltech Pasadena, CA 12 November 2009.
Ch 4. Memory Management Timothy Budd Oregon State University.
Computer Science 340 Software Design & Testing Design By Contract.
Towards Scalable Modular Checking of User-defined Properties Thomas Ball, MSR Brian Hackett, Mozilla Shuvendu Lahiri, MSR Shaz Qadeer, MSR Julien Vanegue,
Software Engineering Prof. Dr. Bertrand Meyer March 2007 – June 2007 Chair of Software Engineering Static program checking and verification Slides: Based.
Introduction Ellen Walker CPSC 201 Data Structures Hiram College.
1 Debugging and Testing Overview Defensive Programming The goal is to prevent failures Debugging The goal is to find cause of failures and fix it Testing.
272: Software Engineering Fall 2012 Instructor: Tevfik Bultan Lecture 3: Modular Verification with Magic, Predicate Abstraction.
Rule Checking SLAM Checking Temporal Properties of Software with Boolean Programs Thomas Ball, Sriram K. Rajamani Microsoft Research Presented by Okan.
Aditya V. Nori, Sriram K. Rajamani Microsoft Research India.
Low-Level Detailed Design SAD (Soft Arch Design) Mid-level Detailed Design Low-Level Detailed Design Design Finalization Design Document.
Newton: A tool for generating abstract explanations of infeasibility1 The Problem P (C Program) BP (Boolean Program of P) CFG(P) CFG(BP)
Reasoning about object structures with Spec# K. Rustan M. Leino Microsoft Research, Redmond, WA Joint work with: Mike Barnett, Ádám Darvas, Manuel Fähndrich,
Automatically Validating Temporal Safety Properties of Interfaces Thomas Ball, Sriram K. MSR Presented by Xin Li.
K. Rustan M. Leino Microsoft Research, Redmond, WA, USA with Mike Barnett, Robert DeLine, Manuel Fahndrich, and Wolfram Schulte Spec# Writing and checking.
Using and Building an Automatic Program Verifier K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond Lecture 0 Marktoberdorf.
K. Rustan M. Leino Principal Researcher Microsoft Research, Redmond, WA, USA 14 Nov 2007 Øredev Malmö, Sweden.
Model Checking C Programs Zijiang (James) Yang Department of Computer Science Western Michigan University In collaboration with NEC Laboratories America.
The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft.
Specifying and verifying programs in Spec# K. Rustan M. Leino Microsoft Research, Redmond, WA, USA Invited talk, PSI 2006 Novosibirsk, Russia 27 June 2006.
SWE 4743 Abstract Data Types Richard Gesick. SWE Abstract Data Types Object-oriented design is based on the theory of abstract data types Domain.
PROGRAMMING PRE- AND POSTCONDITIONS, INVARIANTS AND METHOD CONTRACTS B MODULE 2: SOFTWARE SYSTEMS 13 NOVEMBER 2013.
Static Techniques for V&V. Hierarchy of V&V techniques Static Analysis V&V Dynamic Techniques Model Checking Simulation Symbolic Execution Testing Informal.
1 Automatically Validating Temporal Safety Properties of Interfaces - Overview of SLAM Parts of the slides are from
/ PSWLAB Evidence-Based Analysis and Inferring Preconditions for Bug Detection By D. Brand, M. Buss, V. C. Sreedhar published in ICSM 2007.
Reasoning about object structures with Spec# K. Rustan M. Leino Microsoft Research, Redmond, WA Joint work with: Mike Barnett, Ádám Darvas, Manuel Fähndrich,
Verifying Regular Behavior of C modules Sagar Chaki, Edmund Clarke, Alex Groce, CMU Somesh Jha, Wisconsin.
Accessible Formal Methods A Study of the Java Modeling Language
CSE 143 Error Handling [Section 2.8] 3/30/98 CSE 143.
Verification of concurrent object-oriented programs
Spec# Writing and checking contracts in a .NET language
Hoare-style program verification
Hoare-style program verification
4/28/2019 6:13 PM HW-889P Advanced driver code analysis techniques Tips and tricks to develop more secure & reliable drivers Dave Sielaff Principal Software.
Presentation transcript:

Advanced programming tools at Microsoft K. Rustan M. Leino Microsoft Research, Redmond, WA, USA 16 May 2005 Distinguished lecture, York University Toronto, ON, Canada

Software engineering problem Building and maintaining large systems that are correct

Approach Specifications record design decisions bridge intent and code Tools amplify human effort manage details find inconsistencies ensure quality

Design decisions – examples and trends procedural abstraction int x; assert(x < a.Length); finite-state protocols mark-ups pre- and postconditions, and object invariants

More powerful techniques —a selection 0. PREfix 1. SLAM 2. SpecStrings 3. Spec#

0. PREfix Detects common errors in C/C++ Performs symbolic execution [Bush, Pincus, Sielaff, et al.] Detects common errors in C/C++ incorrect usage of null pointers, memory allocation, uninitialized variables, library idioms, ... Performs symbolic execution detailed C semantics paths simulated in detail, not all paths simulated interprocedural, procedures summarized by small subset of their paths

possible use of uninitialized variable PREfix example int abs(int x) { int y; if (0 <= x) { y = x; } return y; } possible use of uninitialized variable

PREfix virtues Expensive to run Reduces effects of spurious warnings whole-program analysis Reduces effects of spurious warnings filters and prioritizes output, uses heuristics Effective at finding errors 1/8 of bugs fixed in Windows Server 2003 found by PREfix (and PREfast) Widely deployed

The PREfast revolution [Weise, et al.] PREfast – framework for authoring analyses (walks AST) PREfix runs centrally after check-ins, PREfast can run on developer desktops before check-ins Name recognition, plug-ins

On the road to embracing static analysis: PREfix milestone PREfix and PREfast have opened eyes of developers and management to power of compile-time checking

1. Niche: device drivers bugs can have severe effects relatively small code base (usually ≤ 50 KLOC) crash-freedom specified by finite-state API protocols correctness mostly depends on flow of control, not data Acquire() Release() Acquire() Release()

SLAM Software model checking predicate abstraction [Ball, Rajamani, et al.] Software model checking predicate abstraction model checking (state exploration) counterexample-driven predicate refinement

Predicate abstraction and refinement correct model checker boolean program abstract trace predicate abstraction concrete trace C program predicates feasible? no yes error message predicate refinement

SLAM example do { KeAcquireSpinLock(); nPacketsOld = nPackets; if (request) { request = request->Next; KeReleaseSpinLock(); nPackets++; } } while (nPackets != nPacketsOld); Release() Acquire() Release()

SLAM example do { assert ¬P; P := true; // KeAcquireSpinLock(); Predicates: P: spin lock held do { assert ¬P; P := true; // KeAcquireSpinLock(); if ( * ) { assert P; P := false; // KeReleaseSpinLock(); } } while ( * );

error path in abstract program SLAM example Predicates: P: spin lock held do { assert ¬P; P := true; if ( * ) { assert P; P := false; } } while ( * ); error path in abstract program

SLAM example do { KeAcquireSpinLock(); nPacketsOld = nPackets; Predicates: P: spin lock held do { KeAcquireSpinLock(); nPacketsOld = nPackets; if (request) { request = request->Next; KeReleaseSpinLock(); nPackets++; } } while (nPackets != nPacketsOld); infeasible path in concrete program error path in abstract program

SLAM example do { KeAcquireSpinLock(); nPacketsOld = nPackets; Predicates: P: spin lock held Q: nPackets == nPacketsOld do { KeAcquireSpinLock(); nPacketsOld = nPackets; if (request) { request = request->Next; KeReleaseSpinLock(); nPackets++; } } while (nPackets != nPacketsOld); infeasible path in concrete program error path in abstract program

no error path in abstract program; hence, concrete program is correct SLAM example Predicates: P: spin lock held Q: nPackets == nPacketsOld do { assert ¬P; P := true; Q := true; // nPacketsOld = nPackets; if ( * ) { assert P; P := false; Q := if Q then false else * end; // nPackets++; } } while (¬ Q); // nPackets != nPacketsOld no error path in abstract program; hence, concrete program is correct

SLAM at Microsoft finite-state API protocols specified by experts applied to 100s of Windows drivers, for 10s of rules, found 60+ errors Static Driver Verifier transferred to Windows Driver Quality group to be released in DDK

On the road to embracing static analysis: SLAM milestone SLAM showcases specifications and powerful checking

2. SpecStrings company-wide effort to annotate C/C++ APIs [Das, Fähndrich, et al.] company-wide effort to annotate C/C++ APIs standard annotation language (SAL) for describing assumptions about parameters limited checking by PREfast plug-in can catch some null problems and buffer overruns

SpecString example void * memcpy( pre notnull pre writableTo(pre byteCount(num)) post readableTo(pre byteCount(num)) void * dest, pre readableTo(pre byteCount(num)) void * src, size_t num);

SpecStrings at Microsoft emphasizes importance of interfaces better documentation improves checking fewer spurious warnings can detect errors from violations of stated intent

On the road to embracing static analysis: SpecStrings milestone With SpecStrings, developers become used to source-code annotations that go beyond what compiler requires

3. Into the future managed code (C#, …) involve developers more intimately capture design decisions earlier let developers take control of their code reach beyond checking limits of current tools

Spec# Experimental mix of contracts and tool support Aimed at experienced developers who know the high cost of testing and maintenance Superset of C# non-null types pre- and postconditions object invariants Tool support more type checking compiler-emitted run-time checks static program verification contracts everywhere C# into the future type checking run-time checks static verification degree of checking, effort

Specifications today StringBuilder.Append Method (Char[ ], Int32, Int32) Appends the string representation of a specified subarray of Unicode characters to the end of this instance. public StringBuilder Append(char[] value, int startIndex, int charCount); Parameters value A character array. startIndex The starting position in value. charCount The number of characters append. Return Value A reference to this instance after the append operation has occurred. Exceptions Exception Type Condition ArgumentNullException value is a null reference, and startIndex and charCount are not zero. ArgumentOutOfRangeException charCount is less than zero. -or- startIndex is less than zero. startIndex + charCount is less than the length of value.

Spec# specifications Precondition Callers are expected to establish precondition before invoking method Implementations can assume precondition holds on entry public StringBuilder Append( char[ ] value, int startIndex, int charCount); requires value != null || (startIndex == 0 && charCount == 0); requires 0 <= startIndex && 0 <= charCount; requires startIndex + charCount <= value.Length; ensures result == this; Postcondition Implementations are expected to establish postcondition on exit Callers can assume postcondition upon return from method invocation

Object invariants readonly int rows; readonly int columns; readonly double[,] m; readonly int numInitialVars; readonly int numSlackVars; readonly int rhsColumn; readonly ArrayList<object> dims; readonly int[] basisColumns; readonly int[] inBasis; bool constructionDone = false; invariant rows == m.GetLength(0); invariant 1 <= columns && columns == m.GetLength(1); invariant 0 <= numInitialVars; invariant 0 <= numSlackVars && numSlackVars <= rows; invariant numInitialVars + numSlackVars + 1 == columns; invariant rhsColumn == columns - 1; invariant dims.Count == numInitialVars; invariant basisColumns.Length == rows; invariant inBasis.Length == numInitialVars + numSlackVars;

Spec# demo

Spec# verifier architecture Spec# compiler MSIL (“bytecode”) Spec# static program verifier, aka Boogie translator inference engine Boogie PL V.C. generator verification condition automatic theorem prover “correct” or list of errors

Analyzing verification conditions Automatic theorem prover can be hidden from programmer generates counterexamples Interactive theorem prover requires gurus not limited by built-in decision procedures

Generating verification conditions Weakest preconditions int AbsX(Robot c) requires c ≠ null; ensures 0 ≤ result; { if (0 ≤ c.x) { a := c.x; } else { a := −c.x; } return a; } c ≠ null  c ≠ null  (0 ≤ sel(c,x)  c ≠ null  0 ≤ sel(c,x))  (¬(0 ≤ sel(c,x))  c ≠ null  0 ≤ −sel(c,x)) c ≠ null  (0 ≤ sel(c,x)  c ≠ null  0 ≤ sel(c,x))  (¬(0 ≤ sel(c,x))  c ≠ null  0 ≤ −sel(c,x)) c ≠ null  0 ≤ sel(c,x) c ≠ null  0 ≤ −sel(c,x) 0 ≤ a 0 ≤ result

What’s in a language the programming language is the software engineer's primary thinking and working tool

Designing more rigor into the language Examples Type system impose coarse-grained restrictions easy to understand and use sound efficient checking General specifications enforce by mix of dynamic and static checking don’t worry about completeness or decidability Develop good defaults non-null types requires Pre; modifies Frame; ensures Post; Roll in what you can into the type system. Use general specifications where types don’t have their advantages. The defaults cope with the possibly overwhelming generality. requires this.inv = Valid; modifies this.*; ensures true;

Enforcing specifications Run-time checking may leave out expensive checks, if not required for soundness example: modifies clauses Static verification requires more effort from the user modular checking a necessity type checking run-time checks static verification degree of checking, effort

Migration problems To the new language From (!) the new language how does the language compare to existing ones? From (!) the new language development organizations may have process requirements contracts everywhere C# into the future

download Spec# from here Conclusions Trend toward more rigorous languages and checking Desire to contribute customized specifications Tool support is crucial Despite significant advances in the use of static analyses, we need more experience before we’d expect users to take on more detailed verification tasks Some areas where more research will help language design program semantics specification techniques inference algorithms decision procedures methodology http://research.microsoft.com/specsharp download Spec# from here