TPT Tutorial - PikeTec
TPT Tutorial - PikeTec
TPT Tutorial - PikeTec
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
<strong>TPT</strong> <strong>Tutorial</strong><br />
Version 3.0<br />
11. March 2008
Contents<br />
Page 2 <strong>TPT</strong> <strong>Tutorial</strong><br />
1 Introduction _____________________________________________________________________________ 3<br />
1.1 What is <strong>TPT</strong>? _____________________________________________________________________________ 3<br />
1.2 What is <strong>TPT</strong> not? _________________________________________________________________________ 4<br />
1.3 Systematic Testing – What is the Point of it? ____________________________________________ 5<br />
1.4 Determination of the Test Goals _________________________________________________________ 6<br />
1.5 Continuous Behaviour ___________________________________________________________________ 7<br />
1.6 Automated Test Cases for Continuous Behaviour _______________________________________ 7<br />
1.7 Interfaces of Test Cases __________________________________________________________________ 8<br />
2 <strong>TPT</strong> — an introductory Example _______________________________________________________ 10<br />
2.1 Example “Light Automatics” _____________________________________________________________ 10<br />
2.2 Executable Test Case Modelling ________________________________________________________ 13<br />
2.2.1 MATLAB/Simulink Settings _____________________________________________________________ 13<br />
2.2.2 The interfaces of the test cases ________________________________________________________ 18<br />
2.2.3 The first and simplest executable testlet _______________________________________________ 19<br />
2.2.4 More complex test case: “lights on if dark” ____________________________________________ 25<br />
2.2.5 The second test case: “lights on if light” _______________________________________________ 28<br />
2.3 Execution of the Modelled Test Cases __________________________________________________ 31<br />
2.3.1 Test set configuration __________________________________________________________________ 31<br />
2.3.2 Execution Configuration _______________________________________________________________ 31<br />
2.4 Assessment _____________________________________________________________________________ 33<br />
2.5 Report generation_______________________________________________________________________ 34<br />
2.6 Executable platform lights control test _________________________________________________ 34
<strong>TPT</strong> <strong>Tutorial</strong> Page 3<br />
1 Introduction<br />
The introduction explains important and basic concepts for the manual. It includes<br />
answers to questions such as “What is <strong>TPT</strong>, where can it be used and what can’t it do?”,<br />
“What is a systematic test?”, “What does continuous behaviour mean?”, “What is a<br />
reactive test?” and a lot more.<br />
This introduction will be of particular interest to readers who are not yet familiar with<br />
testing strategies in general, continuous behaviour of systems or the basic idea of <strong>TPT</strong>.<br />
However, this chapter may also offer some new insights to other readers.<br />
1.1 What is <strong>TPT</strong>?<br />
<strong>TPT</strong> is a method and tool environment for systematic black box testing of continuous<br />
behaviour 1 . The use of <strong>TPT</strong> makes sense whenever a system comprised of continuously<br />
changing states, behaviour or conditions is to be tested (cf. chapter1.5). The special<br />
features of <strong>TPT</strong> are in particular:<br />
• <strong>TPT</strong> can be used independent of the test computing platform upon which the live<br />
tests should eventually run and of the language the system to be tested has been<br />
implemented. Still, <strong>TPT</strong> supports the fully-automated test execution. (Naturally,<br />
some technical adjustments of the interfaces or extensions to the infrastructure may<br />
be necessary for this). <strong>TPT</strong> offers the possibility of running modelled test cases on<br />
different platforms.<br />
• <strong>TPT</strong> supports systematic testing. This means that during the modelling of test cases<br />
with <strong>TPT</strong> – starting from the functionality of the system to be tested – all test cases are<br />
always viewed together, in order to define an ideal set of test cases which contains few<br />
or no redundancies and takes into account all relevant situations and test cases.<br />
The underlying methodology of <strong>TPT</strong> thereby guarantees that even with a large<br />
number of relevant test cases clarity will not be lost. The advantage of the systematic<br />
approach is explained in more detail in chapter1.3.<br />
1 Please note that in this context “continuous behavior” is time segmented continuous behavior.
Page 4 <strong>TPT</strong> <strong>Tutorial</strong><br />
The tool environment of <strong>TPT</strong> is divided into two areas: the graphic user interface (UI) and<br />
the runtime environment (RE). The UI serves the purpose of modelling test cases by the<br />
tester and is a “100% pure Java”-implementation, which has currently only been tested in<br />
Windows. The RE is necessary for the test execution and is implemented in ANSI-C, Java,<br />
C++, MATLAB/Simulink, LabVIEW or similar, depending on the platform. The reference<br />
implementation of the RE consists of an abstract machine, implemented in ANSI-C, which<br />
can calculate highly optimized byte code.<br />
A clear separation of UI and RE ensures the above-mentioned platform independence of<br />
the essential core of <strong>TPT</strong>.<br />
1.2 What is <strong>TPT</strong> not?<br />
Figure 1: Graphical user interface of <strong>TPT</strong><br />
In <strong>TPT</strong> the selection and modelling of the test cases is performed manually by the tester,<br />
while the test execution takes place automatically. The belief that <strong>TPT</strong> could test a<br />
system in a fully automated manner without any manual effort is thus illusory.<br />
<strong>TPT</strong> is not a debugger. This means that while <strong>TPT</strong> does serve the purpose of uncovering<br />
errors, it does not facilitate locating the root cause. Thus, after the system behaviour has<br />
been detected as erroneous for a test case, other tools must be used in order to detect<br />
the actual location of the error in the system design.<br />
<strong>TPT</strong> is a pure black box testing procedure and therefore does not support any<br />
monitoring of internal data and control flows of the system. This particularly means that<br />
coverage measurements (as in white box testing with statement coverage, branch<br />
coverage, path coverage etc.) are not supported. In order to be able to carry out such<br />
coverage measures other tools must thus be applied in parallel to <strong>TPT</strong>, which perform<br />
such structured test analysis.
<strong>TPT</strong> <strong>Tutorial</strong> Page 5<br />
1.3 Systematic Testing – What is the Point of it?<br />
This chapter begins by explaining why systematic testing is essential for high-quality<br />
product development. This section is not a prerequisite for understanding the following<br />
chapters, they may be skipped.<br />
Test execution of a system with selected test cases is allows analysis of the system<br />
behaviour for these selected cases. To uncover the errors of a complex system it is not<br />
sufficient to view just one test case. On the other hand it is not possible to view all cases.<br />
Test case design is a trade-off of effort spent in test design against the likelihood of<br />
finding errors or risk of not finding errors in the system design, i.e. the goal is to reduce<br />
the risk of undetected errors in the system design getting past the test process.<br />
Thus, testing is always a random sample procedure in which a subset of relevant test<br />
cases is selected from the total set of all possible cases. The aim of test case selection is<br />
to detect as many errors as possible.<br />
The aim of the test execution is to uncover as many error areas as possible by using as<br />
few test cases as possible. Thus, each test case that does not uncover any errors is, from<br />
the test’s point of view, just as disadvantageous as two test cases detecting the same<br />
error. The selection of these test cases is far from trivial and the most demanding task<br />
during testing.<br />
To select the set of test cases, the following approaches are possible but not exhaustive:<br />
Name Description Advantages Disadvantages<br />
Ad-hoc<br />
test cases<br />
Random<br />
test cases<br />
Statistical<br />
tests<br />
Evolutionary<br />
tests<br />
Systematic<br />
tests<br />
The set of test cases is<br />
selected without any<br />
defined rules and<br />
depends on the<br />
expertise of the tester.<br />
The selection of test<br />
cases is automated with<br />
the help of a random<br />
generator.<br />
The test cases are<br />
randomly generated in<br />
accordance with a<br />
statistical distribution<br />
(e.g. operational profile).<br />
The test cases are<br />
determined with the<br />
help of evolutionary<br />
search procedures.<br />
The test cases are<br />
selected in accordance<br />
with specified criteria (e.<br />
g. coverage measures in<br />
white box testing or<br />
“consideration of all test<br />
cases of the<br />
This approach does not<br />
require any planning<br />
and can therefore be<br />
useful in very early<br />
phases of a<br />
development.<br />
Manual test case<br />
selection is not<br />
necessary.<br />
Manual test case<br />
selection is not<br />
necessary; reliability<br />
statements are<br />
(theoretically) possible.<br />
Manual test case<br />
selection is not<br />
necessary.<br />
It is possible to take<br />
specific account of<br />
criteria with which the<br />
tester and/or the<br />
domain expert believes<br />
that the system will,<br />
with some probability,<br />
Ad-hoc test cases are comparatively<br />
unproductive due to the undefined<br />
procedure. Most of the time, the error<br />
detection rate is very low.<br />
Random tests are still very complex in<br />
practice, as the amount of test cases<br />
needed for error detection is usually<br />
extremely high. Thus, random tests are<br />
rarely used.<br />
A statistical distribution function is<br />
needed.<br />
A measure is needed for the<br />
automatic evaluation of test data so<br />
that interesting test data can be<br />
detected (example: If a system is<br />
supposed to control the temperature<br />
of a cooling circuit of a nuclear power<br />
plant the measure may be the<br />
temperature itself. Evolutionary<br />
optimization is used in order to try to<br />
find test data which leads to the<br />
violation of the acceptable<br />
temperature.)<br />
The definition of the test cases must<br />
take place explicitly (to ensure<br />
controllability of the criteria) and<br />
mostly manually, which clearly<br />
increases the effort for the test case<br />
selection.
Page 6 <strong>TPT</strong> <strong>Tutorial</strong><br />
environment” in black<br />
box testing).<br />
show erroneous<br />
behaviour.<br />
Figure 2: Overview of approaches for test case determination<br />
Although systematic testing requires a significant degree of effort during test case<br />
selection, it is still very efficient. The reason for this lies in ’high effort’ provided by<br />
automated test execution (i.e. the actual “testing” of the system) and the ‘lower effort’<br />
manual test evaluation of the system behaviour.<br />
In a complex system many outputs need to be monitored and evaluated, which generally<br />
cannot be completely automated. This means that the behaviour for each test case must<br />
be analyzed individually and at least partly manually. Thus, efficient testing needs to<br />
uncover as many errors as possible with as few test cases as possible. Although ad-hoc<br />
tests do fulfil the first part they detect only a fraction of the errors in the system. Random<br />
tests and statistical tests only uncover a large amount of errors once the number of test<br />
cases is extremely high. Evolutionary tests try to use optimization to generate a relatively<br />
small number of test cases, which are optimized with regard to a certain measure. This<br />
procedure is applicable if such an optimization measure can be defined, which, in<br />
complex systems, may not be possible.<br />
In systematic testing, the set of relevant test cases is kept small due manual determination<br />
of prioritised test cases. Here, the tester can consciously choose where to put the<br />
emphasis regarding selected test cases, and thus differentiate critical aspects from less<br />
critical ones in the test. Despite the manual effort involved in selecting test cases,<br />
systematic testing is essential for high-quality system design analysis.<br />
1.4 Determination of the Test Goals<br />
Whenever one is testing a system, one has certain goals. In many cases they are not<br />
explicit– but exist nevertheless. One very natural test goal is to test the functionality of<br />
the system. This is called a functionality test or logic test. In this case, the test is used to<br />
check whether the functional requirements of the system have been fulfilled. Accordingly,<br />
the selected test cases are strongly linked to the system requirements.<br />
Another test goal, for example, is the real-time test. Here, real-time systems are checked<br />
to see whether the specified time conditions are met. In these tests, preference of<br />
definition is given to those test cases in which time critical factors are highlighted. This<br />
usually means that completely different test cases are needed than for logic tests.<br />
Therefore it is important to be clear about the test goals before starting to model the test<br />
cases. A system containing an integrated set of test cases may be partly evaluated<br />
regarding several test goals at the same time. It is important that the test goal(s) are<br />
clearly defined to determine which test cases should be examined and which should be<br />
classified as non-relevant for the test.<br />
Possible test goals include:<br />
• Functionality test/Logic test: Test regarding functional requirements from the<br />
customer specification document<br />
• Real-time test: Test regarding critical time behaviour for real-time systems<br />
• Marginal test: Test of behaviour for limit values of data areas of interface data<br />
• Memory test: Test regarding violations via illegitimate memory accesses<br />
• Robustness test: Test with data which lies outwith valid input<br />
• Comfort test: Test of the system’s usability from the user’s point of view<br />
• Safety test: Test of safety features
<strong>TPT</strong> <strong>Tutorial</strong> Page 7<br />
• etc.<br />
Furthermore, in larger systems we focus on a narrower set of goals make the whole more<br />
manageable (for example “real-time test during the system initialization”). In smaller<br />
systems – as in the light automatics from chapter 2 – this restriction is not necessary due<br />
to the trivial functionality.<br />
The test which is defined in this way – described by the system to be tested, the test goals<br />
as well as the examined sub-function – is called the test object.<br />
1.5 Continuous Behaviour<br />
As mentioned before, <strong>TPT</strong> supports the testing of continuous behaviour. The simplest<br />
definition of continuous behaviour is: “Continuous behaviour is the behaviour of a system<br />
in a dense (real-) time section”. This means: To analyse the behaviour of a system it is<br />
necessary to continuously watch the input and output interfaces over a certain period of<br />
time (and not only at one point in time or one sequence of moments), this is called<br />
continuous behaviour 2 .<br />
Systems with continuous behaviour are always systems with a high degree of complexity,<br />
infinitely internal state space, which is why it is not enough to just view the interface<br />
behaviour at single points in time. From a practical point of view, one can test the<br />
continuous behaviour for systems whose behaviour “may naturally be described and<br />
analyzed by means of discrete or continuous signal forms”. Each system that operates with<br />
signal forms therefore shows continuous behaviour, which can be tested by using <strong>TPT</strong>.<br />
This characteristic mainly applies to embedded systems, as these systems always<br />
communicate in real time with their environment and influence real values of their<br />
environment. <strong>TPT</strong> is particularly suitable for embedded systems, although the application<br />
range – as suggested above – is decidedly broader.<br />
1.6 Automated Test Cases for Continuous Behaviour<br />
Each test case requires an executable test driver. The test driver’s behaviour is determined<br />
by the test case at runtime. This means that the test case specifies how the input of the<br />
system has to be stimulated. The test driver handles the technical implementation of the<br />
test case’s intention.<br />
Often, there is not a specific test driver available for each test case. Instead, there are test<br />
drivers with a set of controlling parameter values, which allow them to implement many<br />
different test cases. The controlling parameter information for the test case is in the form<br />
of parameter sets, files, scripts, data tables or similar.<br />
For the passive or open loop test, in which the system is being stimulated with certain<br />
predefined inputs (s1, s2, s3), it is sufficient to implement a test driver which uses fixed<br />
data tables, thereby stimulating the system.<br />
<strong>TPT</strong> is also able to model reactive or closed loop tests. For those tests the test case has<br />
the ability to react to the system’s behaviour during runtime. (cf. Figure 3 b)).<br />
2 Please note that real continuous behavior is not possible in sampled systems. Thus the “continuous behavior” is<br />
only quasi-continuous behavior.
Page 8 <strong>TPT</strong> <strong>Tutorial</strong><br />
Stimulat ion<br />
s1<br />
s2<br />
s3<br />
Syst em<br />
Test driver/<br />
Test case<br />
Stimulat ion<br />
s1<br />
s2<br />
s3<br />
Syst em<br />
Test driver/<br />
Test case<br />
a) Open loop test b) Closed loop test<br />
Figure 3: open loop and closed loop test<br />
In closed loop tests, the system to be tested and the test driver interact in the loop with<br />
the help of so-called channels. Channels are continuous variables, which can continuously<br />
change their value over time. The test case stimulates the input channels of the system<br />
with the corresponding signal forms and observes the output channels of the system in<br />
order to react to the system behaviour.<br />
In open loop tests, the feedback between system and test case does not apply. Thus, the<br />
test case can only contain predefined fixed signal forms, which must not dynamically react<br />
to the system behaviour. Therefore a reaction to certain events or states of the system is<br />
not possible. In this respect, it is usually easier to model open loop tests, but they cannot<br />
address an important class of test cases, in particular with regard to the reusability of test<br />
cases.<br />
1.7 Interfaces of Test Cases<br />
The channels to be stimulated or to be observed correspond to the input and the output<br />
channels of the system and thus directly depend on the system and its technical and<br />
logical interfaces. If a test case runs fully automatically, all input channels of the system<br />
must be stimulated by the test case so that no input remains “undefined”. Since the<br />
number of output channels of the system is limited due to technical reasons, each test<br />
case can, as a basic principle, only observe output channels. This means that each test<br />
case for a given system must always define all stimulation channels and be able to<br />
monitor all observation channels. All in all, this means:<br />
All test cases defined for one and the same system have the same interfaces in the form<br />
of observation and stimulation channels.<br />
Stimulation-<br />
Channels<br />
s1<br />
s2<br />
s3<br />
Test driver/<br />
Test case<br />
o1<br />
o2<br />
Figure 4: Interfaces of a test case<br />
Observation-<br />
Channels<br />
This observation is actually quite trivial. However it is also exceptionally important, since it<br />
makes clear that different test cases have something in common for one system. As we<br />
o1<br />
o2<br />
Observation
<strong>TPT</strong> <strong>Tutorial</strong> Page 9<br />
will see later, the basic philosophy of <strong>TPT</strong> is closely related to the identification of a<br />
common base of the test cases.
Page 10 <strong>TPT</strong> <strong>Tutorial</strong><br />
2 <strong>TPT</strong> — an introductory Example<br />
<strong>TPT</strong> addresses a multitude of different facets of testing such as test case specification, a<br />
formal test description language, a framework for test execution, a modelling language<br />
for the test result assessments, automated test analysis and much more. In order to<br />
introduce all these aspects, <strong>TPT</strong> shall be illustrated below using a simple example. Files<br />
used in this example may be found in the folder “\examples”. ATTENTION: When<br />
executing the test cases defined in file "lights_control.tpt", all test results (data, report...)<br />
will be written to the directory, this file has been opened from. This behaviour may cause<br />
errors, in case <strong>TPT</strong> has been installed into a directory it cannot write to. To avoid those<br />
problems, copy this directory to a writable location on your file-system and open the file<br />
from before you execute tests.<br />
2.1 Example “Light Automatics”<br />
The following example is not a simple “Hello World” example, as it is often used for the<br />
introduction of a programming language! In order to illustrate the basic ideas of <strong>TPT</strong> as<br />
well as the usage of the method and the tool, we will walk through a simple example.<br />
The system to be tested shall be a simplification of automatic lighting control for the<br />
headlight of a vehicle with the functionality as described below.
<strong>TPT</strong> <strong>Tutorial</strong> Page 11<br />
Functional specification of the lights control:<br />
The lights control operates the headlights depending on the setting of the light<br />
switch and the light conditions (measured by a sensor):<br />
[#1] The headlights (headlights) can be switched on or off; there are no<br />
intermediate settings.<br />
[#2] The light intensity (illumination) is measured by a light sensor that gives<br />
the brightness range from 0 – 100% with 0% being absolute darkness and<br />
100% being the brightest level of light measureable by the sensor.<br />
[#3] The light switch (switch) has three settings: OFF, ON and AUTO<br />
(automatic mode).<br />
[#4] In ON or OFF the headlights shall always be switched on or off accordingly.<br />
[#5] On AUTO, the status of the headlights depends on the sensed ambient<br />
light conditions as follows (cf. requirements [#6] to [#9]):<br />
[#6] If the system starts in AUTO or has been switched to AUTO the headlights<br />
shall go on immediately if the brightness is 70% or below.<br />
[#7] If the system starts in AUTO or has been switched to AUTO the headlights<br />
shall go off immediately if the brightness is above 70%.<br />
[#8] On AUTO, if the brightness falls below 60% for at least 2 seconds, the<br />
lights go on.<br />
[#9] On AUTO, if the brightness exceeds 70% for at least 3 seconds, the lights<br />
go off again (threshold value).<br />
The light control system is implemented in MATLAB/Simulink. It consists of a Simulink<br />
subsystem that has two inputs (light switch setting switch and ambient light intensity<br />
illumination) and one output (headlights) (cf. Figure 5: Interfaces of lights control<br />
).<br />
light switch<br />
OFF<br />
AUTO<br />
ON<br />
light sensor<br />
switch<br />
illumination<br />
headlights<br />
light control<br />
Figure 5: Interfaces of lights control<br />
headlights<br />
The implementation of the subsystem “lights control” could for instance be as displayed<br />
in Figure 6: Implementation of the light control<br />
Remember that this model is only meant to enhance comprehension of the principles in<br />
the manual. Since <strong>TPT</strong> is a black box test procedure, looking at the internal structure of<br />
the system implementation is neither relevant for test modelling nor for test execution.
Page 12 <strong>TPT</strong> <strong>Tutorial</strong><br />
Figure 6: Implementation of the light control 3<br />
For automated testing of a system such as this it is necessary for a test case to define how<br />
the inputs of the system to be tested shall be stimulated. Conversely, it will be shown that<br />
in many cases it might be necessary for the test case to be able to react to the behaviour<br />
of the system. This creates a loop between the system that is to be tested and the test<br />
case as depicted in Figure 7.<br />
Stimulation<br />
illumination<br />
switch<br />
Test object<br />
„lights control“<br />
Test case<br />
headlights<br />
Figure 7: Loop between system and test case<br />
With the aid of <strong>TPT</strong>, test cases are now defined that show actual processes for the “Test<br />
case” box in Figure 7.<br />
A decision must be made what general test goal shall be pursued in the test i.e. what is<br />
the focus of the system testing before this test case definition can begin.<br />
Relevant test cases differ depending on the test goal: if the test is to examine the<br />
robustness of the system, test cases are primarily selected that test the system behaviour<br />
under faulty conditions. However, if the desired test goal is e.g. the comfort test, test<br />
3 simplified model of implementation<br />
Observation
<strong>TPT</strong> <strong>Tutorial</strong> Page 13<br />
cases are primarily relevant that test the usability of the system. The relevant test cases<br />
turn out very differently depending on the test goal.<br />
The purpose of this tutorial is to show the logic test of the light control in which testing of<br />
the specified functional system behaviour is of prime interest.<br />
A large number of test cases usually have to be modelled to test a test object. One can<br />
approach this modelling by specifying all abstracted test cases that are considered<br />
relevant and then implementing them in the tool, thus making the test cases executable.<br />
This procedure is known as the top-down procedure. One can also begin with a few<br />
precisely formulated test cases and systematically expand them with other relevant test<br />
cases. This approach is known as the bottom-up procedure. Which procedure gets chosen<br />
usually only depends on the fact if an initial set of obvious test cases has already been<br />
established or if the test is begun afresh.<br />
2.2 Executable Test Case Modelling<br />
In the following chapter demonstrates how test cases are modelled and transferred into<br />
an executable form by using <strong>TPT</strong>. All steps necessary for the generation and execution of<br />
a very simple test example are given.<br />
2.2.1 MATLAB/Simulink Settings<br />
Alternatively for MATLAB/Simulink the inputs and outputs can be imported. Also the<br />
MATLAB/Simulink communication has to be established and the test frame needs to be<br />
generated.<br />
Start with a new and plain <strong>TPT</strong>. Choose Execution->Platform in order to set up<br />
MATLAB/Simulink as test execution environment. Now press Add in the lower left corner<br />
and select MATLAB/Simulink as platform type (cf. Figure 8)<br />
Figure 8: Test platform setup<br />
Figure 8: Test platform setup<br />
The platform needs some more configurations in the Platform Configuration window<br />
under the name specified before. Choose the MATLAB version and select Configure (cf.<br />
Figure 9).
Page 14 <strong>TPT</strong> <strong>Tutorial</strong><br />
Figure 9: Platform configuration window<br />
In the configuration window MATLAB/Simulink has to be registered as com server in<br />
order to enable the communication between MATLAB and <strong>TPT</strong> (cf. Figure 10).<br />
Alternatively the communication between <strong>TPT</strong> and MATLAB can be set up using the RMI<br />
protocol. It is possible to start MATLAB from here.<br />
Figure 10: MATLAB configuration
<strong>TPT</strong> <strong>Tutorial</strong> Page 15<br />
Figure 10: MATLAB configuration<br />
Next the model file and the Simulink-block of the system under test are to be selected.<br />
Select the original model file in the Platform Configuration window (cf. Figure 11).<br />
Figure 11: Platform configuration; model settings<br />
When the communication with MATLAB is set up and the block for the system under test<br />
is specified, the interface (namely the inputs and outputs of the selected block) can be<br />
imported by selecting “Extract interface”. In the lights control example light_switch<br />
and light_intensity are outputs of <strong>TPT</strong> but inputs of the system under test.<br />
Headlight is the input to <strong>TPT</strong> and can be used for the assessment of the test results (cf.<br />
Figure 12).
Page 16 <strong>TPT</strong> <strong>Tutorial</strong><br />
Figure 12: Import test interface<br />
When the interface between <strong>TPT</strong> and the Simulink is specified the test-frame can be<br />
extracted. This can be done automatically when a new test frame model file is specified<br />
(cf. Figure 13). The new test frame model file then consists of a copy of the selected<br />
Simulink block and an S-Function block where the execution VM of <strong>TPT</strong> is located.<br />
Figure 13: Generate test frame<br />
By clicking on Generate test-frame the new model file will be generated. When the layout<br />
is not optimal it may be adjusted manually (cf. Figure 14).
<strong>TPT</strong> <strong>Tutorial</strong> Page 17<br />
Figure 14: Test frame in MATLAB/Simulink<br />
Please note: The communication between <strong>TPT</strong> and MATLAB may be observed in the<br />
Console view of the Platform configuration window (cf. Figure 15).<br />
Figure 15: MATLAB-<strong>TPT</strong> communication console
Page 18 <strong>TPT</strong> <strong>Tutorial</strong><br />
In order to make the test executable once the test cases have been modelled, the test<br />
execution configuration is necessary. Please specify here the test frame model file that has<br />
been generated previously (cf. Figure 16).<br />
2.2.2 The interfaces of the test cases<br />
Figure 16: Test execution configuration<br />
In order to model an executable test case, the interfaces to the system under test must be<br />
defined. <strong>TPT</strong> provides a “declaration editor” to enable the specification (name, type, etc.)<br />
of the required channels (cf. Figure 17). In the example of the lights control the input and<br />
output channels depicted in Figure 7: Loop between system and test case<br />
must be declared.
<strong>TPT</strong> <strong>Tutorial</strong> Page 19<br />
Figure 17: Declaration of the input and output channels<br />
Following the declaration of the channels, the interfaces (signature) of the test cases must<br />
be defined. The channels must be selected from a list as observation (input to the test) or<br />
stimulation (output to the test) channels.<br />
Figure 17: Signature-definition for test cases<br />
In Figure 18 the interface is graphically depicted in the signature editor. The headlight<br />
channel is an observation channel and thus an “input” for the test case. (The test case is<br />
represented by the box). The two other channels light_switch and<br />
light_intensity are the corresponding stimulation channels, which are, from the test<br />
case’s point of view, “exits”.<br />
This modelling of the interface sets all the prerequisites for the modelling of the first test<br />
case.<br />
2.2.3 The first and simplest executable testlet<br />
The simplest executable testlet consists of a simple automaton with an initial and final<br />
junction and one state. The state needs to specify the inputs to the system under test.<br />
To add a testlet to a test case, follow the following steps:<br />
1. Left-click the new state icon in the Tool and menu browser<br />
2. Move your cursor into the editor window and left-click to place a new state<br />
The new state appears both in the editor-window and Testlet browser
Page 20 <strong>TPT</strong> <strong>Tutorial</strong><br />
3. Right-click on the new state in the testlet browser and rename it to “Simplest Testlet”:<br />
In order to add an initial and final junction, do the following steps:<br />
1. Left-click into the “main” in the testlet browser for a better overview of your workspace.<br />
Then left-click the new junction icon in the Tool and menu browser:<br />
2. Move the cursor left to the “Simplest State” in the editor window and left-click to place<br />
the initial junction.
<strong>TPT</strong> <strong>Tutorial</strong> Page 21<br />
3. Now left-click the new final icon in the tool and menu browser:<br />
4. Move the cursor right to the “Simplest State” in the editor window and left-click to<br />
place the final junction:<br />
In order to draw the transitions from the initial junction to the testlet and to the final<br />
junction follow the following steps:<br />
1: Left-click a new transition icon in the testlet browser and move the cursor over the<br />
initial junction:
Page 22 <strong>TPT</strong> <strong>Tutorial</strong><br />
2. Left-click and move your cursor over the testlet. You should see a transition pointing<br />
from initial junction to “Simplest Testlet”:<br />
3. Now left-click again to complete the connection:<br />
Follow the same procedure to connect the testlet with the final junction. The test case<br />
should now look like this:
<strong>TPT</strong> <strong>Tutorial</strong> Page 23<br />
Figure 18: Simplest executable test<br />
To configure the behaviour of your testlet, do the following steps:<br />
1. Left-click the “Simple Testlet” in the testlet browser and left-click again the direct<br />
definition icon in the editor window:<br />
2. Now to assign the signature of the testlet move the cursor right to the testlet.<br />
Notice than the area under your cursor changes the colour to gray.<br />
3. Left-click this area to choose both the “light_intensity” and “light_switch” as<br />
output-channels for the “Simplest Testlet”. Now the signature of this state has two<br />
outputs light_intensity and light_switch.
Page 24 <strong>TPT</strong> <strong>Tutorial</strong><br />
Figure 19: Outputs of the state<br />
The content of the simple state needs to be specified as direct definition because it has<br />
no sub-states and cannot refer to another state.<br />
Figure 20: Direct definition for light switch on<br />
We specify the default scenario and set the light switch to one. In this simple test we<br />
expect the headlights to be on.<br />
Please navigate back to the main window in the testlet browser.<br />
In order to make the automaton executable a transition condition for the transition<br />
between the state and the final junction must be specified. Double click on the transition<br />
and edit the formal transition condition. In this example the test terminates after five<br />
seconds.
<strong>TPT</strong> <strong>Tutorial</strong> Page 25<br />
Figure 21: Transition editor<br />
Now select the default scenario in the scenario browser. The automaton appears in grey.<br />
Please select one of the transitions. Since there are no variations modelled in the<br />
automaton the whole path through the automaton appears in solid black.<br />
The simple test case can now be executed. See Section 2.3.<br />
2.2.4 More complex test case: “lights on if dark”<br />
For the modelling of the test case with <strong>TPT</strong> it is necessary to first establish the steps the<br />
test case consists of:<br />
1 Modelling of the behaviour of the light switch position:<br />
1.1 At the beginning of the test case turn light switch to ”ON”, ...<br />
1.2 ... then wait ...<br />
1.3 ... until 10 seconds have passed, ...<br />
1.4 ... then maintain switch position and ...<br />
1.5 ... wait again 4 ...<br />
1.6 ... until another 10 seconds have passed, ...<br />
1.7 ... then end of test.<br />
2 Modelling of the behaviour of the ambient light intensity:<br />
2.1 From the beginning to the end of the test case – i.e. simultaneously to 1 –<br />
”light intensity = dark” is simulated until the test case has reached step 1.7.<br />
Figure 22: Informal process description of the test case<br />
The first part (“Modelling the behaviour of the light switch position”) describes the state<br />
of the light switch position. The second part deals with the behaviour of the ambient light<br />
intensity. Both parts are independent, i.e. there is no direct relation of the light switch<br />
position to the ambient light intensity and vice versa. These two parts are thus described<br />
independently. For the entire test case the two parts are run (quasi) simultaneously: While<br />
4<br />
The fact that in part 1 of the above description we are waiting twice might not make too much sense at this<br />
point in time. However, this peculiarity will be explained further down in this chapter.
Page 26 <strong>TPT</strong> <strong>Tutorial</strong><br />
the light switch position is defined the ambient light intensity is determined<br />
simultaneously.<br />
These two parts of the model suffice to specify the test case completely, since all the<br />
relevant stimuli of the “lights control” system are described (the inputs “light switch<br />
position” and “ambient light intensity”). At this point the informal description of the test<br />
case is implemented in the modelling language of <strong>TPT</strong>.<br />
The modelling of test cases takes place in <strong>TPT</strong> by means of special automatons. The<br />
following example requires a fundamental understanding of automaton notations with<br />
states, transitions etc. The subsequent explanation of the example does not go into the<br />
details of the language semantics, but gives only a rough idea of how test cases are<br />
implemented. For a detailed description of the modelling language please refer to the<br />
<strong>TPT</strong> user manual.<br />
The procedure of the “headlight on and dark” test case is modelled in <strong>TPT</strong> as depicted in<br />
Figure 24.<br />
Figure 23: Process modelling of a test case (in the right-hand window)<br />
Comments on the modelling of the test case from Figure 24:<br />
Comment 1: The automaton language used in <strong>TPT</strong> primarily consists of the “usual”<br />
components for automaton languages (states, transitions, junctions etc.). A feature<br />
specific to <strong>TPT</strong> in comparison with other automaton languages is that the states and<br />
transitions in <strong>TPT</strong> are annotated with natural-language, informal texts. The formal<br />
definitions, which are naturally necessary for the automatic test execution, are hidden<br />
behind these states and transitions and are not depicted in the graphic.<br />
The advantage of the informal description is that test cases can also be read by nontesters<br />
who need not be familiar with the formal modelling language of <strong>TPT</strong>.<br />
The reason for the red text is explained later in this chapter.<br />
Comment 2: The syntactical descriptions behind the natural-language annotations at<br />
transitions and states can be accessed by double-clicking on the respective element in the<br />
<strong>TPT</strong> tool. For instance, the following window opens by double-clicking the first transition<br />
“switch light condition” (after 10s):
<strong>TPT</strong> <strong>Tutorial</strong> Page 27<br />
Figure 24: light switch condition transition<br />
This window depicts the formal condition of the transition (“formal condition”). As we<br />
can see, the “light switch condition” (after 10 s) transition has the formal condition t >=<br />
10 s., i.e. after 10 s the transition condition becomes true and the automaton switches to<br />
the next state. In addition, so-called actions (“actions”) can be defined for the transitions.<br />
In the case of the above transitions no actions are defined at the moment the transition<br />
switch takes place.<br />
Comment 3: Similarly, double-clicking on a state shows the details of the modelling of the<br />
state. Such a state can be defined either by a sub-automaton (in the sense of hierarchical<br />
automatons) or by equations. In the sub-automaton-case, the sub-automaton is shown<br />
after double-clicking. States on the lowest level contain simple equation definitions of the<br />
modelled stimulation channels.<br />
Please note that each state – although it is only informally annotated by means of its<br />
natural-language name in the graphic depiction of the automatons – establishes a<br />
detailed, precise and clear process description.<br />
Comment 4: In Figure 24 the overall process of the test case is divided into two: The upper<br />
part models the procedure for the switch setting, the lower part describes the procedure<br />
of the ambient light intensity. The horizontal line between the two areas indicates that<br />
there are two parallel automatons, which run quasi-simultaneously.<br />
Comment 5: The process of implementing a test case always starts with an initial node,<br />
which is represented by a solid circle (“ “), and which is only a transitions source. As<br />
the test case consists of two parallel automatons there are also two initial nodes – one for<br />
the upper and one for the lower automaton - in which the test case starts simultaneously<br />
at the time t=0. This means that the initial nodes serve as entry points into the test case<br />
and determine which transition should be used to change to the first state of the test<br />
case.<br />
Comment 6: The above automaton changes at the beginning of the test case (thus at t=0) to,<br />
for example, the “initialize light switch”. Simultaneously, the second, parallel automaton<br />
changes to the “light intensity constant dark” state.<br />
Comment 7: The “initialize light switch” state exits after 10 seconds have passed. The<br />
corresponding transition has the formal definition t >= 10 (cf. Figure 25).<br />
This way, it is very simple to show that the transition switches exactly at the time when t<br />
has become greater than or equal to 10. In this, the expression t describes the current<br />
time since the current state has been entered, i.e. it has a local context.<br />
Comment 8: The state “switch light switch to (on)” is depicted in dotted lines because it<br />
references another state (“initial light switch”) and performs the same operations as the<br />
original state.
Page 28 <strong>TPT</strong> <strong>Tutorial</strong><br />
Comment 9: The remaining process is now carried out similarly. The “switch light switch to”<br />
state exits again after 10 seconds. Since the transition switches into a final node, the test<br />
case ends at exactly this moment.<br />
Comment 10: The parallel, lower automaton switches at the time t=0 into the “light intensity<br />
constant dark” state. This state models how the ambient light intensity should behave for<br />
the test case.<br />
Informal process description of the test case in Figure 24:<br />
At the start of the test case, two parallel processes are activated: the process of the upper<br />
and that of the lower automaton. In both cases the process begins at the left-hand initial<br />
node. Since these nodes are not states and the test case may not ‘remain’ in such nodes,<br />
the test case switches directly via corresponding transitions into the “initialize light<br />
switch” and “light intensity constant dark” states. Since no action has been stored for the<br />
upper transition (cf. explanation 2 above), the states are “executed” immediately. Each<br />
state has a clearly defined behaviour: The “initialize light switch” state changes the<br />
channel “light_switch” to LIGHT_ON; the “light intensity constant dark” state sets the<br />
“light_intensity” channel to 0.0 at the earliest possible time.<br />
After this initialization the upper sub-automaton proceeds as follows: The “initialize light<br />
switch” state exits after exactly 10 seconds, if the transition “switch light condition: after<br />
10 s” (cf. explanation 7 above) becomes true. During the switching of the transitions, the<br />
actions within the transitions are executed. This transition does not define an action. Thus<br />
the test case now changes into the “switch light switch to on” state. This state does not<br />
change internal logic nor does it change channels because the “light_switch” is<br />
already set to LIGHT_ON. It thus does “nothing” and only waits for another 10 seconds to<br />
pass – up to the point when the last transition switches “end test after 10 s” and ends the<br />
test case by reaching a final node.<br />
The parallel lower automaton starts after the initialization in the “light intensity constant<br />
dark” state. As long as the automaton is in this state, the “light_intensity” is set to<br />
zero. The parameter t corresponds to the current time since the current state has been<br />
entered (also cf. comment 7 above). The transition leading from the “light intensity dark”<br />
state to the final node has no formal condition. Such a transition switches if the state<br />
ends from “within”. The fact of the matter, however, is that the ”light intensity constant<br />
dark” state does not end from within so that the transition never switches. This means: the<br />
automaton remains in the “light intensity constant dark” state forever. The lower<br />
automaton ends only if the upper automaton is terminated, since a parallel automaton in<br />
<strong>TPT</strong> is always terminated if (at least) one of its sub-automatons ends.<br />
Summary:<br />
For the above example the given explanations for the modelling language of <strong>TPT</strong> allow<br />
implementation of a test case in the <strong>TPT</strong> environment. The automaton mirrors the<br />
informal process description from Figure 23 in a formal manner<br />
2.2.5 The second test case: “lights on if light”<br />
The second test case “lights on if light” differs from the test case “lights on and dark” only<br />
in the sense of the light intensity of the surroundings. The test case is thus almost<br />
identical with the first test case from section 2.2.2 and therefore in the process modelling<br />
looks as follows:
<strong>TPT</strong> <strong>Tutorial</strong> Page 29<br />
Figure 25: Process modelling of the second test case<br />
The upper sub-automaton is unchanged. The only difference in the modelling of the two<br />
test cases consists in the definition of the lower sub-automaton: In the first test case<br />
(Figure 24) the “light intensity constant dark” state has been selected, while, by contrast,<br />
in the second test case (Figure 26) the “light intensity constant light” state is selected.<br />
If we compare these two test cases in a little more detail we will also find that the two test<br />
cases do not differ structurally. The distinction can solely be attributed to the definition of<br />
the behaviour – therefore the semantics– of the “light intensity constant” state. If we now<br />
assume that there was only one “light intensity” state for both test cases together (instead<br />
of “light intensity constant dark” for the first test case and “light intensity light” for the<br />
second), this state apparently has different semantics in the first and second test case,<br />
which results in different test cases.<br />
This is exactly what makes up the basic idea of <strong>TPT</strong>: The joint usage of a state makes it<br />
clear that the behaviour of the “light intensity” state has to be varied between the test<br />
cases, as defined by our descriptive or written form of the test cases. Here, it is important<br />
that this variation of the semantics does not take place locally for every individual test<br />
case, but is assigned globally to the state. This means: If there are test cases where the<br />
ambient light intensity varies between light and dark, the state does not have one but two<br />
(or even more) alternative semantics. Hence, for each specific test case one of these<br />
semantics must be selected at all points of the automaton at which the semantics are not<br />
clear (because there is more than one variant due to test-relevant aspects) in order to<br />
define clear, executable semantics of a test case. How this is done in detail will be<br />
explained further on.<br />
In other words, the following steps are required for the modelling of concrete test<br />
sequences:<br />
1. Modelling of the general process with the “standard semantics” of the states and<br />
transitions<br />
2. Modelling of the variants for the semantics of states and transitions at test-relevant<br />
places<br />
3. Generation of specific test cases by selecting and combining one variant each at all<br />
places of the automaton at which more than one variant exists<br />
We will now illustrate these considerations in an even more explicit manner with the help<br />
of the example of the “light intensity” state: In the above informal process description for
Page 30 <strong>TPT</strong> <strong>Tutorial</strong><br />
the first test case the behaviour of the light intensity has been defined as the equation<br />
light_intensity(t) = 0.0. This is the semantics for the “dark” case. The intensity<br />
does not vary. For the second test case a second “light” semantics must be modelled in<br />
the form of the light_intensity(t) = 100. In order to be able to distinguish these<br />
two variants of “light intensity” (i.e. without having to read the definition equations), they<br />
are given natural-language names:<br />
• “dark” light_intensity(t) = 0<br />
• “light” light_intensity(t) = 100<br />
If we look again at the depiction of the test sequences of the two test cases in Figure 24<br />
or Figure 26 we now see why the state “dark” or, respectively, “light” is depicted in red<br />
in the “light intensity” state: The state itself has the name “light intensity”. There are<br />
several alternative variants of the semantics for this state. Two of these variants are “light”<br />
and “dark”.<br />
Similarly we now find that in the upper sub-automaton of the example there are several<br />
elements for the alternative (marked red) definitions. In this case, there are two<br />
transitions; this means that alternative semantics are possible for transitions as well. States<br />
and transitions for which no red variants are depicted have only one semantic and thus<br />
require no addition to the explicitly selected variant.<br />
Besides variations in states there are also transition variations and so-called path<br />
variations. The tutorial part of this manual will not go into further detail concerning these<br />
types of variations, since the variation principle is similar to the state and transition<br />
variation. Still, these variation types are very important for the expression capability and<br />
the creative diversity of <strong>TPT</strong> test (cf. Figure 27).<br />
Figure 26:<br />
Definition of “<strong>TPT</strong> automaton” and “automaton instance”<br />
The unique feature of the automaton language of <strong>TPT</strong> is, as mentioned before, the fact<br />
that states, transitions and paths do not usually have any clear semantics but define<br />
several variants. Such an automaton is called <strong>TPT</strong> automaton. A <strong>TPT</strong> automaton itself,<br />
therefore, is not executable. Only the selection of the corresponding variants at all variant<br />
locations makes the semantics become clear and executable. Such a selection is called
<strong>TPT</strong> <strong>Tutorial</strong> Page 31<br />
automaton instance. Each automaton instance thus describes an explicit specification of<br />
the semantically ambivalent <strong>TPT</strong> automaton.<br />
2.3 Execution of the Modelled Test Cases<br />
In order to execute modelled test cases a few configurations need to be completed.<br />
2.3.1 Test set configuration<br />
Please select Execution -> Configure Test sets in order to compose tests for<br />
the execution. Click on the Add button for a new test set and select the test cases that<br />
shall be executed (cf. Figure 28).<br />
2.3.2 Execution Configuration<br />
Figure 27: Test set configuration<br />
Select Execution -> Execution configurations in order to select the tests that<br />
shall be executed in a certain environment.<br />
Click on the Add button to create a new execution configuration and select a test set<br />
specified before (cf. Section 2.3.1). Also a data dictionary where the test results shall be<br />
saved and a platform that has been configured before (cf. Section 2.2.1) need to be<br />
specified. May be only execution is selected but also assessments and report generation is<br />
possible (cf. Figure 29).
Page 32 <strong>TPT</strong> <strong>Tutorial</strong><br />
Figure 28: Execution configuration<br />
After clicking on the compile and run buttons the execution starts and the build window<br />
opens. The tests are executed and the <strong>TPT</strong> build window opens (cf. Figure 30).<br />
Figure 29: Build progress window
<strong>TPT</strong> <strong>Tutorial</strong> Page 33<br />
To explore the test results right-click on the scenario in the <strong>TPT</strong> build window and select<br />
view test results. Within the test data viewer the signals can be shown by dragging<br />
the signal into the graph (cf. Figure 31).<br />
2.4 Assessment<br />
Figure 30: View test results<br />
The assessment is programmed in Python under the assessment tab in the main window.<br />
A very simple example can be seen in Figure 32. The script in this example checks if the<br />
headlight is on during the state and when the default scenario is active.<br />
Figure 31: Simple assessment script
Page 34 <strong>TPT</strong> <strong>Tutorial</strong><br />
2.5 Report generation<br />
When the report check box is active in the execution configuration a test report will be<br />
generated from the test and assessment results. There is a default template for the report<br />
but it may be changed using the report template editor. The report can be opened after<br />
test execution and shows details of the test. It can be seen that the exported assessment<br />
results are explicitly shown in the report. Graphs in the report can be opened and zoomed<br />
in (cf. Figure 33).<br />
Figure 32: Test report example<br />
2.6 Executable platform lights control test<br />
A very basic but flexible platform configuration is the Executable platform configuration.<br />
This platform is any executable program that is specified.<br />
The executable must contain the loop of the <strong>TPT</strong>-VM and the system under test. An<br />
example, how this can be accomplished, can be found under “\examples\exeplatform”.<br />
Assume for example the lights control example is implemented as C-function that returns<br />
the “headlight” as function of “light_switch” and “light_intensity” 5 . In order<br />
to create a test-frame for this a test-frame needs to be programmed and compiled that<br />
calls periodically the API of the <strong>TPT</strong> virtual machine and the function<br />
5 unsigned char getHeadlightValue(unsigned char light_switch, double light_intensity);
<strong>TPT</strong> <strong>Tutorial</strong> Page 35<br />
“getHeadlightValue”. Templates and the API for this are available. Please refer to the<br />
lights control example C-code.<br />
Figure 33: Executable platform configuration