27.07.2013 Views

2 Why We Need Model-Based Testing

2 Why We Need Model-Based Testing

2 Why We Need Model-Based Testing

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

110 Exploring and Analyzing Finite <strong>Model</strong> Programs<br />

[AcceptingStateCondition]<br />

public static bool SafeCalibrateEnabled()<br />

{<br />

return (CalibrateEnabled()<br />

&& buffer == InRange<br />

&& previous == double.Parse(InRange));<br />

}<br />

Figure 6.11. Reactive system: accepting state condition for liveness analysis.<br />

now say that an accepting state is a state where a program goal has been achieved,<br />

where some unit of work has been finished, where there is not a portion of work<br />

left undone, where a task has been completed, and where there is not some task left<br />

unfinished. Some judgment and understanding of a program’s purpose is required<br />

in order to identify its accepting states.<br />

Recall that the purpose of our reactive system is to perform a calibration with a<br />

valid temperature sample. Also recall that a temperature sample is considered valid<br />

when it does not differ too much from the preceding sample. Therefore, the goal<br />

of the program has been achieved when two successive within-range temperatures<br />

have been sampled, and a Calibration action occurs. Liveness analysis requires that<br />

we express this in terms of a state, not an action, so once again we subsitute the<br />

action’s enabling condition for the action itself. The accepting state condition is<br />

CalibrateEnabled() && buffer == InRange<br />

&& previous == double.Parse(InRange)<br />

<strong>We</strong> wrap this expression in a static method, label it with the [AcceptingStateCondition]<br />

attribute, and place it in the Controller class in the Reactive model program<br />

namespace (Figure 6.11).<br />

Now that we have defined the accepting state condition, exploration can find all<br />

of the accepting states and dead states in the generated FSM. <strong>We</strong> command the mpv<br />

tool to explore the reactive system model program, and to count and display unsafe<br />

states:<br />

mpv /r:Controller.dll Reactive.Factory.Create /livenessCheckIsOn+ ...<br />

Figure 6.12 shows the generated FSM. <strong>We</strong> had to increase MaxTransitions to<br />

300 to generate the true FSM. The mpv tool finds 239 transitions and 121 states,<br />

including 2 accepting states and 61 dead states. The accepting states are marked but<br />

they are hard to find in Figure 6.12. They are easier to find in the mpv session, where<br />

we can magnify and scroll the graph.<br />

The dead states are easier to find, because there are so many of them. Near the<br />

initial state, the FSM divides into two regions, each with many interior links but no<br />

more free ebooks download links at:<br />

http://www.ebook-x.com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!