1 / 21

Modeling Software System with FSM

Modeling Software System with FSM. We have used mathematical models of partitioned equivalence classes , checklists , probability trees to depict the software systems from input, output, functional, and usage perspectives.

fonda
Télécharger la présentation

Modeling Software System with FSM

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Modeling Software System with FSM • We have used mathematical models of partitioned equivalence classes, checklists, probability trees to depict the software systems from input, output, functional, and usage perspectives. • We need a more sophisticated tool called Finite State Machine (FSM) to model either the internal or external behavior (functionalities)of a software. • “Constructing” the FSM model forces us to think about a sequence of functionalities that form a complex behavior • “Tracing” the transitions in FSM model forces us to devise a set of input values that must be sequenced in a specific manner to allow the transition to occur. So we can trace complex computations or behavior with FSM. • In constructing and tracing FSM, we can “test”: • the major states of the system (missing, extra, or incorrect behavior) • the transition of states (missing, extra, or incorrect transitions of behavior) • input and output (missing, extra, or incorrect inputs and/or outputs)

  2. A Simple “informal FSM” to model a “light-flip-switch” ON OFF flip flip flip on off The light may be in either an ON or OFF state. When the switch is flipped, it changes to the opposite state. off on 1) This FSM model allows us to partition the system by states and test for the 2 states. 2) This FSM model also helps us develop the test cases for transitions (flip) from one state to the other state. (Here the transitions are pretty easy)

  3. Formal Definition of (deterministic) FSM • A Finite State Machine is a model, FSM, which includes: • a set of states S = {s1, s2, ----, sn} • a set of inputs I = {i1, i2, -----, in} • A set of rules that defines the transitions from states to states S x I -> S • A designated special state(s) called initial state • A designated special state(s) called terminal state • We sometimes include the output from a state in the FSM model (Moore machines) • - When the transition is not deterministic, then we have a Non-Deterministic FSM

  4. A Simple FSM Example States = { 0, 1, 2) 0 : is initial state 2 : is final state marked as 2’ Input = {a, b} Transition rule: 0 x a -> 1 0 x b -> 0 1 x a -> 2 1 x b -> 1 b b 0 1 a a b 0 1 0 a 1 2 1 2 - - 2’ This FSM “accepts” strings of a’s and b’s that contains exactly 2 a’s and terminates with a

  5. Constructing FSM • A “general” Guideline to constructing FSM: • Collect the information for constructing FSM • From requirements or design (black box-white box testing) • From code (white box testing) • Construction of Initial FSM • Identify states • Identify transitions • Identify inputs and outputs • Model Validation, Refinement and Modification

  6. Example: Constructing FSM • Consider the following pseudo-code segment: • initialize sum,n as integers of zero value • ask for and read in the value of n • validity check the input value of n • if the input n is valid then compute (sum = (n * (n+1))/2) ; print out sum and terminate • if the input n is invalid then issue a message and return to step 2

  7. FSM as a Modeling tool • Great for simplification and abstraction but • For many “real” software projects, the number of states become too big and needs to be abstracted to a reasonably small number • Allows us to detect “mistakes” but • Errors of omission is still difficult to detect and requires concerted effort and questioning • A good tool in aiding the development of test scenarios and test cases Rarely does a single input drive through an application. Complex applications often require a “sequence” of inputs to drive the application from state to state. Finite State Machine model helps in constructing the input sequences.

  8. Augmenting FSM • We said : for many large commercial systems, the number of states and transition rules become so large that it becomes unmanageable. So --- • Based on the assumption that the software areas that are heavily utilized, if it contains defects, will have a higher probability of encountering those defects, we should perhaps focus on testing certain highly utilized sections of software first and more thoroughly. • Augment with “output” • This brings us to re-look at modeling with FSM with some augmented information --- such as customer/user “usage frequency distribution.” ---- (later section on Markov Model)

  9. Graphical FSM representation from your (text-book)Augmenting with output/(not very strict with notation) A: Power up B: initialize Mobile station Unable to Receive paging Channel / _ C: Idle Mobile station Finished Other Tasks / _ Paging Channel Message/ _ E: mobile station control on Traffic channel D: Access system Making a call / _

  10. Tabular Representation of same FSM

  11. Non-Deterministic model • For modeling certain situations such “traffic light” or “phone switching systems”, we need to use deterministic finite state machine • But there are situations that lends itself to non-deterministic modeling: • Game where the next move is not deterministic • GUI screen where the user choice is not deterministic • Weather projection where predictions can not be deterministic

  12. A simple Non-Deterministic FSM (NDFSM) • A Non-Deterministic FSM is a FSM where one or more states, given the same input, may have more than one transition rule. b States = { 0, 1, 2) 0 : is initial state 2 : is final state marked as 2’ Input = {a, b} Transition rule: 0 x a -> 1 0 x b -> 0 1 x a -> 2 1 x a -> 1 1 x b -> 1 a, b 0 1 a a 2’ This NDFSM “accepts” only strings of a’s and b’s that terminates with a

  13. Markov Model • A Markov Model is a NDFSM in which the state at each step can bepredicted by a probability distribution associated with the current state. • A Markov Model is a triple M = (S, Ω, A) where: • S is a finite set of states • Ω is a vector that contains the initial probabilitiesof each state in S • A is a matrix that represents the transition probabilities expressed as A[x,y] = Prob(state y at time t given state x at time t-1) ; so A[x,y] expresses the probability that, if M is in state x, it will go to state y next.

  14. Markov Model Example .5 M = (S, Ω, A) where: S = {sun, rain} Ω= {sun=.4; rain =.6} A: [sun,sun] = .75 [sun,rain] = .25 [rain, sun] = .5 [rain,rain] = .5 Ω(sun) = .4 Sun Ω(rain) = .6 Rain .5 .25 .75

  15. Using Markov Model • We can answer the general question of “what is the probability that we will observe a sequence of s1,s2, ----, sn of states?” by: • Use: s1 as the initial start state with Ω(s1) probability • Use: Probability(s1, ----, sn) = Ω(s1) * ∏ A[si-1, si] where i = 2 to n Recall that A[si-1,si] = probability of being in state si given that previous state was si-1

  16. Sample Question with Markov Model .5 M = (S, Ω, A) where: S = {sun, rain} Ω= {sun=.4; rain =.6} A: [sun,sun] = .75 [sun,rain] = .25 [rain, sun] = .5 [rain,rain] = .5 Ω(sun) = .4 Sun Ω(rain) = .6 Rain .5 .25 .75 What is the probability that we will get 5 straight sunny days? Answer: - Ω(sun) = .4 and A[sun,sun] = .75; - Probability(sunny,sunny,sunny,sunny,suunny) = Ω(s1) * ∏A[si-1, si] - Probability(sunny,sunny,sunny,sunny,suunny) =.4 x .75 x .75 x .75 x .75 = .126

  17. A past student’s Suggested Markov Model Replace Ω with Init state and transitions Init M = (S, A, Init) where: S = {Init, sun, rain} A: [Init, sun] = .4 [Init, rain] = .6 [sun,sun] = .75 [sun,rain] = .25 [rain, sun] = .5 [rain,rain] = .5 .5 .6 .4 sun rain .5 .25 .75 What is the probability that we will get 5 straight sunny days? Answer: - A[Init,sun] = .4 and A[sun,sun] = .75; - Probability(sunny,sunny,sunny,sunny,suunny) = ∏A[si-1, si] - Probability(sunny,sunny,sunny,sunny,suunny) =.4 x .75 x .75 x .75 x .75 = .126

  18. Another Question with Markov Model .1 M = (S, Ω, A) where: S = {operational, broken} Ω= {op = .90; br =.10} A (for daily transitions): [op, op] = .95 [op, br] = .05 [br, br] = .1 [br, op] = .9 Ω(op) = .90 operational Ω(br) = .10 broken .9 .05 .95 If the system is already operational what is the probability that it remains operational for 5 more continuous days? Answer: - Ω(op) = .90 and A[op, op] = .95; - Probability(op, op, op, op, op) = ∏A[si-1, si] <-(we are already in operational) - Probability(op, op, op, op, op) =.95 x .95 x .95 x .95 x .95 = .77

  19. Model Based Testing • There are times you will hear the term, Model-Based Testing ------ It involves 2 steps: • Use a formal model, such as FSM described here, to model the system (e.g. states that the system may go through) that is to be tested. • Then use that model to develop test cases which will cover the model (e.g. all the states described in the FSM model)

More Related