ElementaryBlock Element/en

From expecco Wiki (Version 2.x)
Revision as of 14:55, 1 April 2014 by Cg (talk | contribs) (Die Seite wurde neu angelegt: „An elementary block provides the basic functionality of an expecco testsuite. It is used to model basic calculations or logical combinations, or to query and c…“)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

An elementary block provides the basic functionality of an expecco testsuite. It is used to model basic calculations or logical combinations, or to query and control external devices. These can be local or remote processes as well as hardware devices that are attached by some kind of hardware interface.

The behavior of an elementary block is defined by:

  • a piece of textual program code, which is written in a particular programming language
  • a call to a DLL function
  • a call to an external program (script)
  • a remote procedure call

Expecco provides builtin language interpreters and compilers for two scripting languages: the builtIn Smalltalk and the built in JavaScript-like scripting language. Both of them support highlevel symbolic debugging including single-step, breakpoints or inspection of variables. The debugger even allows for code changes to be done to the running program (for example, if the program is stopped at a breakpoint). When such an elementary block is executed, the script code runs inside the expecco process.

Additional builtIn scripting languages (Ruby and Lisp) are being prepared.

Other scripting languages (Perl, TCL, Python, etc.) are called via an external script interpreters. It is also possible to call existing command line scripts (Shell under Unix or Windows+cygwin, Batch under Windows).

Finally, with the Java Bridge extension plugin, elementary blocks can also be written in groovy, which is a scripting language with a syntax similar to Java/JavaScript, and which is transparently (and dynamically) compiled to Java bytecode, to be executed inside the system under test. Groovy blocks are useful to define callbacks, subclasses of existing classes or to set up complicated Java objects inside a tested Java application. When such a block is executed, the script code runs inside a JavaVM, which can be either a local one, dedicated to script execution, or on the target system (the system under test). More detail is found in the Expecco API Documentation.

The source code is usually edited in the code editor. It is interpreted according to the used language’s syntax at runtime. For the builtin languages Smalltalk and JavaScript, it is possible to switch the syntax pattern for already implemented blocks, causing the code to be automatically converted to that particular syntax style. The values of data pins can be directly accessed in the code using the pin's name. The external interface of an elementary block (e.g. number of pins) is defined in the schema editor.

Notice that the standard library as delivered already contains a number of useful elementary blocks for a wide range of applications. So that the need to define your own elementary blocks is often limited to special interfacing or specialized processing of data.


Coded Block Examples[edit]

Here is a block to compute the minimum and maximum values of a mathematical function over a range of x-values. It is especially flexible, as the name of the function can be passed as an argument (for example: 'sin', 'cos' or 'arcTan'). The block's definition is:

Min max elementaryBlock.jpg

and its code could be written in Smalltalk as:

execute
    |fn minY maxY y|

    fn := functionName value asSymbol.

    (x0 value) to:(x1 value) by:(dX value) do:[:x |
        y := x perform:fn.
        minY := minY isNil ifTrue:[y] ifFalse:[ minY min:y ].
        maxY := maxY isNil ifTrue:[y] ifFalse:[ maxY max:y ].
    ].

    min value:minY.
    max value:maxY.

or in JavaScript as:

execute() {
    var fn, minY, maxY, x, y;

    fn = functionName.value().asSymbol();
    for (x = x0.value(); x <= x1.value(); x += dX.value()) {
        y = x.perform(fn);
        minY = (minY.isNil()) ? y : minY.min(y);
        maxY = (maxY.isNil()) ? y : maxY.max(y);
    }
    min.value(minY);
    max.value(maxY);
 }

(notice the use of the "perform"-function, to call a function by name)


Of course, as usual, there are multiple ways to write the same function; an experienced Smalltalker would write:

execute
    |fn minMax|

    fn := functionName value asSymbol.

    minMax := ((x0 value) to:(x1 value) by:(dX value))
                  collect:[:x | x perform:fn])
                      minMax.
    min value:minMax first.
    max value:minMax second.

and a JavaScript programmer might prefer:

execute() {
    var fn, minY, maxY, x, y;

    fn = functionName.value;
    for (x = x0.value; x <= x1.value; x += dX.value) {
        y = x.perform(fn.asSymbol());
        minY = (minY == null) ? y : Math.min(minY,y);
        maxY = (maxY == null) ? y : Math.max(maxY,y);
    }
    min.value(minY);
    max.value(maxY);
 }


