SWEN421 – Lecture 3 Building High Integrity Software with SPARK Ada

Slides:



Advertisements
Similar presentations
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
Advertisements

Copyright W. Howden1 Programming by Contract CSE 111 6/4/2014.
Formal Methods in Software Engineering
Giving a formal meaning to “Specialization” In these note we try to give a formal meaning to specifications, implementations, their comparisons. We define.
INSE web pages u Please explore them! – – u EVERYONE: please follow the “ minilecture.
Functions ROBERT REAVES. Functions  Interface – the formal description of what a subprogram does and how we communicate with it  Encapsulation – Hiding.
Today’s Agenda  Correctness Issues. Why Correctness?  Programming is engineering Program is a product Program quality to be determined during production.
Copyright © 2006 Addison-Wesley. All rights reserved. 3.5 Dynamic Semantics Meanings of expressions, statements, and program units Static semantics – type.
The Z Specification Language
Software Engineering and Design Principles Chapter 1.
Software Testing and Quality Assurance
Slides prepared by Rose Williams, Binghamton University Chapter 13 Interfaces and Inner Classes.
OOP #10: Correctness Fritz Henglein. Wrap-up: Types A type is a collection of objects with common behavior (operations and properties). (Abstract) types.
Basic Definitions Data Structures: Data Structures: A data structure is a systematic way of organizing and accessing data. Or, It’s the logical relationship.
Describing Syntax and Semantics
Adding Contracts to Ada Ehud Lamm Adding Design By Contract to Ada.
Abstract Data Types and Encapsulation Concepts
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 12 Imperative Programming I really hate this.
Ranga Rodrigo. Class is central to object oriented programming.
Computer Science School of Computing Clemson University Discrete Math and Reasoning about Software Correctness Murali Sitaraman
CS 331 Modules Chapter 6. Overview Decomposition and abstraction Program organization Abstract vs. concrete User-defined types Example discussion.
Lecture 16 March 22, 2011 Formal Methods CS 315 Spring Adapted from slides provided by Jason Hallstrom and Murali Sitaraman (Clemson)
Functions Part I (Syntax). What is a function? A function is a set of statements which is split off into a separate entity that can be used like a “new.
111 Protocols CS 4311 Wirfs Brock et al., Designing Object-Oriented Software, Prentice Hall, (Chapter 8) Meyer, B., Applying design by contract,
Low-Level Detailed Design SAD (Soft Arch Design) Mid-level Detailed Design Low-Level Detailed Design Design Finalization Design Document.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Slide: 1 Copyright © AdaCore Subprograms Presented by Quentin Ochem university.adacore.com.
CSC3315 (Spring 2008)1 CSC 3315 Subprograms Hamid Harroud School of Science and Engineering, Akhawayn University
High Integrity Ada in a UML and C world Peter Amey, Neil White Presented by Liping Cai.
Chapter 5: Sequences, Mathematical Induction, and Recursion 5.5 Application: Correctness of Algorithms 1 [P]rogramming reliability – must be an activity.
Pre- and postconditions, Using assertions and exceptions 1 Pre- and postconditions Using assertions and exceptions.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
ECSE Software Engineering 1I HO 4 © HY 2012 Lecture 4 Formal Methods A Library System Specification (Continued) From Specification to Design.
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 1: Introduction Data.
Verificare şi Validarea Sistemelor Soft Tem ă Laborator 1 ESC/Java2 Extended Static Checker for Java Dat ă primire laborator: Lab 1 Dat ă predare laborator:
ANU COMP2110 Software Design in 2003 Lecture 10Slide 1 COMP2110 Software Design in 2004 Lecture 12 Documenting Detailed Design How to write down detailed.
L13: Design by Contract Definition Reliability Correctness Pre- and post-condition Asserts and Exceptions Weak & Strong Conditions Class invariants Conditions.
1 Chapter 11 © 1998 by Addison Wesley Longman, Inc The Concept of Abstraction - The concept of abstraction is fundamental in programming - Nearly.
Object Design More Design Patterns Object Constraint Language Object Design Specifying Interfaces Review Exam 2 CEN 4010 Class 18 – 11/03.
CSC 243 – Java Programming, Spring, 2014 Week 4, Interfaces, Derived Classes, and Abstract Classes.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
CSC 243 – Java Programming, Fall, 2008 Tuesday, September 30, end of week 5, Interfaces, Derived Classes, and Abstract Classes.
Introduction To Algorithm and Data Structures Course Teacher: Moona Kanwal -Algorithm Design -Algorithm Analysis -Data structures -Abstract Data Type.
1 Team Skill 3 Defining the System Part 1: Use Case Modeling Noureddine Abbadeni Al-Ain University of Science and Technology College of Engineering and.
J-P. Rosen Adalog J-P. Rosen Adalog The contract model of Ada 2012.
Chapter 3 of Programming Languages by Ravi Sethi
SWEN421 – Lecture 4 Contracts and Correctness
Design by Contract Jim Fawcett CSE784 – Software Studio
Design by Contract Jim Fawcett CSE784 – Software Studio
Types for Programs and Proofs
11.1 The Concept of Abstraction
Subroutines Idea: useful code can be saved and re-used, with different data values Example: Our function to find the largest element of an array might.
Specifying Object Interfaces
Algorithm design and Analysis
Introduction to Data Structures
Unified Modeling Language
Packages and Interfaces
Slides by Steve Armstrong LeTourneau University Longview, TX
Hoare-style program verification
Data Structures and Algorithms for Information Processing
CSE 501N Fall ‘09 13: Interfaces and Multiple Representation
Programming Languages and Paradigms
Java Modeling Language (JML)
Algebraic Specification Software Specification Lecture 34
Contract-Based Programming with/without Ada 2012
Formal Methods Lecture 16 March 22, 2011 CS 315 Spring 2011
Generics, Lambdas and Reflection
11.1 The Concept of Abstraction
Chapter 11 Abstraction - The concept of abstraction is fundamental in
Presentation transcript:

