Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Formal Methods in SE Qaisar Javaid Assistant Professor Lecture 05.

Similar presentations

Presentation on theme: "1 Formal Methods in SE Qaisar Javaid Assistant Professor Lecture 05."— Presentation transcript:

1 1 Formal Methods in SE Qaisar Javaid Assistant Professor Lecture 05

2 2 Some related books: Also:Mainly:

3 3 Goal: software reliability Use software engineering methodologies to develop the code. Use formal methods during code development

4 4 What are formal methods? Techniques for analyzing systems, based on some mathematics. This does not mean that the user must be a mathematician. Some of the work is done in an informal way, due to complexity.

5 5 Examples for FM Deductive verification: Using some logical formalism, prove formally that the software satisfies its specification. Model checking: Use some software to automatically check that the software satisfies its specification. Testing: Check executions of the software according to some coverage scheme.

6 6 Typical situation: Boss: Mark, I want that the new internet marketing software will be flawless. OK? Mark: Hmmm. Well,..., Aham, Oh! Ah??? Where do I start? Bob: I have just the solution for you. It would solve everything.

7 7 Some concerns Which technique? Which tool? Which experts? What limitations? What methodology? At which points? How expensive? How many people? Needed expertise. Kind of training. Size limitations. Exhaustiveness. Reliability. Expressiveness. Support.

8 8 Badmouth Formal methods can only be used by mathematicians. The verification process is itself prone to errors, so why bother? Using formal methods will slow down the project.

9 9 Some answers... Formal methods can only be used by mathematicians. Wrong. They are based on some math but the user should not care. The verification process is itself prone to errors, so why bother? We opt to reduce the errors, not eliminate them. Using formal methods will slow down the project. Maybe it will speed it up, once errors are found earlier.

10 10 Some exaggerations Automatic verification can always find errors. Deductive verification can show that the software is completely safe. Testing is the only industrial practical method.

11 11 Our approach Learn several methods (deductive verification, model checking, testing process algebra). Learn advantages and limitations, in order to choose the right methods and tools. Learn how to combine existing methods.

12 12 Emphasis The process: Selecting the tools, Modeling, Verification, Locating errors. Use of tools: Hands on. PVS, SPIN Visual notation: Statecharts, MSCs, UML.

13 13 Some emphasis The process of selecting and using formal methods. The appropriate notation. In particular, visual notation. Hands-on experience with tools.

14 14 The unbearable easiness of grading During class, choose some small project in groups, e.g., Explore some examples using tools. Implementing a simple algorithm. Dealing with new material. or covering advanced subject. - Office presentation (1 hour). - Written description (2-3 pages + computer output or 6-10 pages). - Class presentation (0.5-1.5 hours per group).

15 15 Example topics Project: Verify some example using some tools. Communication protocols. Mutual exclusion. Advanced topics: Abstractions. Reductions. Partitions. Static analysis. Verifying pushdown automata. Verifying security protocols.

16 16 Where do we start? Boss: Mark, can you verify this for me? Mark: OK, first I have to...

17 17 Things to do Check the kind of software to analyze. Choose methods and tools. Express system properties. Model the software. Apply methods. Obtain verification results. Analyze results. Identify errors. Suggest correction.

18 18 Different types of software Sequential. Concurrent. Distributed. Reactive. Protocols. Abstract algorithms. Finite state.

19 19 Specification: Informal, textual, visual The value of x will be between 1 and 5, until some point where it will become 7. In any case it will never be negative. (1 =0)) 1<=x<=5 X=7 X>=0

20 20 Verification methods Finite state machines. Apply model checking. Apply deductive verification (theorem proving). Program too big, too complicated. Apply testing techniques. Apply a combination of the above!

21 21 Modeling Use the program text. Translate to a programming language embedded in some proof system. Translate to some notation (transition system). Translate to finite automata. Use visual notation. Special case: black box system.

22 22 Modeling Software Systems for Analysis

23 23 Modelling and specification for verification and validation How to specify what the software is supposed to do? Can we use the UML model or parts of it? How to model it in a way that allows us to check it?

24 24 Systems of interest Sequential systems. Concurrent systems (multi-threaded). 1. Distributive systems. 2. Reactive systems. 3. Embedded systems (software + hardware).

25 25 Sequential systems. Perform some computational task. Have some initial condition, e.g.,  0  i  n A[i] integer. Have some final assertion, e.g.,  0  i  n-1 A[i]  A[i+1]. (What is the problem with this spec?) Are supposed to terminate.

26 26 Concurrent Systems Involve several computation agents. Termination may indicate an abnormal event (interrupt, strike). May exploit diverse computational power. May involve remote components. May interact with users (Reactive). May involve hardware components (Embedded).

27 27 Problems in modeling systems Representing concurrency: - Allow one transition at a time, or - Allow coinciding transitions. Granularity of transitions. Assignments and checks? Application of methods? Global (all the system) or local (one thread at a time) states.

28 28 Modeling. The states based model. V={v 0,v 1,v 2, …} - a set of variables, over some domain. p(v 0, v 1, …, v n ) - a parametrized assertion, e.g., v 0 =v 1 +v 2 /\ v 3 >v 4. A state is an assignment of values to the program variables. For example: s= For predicate (first order assertion) p: p(s) is p under the assignment s. Example: p is x>y /\ y>z. s=. Then we have 4>3 /\ 3>5, which is false.

29 29 State space The state space of a program is the set of all possible states for it. For example, if V={a, b, c} and the variables are over the naturals, then the state space includes:,,, …

30 30 Atomic Transitions Each atomic transition represents a small piece of code such that no smaller piece of code is observable. Is a:=a+1 atomic? In some systems, e.g., when a is a register and the transition is executed using an inc command.

31 31 Non atomicity Execute the following when a=0 in two concurrent processes: P 1 :a=a+1 P 2 :a=a+1 Result: a=2. Is this always the case? Consider the actual translation: P 1 :load R1,a inc R1 store R1,a P 2 :load R2,a inc R2 store R2,a a may be also 1.

32 32 Scenario P 1 :load R1,a inc R1 store R1,a P 2 :load R2,a inc R2 store R2,a a=0 R1=0 R2=0 R1=1 R2=1 a=1

33 33 Representing transitions Each transition has two parts: The enabling condition: a predicate. The transformation: a multiple assignment. For example: a>b  (c,d ):=(d,c ) This transition can be executed in states where a>b. The result of executing it is switching the value of c with d.

34 34 Initial condition A predicate I. The program can start from states s such that I (s) holds. For example: I (s)=a >b /\ b >c.

35 35 A transition system A (finite) set of variables V over some domain. A set of states . A (finite) set of transitions T, each transition e  t has an enabling condition e, and a transformation t. An initial condition I.

36 36 Example V={a, b, c, d, e}.  : all assignments of natural numbers for variables in V. T={c >0  (c,e):=(c -1,e +1), d >0  (d,e):=(d -1,e +1)} I: c =a /\ d =b /\ e =0 What does this transition system do?

Download ppt "1 Formal Methods in SE Qaisar Javaid Assistant Professor Lecture 05."

Similar presentations

Ads by Google