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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Systems with Finite <strong>Model</strong>s 107<br />

[StateInvariant]<br />

public static bool CalibrateInRange()<br />

{<br />

return (!CalibrateEnabled()<br />

|| buffer == InRange);<br />

}<br />

Figure 6.8. Reactive system: state invariant for safety analysis.<br />

safety analysis requires that we identify states. <strong>We</strong> resolve this by describing the<br />

states where the action is enabled, instead of the action itself. In the unsafe states, the<br />

calibration action is enabled but the temperature is invalid. This Boolean expression<br />

is true in the unsafe states:<br />

CalibrateEnabled() && buffer != InRange // unsafe states<br />

It is often easier to describe the unsafe states first, as we did here. Negate the<br />

expression for unsafe states to obtain the safety condition. 4<br />

!CalibrateEnabled() || buffer == InRange // safety condition<br />

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

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

namespace (Figure 6.8).<br />

Now that we have defined the state invariant, exploration can find all of the unsafe<br />

states in the generated FSM. <strong>We</strong> command the mpv tool to explore the reactive system<br />

model program, and to count and display unsafe states:<br />

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

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

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

4 unsafe states. The unsafe states are marked but they are hard to find in Figure 6.9.<br />

They are easier to find in the mpv session, where we can magnify and scroll the<br />

graph.<br />

To check that the unsafe states found by exploration include the one we expect,<br />

we explore interactively. <strong>We</strong> reproduce the OutOfRangeMessageWhenIdle run we<br />

found by experimenting with the implementation (Chapter 3, Section 3.4). The<br />

FSM we generate shows a path to one of the unsafe states (Figure 6.10). This FSM<br />

contains the second trace we wrote in Chapter 5, Section 5.7.1. The unsafe state is<br />

the state labeled 105 near the bottom of the diagram, where Calibrate is enabled.<br />

4 Here we apply De Morgan’s Law, which shows how to negate expressions involving and and<br />

or: !(p && q) == !p || !q.<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!