Services and Modeling for Embedded Software Development
Embecosm divider strip
Prev  Next

Chapter 3.  Writing tests using expect

3.1. Test results
3.2. The expect command
3.2.1. Patterns for use with the expect command
3.3. An example test
3.3.1. Automating testing

Each DejaGnu test is a sequence of expect commands. These are standard TCL commands with some additions, which make the language particularly suitable for testing. man expect documents all the commands specific to expect. The most useful of these are:

expect

This is the most important of the commands. It takes a series of pairs of patterns and actions and waits until one of the patterns matches the output of a spawned process (see spawn below), or a specified time period has passed or an end of file has been seen. When a pattern matches, its corresponding body is executed.

This command has a considerable number of options, and is described in detail in a separate section (see Section 3.2).

send

This command is used to send data to the standard input of a spawned process (see spawn below).

send_error, send_log, send_user

These commands are used to send output to respectively the standard error of the user, the log file and the standard output of the user. In other words for data that is not to go to the spawned process.

spawn
spawn [opts] program args
	    

spawn starts a program and its arguments in a child process, connecting its stdin, stdout and stderr so they may be written and read by other expect commands, most notably the expect command.

[Note]Note

There is the potential for confusion here, since expect is both the name of the language and a command within that language.

Expect defines and uses a number of TCL global variables. The most important are associated with the expect command and documented in the section on that command (see Section 3.2).

On top of this DejaGnu defines a number of procedures which facilitate testing. These are documented in the DejaGnu manual's section on Unit Testing [3]. The most useful are:

fail, pass, xfail, xpass, untested, unresolved, unsupported

These procedures all report the result of a test. They are described in more detail below (see Section 3.1.

warning

Writes a message to the log, prepended by the string WARNING. Once more than warning_threshold warnings have been given the test is assumed to be unresolved. The next call to one of the result procedures will behave as though unresolved had been called.

The value of warning_threshold (default 3) may be read and written with get_warning_threshold and set_warning_threshold.

perror

Writes a message to the log, prepended by the string ERROR. The next call to one of the result procedures will behave as though unresolved had been called.

Embecosm divider strip