SWEN421 – Lecture 3 Building High Integrity Software with SPARK Ada 21/3/17 SWEN421 - Lecture 3

Approaches to High Integrity Software High level design: module specifications/interfaces/abstract types Module design: data structure invariants Subprogram design: contracts, loop invariants/variants Static correctness checking: static analysis, proof obligations Dynamic correctness checking: testing, run-time checks 21/3/17 SWEN421 - Lecture 3

High Level Design System is designed as a collection of components/modules Interact with each other via well defined interfaces Modules hide information about implementation and data that other modules don’t need access to Interface provides data types, public variables and operations on them Java interfaces specify names of operations, and types of arguments and results, but no semantics – no difference between a stack and a queue! In formal approach, we specify operations formally, in terms of relationships between allowable input and output values E.g. if given two ordered sequences, merge will produced an ordered sequence containing all of the elements of both inputs What about repeated elements??? 21/3/17 SWEN421 - Lecture 3

Programming with Modules An Ada package (module) has two parts: specification and body Other modules can only see the specification Private part of specification declares types, etc. needed in the public part Formal specifications allow us to prove correctness of top level design, before components have been implemented Dependency contracts provide finer control over what each operation can access and/or update (later) 21/3/17 SWEN421 - Lecture 3

Programming by successive refinement We can develop a system in several steps, from an abstract specification through more and more concrete layers till we reach a final implementation Can prove correctness of each refinement/layer relative to the one above it, rather than proving correctness of implementation wrt abstract specification in one step 21/3/17 SWEN421 - Lecture 3

Specification facilities in Spark Ada Ada has two mechanisms for adding meta-level information to programs: Pragmas were in original Ada, for providing compiler operations, hardware specific details, etc. pragma name(value); eg: pragma SPARK_Mode(On); Aspects were added in Ada 2012, for providing other kinds of program annotations with name => definition eg: with SPARK_Mode => On Some things can be defined using either. Ex: Look up the lists of pragmas and aspects available! 21/3/17 SWEN421 - Lecture 3

Contracts for subprograms Subprograms are specified in terms of: Precondition defining allowable inputs Postcondition defining allowable out put for any allowable input In Ada these are given as aspects, Pre and Post (cf requires and ensures in Whiley) procedure Sqrt(x: in Integer; z: out Integer) with Pre => x >= 0, Post => z**2 <= x and (z+1)**2 > x; Function Min(x, y: in Integer) return Integer with Post => (Abs’Result = x or Abs’Result = y) and Abs’Result >= x and Abs’Result >= y 21/3/17 SWEN421 - Lecture 3

Contracts for subprograms Contracts need not specify all relevant details procedure Insert1(x: in Integer; a: in array(<>) Integer; b: out array(<>) Integer) with Post => b’Length = a’Length+1; procedure Insert2(x: in Integer; a: in array(<>) Integer ; b: out array(<>) Integer) with Pre => (for all i in a’First .. a’Last-1 => a(i) <= a(i+1)), Post => (for all i in b’First .. b’Last-1 => b(i) <= b(i+1)); procedure Insert3(x: in Integer; a: in array(<>) Integer ; b: out array(<>) Integer) with Pre => (for all i in a’First .. a’Last-1 => a(i) <= a(i+1)), Post => (for all i in b’First .. b’Last-1 => b(i) <= b(i+1)) and (for some k in b’Range => (for all i in b’First .. k-1 => b(i) = a(i)) and b(k) = x and (for all i in k+1 .. b’Last => b(i) = a(i-1))) Pre and postconditions often need to use quantifiers Use specification functions to capture abstractions and simply specifications: ord(a) Use collections to express specifications more abstractly (later) 21/3/17 SWEN421 - Lecture 3