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.

134 Structuring <strong>Model</strong> Programs with Features and Composition<br />

0<br />

Message("99.9")<br />

1<br />

Message("999.9")<br />

2<br />

Calibrate()<br />

3<br />

Figure 7.18. Reactive system: scenario FSM for safety analysis.<br />

The preceding example resembles simulation or interactive exploration in checking<br />

just one run. But a scenario model program can describe more than one run.<br />

In the next example we take advantage of this to reveal the safety violations in the<br />

reactive system that we exposed by a different technique in Chapter 6, Section 6.3.1.<br />

Recall that we had to write a Boolean expression that described the safe states. Now<br />

we will describe the safety violation in terms of actions, not states.<br />

A safety violation occurs if the program performs a calibration after it receives a<br />

message that contains an out-of-range temperature. In order to enable the calibration,<br />

the program must first receive an in-range temperature. The safety violation can be<br />

described by a scenario that contains just those three actions:<br />

FSM(0,AcceptingStates(),Transitions(<br />

t(0,Message("99.9"),1),<br />

t(1,Message("999.9"),2),<br />

t(2,Calibrate(),3)))<br />

It is not necessary to include any other action in the scenario, because they will<br />

be filled-in by interleaving when we compose the scenario with the contract model<br />

program. Recall that any actions that are not explicitly included in the vocabulary of<br />

the scenario model program can interleave among its actions when it is composed.<br />

Here we make use of that fact to complete the runs. Many interleavings are possible,<br />

so this scenario describes many runs.<br />

<strong>We</strong> compose this scenario machine (whose FSM appears in Figure 7.18) with<br />

the contract model program (whose FSM, with unsafe states highlighted, appears in<br />

Figure 6.9 in Chapter 6). The projection of the product onto the scenario resembles<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!