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.

226 Compositional <strong>Model</strong>ing<br />

a lot of implementation freedom in the way that the server can grant credits and in<br />

the way that the client can ask for new credits or use the available message IDs.<br />

This is an example of a sliding window protocol. Here the pool of identifiers is<br />

the “window” whose contents change or “slide” as time progresses. However, the<br />

pool is not necessarily a consecutive interval of numbers because the client does not<br />

have to pick the numbers from the pool in any particular order.<br />

This feature is defined uniformly for all of the commands that are communicated<br />

between the server and the client, except for Cancel.<br />

State variables<br />

The model program of the credits feature is shown in Figure 14.1. The model program<br />

has three state variables: window is the set of all message IDs that the client may use<br />

to send new requests to the server, requests is a map containing all the outstanding<br />

credit requests with message IDs as keys, and maxId is the largest ID that has been<br />

granted by the server. In the initial state of the model program the only possible<br />

message ID is 0, the maximum ID is also 0, and there are no pending requests.<br />

Actions<br />

The action vocabulary of the credits model program consists of the action symbols<br />

ReqSetup, ReqWork, ResSetup, and ResWork. The action symbol Cancel is not in the<br />

vocabulary.<br />

In order to use features and composition most effectively, we treat the relation between<br />

actions and methods more freely here than in previous examples. The actions<br />

(ResSetup etc.) which were defined at the beginning of Section 14.2 are distinct<br />

from the methods (Res etc.) in the code in Figure 14.1; they have different names<br />

and different parameters. It is the actions that appear in the traces (Figure 14.18<br />

etc.), not the methods.<br />

Each action is associated with its method (ResSetup with Res etc.) by labeling<br />

the method with an Action attribute whose argument indicates the action names and<br />

parameters, following the rules given in Appendix A. Two or more actions may use<br />

the same update rule (that is why actions and methods have different names here). For<br />

example, the setup response and the work response actions ResSetup and ResWork<br />

both use the update rule Res. Furthermore, these actions have three parameters but<br />

the update rule only has two. An underscore in the attribute indicates that the<br />

action’s third parameter is not used by this update rule. These same two actions are<br />

associated with a different update rule (also named Res) in the cancellation model<br />

program (Figure 14.7). In that rule, it is the action’s second parameter which is not<br />

used.<br />

In the product model program which is formed by composition, the actions of<br />

the separate model programs are combined. When a combined action executes, all<br />

of its update rules execute and all of its parameters are used. It is the actions (the<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!