The block could be used to calculate the min/max of the sine function in the range 0..1 as follows:

Min max in use with sine.jpg

Shell Script Blocks[edit]

Under the Unix operating system (incl. linux, solaris) or Windows plus Cygwin (or a similar shell implementation which is bash/ksh compatible), you can also execute shell-script blocks. For example, here is a script to read its input, filter all lines beginning with some pattern, sort them, and pass them on as output:

grep "^xx" | sort

of course, arbitrarily commands can be called (even programs with their own GUI). Under Windows, make sure that you have installed an appropriate shell emulator, and that it is either found along the PATH, or that you have specified the sh-path in the expecco-settings dialog (in "External Tools" - "Shell Path").

Batch Script Blocks[edit]

These are similar to shell scripts, but use the Windows-batch file syntax. These cannot be executed on Unix systems, so your tests become OS-dependent, if you use them. The example code below would check out some source code from a cvs repository and start a build:

REM
REM batch file script (windows only)
REM
echo Checking out...
cvs co myProgram
cd myProgram
echo Building...
make

DLL-Calls[edit]

DLL-call blocks define an interface to a function which is contained inside a DLL (Dynamic Link Library). For a dll-call to be possible, the functions attributes have to be entered into the dll-call editor. These are:

  • name of the dll (for example: "user32.dll")
  • name of the function within the dll
  • the calltype (WINAPI or C-Call).
  • the number and types of the arguments
  • the type of the return value.

In addition, it is possible to specifiy that the dll-call is to be executed by a separate API-call thread. This avoids a blocking of the expecco user interface and other executing activities, for long running dll-calls. (asynchronous dll-calls are only supported by expecco rel. 1.7.4 and later)  

SOAP-Calls[edit]

These blocks define a remote procedure call via the SOAP protocol. SOAP blocks are normally generated automatically, by importing a wsdl service description. For more information, please refer to the WSDL Import Plugin description.

 

XML-RPC-Calls[edit]

These blocks define XML-RPC remote procedure calls. XML-RPC is a very light-weight and low-overhead XML-based protocol, which is supported by many service oriented applications (among them, expecco and expeccoNET themself). For an XML-RPC call, the following information is mandatory:

There are 3 alternative ways, to specify the URL:

  • hardwired as a string in the blocks specification (not recommended)
  • via an environment variable
  • via a pin value (freeze or dynamic)
Hardwired Service URL[edit]

Because this is very unflexible, it should be only used for very constant URLs, or while exploring a service interface. For this, type the URL into the blocks specification form.

Specifying the Service URL via an Environment Variable[edit]

Use a macro-replacement pattern such as "%(RPC_HOST)" in the URL field (as above). This will be replaced by a corresponding variable name from the reachable environment variable named accordingly. You can either specify a full URL (i.e. host, port and path) or a partial URL using this mechanism. For example, you can also provide the URL via 3 separate environment variables, by entering: "%(RPC_HOST):%(RPC_PORT)/%(RPC_PATH)". A runtime error will be reported, if the variable expansion leads to an invalid URL. However, if a missing expansion leads to a valid URL, no error is reported. This allows for optional fields to be added to the URL, for example as in: "%(JIRA_HOST)%(OPTIONAL_RPC_PORT)/jira/rpc/xmlrpc".

Providing the URL via an Input Pin[edit]

Add an input pin with the (obligatory) name "url", and deliver it a string value. This is the most flexible way, as the URL value can be dynamically generated by any other block, or be provided via a pin-freeze value. If a url-pin is present, but not connected, it is ignored and the above variable mechanism is used. Otherwise, the pin-value takes precedence over any value in the specification.


 


See Also[edit]

For a list of already existing blocks, see Standard Library
For the programmer API for the built in languages see: Expecco API
For information on the functions avaliable in the built-in classes, please refer to the [Smalltalk/X Online Documentation] and especially the [Class Reference]. For example, some of the mathematical functions are described [here] and String processing functions are found [here] and [here].

For other tree elements see: Tree Elements.
Back to Online Documentation.



Copyright © 2014-2020 eXept Software AG