\input texinfo @c -*- Texinfo -*- @setfilename dejagnu.info @documentencoding us-ascii @settitle DejaGnu @finalout @c man begin INCLUDE @include version.texi @c man end @copying @c man begin COPYRIGHT Copyright @copyright{} 1992-2020, 2022, 2023, 2024 Free Software Foundation, Inc. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled ``GNU Free Documentation License''. @c man end @end copying @dircategory Software development @direntry * DejaGnu: (dejagnu). The GNU testing framework. @end direntry @titlepage @title DejaGnu @ifset VERSION_PACKAGE @subtitle @value{VERSION_PACKAGE} @end ifset @subtitle Version @value{VERSION} @sp 1 @subtitle @value{UPDATED} @author Rob Savoye et al. @author Cygnus Support and the GNU Project @page @vskip 0pt plus 1filll @insertcopying @end titlepage @contents @node Top, Introduction, , (dir) @top DejaGnu @menu * Introduction:: * Running tests:: * Running other DejaGnu commands:: * Customizing DejaGnu:: * Extending DejaGnu:: * Unit testing:: * Built-in Procedures:: * GNU Free Documentation License:: * Concept Index:: * Procedure Index:: * Variable Index:: @detailmenu Introduction * What is DejaGnu?:: * New in this release: Release Notes * Design goals:: * A POSIX conforming test framework: A POSIX Conforming Test Framework. * Installation:: Running tests * Running 'make check': Make Check. * Running runtest: Runtest. * Output files: Output Files. Running other DejaGnu commands * Invoking dejagnu:: Command line options for the launcher itself. * Invoking dejagnu help:: Reading man pages for dejagnu subcommands. * Invoking dejagnu report card:: Summarizing test results from many tools. Customizing DejaGnu * Global configuration file:: * Local configuration file:: * Board configuration file:: * Remote host testing:: * Configuration file values:: Extending DejaGnu * Adding a new testsuite:: * Adding a new tool:: * Adding a new target:: * Adding a new board:: * Board file values:: * Writing a test case:: * Debugging a test case:: * Adding a test case to a testsuite:: * Test case special variables: Test case variables. Unit testing * What is unit testing?:: Unit testing and system testing. * Running unit tests:: * DejaGnu unit test protocol:: DejaGnu native unit testing protocol. * C unit testing API:: * C++ unit testing API:: Reference * Built-in Procedures:: Indices * Concept Index:: * Procedure Index:: * Variable Index:: @end detailmenu @end menu @node Introduction, Running tests, Top, Top @chapter Introduction @menu * What is DejaGnu?:: * New in this release: Release Notes. * Design goals:: * A POSIX compliant test framework: A POSIX Conforming Test Framework. * Installation:: @end menu @node What is DejaGnu?, Release Notes, , Introduction @section What is DejaGnu? DejaGnu is a framework for testing other programs, providing a single front-end for all tests. You can think of it as a library of Tcl procedures to help with writing a test harness. A @emph{test harness} is the infrastructure that is created to test a specific program or tool. Each program can have multiple testsuites, all supported by a single test harness. DejaGnu is written in Expect, which in turn uses Tcl, the Tool command language. There is more information on Tcl at the @uref{https://www.tcl.tk,Tcl/Tk web site} and the @uref{https://core.tcl-lang.org/expect/,Expect web site}. There is also some historical information about Expect at the @uref{https://www.nist.gov/services-resources/software/expect,NIST web site}. Julia Menapace first coined the term @emph{DejaGnu} to describe an earlier testing framework she wrote at Cygnus Support for testing GDB. When we replaced it with the Expect-based framework, it was like DejaGnu all over again. More importantly, it was also named after my daughter, Deja Snow Savoye, who was a toddler during DejaGnu's beginnings. DejaGnu offers several advantages for testing: @itemize @item The flexibility and consistency of the DejaGnu framework make it easy to write tests for any program, with either batch-oriented, or interactive programs. @item DejaGnu provides a layer of abstraction which allows you to write tests that are portable to any host or target where a program must be tested. For instance, a test for @code{GDB} can run from any supported host system on any supported target system. DejaGnu runs tests on many single board computers, whose operating software ranges from a simple boot monitor to a real-time OS. @item All tests have the same output format. This makes it easy to integrate testing into other software development processes. DejaGnu's output is designed to be parsed by other filtering script and it is also human readable. @item Using Tcl and Expect, it's easy to create wrappers for existing testsuites. By incorporating existing tests under DejaGnu, it's easier to have a single set of report analyse programs.. @end itemize Running tests requires two things: the testing framework and the testsuites themselves. Tests are usually written in Expect using Tcl, but you can also use a Tcl script to run a testsuite that is not based on Expect. Expect script filenames conventionally use @file{.exp} as a suffix. For example, the main implementation of the DejaGnu test driver is in the file @file{runtest.exp}. @node Release Notes, Design goals, What is DejaGnu?, Introduction @section New in this release The following major, user-visible changes have been introduced since version 1.5.3. @enumerate @item Support for target communication via SSH has been added. @item A large number of very old config and baseboard files have been removed. If you need to resurrect these, you can get them from version 1.5.3. If you can show that a board is still in use, it can be put back in the distribution. @item The @command{--status} command line option is now the default. This means that any error in the testsuite Tcl scripts will cause runtest to abort with exit status code 2. The @command{--status} option has been removed from the documentation, but will continue to be accepted for backward compatibility. @item @command{runtest} now exits with exit code 0 if the testsuite "passed", 1 if something unexpected happened (eg, FAIL, XPASS or UNRESOLVED), and 2 if an exception is raised by the Tcl interpreter. @item @command{runtest} now exits with the standard exit codes of programs that are terminated by the SIGINT, SIGTERM and SIGQUIT signals. @item The user-visible utility procedures @code{absolute}, @code{psource} and @code{slay} have been removed. If a testsuite uses any of these procedures, a copy of the procedure should be made and placed in the lib directory of the testsuite. @item Support was added for testing the D compiler. @item @file{~/.dejagnurc} is now loaded last, not first. This allows the user to have the ability to override anything in their environment (even the @file{site.exp} file specified by @code{$DEJAGNU}). @item The user-visible utility procedure @code{unsetenv} is @strong{deprecated} and will be removed in the next release. If a testsuite uses this procedure, a copy should be made and placed in the lib directory of the testsuite. @end enumerate @node Design goals, A POSIX Conforming Test Framework, Release Notes, Introduction @section Design goals @cindex design goals DejaGnu grew out of the internal needs of Cygnus Solutions (formerly Cygnus Support). Cygnus maintained and enhanced a variety of free programs in many different environments and needed a testing tool that: @itemize @item was useful to developers while fixing bugs; @item automated running many tests during a software release process; @item was portable among a variety of host computers; @item supported a cross-development environment; @item permitted testing of interactive programs like @code{GDB}; and @item permitted testing of batch-oriented programs like @code{GCC}. @end itemize Some of the requirements proved challenging. For example, interactive programs do not lend themselves very well to automated testing. But all the requirements are important. For instance, it is imperative to make sure that @code{GDB} works as well when cross-debugging as it does in a native configuration. Probably the greatest challenge was testing in a cross-development environment. Most cross-development environments are customized by each developer. Even when buying packaged boards from vendors there are many differences. The communication interfaces vary from a serial line to Ethernet. DejaGnu was designed with a modular communication setup, so that each kind of communication can be added as required and supported thereafter. Once a communication procedure is written, any test can use it. Currently DejaGnu can use @code{ssh}, @code{rsh}, @code{rlogin}, @code{telnet}, @code{tip}, and @code{kermit} for remote communications. @node A POSIX Conforming Test Framework, Installation, Design goals, Introduction @section A POSIX compliant test framework @cindex POSIX compliant test framework @cindex POSIX 1003.3 DejaGnu conforms to the POSIX 1003.3 standard for test frameworks. Rob Savoye was a member of that committee. POSIX standard 1003.3 defines what a testing framework needs to provide to create a POSIX compliant testsuite. This standard is primarily oriented to checking POSIX conformance, but its requirements also support testing of features not related to POSIX conformance. POSIX 1003.3 does not specify a particular testing framework, but at this time there is only one other POSIX conforming test framework. TET was created by Unisoft for a consortium comprised of X/Open, Unix International and the Open Software Foundation. @cindex assertions The POSIX documentation refers to @dfn{assertions}. An assertion is a description of behavior. For example, if a standard says ``The sun shall shine'', a corresponding assertion might be ``The sun is shining.'' A test based on this assertion would pass or fail depending on whether it is day or night. It is important to note that the standard being tested is never 1003.3; the standard being tested is some other standard, for which the assertions were written. As there is no testsuite to verify that testing frameworks are POSIX 1003.3 compliant, this is done by repeatedly reading the standard and experimenting. One of the main things POSIX 1003.3 does specify is the set of allowed output messages and their definitions. Four messages are supported for a required feature of POSIX conforming systems and a fifth for a conditional feature. DejaGnu supports all five output messages. In this sense a testsuite that uses exactly these messages can be considered POSIX compliant. These definitions specify the output of a test case: @table @asis @item PASS A test has succeeded. That is, it demonstrated that the assertion is true. @item FAIL A test has not succeeded -- the assertion is false. The @emph{FAIL} message is based on this test case only. Other messages are used to indicate a failure of the framework. As with @emph{PASS}, POSIX tests must return @emph{FAIL} rather than @emph{XFAIL} even if a failure was expected. @item XFAIL POSIX 1003.3 does not incorporate the notion of expected failures, so @emph{PASS}, instead of @emph{XPASS}, must also be returned for test cases which were expected to fail and did not. This means that @emph{PASS} is in some sense more ambiguous than if @emph{XPASS} is also used. @item UNRESOLVED A test produced indeterminate results. Usually, this means the test executed in an unexpected fashion. This outcome requires a human to go over results to determine if the test should have passed or failed. This message is also used for any test that requires human intervention because it is beyond the abilities of the testing framework. Any unresolved test should resolved to @emph{PASS} or @emph{FAIL} before a test run can be considered finished. Note that for POSIX, each assertion must produce a test result code. If the test isn't actually run, it must produce @emph{UNRESOLVED} rather than just leaving that test out of the output. This means that you have to be careful when writing tests to not carelessly use Tcl commands like @emph{return}---if you alter the flow of control of the Tcl code you must insure that every test still produces some result code. Here are some of the ways a test may wind up @emph{UNRESOLVED}: @end table @itemize @item Execution of a test is interrupted. @item A test does not produce a clear result. This is usually because there was an @emph{ERROR} from DejaGnu while processing the test, or because there were three or more @emph{WARNING} messages. Any @emph{WARNING} or @emph{ERROR} messages can invalidate the output of the test. This usually requires a human to examine the output to determine what really happened -- and to improve the test case. @item A test depends on a previous test, which has failed. @item The test was set up incorrectly. @item A test script aborts due to a Tcl error. In this case, the DejaGnu framework inserts an @emph{UNRESOLVED} result as a placeholder for an unknown number of tests that were not run because the script crashed. @end itemize @table @asis @item UNTESTED A test was not run. This is a placeholder used when there is no real test case yet. @end table @table @asis @item UNSUPPORTED There is no support for the tested case. This may mean that a conditional feature of an operating system, or of a compiler, is not implemented. DejaGnu also uses this message when a testing environment (often a ``bare board'' target) lacks basic support for compiling or running the test case. For example, a test for the system subroutine @emph{gethostname} would never work on a target board running only a boot monitor. @end table DejaGnu uses the same output procedures to produce these messages for all testsuites and these procedures are already known to conform to POSIX 1003.3. For a DejaGnu testsuite to conform to POSIX 1003.3, you must avoid the @emph{setup_xfail} procedure as described in the @emph{PASS} section above and you must be careful to return @emph{UNRESOLVED} where appropriate, as described in the @emph{UNRESOLVED} section above. @node Installation, , A POSIX Conforming Test Framework, Introduction @section Installation Refer to the @file{INSTALL} in the source distribution for detailed installation instructions. Note that there is no compilation step as with many other GNU packages, as DejaGnu consists of interpreted code only. Save for its own small testsuite, the DejaGnu distribution does not include any testsuites. Testsuites for the various GNU development tools are included with those packages. After configuring the top-level DejaGnu directory, unpack and configure the test directories for the tools you want to test; then, in each test directory, run @emph{make check} to build auxiliary programs required by some of the tests, and run the test suites. @node Running tests, Running other DejaGnu commands, Introduction, Top @chapter Running tests There are two ways to execute a testsuite. The most common way is when there is existing support in the @file{Makefile} of the tool being tested. This usually consists of a @emph{check} target. The other way is to execute the @code{runtest} program directly. To run @code{runtest} directly from the command line requires either all of the correct command line options, or a @ref{Local configuration file} must be set up correctly. @menu * Running `make check': Make Check. * Running runtest: Runtest. * Output files: Output Files. @end menu @node Make Check, Runtest, , Running tests @section Running `make check' To run tests from an existing collection, first use @code{configure} as usual to set up the build directory. Then type @code{make check}. If the @emph{check} target exists, it usually saves you some trouble. For instance, it can set up any auxiliary programs or other files needed by the tests. The most common file the @emph{check} target depends on is the @file{site.exp} file. The @file{site.exp} contains various variables that DejaGnu uses to determine the configuration of the program being tested. Once you have run @emph{make check} to build any auxiliary files, you can invoke the test driver @code{runtest} directly to repeat the tests. You will also have to execute @code{runtest} directly for test collections with no @emph{check} target in the @file{Makefile}. GNU Automake has built-in support for DejaGnu. To add DejaGnu support to your generated @file{Makefile.in}, just add the keyword @code{dejagnu} to the AUTOMAKE_OPTIONS variable in @file{Makefile.am}. This will ensure that the generated @file{Makefile.in} has a @code{check} target that invokes DejaGnu correctly. @xref{Tests,, DejaGnu Tests, automake, The GNU Automake Manual}. @node Runtest, Output Files, Make Check, Running tests @section Running runtest @pindex runtest @code{runtest} is the test driver for DejaGnu. You can specify two kinds of things on the @code{runtest} command line: command line options, and Tcl variables that are passed to the test scripts. The options are listed alphabetically below. @code{runtest} returns one of the following exit codes: @table @asis @item 0 if all tests passed including expected failures and unsupported tests. @item 1 if any test failed, passed unexpectedly, or was unresolved. @item 2 if Expect encountered any error in the test scripts. @end table @menu * Output States:: * Invoking runtest:: * Common Options: Common Operations. @end menu @node Output States, Invoking runtest, , Runtest @subsection Output States @cindex output states @file{runtest} flags the outcome of each test as one of these cases. See @ref{A POSIX Conforming Test Framework} for a discussion of how POSIX specifies the meanings of these cases. @table @asis @item PASS The most desirable outcome: the test was expected to succeed and did succeed. @item XPASS A pleasant kind of failure: a test was expected to fail, but succeeded. This may indicate progress; inspect the test case to determine whether you should amend it to stop expecting failure. @item FAIL A test failed, although it was expected to succeed. This may indicate regress; inspect the test case and the failing software to locate the bug. @item XFAIL A test failed, but it was expected to fail. This result indicates no change in a known bug. If a test fails because the operating system where the test runs lacks some facility required by the test, the outcome is @emph{UNSUPPORTED} instead. @item UNRESOLVED Output from a test requires manual inspection; the testsuite could not automatically determine the outcome. For example, your tests can report this outcome is when a test does not complete as expected. @item UNTESTED A test case is not yet complete, and in particular cannot yet produce a @emph{PASS} or @emph{FAIL}. You can also use this outcome in dummy ``tests'' that note explicitly the absence of a real test case for a particular property. @item UNSUPPORTED A test depends on a conditionally available feature that does not exist (in the configured testing environment). For example, you can use this outcome to report on a test case that does not work on a particular target because its operating system support does not include a required subroutine. @end table @code{runtest} may also display the following messages: @table @asis @item ERROR Indicates a major problem (detected by the test case itself) in running the test. This is usually an unrecoverable error, such as a missing file or loss of communication to the target. POSIX testsuites should not emit this message; use @emph{UNSUPPORTED}, @emph{UNTESTED}, or @emph{UNRESOLVED} instead, as appropriate. @item WARNING Indicates a possible problem in running the test. Usually warnings correspond to recoverable errors, or display an important message about the following tests. @item NOTE An informational message about the test case. @end table @node Invoking runtest, Common Operations, Output States, Runtest @subsection Invoking runtest @cindex runtest, invoking This is the full set of command line options that @code{runtest} recognizes. Option names may be abbreviated to the shortest unique string. @table @asis @item @code{-a}, @code{--all} Display all test output. By default, @emph{runtest} shows only the output of tests that produce unexpected results; that is, tests with status @emph{FAIL} (unexpected failure), @emph{XPASS} (unexpected success), or @emph{ERROR} (a severe error in the test case itself). Specify @code{--all} to see output for tests with status @emph{PASS} (success, as expected) @emph{XFAIL} (failure, as expected), or @emph{WARNING} (minor error in the test case itself). @item @code{--build [triplet]} @emph{triplet} is a system triplet of the form @emph{cpu-manufacturer-os}. This is the type of machine DejaGnu and the tools to be tested are built on. For a normal cross environment this is the same as the host, but for a Canadian cross, they are different. @item @code{-D0}, @code{-D1} Start the internal Tcl debugger. The Tcl debugger supports breakpoints, single stepping, and other common debugging activities. See the document @uref{http://expect.sourceforge.net/doc/tcl-debug.ps, Debugger for Tcl Applications} by Don Libes. If you specify @emph{-D1}, the @emph{expect} shell stops at a breakpoint as soon as DejaGnu invokes it. If you specify @emph{-D0}, DejaGnu starts as usual, but you can enter the debugger by sending an interrupt (e.g. by typing @key{Ctrl}-@key{c}). @item @code{--debug} Turns on the Expect internal debugging output. Debugging output is displayed as part of the @emph{runtest} output, and logged to a file called @file{dbg.log}. The extra debugging output does @emph{not} appear on standard output, unless the verbose level is greater than 2 (for instance, to see debug output immediately, specify @code{--debug -v -v}). The debugging output shows all attempts at matching the test output of the tool with the scripted patterns describing expected output. The output generated with @code{--strace} also goes into @file{dbg.log}. @item @code{--global_init [name]} Use @emph{name} as the global init file instead of @file{site.exp} in @emph{libdir}. The default is, of course, @file{site.exp}. Note that this option accepts a relative file name, interpreted starting at @emph{libdir}, so a file in a subdirectory may be used. This is probably less useful for most sites, but is orthogonal with the @code{--local_init} option and may be useful in large testing labs. @item @code{--help} Prints out a short summary of the @emph{runtest} options, then exits (even if you specify other options). @item @code{--host [triplet]} @emph{triplet} is a system triplet of the form @emph{cpu-manufactuer-os}. Use this option to override the default string recorded by your configuration's choice of host. This choice does not change how anything is actually configured unless --build is also specified; it affects @emph{only} DejaGnu procedures that compare the host string with particular values. The procedures @emph{ishost}, @emph{istarget}, @emph{isnative}, and @emph{setup_xfail} are affected by @code{--host}. In this usage, @emph{host} refers to the machine that the tests are to be run on, which may not be the same as the @emph{build} machine. If @code{--build} is also specified, then @code{--host} refers to the machine that the tests will be run on, not the machine DejaGnu is run on. @item @code{--host_board [name]} The host board to use. @item @code{--ignore [tests(s)] } The name(s) of specific tests to ignore. @item @code{--local_init [name]} Use @emph{name} as the testsuite local init file instead of @file{site.exp} in the current directory and in @emph{objdir}. The default is, of course, @file{site.exp}. Note that this option accepts a relative file name, so a file in a subdirectory may be used. @item @code{--log_dialog} Emit Expect output to stdout. The Expect output is usually only written to the @file{.log} file. By enabling this option, they are also printed to standard output. @item @code{--mail [address(es)]} Send test results to one or more email addresses. @item @code{--objdir [path]} Use @emph{path} as the top directory containing any auxiliary compiled test code. The default is '.'. Use this option to locate pre-compiled test code. You can normally prepare any auxiliary files needed with @emph{make}. @item @code{--outdir [path]} Write log files in directory @file{path}. The default is '.', the directory where you start @emph{runtest}. This option affects only the summary (@file{.sum}) and the detailed log files (@file{.log}). The DejaGnu debug log @file{dbg.log} always appears (when requested) in the local directory. @item @code{--reboot [name]} Reboot the target board when @code{runtest} starts. When running tests on a separate target board, it is safer to reboot the target to be certain of its state. However, when developing test scripts, rebooting can take a lot of time. @item @code{--srcdir [path]} Use @file{path} as the top directory for test scripts to run. @emph{runtest} looks in this directory for any subdirectory whose name begins with the toolname (specified with @code{--tool}). For instance, with @code{--tool gdb}, @emph{runtest} uses tests in subdirectories @file{gdb.*} (with the usual shell-like filename expansion). If you do not use @code{--srcdir}, @emph{runtest} looks for test directories under the current working directory. @item @code{--strace [n]} Turn on internal tracing for @emph{expect}, to n levels deep. By adjusting the level, you can control the extent to which your output expands multi-level Tcl statements. This allows you to ignore some levels of @emph{case} or @emph{if} statements. Each procedure call or control structure counts as one ``level''. The output is recorded in the same file, @file{dbg.log}, used for output from @code{--debug}. @item @code{--target [triplet]} Use this option to override the default setting (native testing). @emph{triplet} is a system triplet of the form @emph{cpu-manufacturer-os}. This option changes the configuration @code{runtest} uses for the default tool names, and other setup information. @item @code{--target_board [name(s)]} The list of target boards to run tests on. @item @code{--tool [name(s)]} Specifies which testsuite to run, and what initialization module to use. @code{--tool} is used @emph{only} for these two purposes. It is @emph{not} used to name the executable program to test. Executable tool names (and paths) are recorded in @file{site.exp} and you can override them by specifying Tcl variables on the command line. For example, including @code{--tool} gcc on the command line runs tests from all test subdirectories whose names match @file{gcc.*}, and uses one of the initialization modules named @file{config/*-gcc.exp}. To specify the name of the compiler (perhaps as an alternative path to what @emph{runtest} would use by default), use @emph{GCC=path-to-gcc} on the @emph{runtest} command line. @item @code{--tool_exec [name]} The path to the tool executable to test. @item @code{--tool_opts [options]} A list of additional options to pass to the tool. @item @code{-v}, @code{--verbose} Turns on more output. Repeating this option increases the amount of output displayed. Level one (@emph{-v}) is simply test output. Level two (@emph{-v -v}) shows messages on options, configuration, and process control. Verbose messages appear in the detailed (@file{*.log}) log file, but not in the summary (@file{*.sum}) log file. @item @code{-V}, @code{--version} Prints out the version numbers of DejaGnu, Expect, and Tcl. @item @code{-x}, @code{--xml} Generate XML output. The output file is named after the tool with an .xml extension. @item @file{testfile}.exp[=arg(s)] Specify the names of testsuites to run. By default, @emph{runtest} runs all tests for the tool, but you can restrict it to particular testsuites by giving the names of the @emph{.exp} scripts that control them. @emph{testsuite}.exp cannot include directory names, only plain filenames. @code{arg(s)} specifies a subset of test cases to run. For compiler or assembler tests, which often use a single @emph{.exp} script covering many different test case files, this option allows you to further restrict the tests by listing particular test cases. For larger testsuites such as that included in GCC, this can save a lot of time. Some tools support wildcards here, but this varies from tool to tool. Typically the wildcards @emph{?}, @emph{*}, and @emph{[chars]} are recognized. @item @code{tclvar}=value You can define Tcl variables for use by your test scripts in the same style used with @emph{make} for environment variables. For example, @emph{runtest GDB=gdb.old} defines a variable called @code{GDB}; when your scripts refer to @code{$GDB} in this run, they use the value @emph{gdb.old}. The default Tcl variables used for most tools are defined in the main DejaGnu @emph{Makefile}; their values are captured in the @file{site.exp} file. @end table @node Common Operations, , Invoking runtest, Runtest @subsection Common Options @cindex options, common Typically, you don't need to use any command line options. The @code{--tool} option is only required when there is more than one testsuite in the same directory. The default options are in the local @file{site.exp} file, created by @code{make site.exp}. For example, if the directory @file{gdb/testsuite} contains a collection of DejaGnu tests for GDB, you can run them like this: @example $ cd gdb/testsuite $ runtest --tool gdb @end example The test output follows, then ends with: @example === gdb Summary === # of expected passes 508 # of expected failures 103 /usr/latest/bin/gdb version 4.14.4 -nx @end example You can use the option @code{--srcdir} to point to some other directory containing a collection of tests: @example $ runtest --srcdir /devo/gdb/testsuite @end example By default, @code{runtest} prints only the names of the tests it runs, output from any tests that have unexpected results, and a summary showing how many tests passed and how many failed. To display output from all tests (whether or not they behave as expected), use the @code{-a} (all) option. For more verbose output about processes being run, communication, and so on, use @code{-v} (verbose). To see even more output, use multiple @code{-v} options. See @ref{Invoking runtest} for a more detailed explanation of each @code{runtest} option. @node Output Files, , Runtest, Running tests @section Output files DejaGnu always writes two kinds of output files. Summary output is written to the @file{.sum} file, and detailed output is written to the @file{.log} file. The tool name determines the prefix for these files. For example, after running with @code{--tool gdb}, the output files will be called @file{gdb.sum} and @file{gdb.log}. For troubleshooting, a debug log file that logs the operation of Expect is available. Each of these will be described in turn. @menu * Summary log file:: * Detailed log file:: * Debug log file:: @end menu @node Summary log file, Detailed log file, , Output Files @subsection Summary log file @cindex output file, summary log DejaGnu always produces a summary (@file{.sum}) output file. This summary lists the names of all test files run. For each test file, one line of output from each @code{pass} command (showing status @emph{PASS} or @emph{XPASS}) or @code{fail} command (status @emph{FAIL} or @emph{XFAIL}), trailing summary statistics that count passing and failing tests (expected and unexpected), the full pathname of the tool tested, and the version number of the tool. All possible outcomes, and all errors, are always reflected in the summary output file, regardless of whether or not you specify @code{--all}. If any of your tests use the procedures @code{unresolved}, @code{unsupported}, or @code{untested}, the summary output also tabulates the corresponding outcomes. For example, after running @code{runtest --tool binutils} a summary log file will be written to @file{binutils.sum}. Normally, DejaGnu writes this file in your current working directory. Use the @code{--outdir} option to select a different output directory. @strong{Sample summary log} @example Test Run By bje on Sat Nov 14 21:04:30 AEDT 2015 @ === gdb tests === Running ./gdb.t00/echo.exp ... PASS: Echo test Running ./gdb.all/help.exp ... PASS: help add-symbol-file PASS: help aliases PASS: help breakpoint "bre" abbreviation FAIL: help run "r" abbreviation Running ./gdb.t10/crossload.exp ... PASS: m68k-elf (elf-big) explicit format; loaded XFAIL: mips-ecoff (ecoff-bigmips) "ptype v_signed_char" signed C types @ === gdb Summary === # of expected passes 5 # of expected failures 1 # of unexpected failures 1 /usr/latest/bin/gdb version 4.6.5 -q @end example @node Detailed log file, Debug log file, Summary log file, Output Files @subsection Detailed log file @cindex output file, detailed log DejaGnu also saves a detailed log file (@file{.log}), showing any output generated by test cases as well as the summary output. For example, after running @code{runtest --tool binutils}, a detailed log file will be written to @file{binutils.log}. Normally, DejaGnu writes this file in your current working directory. Use the @code{--outdir} option to select a different output directory. @strong{Sample detailed log for g++ tests} @example Test Run By bje on Sat Nov 14 21:07:23 AEDT 2015 @ === g++ tests === Running ./g++.other/t01-1.exp ... PASS: operate delete Running ./g++.other/t01-2.exp ... FAIL: i960 bug EOF p0000646.C: In function `int warn_return_1 ()': p0000646.C:109: warning: control reaches end of non-void function p0000646.C: In function `int warn_return_arg (int)': p0000646.C:117: warning: control reaches end of non-void function p0000646.C: In function `int warn_return_sum (int, int)': p0000646.C:125: warning: control reaches end of non-void function p0000646.C: In function `struct foo warn_return_foo ()': p0000646.C:132: warning: control reaches end of non-void function Running ./g++.other/t01-4.exp ... FAIL: abort 900403_04.C:8: zero width for bit-field `foo' Running ./g++.other/t01-3.exp ... FAIL: segment violation 900519_12.C:9: parse error before `;' 900519_12.C:12: Segmentation violation /usr/latest/bin/gcc: Internal compiler error: program cc1plus got fatal signal @ === g++ Summary === # of expected passes 1 # of expected failures 3 /usr/latest/bin/g++ version cygnus-2.0.1 @end example @node Debug log file, , Detailed log file, Output Files @subsection Debug log file @cindex output file, debug log The @code{runtest} option @code{--debug} creates a file showing the output from Expect in debugging mode. The @file{dbg.log} file is created in the current directory. The log file shows the string sent to the tool being tested by each @code{send} command and the pattern it compares with the tool output by each @code{expect} command. The log messages begin with a message of the form: @example expect: does @{tool output@} (spawn_id n) match pattern @{expected pattern@}? @end example For every unsuccessful match, Expect issues a @emph{no} after this message. If other patterns are specified for the same Expect command, they are reflected also, but without the first part of the message (@emph{expect... match pattern}). When Expect finds a match, the log for the successful match ends with @emph{yes}, followed by a record of the Expect variables set to describe a successful match. @strong{Example debug log file for a GDB test} @example send: sent @{break gdbme.c:34\n@} to spawn id 6 expect: does @{@} (spawn_id 6) match pattern @{Breakpoint.*at.* file gdbme.c, line 34.*\(gdb\) $@}? no @{.*\(gdb\) $@}? no expect: does @{@} (spawn_id 0) match pattern @{return@} ? no @{\(y or n\) @}? no @{buffer_full@}? no @{virtual@}? no @{memory@}? no @{exhausted@}? no @{Undefined@}? no @{command@}? no break gdbme.c:34 Breakpoint 8 at 0x23d8: file gdbme.c, line 34. (gdb) expect: does @{break gdbme.c:34\r\nBreakpoint 8 at 0x23d8: file gdbme.c, line 34.\r\n(gdb) @} (spawn_id 6) match pattern @{Breakpoint.*at.* file gdbme.c, line 34.*\(gdb\) $@}? yes expect: set expect_out(0,start) @{18@} expect: set expect_out(0,end) @{71@} expect: set expect_out(0,string) @{Breakpoint 8 at 0x23d8: file gdbme.c, line 34.\r\n(gdb) @} epect: set expect_out(spawn_id) @{6@} expect: set expect_out(buffer) @{break gdbme.c:34\r\nBreakpoint 8 at 0x23d8: file gdbme.c, line 34.\r\n(gdb) @} PASS: 70 0 breakpoint line number in file @end example This example exhibits three properties of Expect and DejaGnu that might be surprising at first glance: @itemize @item Empty output for the first attempted match. The first set of attempted matches shown ran against the output @emph{@{@}} --- that is, no output. Expect begins attempting to match the patterns supplied immediately; often, the first pass is against incomplete output (or completely before all output, as in this case). @item Interspersed tool output. The beginning of the log entry for the second attempted match may be hard to spot: this is because the prompt @emph{@{(gdb) @}} appears on the same line, just before the @emph{expect:} that marks the beginning of the log entry. @item Fail-safe patterns. Many of the patterns tested are fail-safe patterns provided by GDB testing utilities, to reduce possible indeterminacy. It is useful to anticipate potential variations caused by extreme system conditions (GDB might issue the message @emph{virtual memory exhausted} in rare circumstances), or by changes in the tested program (@emph{Undefined command} is the likeliest outcome if the name of a tested command changes). The pattern @emph{@{return@}} is a particularly interesting fail-safe to notice; it checks for an unexpected @key{RET} prompt. This may happen, for example, if the tested tool can filter output through a pager. These fail-safe patterns (like the debugging log itself) are primarily useful while developing test scripts. Use the @code{error} procedure to make the actions for fail-safe patterns produce messages starting with @emph{ERROR} on standard output, and in the detailed log file. @end itemize @node Running other DejaGnu commands, Customizing DejaGnu, Running tests, Top @chapter Running other DejaGnu commands DejaGnu now features auxiliary commands not directly related to running tests, but somehow related to the broader purpose of testing. These commands are run via the @command{dejagnu} multiplex launcher, which locates an appropriate script and the required interpreter and then runs the requested command. @menu * Invoking dejagnu:: Command line options for the launcher itself. * Invoking dejagnu help:: Reading man pages for dejagnu subcommands. * Invoking dejagnu report card:: Summarizing test results from many tools. @end menu @node Invoking dejagnu, Invoking dejagnu help, Running other DejaGnu commands, Running other DejaGnu commands @section Invoking @command{dejagnu} @cindex dejagnu, invoking The @command{dejagnu} launcher is primarily designed to pass most options on to the scripts that it runs, but does process the @option{--help} and @option{--version} options entirely internally, while also recognizing the @option{--verbose} option. @example @command{dejagnu} [options...] @command{dejagnu} --help @command{dejagnu} --version @end example Note that the command names may contain multiple words. In this case, the command can be given as separate arguments to @command{dejagnu} or combined with dashes (@samp{-}); both forms are equivalent. All words of the command name must appear before any options. The search for a command terminates when an option is found. Note that the first valid command found is used. A longer command name can be shadowed by a shorter command name that happens to be a prefix of the longer name, if the command name is given as multiple arguments. The equivalent form with the longer command name combined using dashes into a single argument will correctly refer to the otherwise shadowed command. The @command{dejagnu} launcher can also be run using symbolic links, provided that the shell places the name under which @command{dejagnu} was invoked in @code{$0}. Any dash-separated words after ``dejagnu'' in the name of such a link are taken to be the leading words of a command name. The @command{dejagnu} launcher supports alternate implementations depending upon available interpreters. Options for the @command{dejagnu} launcher itself cannot be abbreviated, since the launcher has no way to know which abbreviations are unique and which would be ambiguous to the invoked command. @table @asis @item @code{--help} Print a help message instead of running a command. @item @code{-V}, @code{--version} Print a version banner for the launcher itself including the version of DejaGnu. Any command given is ignored. @item @code{-v}, @code{--verbose} Emit additional output describing the inner workings of the @command{dejagnu} launcher. This option is also passed on to the invoked command. @end table All arguments after the command name are passed to the invoked command. @node Invoking dejagnu help, Invoking dejagnu report card, Invoking dejagnu, Running other DejaGnu commands @section Invoking @command{dejagnu help} @cindex dejagnu help, invoking The @command{dejagnu help} tool displays long-form documentation for DejaGnu auxiliary commands that are invoked using the @command{dejagnu} launcher. @example @command{dejagnu help} [options...] @end example Again, command names may contain multiple words. This command forms an operand by joining all words in the command name using dashes (@samp{-}) and prepending @samp{dejagnu-}. This is then used as the name of a manual page and passed to the @command{man} command. If the manual page is in a particular directory relative to the script implementing this command, a full file name is produced, otherwise, @command{man} performs its normal search. The @option{--verbose} option causes additional output describing the inner workings of the @command{dejagnu help} command to be produced. The @option{--path}, @option{-w}, and @option{-W} options are passed to @command{man}. @node Invoking dejagnu report card, , Invoking dejagnu help, Running other DejaGnu commands @section Invoking @command{dejagnu report card} @cindex dejagnu report card, invoking @cindex dejagnu report-card, invoking The @command{dejagnu report card} tool produces a tabular summary of the results from test runs by reading the summary files that DejaGnu produces. @example @command{dejagnu report card} [