* debian/changelog: Add entry for new release.
[dejagnu.git] / doc / user.sgml
blob7c38d4d5c397081139b542091ec1df58d781798e
1 <chapter id=runningtests>
2 <title>Running Tests</title>
4 <para>There are two ways to execute a test suite. The most
5 common way is when there is existing support in the
6 <filename>Makefile</filename>. This support consists of a
7 <emphasis>check</emphasis> target. The other way is to execute the
8 <command>runtest</command> program directly. To run
9 <command>runtest</command> directcly from the command line requires
10 either all the correct options, or the <xref linkend=local> must be setup
11 correctly.</para>
13 <sect1 id=makecheck xreflabel="Make Check">
14 <title>Make check</title>
16 <para>To run tests from an existing collection, first use
17 <command>configure</command> as usual to set up the
18 build directory. Then try typing:</para>
20 <screen>
21 make check
22 </screen>
24 <para>If the <emphasis>check</emphasis> target exists, it
25 usually saves you some trouble. For instance, it can set up any
26 auxiliary programs or other files needed by the tests. The most
27 common file the check builds is the
28 <emphasis>site.exp</emphasis>. The site.exp file contains
29 various variables that DejaGnu used to dertermine the
30 configuration of the program being tested. This is mostly for
31 supporting remote testing.</para>
33 <para>The <emphasis>check</emphasis> target is supported by GNU
34 <productname>Automake</productname>. To have DejaGnu support added to your
35 generated <filename>Makefile.in</filename>, just add the keyword
36 dejagnu to the AUTOMAKE_OPTIONS variable in your
37 <filename>Makefile.am</filename> file.</para>
39 <para>Once you have run <emphasis>make check</emphasis> to build
40 any auxiliary files, you can invoke the test driver
41 <command>runtest</command> directly to repeat the tests.
42 You will also have to execute <command>runtest</command>
43 directly for test collections with no
44 <emphasis>check</emphasis> target in the
45 <filename>Makefile</filename>.</para>
47 </sect1>
49 <sect1 id=runtest xreflabel="Runtest">
50 <title>Runtest</title>
52 <para><command>runtest</command> is the executable test driver
53 for DejaGnu. You can specify two kinds of things on the
54 <command>runtest</command> command line: command line options,
55 and Tcl variables for the test scripts. The options are listed
56 alphabetically below.</para>
58 <para><command>runtest</command> returns an exit code of
59 <emphasis>1</emphasis> if any test has an unexpected result; otherwise
60 (if all tests pass or fail as expected) it returns <emphasis>0</emphasis>
61 as the exit code.</para>
63 <sect2 id=outputs xreflabel="Output States">
64 <title>Output States</title>
66 <para><filename>runtest</filename> flags the outcome of each
67 test as one of these cases. <xref linkend=posix> for a
68 discussion of how POSIX specifies the meanings of these
69 cases.</para>
71 <variablelist>
72 <varlistentry>
73 <term>PASS</term>
74 <listitem><para>The most desirable outcome: the test succeeded, and
75 was expected to succeed.</para></listitem>
76 </varlistentry>
78 <varlistentry>
79 <term>XPASS</term>
80 <listitem><para>A pleasant kind of failure: a test was expected to
81 fail, but succeeded. This may indicate progress; inspect the test
82 case to determine whether you should amend it to stop expecting
83 failure.</para></listitem>
84 </varlistentry>
86 <varlistentry>
87 <term>FAIL</term>
88 <listitem><para>A test failed, although it was expected to succeed.
89 This may indicate regress; inspect the test case and the failing
90 software to ocate the bug.</para></listitem>
91 </varlistentry>
93 <varlistentry>
94 <term>XFAIL</term>
95 <listitem><para>A test failed, but it was expected to fail. This
96 result indicates no change in a known bug. If a test fails because
97 the operating system where the test runs lacks some facility required
98 by the test, the outcome is <emphasis>UNSUPPORTED</emphasis>
99 instead.</para></listitem>
100 </varlistentry>
102 <varlistentry>
103 <term>UNRESOLVED</term>
104 <listitem><para>Output from a test requires manual inspection; the
105 test suite could not automatically determine the outcome. For
106 example, your tests can report this outcome is when a test does not
107 complete as expected.</para></listitem>
108 </varlistentry>
110 <varlistentry>
111 <term>UNTESTED</term>
112 <listitem><para>A test case is not yet complete, and in particular
113 cannot yet produce a <emphasis>PASS</emphasis> or
114 <emphasis>FAIL</emphasis>. You can also use this outcome in dummy
115 ``tests'' that note explicitly the absence of a real test case for a
116 particular property.</para></listitem>
117 </varlistentry>
119 <varlistentry>
120 <term>UNSUPPORTED</term>
121 <listitem><para>A test depends on a conditionally available feature
122 that does not exist (in the configured testing environment). For
123 example, you can use this outcome to report on a test case that does
124 not work on a particular target because its operating system support
125 does not include a required subroutine.</para></listitem>
126 </varlistentry>
127 </variablelist>
129 <para>runtest may also display the following messages:</para>
131 <variablelist>
132 <varlistentry>
133 <term>ERROR</term>
134 <listitem><para>Indicates a major problem (detected by the test case
135 itself) in running the test. This is usually an unrecoverable error,
136 such as a missing file or loss of communication to the target. (POSIX
137 test suites should not emit this message; use
138 <emphasis>UNSUPPORTED</emphasis>, <emphasis>UNTESTED</emphasis>, or
139 <emphasis>UNRESOLVED</emphasis> instead, as
140 appropriate.)</para></listitem>
141 </varlistentry>
143 <varlistentry>
144 <term>WARNING</term>
145 <listitem><para>Indicates a possible problem in running the
146 test. Usually warnings correspond to recoverable errors, or display
147 an important message about the following tests.</para></listitem>
148 </varlistentry>
150 <varlistentry>
151 <term>NOTE</term>
152 <listitem><para>An informational message about the test
153 case.</para></listitem>
154 </varlistentry>
155 </variablelist>
157 </sect2>
159 <sect2 id=invoking xreflabel="Invoking Runtest">
160 <title>Invoking Runtest</title>
162 <para>This is the full set of command line options that
163 <filename>runtest</filename> recognizes. Arguments may be
164 abbreviated to the shortest unique string.</para>
166 <variablelist>
167 <varlistentry>
168 <term><option>--all</option> (-a)</term>
169 <listitem><para>Display all test output. By default,
170 <emphasis>runtest</emphasis> shows only the output of tests that
171 produce unexpected results; that is, tests with status
172 <emphasis>FAIL</emphasis> (unexpected failure),
173 <emphasis>XPASS</emphasis> (unexpected success), or
174 <emphasis>ERROR</emphasis> (a severe error in the test case
175 itself). Specify <emphasis>--all</emphasis> to see output for tests
176 with status <emphasis>PASS</emphasis> (success, as expected)
177 <emphasis>XFAIL</emphasis> (failure, as expected), or
178 <emphasis>WARNING</emphasis> (minor error in the test case
179 itself).</para></listitem>
180 </varlistentry>
182 <varlistentry>
183 <term><option>--build [string]</option></term>
184 <listitem><para><emphasis>string</emphasis> is a full configuration
185 ``triple'' name as used by <command>configure</command>. This
186 is the type of machine DejaGnu and the tools to be tested are built
187 on. For a normal cross this is the same as the host, but for a
188 canadian cross, they are seperate.</para></listitem>
189 </varlistentry>
191 <varlistentry>
192 <term><option>--host [string]</option></term>
193 <listitem><para><symbol>string</symbol> is a full configuration
194 ``triple'' name as used by <emphasis>configure</emphasis>. Use this
195 option to override the default string recorded by your
196 configuration's choice of host. This choice does not change how
197 anything is actually configured unless --build is also specified; it
198 affects <emphasis>only</emphasis> DejaGnu procedures that compare the
199 host string with particular values. The procedures
200 <emphasis>ishost</emphasis>, <emphasis>istarget</emphasis>,
201 <emphasis>isnative</emphasis>, and <emphasis>setup</emphasis>xfail}
202 are affected by <emphasis>--host</emphasis>. In this usage,
203 <emphasis>host</emphasis> refers to the machine that the tests are to
204 be run on, which may not be the same as the
205 <emphasis>build</emphasis> machine. If <emphasis>--build</emphasis>
206 is also specified, then <emphasis>--host</emphasis> refers to the
207 machine that the tests wil, be run on, not the machine DejaGnu is run
208 on.</para></listitem>
209 </varlistentry>
211 <varlistentry>
212 <term><option>--host_board [name]</option></term>
213 <listitem><para>The host board to use.</para></listitem>
214 </varlistentry>
216 <varlistentry>
217 <term><option>--target [string]</option></term>
218 <listitem><para>Use this option to override the default setting
219 (running native tests). <emphasis>string</emphasis> is a full
220 configuration ``triple'' name of the form
221 <emphasis>cpu-vendor-os</emphasis> as used by
222 <command>configure</command>. This option changes the
223 configuration <emphasis>runtest</emphasis> uses for the default tool
224 names, and other setup information.</para></listitem>
225 </varlistentry>
227 <varlistentry>
228 <term><option>--debug</option> (-de)</term>
229 <listitem><para>Turns on the <emphasis>expect</emphasis> internal
230 debugging output. Debugging output is displayed as part of the
231 <emphasis>runtest</emphasis> output, and logged to a file called
232 <filename>dbg.log</filename>. The extra debugging output does
233 <emphasis>not</emphasis> appear on standard output, unless the
234 verbose level is greater than 2 (for instance, to see debug output
235 immediately, specify <emphasis>--debug</emphasis>-v -v}). The
236 debugging output shows all attempts at matching the test output of
237 the tool with the scripted patterns describing expected output. The
238 output generated with <emphasis>--strace</emphasis> also goes into
239 <filename>dbg.log</filename>.</para></listitem>
240 </varlistentry>
242 <varlistentry>
243 <term><option>--help</option> (-he)</term>
244 <listitem><para>Prints out a short summary of the
245 <emphasis>runtest</emphasis> options, then exits (even if you also
246 specify other options).</para></listitem>
247 </varlistentry>
249 <varlistentry>
250 <term><option>--ignore [name(s)] </option></term>
251 <listitem><para>The names of specific tests to
252 ignore.</para></listitem>
253 </varlistentry>
255 <varlistentry>
256 <term><option>--objdir [path]</option></term>
257 <listitem><para>Use <emphasis>path</emphasis> as the top directory
258 containing any auxiliary compiled test code. This defaults to
259 <filename>.</filename>. Use this option to locate pre-compiled test
260 code. You can normally prepare any auxiliary files needed with
261 <emphasis>make</emphasis>.</para></listitem>
262 </varlistentry>
264 <varlistentry>
265 <term><option>--outdir [path]</option></term>
266 <listitem><para>Write output logs in directory
267 <filename>path</filename>. The default is <emphasis>.},
268 the</emphasis> directory where you start
269 <emphasis>runtest</emphasis>. This option affects only the summary
270 and the detailed log files
271 <filename>tool.sum</filename> and
272 <filename>tool.log</filename>. The DejaGnu debug
273 log <filename>dbg.log</filename> always appears (when requested) in
274 the local directory.</para></listitem>
275 </varlistentry>
277 <varlistentry>
278 <term><option>--reboot [name]</option></term>
279 <listitem><para>Reboot the target board when
280 <emphasis>runtest</emphasis> initializes. Usually, when running tests
281 on a separate target board, it is safer to reboot the target to be
282 certain of its state. However, when developing test scripts,
283 rebooting takes a lot of time.</para></listitem>
284 </varlistentry>
286 <varlistentry>
287 <term><option>--srcdir [path]</option></term>
288 <listitem><para>Use <filename>path</filename> as the top directory
289 for test scripts to run. <emphasis>runtest</emphasis> looks in this
290 directory for any subdirectory whose name begins with the toolname
291 (specified with <emphasis>--tool</emphasis>). For instance, with
292 <emphasis>--tool</emphasis>gdb}, <emphasis>runtest</emphasis> uses
293 tests in subdirectories <filename>gdb.*</filename> (with the usual
294 shell-like filename expansion). If you do not use
295 <emphasis>--srcdir</emphasis>, <emphasis>runtest</emphasis> looks for
296 test directories under the current working
297 directory.</para></listitem>
298 </varlistentry>
300 <varlistentry>
301 <term><option>--strace [number]</option></term>
302 <listitem><para>Turn on internal tracing for
303 <emphasis>expect</emphasis>, to n levels deep. By adjusting the
304 level, you can control the extent to which your output expands
305 multi-level Tcl statements. This allows you to ignore some levels of
306 <emphasis>case</emphasis> or <emphasis>if</emphasis> statements.
307 Each procedure call or control structure counts as one ``level''. The
308 output is recorded in the same file, <filename>dbg.log</filename>,
309 used for output from <emphasis>--debug</emphasis>.</para></listitem>
310 </varlistentry>
312 <varlistentry>
313 <term><option>--connect [program]</option></term>
314 <listitem><para>Connect to a target testing environment as specified
315 by <emphasis>type</emphasis>, if the target is not the computer
316 running <emphasis>runtest</emphasis>. For example, use
317 <emphasis>--connect</emphasis> to change the program used to connect
318 to a ``bare board'' boot monitor. The choices for
319 <emphasis>type</emphasis> in the DejaGnu 1.4 distribution are
320 <emphasis>rlogin</emphasis>, <emphasis>telnet</emphasis>,
321 <emphasis>rsh</emphasis>, <emphasis>tip</emphasis>,
322 <emphasis>kermit</emphasis>, and <emphasis>mondfe</emphasis>.</para>
324 <para>The default for this option depends on the configuration most
325 convenient communication method available, but often other
326 alternatives work as well; you may find it useful to try alternative
327 connect methods if you suspect a communication problem with your
328 testing target.</para></listitem>
329 </varlistentry>
331 <varlistentry>
332 <term><option>--baud [number]</option></term>
333 <listitem><para>Set the default baud rate to something other than
334 9600. (Some serial interface programs, like <emphasis>tip</emphasis>,
335 use a separate initialization file instead of this
336 value.)</para></listitem>
337 </varlistentry>
339 <varlistentry>
340 <term><option>--target_board [name(s)]</option></term>
341 <listitem><para>The list of target boards to run tests
342 on.</para></listitem>
343 </varlistentry>
345 <varlistentry id=tool-opt>
346 <term><option>--tool[name(s)]</option></term>
347 <listitem><para>Specifies which test suite to run, and what
348 initialization module to use. <option>--tool</option> is used
349 <emphasis>only</emphasis> for these two purposes. It is
350 <emphasis>not</emphasis> used to name the executable program to
351 test. Executable tool names (and paths) are recorded in
352 <filename>site.exp</filename> and you can override them by specifying
353 Tcl variables on the command line.</para>
355 <para>For example, including "<option>--tool</option> gcc" on the
356 <emphasis>runtest</emphasis> command line runs tests from all test
357 subdirectories whose names match <filename>gcc.*</filename>, and uses
358 one of the initialization modules named
359 <filename>config/*-gcc.exp</filename>. To specify the name of the
360 compiler (perhaps as an alternative path to what
361 <emphasis>runtest</emphasis> would use by default), use
362 <emphasis>GCC=binname</emphasis> on the <emphasis>runtest</emphasis>
363 command line.</para></listitem>
364 </varlistentry>
366 <varlistentry>
367 <term><option>--tool_exec [name]</option></term>
368 <listitem><para>The path to the tool executable to
369 test.</para></listitem>
370 </varlistentry>
372 <varlistentry>
373 <term><option>--tool_opts [options]</option></term>
374 <listitem><para>A list of additional options to pass to the
375 tool.</para></listitem>
376 </varlistentry>
378 <varlistentry>
379 <term><option>--verbose</option> (-v)</term>
380 <listitem><para>Turns on more output. Repeating this option increases
381 the amount of output displayed. Level one (<emphasis>-v</emphasis>)
382 is simply test output. Level two (<emphasis>-v</emphasis>-v}) shows
383 messages on options, configuration, and process control. Verbose
384 messages appear in the detailed (<filename>*.log</filename>) log
385 file, but not in the summary (<filename>*.sum</filename>) log
386 file.</para></listitem>
387 </varlistentry>
389 <varlistentry>
390 <term><option>--version</option> (-V)</term>
391 <listitem><para>Prints out the version numbers of DejaGnu,
392 <emphasis>expect</emphasis> and Tcl, and exits without running any
393 tests.</para></listitem>
394 </varlistentry>
396 <varlistentry>
397 <term><option>--D[0-1]</option></term>
398 <listitem><para>Start the internal Tcl debugger. The Tcl debugger
399 supports breakpoints, single stepping, and other common debugging
400 activities. See the document "Debugger for Tcl Applications" by Don
401 Libes. (Distributed in PostScript form with
402 <emphasis>expect</emphasis> as the file
403 <filename>expect/tcl-debug.ps.</filename>. If you specify
404 <emphasis>-D1</emphasis>, the <emphasis>expect</emphasis> shell stops
405 at a breakpoint as soon as DejaGnu invokes it. If you specify
406 <emphasis>-D0</emphasis>, DejaGnu starts as usual, but you can enter
407 the debugger by sending an interrupt (e.g. by typing
408 <keycombo><keycap>C</keycap><keycap>c</keycap></keycombo>).
409 </para></listitem>
410 </varlistentry>
412 <varlistentry>
413 <term><filename>testfile</filename>.exp[=arg(s)]</term>
414 <listitem><para>Specify the names of testsuites to run. By default,
415 <emphasis>runtest</emphasis> runs all tests for the tool, but you can
416 restrict it to particular testsuites by giving the names of the
417 <emphasis>.exp expect</emphasis> scripts that control
418 them. <emphasis>testsuite</emphasis>.exp may not include path
419 information; use plain filenames.</para></listitem>
420 </varlistentry>
422 <varlistentry>
423 <term><filename>testfile</filename>.exp="testfile1 ..."</term>
424 <listitem><para>Specify a subset of tests in a suite to run. For
425 compiler or assembler tests, which often use a single
426 <emphasis>.exp</emphasis> script covering many different source
427 files, this option allows you to further restrict the tests by
428 listing particular source files to compile. Some tools even support
429 wildcards here. The wildcards supported depend upon the tool, but
430 typically they are <emphasis>?</emphasis>, <emphasis>*</emphasis>,
431 and <emphasis>[chars]</emphasis>.</para></listitem>
432 </varlistentry>
434 <varlistentry>
435 <term><symbol>tclvar</symbol>=value</term>
436 <listitem><para>You can define Tcl variables for use by your test
437 scripts in the same style used with <emphasis>make</emphasis> for
438 environment variables. For example, <emphasis>runtest
439 GDB=gdb.old</emphasis> defines a variable called
440 <command>GDB</command>; when your scripts refer to
441 <symbol>$GDB</symbol> in this run, they use the value
442 <emphasis>gdb.old</emphasis>.</para>
444 <para>The default Tcl variables used for most tools are defined in
445 the main DejaGnu <emphasis>Makefile</emphasis>; their values are
446 captured in the <filename>site.exp</filename> file.</para></listitem>
447 </varlistentry>
448 </variablelist>
449 </sect2>
451 <sect2 id=common xreflabel="Common Operations">
452 <title>Common Options</title>
454 <para>Typically, you don't need must to use any command-line options.
455 <option>--tool</option> used is only required when there are more than
456 one test suite in the same directory. The default options are in the
457 local site.exp file, created by "make site.exp".</para>
459 <para>For example, if the directory <filename>gdb/testsuite</filename>
460 contains a collection of DejaGnu tests for GDB, you can run them like
461 this:</para>
463 <screen>
464 eg$ cd gdb/testsuite
465 eg$ runtest --tool gdb
466 </screen>
468 <para>Test output follows, ending with:</para>
470 <screen>
471 === gdb Summary ===
473 # of expected passes 508
474 # of expected failures 103
475 /usr/latest/bin/gdb version 4.14.4 -nx
476 </screen>
478 <para>You can use the option <emphasis>--srcdir</emphasis> to point to
479 some other directory containing a collection of tests:</para>
481 <screen>
482 eg$ runtest--srcdir /devo/gdb/testsuite
483 </screen>
485 <para>By default, <command>runtest</command> prints only the
486 names of the tests it runs, output from any tests that have unexpected
487 results, and a summary showing how many tests passed and how many
488 failed. To display output from all tests (whether or not they behave
489 as expected), use the <emphasis>--all</emphasis> option. For more
490 verbose output about processes being run, communication, and so on, use
491 <emphasis>--verbose</emphasis>. To see even more output, use multiple
492 <emphasis>--verbose</emphasis> options. for a more detailed explanation
493 of each <command>runtest</command> option.</para>
495 <para>Test output goes into two files in your current directory:
496 summary output in <filename>tool.sum</filename>,
497 and detailed output in <filename>
498 tool.log</filename>. (<emphasis>tool</emphasis>
499 refers to the collection of tests; for example, after a run with
500 <emphasis>--tool</emphasis> gdb, look for output files
501 <filename>gdb.sum</filename> and
502 <filename>gdb.log</filename>.)</para>
503 </sect2>
504 </sect1>
506 <sect1 id=outputfiles xreflabel="Output Files">
508 <title>The files DejaGnu produces.</title>
510 <para>DejaGnu always writes two kinds of output files: summary
511 logs and detailed logs. The contents of both of these are
512 determined by your tests.</para>
514 <para>For troubleshooting, a third kind of output file is useful:
515 use <option>--debug</option> to request an output file showing
516 details of what <productname>Expect</productname> is doing
517 internally.</para>
519 <sect2 id=sum xreflabel="Summary File">
520 <title>Summary File</title>
522 <para>DejaGnu always produces a summary output file
523 <filename>tool.sum</filename>. This summary shows the names of
524 all test files run; for each test file, one line of output from
525 each <command>pass</command> command (showing status
526 <emphasis>PASS</emphasis> or <emphasis>XPASS</emphasis>) or
527 <command>fail</command> command (status
528 <emphasis>FAIL</emphasis> or <emphasis>XFAIL</emphasis>);
529 trailing summary statistics that count passing and failing tests
530 (expected and unexpected); and the full pathname and version
531 number of the tool tested. (All possible outcomes, and all
532 errors, are always reflected in the summary output file,
533 regardless of whether or not you specify
534 <option>--all</option>.)</para>
536 <para>If any of your tests use the procedures
537 <command>unresolved</command>, <command>unsupported</command>,
538 or <command>runtested</command>, the summary output also
539 tabulates the corresponding outcomes.</para>
541 <para>For example, after <command>runtest --tool
542 binutils</command>, look for a summary log in
543 <filename>binutils.sum</filename>. Normally, DejaGnu writes this
544 file in your current working directory; use the
545 <option>--outdir</option> option to select a different
546 directory.</para>
548 <example>
549 <title>Here is a short sample summary log</title>
551 <screen>
552 Test Run By rob on Mon May 25 21:40:57 PDT 1992
553 === gdb tests ===
554 Running ./gdb.t00/echo.exp ...
555 PASS: Echo test
556 Running ./gdb.all/help.exp ...
557 PASS: help add-symbol-file
558 PASS: help aliases
559 PASS: help breakpoint "bre" abbreviation
560 FAIL: help run "r" abbreviation
561 Running ./gdb.t10/crossload.exp ...
562 PASS: m68k-elf (elf-big) explicit format; loaded
563 XFAIL: mips-ecoff (ecoff-bigmips) "ptype v_signed_char" signed C types
564 === gdb Summary ===
565 # of expected passes 5
566 # of expected failures 1
567 # of unexpected failures 1
568 /usr/latest/bin/gdb version 4.6.5 -q
569 </screen>
570 </example>
572 </sect2>
574 <sect2 id=log xreflabel="Log File">
575 <title>Log File</title>
577 <para>DejaGnu also saves a detailed log file
578 <filename>tool.log</filename>, showing any output generated by
579 tests as well as the summary output. For example, after
580 <command>runtest --tool binutils</command>, look for a detailed
581 log in <filename>binutils.log</filename>. Normally, DejaGnu
582 writes this file in your current working directory; use the
583 <option>--outdir</option> option to select a different
584 directory.</para>
587 <example>
588 <title>Here is a brief example showing a detailed log for
589 <productname>G++</productname> tests</title>
591 <screen>
592 Test Run By rob on Mon May 25 21:40:43 PDT 1992
594 === g++ tests ===
596 --- Running ./g++.other/t01-1.exp ---
597 PASS: operate delete
599 --- Running ./g++.other/t01-2.exp ---
600 FAIL: i960 bug EOF
601 p0000646.C: In function `int warn_return_1 ()':
602 p0000646.C:109: warning: control reaches end of non-void function
603 p0000646.C: In function `int warn_return_arg (int)':
604 p0000646.C:117: warning: control reaches end of non-void function
605 p0000646.C: In function `int warn_return_sum (int, int)':
606 p0000646.C:125: warning: control reaches end of non-void function
607 p0000646.C: In function `struct foo warn_return_foo ()':
608 p0000646.C:132: warning: control reaches end of non-void function
610 --- Running ./g++.other/t01-4.exp ---
611 FAIL: abort
612 900403_04.C:8: zero width for bit-field `foo'
613 --- Running ./g++.other/t01-3.exp ---
614 FAIL: segment violation
615 900519_12.C:9: parse error before `;'
616 900519_12.C:12: Segmentation violation
617 /usr/latest/bin/gcc: Internal compiler error: program cc1plus got fatal signal
619 === g++ Summary ===
621 # of expected passes 1
622 # of expected failures 3
623 /usr/latest/bin/g++ version cygnus-2.0.1
624 </screen>
625 </example>
627 </sect2>
629 <sect2 id=debugfile xreflabel="Debug Log File">
630 <title>Debug Log File</title>
632 <para>With the <option>--debug</option> option, you can request
633 a log file showing the output from
634 <productname>Expect</productname> itself, running in debugging
635 mode. This file (<filename>dbg.log</filename>, in the directory
636 where you start <command>runtest</command>) shows each pattern
637 <productname>Expect</productname> considers in analyzing test
638 output.</para>
640 <para>This file reflects each <command>send</command> command,
641 showing the string sent as input to the tool under test; and
642 each <productname>Expect</productname> command, showing each
643 pattern it compares with the tool output.</para>
645 <example>
646 <title>The log messages begin with a message of the form</title>
648 <screen>
650 expect: does {<symbol>tool output</symbol>} (spawn_id <symbol>n</symbol>)
651 match pattern {<emphasis>expected pattern</emphasis>}?
653 </screen>
654 </example>
656 <para>For every unsuccessful match,
657 <productname>Expect</productname> issues a
658 <emphasis>no</emphasis> after this message; if other patterns
659 are specified for the same <productname>Expect</productname>
660 command, they are reflected also, but without the first part of
661 the message (<emphasis>expect... match pattern</emphasis>).</para>
663 <para>When <productname>Expect</productname> finds a match, the
664 log for the successful match ends with <emphasis>yes</emphasis>,
665 followed by a record of the <productname>Expect</productname>
666 variables set to describe a successful match.</para>
668 <example>
669 <title>Here is an excerpt from the debugging log for a
670 <productname>GDB</productname> test:</title>
672 <screen>
673 send: sent {break gdbme.c:34\n} to spawn id 6
674 expect: does {} (spawn_id 6) match pattern {Breakpoint.*at.* file
675 gdbme.c, line 34.*\(gdb\) $}? no
676 {.*\(gdb\) $}? no
677 expect: does {} (spawn_id 0) match pattern {return} ? no
678 {\(y or n\) }? no
679 {buffer_full}? no
680 {virtual}? no
681 {memory}? no
682 {exhausted}? no
683 {Undefined}? no
684 {command}? no
685 break gdbme.c:34
686 Breakpoint 8 at 0x23d8: file gdbme.c, line 34.
687 (gdb) expect: does {break gdbme.c:34\r\nBreakpoint 8 at 0x23d8:
688 file gdbme.c, line 34.\r\n(gdb) } (spawn_id 6) match pattern
689 {Breakpoint.*at.* file gdbme.c, line 34.*\(gdb\) $}? yes
690 expect: set expect_out(0,start) {18}
691 expect: set expect_out(0,end) {71}
692 expect: set expect_out(0,string) {Breakpoint 8 at 0x23d8: file
693 gdbme.c, line 34.\r\n(gdb) }
694 epect: set expect_out(spawn_id) {6}
695 expect: set expect_out(buffer) {break gdbme.c:34\r\nBreakpoint 8
696 at 0x23d8: file gdbme.c, line 34.\r\n(gdb) }
697 PASS: 70 0 breakpoint line number in file
698 </screen>
699 </example>
701 <para>This example exhibits three properties of
702 <productname>Expect</productname> and
703 <productname>DejaGnu</productname> that might be surprising at
704 first glance:</para>
706 <itemizedlist mark="bullet">
707 <listitem><para>Empty output for the first attempted match. The
708 first set of attempted matches shown ran against the output
709 <emphasis>{}</emphasis> --- that is, no
710 output. <productname>Expect</productname> begins
711 attempting to match the patterns supplied immediately; often,
712 the first pass is against incomplete output (or completely
713 before all output, as in this case).</para></listitem>
715 <listitem><para>Interspersed tool output. The beginning of
716 the log entry for the second attempted match may be hard to
717 spot: this is because the prompt <emphasis>{(gdb) }</emphasis>
718 appears on the same line, just before the
719 <emphasis>expect:</emphasis> that marks the beginning of the
720 log entry.</para></listitem>
722 <listitem><para>Fail-safe patterns. Many of the patterns
723 tested are fail-safe patterns provided by
724 <productname>GDB</productname> testing utilities, to reduce
725 possible indeterminacy. It is useful to anticipate potential
726 variations caused by extreme system conditions
727 (<productname>GDB</productname> might issue the message
728 <emphasis>virtual memory exhausted</emphasis> in rare
729 circumstances), or by changes in the tested program
730 (<emphasis>Undefined command</emphasis> is the likeliest
731 outcome if the name of a tested command changes).</para>
733 <para>The pattern <emphasis>{return}</emphasis> is a
734 particularly interesting fail-safe to notice; it checks for an
735 unexpected <keycap>RET</keycap> prompt. This may happen,
736 for example, if the tested tool can filter output through a
737 pager.</para>
739 <para>These fail-safe patterns (like the debugging log itself)
740 are primarily useful while developing test scripts. Use the
741 <command>error</command> procedure to make the actions for
742 fail-safe patterns produce messages starting with
743 <emphasis>ERROR</emphasis> on standard output, and in the
744 detailed log file.</para></listitem>
745 </itemizedlist>
746 </sect2>
747 </sect1>
748 </chapter>
750 <chapter id=Customizing xreflabel="Customizing DejaGnu">
751 <title>Customizing DejaGnu</title>
753 <para>The site configuration file, <filename>site.exp</filename>,
754 captures configuration-dependent values and propagates them to the
755 DejaGnu test environment using Tcl variables. This ties the
756 DejaGnu test scripts into the <command>configure</command> and
757 <command>make</command> programs. If this file is setup correctly,
758 it is possible to execute a test suite merely by typing
759 <command>runtest</command>.</para>
761 <para>DejaGnu supports two <filename>site.exp</filename>
762 files. The multiple instances of <filename>site.exp</filename> are
763 loaded in a fixed order built into DejaGnu. The first file loaded
764 is the local file <filename>site.exp</filename>, and then the
765 optional global <filename>site.exp</filename> file as
766 pointed to by the <symbol>DEJAGNU</symbol> environment
767 variable.</para>
769 <para>There is an optional <emphasis>master</emphasis>
770 <filename>site.exp</filename>, capturing configuration values that
771 apply to DejaGnu across the board, in each configuration-specific
772 subdirectory of the DejaGnu library directory.
773 <command>runtest</command> loads these values first. The master
774 <filename>site.exp</filename> contains the default values for all
775 targets and hosts supported by DejaGnu. This master file is
776 identified by setting the environment variable
777 <symbol>DEJAGNU</symbol> to the name of the file. This is also
778 refered to as the ``global'' config file.</para>
780 <para>Any directory containing a configured test suite also has a
781 local <filename>site.exp</filename>, capturing configuration values
782 specific to the tool under test. Since <command>runtest</command>
783 loads these values last, the individual test configuration can
784 either rely on and use, or override, any of the global values from
785 the global <filename>site.exp</filename> file.</para>
787 <para>You can usually generate or update the testsuite's local
788 <filename>site.exp</filename> by typing <command>make
789 site.exp</command> in the test suite directory, after the test
790 suite is configured.</para>
792 <para>You can also have a file in your home directory called
793 <filename>.dejagnurc</filename>. This gets loaded first before the
794 other config files. Usually this is used for personal stuff, like
795 setting the <symbol>all_flag</symbol> so all the output gets
796 printed, or your own verbosity levels. This file is usually
797 restricted to setting command line options.</para>
799 <para>You can further override the default values in a
800 user-editable section of any <filename>site.exp</filename>, or by
801 setting variables on the <command>runtest</command> command
802 line.</para>
804 <sect1 id=local xreflabel="Local Config File">
805 <title>Local Config File</title>
807 <para>It is usually more convenient to keep these <emphasis>manual
808 overrides</emphasis> in the <filename>site.exp</filename>
809 local to each test directory, rather than in the global
810 <filename>site.exp</filename> in the installed DejaGnu
811 library. This file is mostly for supplying tool specific info
812 that is required by the test suite.</para>
814 <para>All local <filename>site.exp</filename> files have
815 two sections, separated by comment text. The first section is
816 the part that is generated by <command>make</command>. It is
817 essentially a collection of Tcl variable definitions based on
818 <filename>Makefile</filename> environment variables. Since they
819 are generated by <command>make</command>, they contain the
820 values as specified by <command>configure</command>. (You can
821 also customize these values by using the <option>--site</option>
822 option to <command>configure</command>.) In particular, this
823 section contains the <filename>Makefile</filename>
824 variables for host and target configuration data. Do not edit
825 this first section; if you do, your changes are replaced next
826 time you run <command>make</command>.</para>
828 <example>
829 <title>The first section starts with</title>
831 <programlisting>
832 ## these variables are automatically generated by make ##
833 # Do not edit here. If you wish to override these values
834 # add them to the last section
835 </programlisting>
836 </example>
838 <para>In the second section, you can override any default values
839 (locally to DejaGnu) for all the variables. The second section
840 can also contain your preferred defaults for all the command
841 line options to <command>runtest</command>. This allows you to
842 easily customize <command>runtest</command> for your preferences
843 in each configured test-suite tree, so that you need not type
844 options repeatedly on the command line. (The second section may
845 also be empty, if you do not wish to override any defaults.)</para>
847 <example>
848 <title>The first section ends with this line</title>
850 <programlisting>
851 ## All variables above are generated by configure. Do Not Edit ##
852 </programlisting>
853 </example>
855 <para>You can make any changes under this line. If you wish to
856 redefine a variable in the top section, then just put a
857 duplicate value in this second section. Usually the values
858 defined in this config file are related to the configuration of
859 the test run. This is the ideal place to set the variables
860 <symbol>host_triplet</symbol>, <symbol>build_triplet</symbol>,
861 <symbol>target_triplet</symbol>. All other variables are tool
862 dependant. ie for testing a compiler, the value for
863 <symbol>CC</symbol> might be set to a freshly built binary, as
864 opposed to one in the user's path.</para>
866 <para>Here's an example local site.exp file, as used for
867 <productname>GCC/G++</productname> testing.</para>
869 <example>
870 <title>Local Config File</title>
872 <programlisting>
873 ## these variables are automatically generated by make ##
874 # Do not edit here. If you wish to override these values
875 # add them to the last section
876 set rootme "/build/devo-builds/i586-pc-linux-gnulibc1/gcc"
877 set host_triplet i586-pc-linux-gnulibc1
878 set build_triplet i586-pc-linux-gnulibc1
879 set target_triplet i586-pc-linux-gnulibc1
880 set target_alias i586-pc-linux-gnulibc1
881 set CFLAGS ""
882 set CXXFLAGS "-I/build/devo-builds/i586-pc-linux-gnulibc1/gcc/../libio -I$srcdir/../libg++/src -I$srcdir/../libio -I$srcdir/../libstdc++ -I$srcdir/../libstdc++/stl -L/build/devo-builds/i586-pc-linux-gnulibc1/gcc/../libg++ -L/build/devo-builds/i586-pc-linux-gnulibc1/gcc/../libstdc++"
883 append LDFLAGS " -L/build/devo-builds/i586-pc-linux-gnulibc1/gcc/../ld"
884 set tmpdir /build/devo-builds/i586-pc-linux-gnulibc1/gcc/testsuite
885 set srcdir "${srcdir}/testsuite"
886 ## All variables above are generated by configure. Do Not Edit ##
888 </programlisting>
889 </example>
891 <para>This file defines the required fields for a local config
892 file, namely the three config triplets, and the srcdir. It also
893 defines several other Tcl variables that are used exclusivly by
894 the GCC test suite. For most test cases, the CXXFLAGS and LDFLAGS
895 are supplied by DejaGnu itself for cross testing, but to test a
896 compiler, GCC needs to manipulate these itself.</para>
898 </sect1>
899 <sect1 id=global xreflabel="Global Config File">
900 <title>Global Config File</title>
902 <para>The master config file is where all the target specific
903 config variables get set for a whole site get set. The idea is
904 that for a centralized testing lab where people have to share a
905 target between multiple developers. There are settings for both
906 remote targets and remote hosts. Here's an example of a Master
907 Config File (also called the Global config file) for a
908 <emphasis>canadian cross</emphasis>. A canadian cross is when
909 you build and test a cross compiler on a machine other than the
910 one it's to be hosted on.</para>
912 <para>Here we have the config settings for our California
913 office. Note that all config values are site dependant. Here we
914 have two sets of values that we use for testing m68k-aout cross
915 compilers. As both of these target boards has a different
916 debugging protocol, we test on both of them in sequence.</para>
918 <example>
919 <title>Global Config file</title>
921 <programlisting>
923 # Make sure we look in the right place for the board description files.
924 if ![info exists boards_dir] {
925 set boards_dir {}
927 lappend boards_dir "/nfs/cygint/s1/cygnus/dejagnu/boards"
929 verbose "Global Config File: target_triplet is $target_triplet" 2
930 global target_list
932 case "$target_triplet" in {
933 { "native" } {
934 set target_list "unix"
936 { "sparc64-*elf" } {
937 set target_list "sparc64-sim"
939 { "mips-*elf" } {
940 set target_list "mips-sim wilma barney"
942 { "mips-lsi-elf" } {
943 set target_list "mips-lsi-sim{,soft-float,el}"
945 { "sh-*hms" } {
946 set target_list { "sh-hms-sim" "bloozy" }
949 </programlisting>
950 </example>
952 <para>In this case, we have support for several cross compilers,
953 that all run on this host. For testing on operating systems that
954 don't support Expect, DejaGnu can be run on the local build
955 machine, and it can connect to the remote host and run all the
956 tests for this cross compiler on that host. All the remote OS
957 requires is a working telnetd.</para>
959 <para>As you can see, all one does is set the variable
960 <symbol>target_list</symbol> to the list of targets and options to
961 test. The simple settings, like for
962 <emphasis>sparc64-elf</emphasis> only require setting the name of
963 the single board config file. The <emphasis>mips-elf</emphasis>
964 target is more complicated. Here it sets the list to three target
965 boards. One is the default mips target, and both
966 <emphasis>wilma</emphasis> <emphasis>barney</emphasis> are
967 symbolic names for other mips boards. Symbolic names are covered
968 in the <xref linkend=addboard> chapter. The more complicated
969 example is the one for <emphasis>mips-lsi-elf</emphasis>. This one
970 runs the tests with multiple iterations using all possible
971 combinations of the <option>--soft-float</option> and the
972 <option>--el</option> (little endian) option. Needless to say,
973 this last feature is mostly compiler specific.</para>
975 </sect1>
977 <sect1 id=boardconfig xreflabel="Board Config File">
978 <title>Board Config File</title>
980 <para>The board config file is where board specfic config data
981 is stored. A board config file contains all the higher-level
982 configuration settings. There is a rough inheritance scheme, where it is
983 possible to base a new board description file on an existing one. There
984 are also collections of custom procedures for common environments. For
985 more information on adding a new board config file, go to the <xref
986 linkend=addboard> chapter. </para>
988 <para>An example board config file for a GNU simulator is as
989 follows. <function>set_board_info</function> is a procedure that sets the
990 field name to the specified value. The procedures in square brackets
991 <emphasis>[]</emphasis> are <emphasis>helper procedures</emphasis>. Thes
992 are used to find parts of a tool chain required to build an executable
993 image that may reside in various locations. This is mostly of use for
994 when the startup code, the standard C lobraries, or the tool chain itself
995 is part of your build tree.</para>
997 <example>
998 <title>Board Config File</title>
1000 <programlisting>
1001 # This is a list of toolchains that are supported on this board.
1002 set_board_info target_install {sparc64-elf}
1004 # Load the generic configuration for this board. This will define any
1005 # routines needed by the tool to communicate with the board.
1006 load_generic_config "sim"
1008 # We need this for find_gcc and *_include_flags/*_link_flags.
1009 load_base_board_description "basic-sim"
1011 # Use long64 by default.
1012 process_multilib_options "long64"
1014 setup_sim sparc64
1016 # We only support newlib on this target. We assume that all multilib
1017 # options have been specified before we get here.
1018 set_board_info compiler "[find_gcc]"
1019 set_board_info cflags "[libgloss_include_flags] [newlib_include_flags]"
1020 set_board_info ldflags "[libgloss_link_flags] [newlib_link_flags]"
1021 # No linker script.
1022 set_board_info ldscript "";
1024 # Used by a few gcc.c-torture testcases to delimit how large the
1025 # stack can be.
1026 set_board_info gcc,stack_size 16384
1027 # The simulator doesn't return exit statuses and we need to indicate this
1028 # the standard GCC wrapper will work with this target.
1029 set_board_info needs_status_wrapper 1
1030 # We can't pass arguments to programs.
1031 set_board_info noargs 1
1032 </programlisting>
1033 </example>
1035 <para>There are five helper procedures used in this example. The first
1036 one, <function>find gcc</function> looks for a copy of the GNU compiler in
1037 your build tree, or it uses the one in your path. This will also return
1038 the proper transformed name for a cross compiler if you whole build tree
1039 is configured for one. The next helper procedures are
1040 <function>libgloss_include_flags</function> &
1041 <function>libgloss_link_flags</function>. These return the proper flags to
1042 compiler and link an executable image using <xref
1043 linkend=libgloss>, the GNU BSP (Board Support Package). The final
1044 procedures are <function>newlib_include_flag</function> &
1045 <function>newlib_include_flag</function>. These find the Newlib C
1046 library, which is a reentrant standard C library for embedded systems
1047 comprising of non GPL'd code.</para>
1049 </sect1>
1051 <sect1 id=releng xreflabel="Remote Host Testing">
1052 <title>Remote Host Testing</title>
1054 <note><para>Thanks to Dj Delorie for the original paper that
1055 this section is based on.</para></note>
1057 <para>DejaGnu also supports running the tests on a remote
1058 host. To set this up, the remote host needs an ftp server, and a
1059 telnet server. Currently foreign operating systems used as
1060 remote hosts are VxWorks, VRTX, Dos/Win3.1, MacOS, and
1061 win95/win98/NT.</para>
1063 <para>The recommended source for a win95/win98/NT based ftp
1064 server is to get IIS (either IIS 1 or Personal Web Server) from
1065 <ulink
1066 URL="http://www.microsoft.com">http://www.microsoft.com</ulink>.
1067 When you install it, make sure you install the FTP server - it's
1068 not selected by default. Go into the IIS manager and change the
1069 FTP server so that it does not allow anonymous ftp. Set the home
1070 directory to the root directory (i.e. c:\) of a suitable
1071 drive. Allow writing via ftp.</para>
1073 <para>It will create an account like IUSR_FOOBAR where foobar is
1074 the name of your machine. Go into the user editor and give that
1075 account a password that you don't mind hanging around in the
1076 clear (i.e. not the same as your admin or personal
1077 passwords). Also, add it to all the various permission groups.</para>
1079 <para>You'll also need a telnet server. For win95/win98/NT, go
1080 to the <ulink URL="http://ataman.com">Ataman</ulink> web site,
1081 pick up the Ataman Remote Logon Services for Windows, and
1082 install it. You can get started on the eval period anyway. Add
1083 IUSR_FOOBAR to the list of allowed users, set the HOME directory
1084 to be the same as the FTP default directory. Change the Mode
1085 prompt to simple.</para>
1087 <para>Ok, now you need to pick a directory name to do all the
1088 testing in. For the sake of this example, we'll call it piggy
1089 (i.e. c:\piggy). Create this directory.</para>
1091 <para>You'll need a unix machine. Create a directory for the
1092 scripts you'll need. For this example, we'll use
1093 /usr/local/swamp/testing. You'll need to have a source tree
1094 somewhere, say /usr/src/devo. Now, copy some files from
1095 releng's area in SV to your machine:</para>
1097 <example>
1098 <title>Remote host setup</title>
1100 <screen>
1101 cd /usr/local/swamp/testing
1102 mkdir boards
1103 scp darkstar.welcomehome.org:/dejagnu/cst/bin/MkTestDir .
1104 scp darkstar.welcomehome.org:/dejagnu/site.exp .
1105 scp darkstar.welcomehome.org:/dejagnu/boards/useless98r2.exp boards/foobar.exp
1106 export DEJAGNU=/usr/local/swamp/testing/site.exp
1108 </screen>
1109 </example>
1111 <para>You must edit the boards/foobar.exp file to reflect your
1112 machine; change the hostname (foobar.com), username
1113 (iusr_foobar), password, and ftp_directory (c:/piggy) to match
1114 what you selected.</para>
1116 <para>Edit the global <filename> site.exp</filename> to reflect your
1117 boards directory:</para>
1119 <example>
1120 <title>Add The Board Directory</title>
1122 <programlisting>
1123 lappend boards_dir "/usr/local/swamp/testing/boards"
1124 </programlisting>
1125 </example>
1127 <para>Now run MkTestDir, which is in the contrib
1128 directory. The first parameter is the toolchain prefix, the
1129 second is the location of your devo tree. If you are testing a
1130 cross compiler (ex: you have sh-hms-gcc.exe in your PATH on
1131 the PC), do something like this:</para>
1133 <example>
1134 <title>Setup Cross Remote Testing</title>
1136 <programlisting>
1137 ./MkTestDir sh-hms /usr/dejagnu/src/devo
1138 </programlisting>
1139 </example>
1141 <para>If you are testing a native PC compiler (ex: you have
1142 gcc.exe in your PATH on the PC), do this:</para>
1144 <example>
1145 <title>Setup Native Remote Testing</title>
1147 <programlisting>
1148 ./MkTestDir '' /usr/dejagnu/src/devo
1149 </programlisting>
1150 </example>
1152 <para>To test the setup, <command>ftp</command> to your PC
1153 using the username (iusr_foobar) and password you selected. CD
1154 to the test directory. Upload a file to the PC. Now telnet to
1155 your PC using the same username and password. CD to the test
1156 directory. Make sure the file is there. Type "set" and/or "gcc
1157 -v" (or sh-hms-gcc -v) and make sure the default PATH contains
1158 the installation you want to test.</para>
1160 <example>
1161 <title>Run Test Remotely</title>
1163 <programlisting>
1164 cd /usr/local/swamp/testing
1165 make -k -w check RUNTESTFLAGS="--host_board foobar --target_board foobar -v -v" > check.out 2>&1
1166 </programlisting>
1167 </example>
1169 <para>To run a specific test, use a command like this (for
1170 this example, you'd run this from the gcc directory that
1171 MkTestDir created):</para>
1173 <example>
1174 <title>Run a Test Remotely</title>
1176 <programlisting>
1177 make check RUNTESTFLAGS="--host_board sloth --target_board sloth -v compile.exp=921202-1.c"
1178 </programlisting>
1179 </example>
1181 <para>Note: if you are testing a cross-compiler, put in the
1182 correct target board. You'll also have to download more .exp
1183 files and modify them for your local configuration. The -v's
1184 are optional.</para>
1186 </sect1>
1188 <sect1 id=configfile xreflabel="Config File Values">
1189 <title>Config File Values</title>
1191 <para>DejaGnu uses a named array in Tcl to hold all the info for
1192 each machine. In the case of a canadian cross, this means host
1193 information as well as target information. The named array is
1194 called <symbol>target_info</symbol>, and it has two indices. The
1195 following fields are part of the array.</para>
1197 <sect2 id=optiondefs xreflabel="Option Variables">
1198 <title>Command Line Option Variables</title>
1200 <para>In the user editable second section of the <xref
1201 linkend=personal> you can not only override the configuration
1202 variables captured in the first section, but also specify
1203 default values for all on the <command>runtest</command>
1204 command line options. Save for <option>--debug</option>,
1205 <option>--help</option>, and <option>--version</option>, each
1206 command line option has an associated Tcl variable. Use the
1207 Tcl <command>set</command> command to specify a new default
1208 value (as for the configuration variables). The following
1209 table describes the correspondence between command line
1210 options and variables you can set in
1211 <filename>site.exp</filename>. <xref linkend=invoking>, for
1212 explanations of the command-line options.</para>
1214 <para><table frame=all rowsep=0 colsep=0>
1215 <title>Tcl Variables For Command Line Options</title>
1217 <tgroup cols=3 align="char" rowsep=1 colsep=0>
1218 <thead><row>
1219 <entry>runtest</entry><entry>Tcl</entry>
1220 <entry>option</entry><entry>variable</entry><entry>description</entry>
1221 </row></thead>
1222 <tbody>
1224 <row>
1225 <entry>--all</entry>
1226 <entry>all_flag</entry>
1227 <entry>display all test results if set</entry>
1228 </row>
1230 <row>
1231 <entry>--baud</entry>
1232 <entry>baud</entry>
1233 <entry>set the default baud rate to something other than
1234 9600.</entry>
1235 </row>
1237 <row>
1238 <entry>--connect</entry>
1239 <entry>connectmode</entry>
1240 <entry><command>rlogin</command>,
1241 <command>telnet</command>, <command>rsh</command>,
1242 <command>kermit</command>, <command>tip</command>, or
1243 <command>mondfe</command></entry>
1244 </row>
1246 <row>
1247 <entry>--outdir</entry>
1248 <entry>outdir</entry>
1249 <entry>directory for <filename>tool.sum</filename> and
1250 <filename>tool.log.</filename></entry>
1251 </row>
1253 <row>
1254 <entry>--objdir</entry>
1255 <entry>objdir</entry>
1256 <entry>directory for pre-compiled binaries</entry>
1257 </row>
1259 <row>
1260 <entry>--reboot</entry>
1261 <entry>reboot</entry>
1262 <entry>reboot the target if set to
1263 <emphasis>"1"</emphasis>; do not reboot if set to
1264 <emphasis>"0"</emphasis> (the default).</entry>
1265 </row>
1267 <row>
1268 <entry>--srcdir</entry>
1269 <entry>srcdir</entry>
1270 <entry>directory of test subdirectories</entry>
1271 </row>
1273 <row>
1274 <entry>--strace</entry>
1275 <entry>tracelevel</entry>
1276 <entry>a number: Tcl trace depth</entry>
1277 </row>
1279 <row>
1280 <entry>--tool</entry>
1281 <entry>tool</entry>
1282 <entry>name of tool to test; identifies init, test subdir</entry>
1283 </row>
1285 <row>
1286 <entry>--verbose</entry>
1287 <entry>verbose</entry>
1288 <entry>verbosity level. As option, use multiple times; as
1289 variable, set a number, 0 or greater.</entry>
1290 </row>
1292 <row>
1293 <entry>--target</entry>
1294 <entry>target_triplet</entry>
1295 <entry>The canonical configuration string for the target.</entry>
1296 </row>
1298 <row>
1299 <entry>--host</entry>
1300 <entry>host_triplet</entry>
1301 <entry>The canonical configuration string for the host.</entry>
1302 </row>
1304 <row>
1305 <entry>--build</entry>
1306 <entry>build_triplet</entry>
1307 <entry>The canonical configuration string for the build
1308 host.</entry>
1309 </row>
1311 <row>
1312 <entry>--mail</entry>
1313 <entry>address</entry>
1314 <entry>Email the output log to the specified address.</entry>
1315 </row>
1317 </tbody>
1318 </tgroup>
1319 </table>
1320 </para>
1322 </sect2>
1324 <sect2 id=personal xreflabel="Personal Config File">
1325 <title>Personal Config File</title>
1327 <para>The personal config file is used to customize
1328 <command>runtest's</command> behaviour for each person. It's
1329 typically used to set the user prefered setting for verbosity,
1330 and any experimental Tcl procedures. My personal
1331 <filename>~/.dejagnurc</filename> file looks like:</para>
1333 <example>
1334 <title>Personal Config File</title>
1336 <programlisting>
1337 set all_flag 1
1338 set RLOGIN /usr/ucb/rlogin
1339 set RSH /usr/local/sbin/ssh
1340 </programlisting>
1341 </example>
1343 <para>Here I set <symbol>all_flag</symbol> so I see all the test
1344 cases that PASS along with the ones that FAIL. I also set
1345 <symbol>RLOGIN</symbol> to the BSD version. I have
1346 <productname>Kerberos</productname> installed, and when I rlogin
1347 to a target board, it usually isn't supported. So I use the non
1348 secure version rather than the default that's in my path. I also
1349 set <symbol>RSH</symbol> to the <productname>SSH</productname>
1350 secure shell, as rsh is mostly used to test unix
1351 machines within a local network here.</para>
1353 </sect2>
1354 </sect1>
1356 </chapter>
1358 <chapter id=Extending xreflabel="Extending DejaGnu">
1359 <title>Extending DejaGnu</title>
1361 <sect1 id=addsuite xreflabel="Adding a new Test Suite">
1362 <title>Adding A New Test Suite</title>
1364 <para>The testsuite for a new tool should always be located in that tools
1365 source directory. DejaGnu require the directory be named
1366 <filename>testsuite</filename>. Under this directory, the test cases go
1367 in a subdirectory whose name begins with the tool name. For example, for
1368 a tool named <emphasis>flubber</emphasis>, each subdirectory containing
1369 testsuites must start with <emphasis>"flubber."</emphasis>.</para>
1371 </sect1>
1373 <sect1 id=addtool xreflabel="Adding A New Tool">
1374 <title>Adding A New Tool</title>
1376 <para>In general, the best way to learn how to write (code or even prose)
1377 is to read something similar. This principle applies to test cases and
1378 to test suites. Unfortunately, well-established test suites have a way
1379 of developing their own conventions: as test writers become more
1380 experienced with DejaGnu and with Tcl, they accumulate more utilities,
1381 and take advantage of more and more features of
1382 <productname>Expect</productname> and <productname>Tcl</productname> in
1383 general.</para>
1385 <para>Inspecting such established test suites may make the prospect of
1386 creating an entirely new test suite appear overwhelming. Nevertheless,
1387 it is quite straightforward to get a new test suite going.</para>
1389 <para>There is one test suite that is guaranteed not to grow more
1390 elaborate over time: both it and the tool it tests were created expressly
1391 to illustrate what it takes to get started with DejaGnu. The
1392 <filename>example/</filename> directory of the DejaGnu distribution
1393 contains both an interactive tool called <command>calc</command>, and a
1394 test suite for it. Reading this test suite, and experimenting with it,
1395 is a good way to supplement the information in this section. (Thanks to
1396 Robert Lupton for creating calc and its test suite---and also the first
1397 version of this section of the manual!)</para>
1399 <para>To help orient you further in this task, here is an outline of the
1400 steps to begin building a test suite for a program example.</para>
1402 <itemizedlist mark=bullet>
1404 <listitem><para>Create or select a directory to contain your new
1405 collection of tests. Change into that directory (shown here as
1406 <filename>testsuite</filename>):</para>
1408 <para>Create a <filename>configure.in</filename> file in this directory,
1409 to control configuration-dependent choices for your tests. So far as
1410 DejaGnu is concerned, the important thing is to set a value for the
1411 variable <symbol>target_abbrev</symbol>; this value is the link to the
1412 init file you will write soon. (For simplicity, we assume the
1413 environment is Unix, and use <emphasis>unix</emphasis> as the
1414 value.)</para>
1416 <para>What else is needed in <filename>configure.in</filename> depends on
1417 the requirements of your tool, your intended test environments, and which
1418 configure system you use. This example is a minimal configure.in for use
1419 with <productname>GNU Autoconf</productname>. </para></listitem>
1421 <listitem><para>Create <filename>Makefile.in</filename> (if you are using
1422 Autoconf), or <filename>Makefile.am</filename>(if you are using
1423 Automake), the source file used by configure to build your
1424 <filename>Makefile</filename>. If you are using GNU Automake.just add the
1425 keyword <emphasis>dejagnu</emphasis> to the
1426 <emphasis>AUTOMAKE_OPTIONS</emphasis> variable in your
1427 <filename>Makefile.am</filename> file. This will add all the Makefile
1428 support needed to run DejaGnu, and support the <xref linkend=makecheck>
1429 target.</para>
1431 <para>You also need to include two targets important to DejaGnu:
1432 <emphasis>check</emphasis>, to run the tests, and
1433 <emphasis>site.exp</emphasis>, to set up the Tcl copies of
1434 configuration-dependent values. This is called the <xref linkend=local>
1435 The check target must run the <command>runtest</command> program to
1436 execute the tests.</para>
1438 <para>The <filename>site.exp</filename> target should usually set up
1439 (among other things) the $tool variable for the name of your program. If
1440 the local site.exp file is setup correctly, it is possible to execute the
1441 tests by merely typing <command>runtest</command> on the command
1442 line.</para>
1444 <example>
1445 <title>Sample Makefile.in Fragment</title>
1447 <programlisting>
1448 # Look for a local version of DejaGnu, otherwise use one in the path
1449 RUNTEST = `if test -f $(top_srcdir)/../dejagnu/runtest; then \
1450 echo $(top_srcdir) ../dejagnu/runtest; \
1451 else \
1452 echo runtest; \
1455 # The flags to pass to runtest
1456 RUNTESTFLAGS =
1458 # Execute the tests
1459 check: site.exp all
1460 $(RUNTEST) $(RUNTESTFLAGS) \
1461 --tool <symbol>${example}</symbol> --srcdir $(srcdir)
1463 # Make the local config file
1464 site.exp: ./config.status Makefile
1465 @echo "Making a new config file..."
1466 -@rm -f ./tmp?
1467 @touch site.exp
1469 -@mv site.exp site.bak
1470 @echo "## these variables are automatically\
1471 generated by make ##" > ./tmp0
1472 @echo "# Do not edit here. If you wish to\
1473 override these values" >> ./tmp0
1474 @echo "# add them to the last section" >> ./tmp0
1475 @echo "set host_os ${host_os}" >> ./tmp0
1476 @echo "set host_alias ${host_alias}" >> ./tmp0
1477 @echo "set host_cpu ${host_cpu}" >> ./tmp0
1478 @echo "set host_vendor ${host_vendor}" >> ./tmp0
1479 @echo "set target_os ${target_os}" >> ./tmp0
1480 @echo "set target_alias ${target_alias}" >> ./tmp0
1481 @echo "set target_cpu ${target_cpu}" >> ./tmp0
1482 @echo "set target_vendor ${target_vendor}" >> ./tmp0
1483 @echo "set host_triplet ${host_canonical}" >> ./tmp0
1484 @echo "set target_triplet ${target_canonical}">>./tmp0
1485 @echo "set tool binutils" >> ./tmp0
1486 @echo "set srcdir ${srcdir}" >> ./tmp0
1487 @echo "set objdir `pwd`" >> ./tmp0
1488 @echo "set <symbol>${examplename}</symbol> <symbol>${example}</symbol>" >> ./tmp0
1489 @echo "## All variables above are generated by\
1490 configure. Do Not Edit ##" >> ./tmp0
1491 @cat ./tmp0 > site.exp
1492 @sed < site.bak \
1493 -e '1,/^## All variables above are.*##/ d' \
1494 >> site.exp
1495 -@rm -f ./tmp?
1497 </programlisting>
1498 </example>
1499 </listitem>
1501 <listitem><para>Create a directory (in <filename>testsuite</filename>)
1502 called <filename>config</filename>. Make a <emphasis>Tool Init
1503 File</emphasis> in this directory. Its name must start with the
1504 <symbol>target_abbrev</symbol> value, or be named
1505 <filename>default.exp</filename> so call it
1506 <filename>config/unix.exp</filename> for our Unix based example. This
1507 is the file that contains the target-dependent procedures.
1508 Fortunately, on Unix, most of them do not have to do very much in
1509 order for <command>runtest</command> to run.</para>
1511 <para>If the program being tested is not interactive, you can get
1512 away with this minimal <filename>unix.exp</filename> to begin
1513 with:</para>
1515 <example>
1516 <title>Simple Batch Program Tool Init File</title>
1518 <programlisting>
1520 proc foo_exit {} {}
1521 proc foo_version {} {}
1523 </programlisting>
1524 </example>
1526 <para>If the program being tested is interactive, however, you might
1527 as well define a <emphasis>start</emphasis> routine and invoke it by
1528 using an init file like this:</para>
1530 <example>
1531 <title>Simple Interactive Program Tool Init File</title>
1533 <programlisting>
1535 proc foo_exit {} {}
1536 proc foo_version {} {}
1538 proc foo_start {} {
1539 global ${examplename}
1540 spawn ${examplename}
1541 expect {
1542 -re "" {}
1546 # Start the program running we want to test
1547 foo_start
1549 </programlisting>
1550 </example>
1551 </listitem>
1553 <listitem><para>Create a directory whose name begins with your tool's
1554 name, to contain tests. For example, if your tool's name is
1555 <emphasis>gcc</emphasis>, then the directories all need to start with
1556 <emphasis>"gcc."</emphasis>.</para></listitem>
1558 <listitem><para>Create a sample test file. Its name must end with
1559 <filename>.exp</filename>. You can use
1560 <filename>first-try.exp</filename>. To begin with, just write there a
1561 line of Tcl code to issue a message.</para>
1563 <example>
1564 <title>Testing A New Tool Config</title>
1566 <programlisting>
1568 send_user "Testing: one, two...\n"
1570 </programlisting>
1571 </example>
1572 </listitem>
1574 <listitem><para>Back in the <filename>testsuite</filename> (top
1575 level) directory, run <command>configure</command>. Typically you do
1576 this while in the build directory. You may have to specify more of a
1577 path, if a suitable configure is not available in your execution
1578 path.</para></listitem>
1580 <listitem><para>e now ready to triumphantly type <command>make
1581 check</command> or <command>runtest</command>. You should see
1582 something like this:</para>
1584 <example>
1585 <title>Example Test Case Run</title>
1587 <screen>
1588 Test Run By rhl on Fri Jan 29 16:25:44 EST 1993
1590 === example tests ===
1592 Running ./example.0/first-try.exp ...
1593 Testing: one, two...
1595 === example Summary ===
1597 </screen>
1598 </example>
1600 <para>There is no output in the summary, because so far the example
1601 does not call any of the procedures that establish a test
1602 outcome.</para></listitem>
1604 <listitem><para>Write some real tests. For an interactive tool, you
1605 should probably write a real exit routine in fairly short order. In
1606 any case, you should also write a real version routine
1607 soon. </para></listitem>
1609 </itemizedlist>
1611 </sect1>
1613 <sect1 id=addtarget xreflabel="Adding A New Target">
1614 <title>Adding A New Target</title>
1616 <para>DejaGnu has some additional requirements for target support, beyond
1617 the general-purpose provisions of configure. DejaGnu must actively
1618 communicate with the target, rather than simply generating or managing
1619 code for the target architecture. Therefore, each tool requires an
1620 initialization module for each target. For new targets, you must supply
1621 a few Tcl procedures to adapt DejaGnu to the target. This permits
1622 DejaGnu itself to remain target independent.</para>
1624 <para>Usually the best way to write a new initialization module is to
1625 edit an existing initialization module; some trial and error will be
1626 required. If necessary, you can use the @samp{--debug} option to see what
1627 is really going on.</para>
1629 <para>When you code an initialization module, be generous in printing
1630 information controlled by the <function>verbose</function>
1631 procedure.</para>
1633 <para>For cross targets, most of the work is in getting the
1634 communications right. Communications code (for several situations
1635 involving IP networks or serial lines) is available in a DejaGnu library
1636 file.</para>
1638 <para>If you suspect a communication problem, try running the connection
1639 interactively from <productname>Expect</productname>. (There are three
1640 ways of running <productname>Expect</productname> as an interactive
1641 interpreter. You can run <productname>Expect</productname> with no
1642 arguments, and control it completely interactively; or you can use
1643 <command>expect -i</command> together with other command-line options and
1644 arguments; or you can run the command <command>interpreter</command> from
1645 any <productname>Expect</productname> procedure. Use
1646 <command>return</command> to get back to the calling procedure (if any),
1647 or <command>return -tcl</command> to make the calling procedure itself
1648 return to its caller; use <command>exi</command>t or end-of-file to leave
1649 Expect altogether.) Run the program whose name is recorded in
1650 <symbol>$connectmode</symbol>, with the arguments in
1651 <symbol>$targetname</symbol>, to establish a connection. You should at
1652 least be able to get a prompt from any target that is physically
1653 connected.</para>
1655 </sect1>
1657 <sect1 id=addboard xreflabel="Adding A New Board">
1658 <title>Adding A New Board</title>
1660 <para>Adding a new board consists of creating a new board config
1661 file. Examples are in
1662 <filename>dejagnu/baseboards</filename>. Usually to make a new
1663 board file, it's easiest to copy an existing one. It is also
1664 possible to have your file be based on a
1665 <emphasis>baseboard</emphasis> file with only one or two
1666 changes needed. Typically, this can be as simple as just
1667 changing the linker script. Once the new baseboard file is done,
1668 add it to the <symbol>boards_DATA</symbol> list in the
1669 <filename>dejagnu/baseboards/Makefile.am</filename>, and regenerate the
1670 Makefile.in using automake. Then just rebuild and install DejaGnu. You
1671 can test it by:</para>
1673 <para>There is a crude inheritance scheme going on with board files, so
1674 you can include one board file into another, The two main procedures used
1675 to do this are <function>load_generic_config</function> and
1676 <function>load_base_board_description</function>. The generic config file
1677 contains other procedures used for a certain class of target. The
1678 board description file is where the board specfic settings go. Commonly
1679 there are similar target environments with just different
1680 processors.</para>
1682 <example>
1683 <title>Testing a New Board Config File</title>
1685 <screen>
1686 make check RUNTESTFLAGS="--target_board=<emphasis>newboardfile</emphasis>".
1687 </screen>
1688 </example>
1690 <para>Here's an example of a board config file. There are
1691 several <emphasis>helper procedures</emphasis> used in this
1692 example. A helper procedure is one that look for a tool of files
1693 in commonly installed locations. These are mostly used when
1694 testing in the build tree, because the executables to be tested
1695 are in the same tree as the new dejagnu files. The helper
1696 procedures are the ones in square braces
1697 <emphasis>[]</emphasis>, which is the Tcl execution characters.</para>
1699 <example>
1700 <title>Example Board Config File</title>
1702 <programlisting>
1704 # Load the generic configuration for this board. This will define a basic
1705 # set of routines needed by the tool to communicate with the board.
1706 load_generic_config "sim"
1708 # basic-sim.exp is a basic description for the standard Cygnus simulator.
1709 load_base_board_description "basic-sim"
1711 # The compiler used to build for this board. This has *nothing* to do
1712 # with what compiler is tested if we're testing gcc.
1713 set_board_info compiler "[find_gcc]"
1715 # We only support newlib on this target.
1716 # However, we include libgloss so we can find the linker scripts.
1717 set_board_info cflags "[newlib_include_flags] [libgloss_include_flags]"
1718 set_board_info ldflags "[newlib_link_flags]"
1720 # No linker script for this board.
1721 set_board_info ldscript "-Tsim.ld";
1723 # The simulator doesn't return exit statuses and we need to indicate this.
1724 set_board_info needs_status_wrapper 1
1726 # Can't pass arguments to this target.
1727 set_board_info noargs 1
1729 # No signals.
1730 set_board_info gdb,nosignals 1
1732 # And it can't call functions.
1733 set_board_info gdb,cannot_call_functions 1
1735 </programlisting>
1736 </example>
1738 </sect1>
1740 <sect1 id=boarddefs xreflabel="Board File Values">
1741 <title>Board Config File Values</title>
1743 <para>These fields are all in the <symbol>board_info</symbol> These are
1744 all set by using the <function>set_board_info</function> procedure. The
1745 parameters are the field name, followed by the value to set the field
1746 to.</para>
1748 <para><table frame=all rowsep=0 colsep=0>
1749 <title>Common Board Info Fields</title>
1751 <tgroup cols=3 align="char" rowsep=1 colsep=0>
1752 <thead><row>
1753 <entry>Field</entry>
1754 <entry>Sample Value</entry>
1755 <entry>Description</entry>
1756 </row></thead>
1757 <tbody>
1759 <row>
1760 <entry>compiler</entry>
1761 <entry>"[find_gcc]"</entry>
1762 <entry>The path to the compiler to use.</entry>
1763 </row>
1765 <row>
1766 <entry>cflags</entry>
1767 <entry>"-mca"</entry>
1768 <entry>Compilation flags for the compiler.</entry>
1769 </row>
1771 <row>
1772 <entry>ldflags</entry>
1773 <entry>"[libgloss_link_flags] [newlib_link_flags]"</entry>
1774 <entry>Linking flags for the compiler.</entry>
1775 </row>
1777 <row>
1778 <entry>ldscript</entry>
1779 <entry>"-Wl,-Tidt.ld"</entry>
1780 <entry>The linker script to use when cross compiling.</entry>
1781 </row>
1783 <row>
1784 <entry>libs</entry>
1785 <entry>"-lgcc"</entry>
1786 <entry>Any additional libraries to link in.</entry>
1787 </row>
1789 <row>
1790 <entry>shell_prompt</entry>
1791 <entry>"cygmon>"</entry>
1792 <entry>The command prompt of the remote shell.</entry>
1793 </row>
1795 <row>
1796 <entry>hex_startaddr</entry>
1797 <entry>"0xa0020000"</entry>
1798 <entry>The Starting address as a string.</entry>
1799 </row>
1801 <row>
1802 <entry>start_addr</entry>
1803 <entry>0xa0008000</entry>
1804 <entry>The starting address as a value.</entry>
1805 </row>
1807 <row>
1808 <entry>startaddr</entry>
1809 <entry>"a0020000"</entry>
1810 <entry></entry>
1811 </row>
1813 <row>
1814 <entry>exit_statuses_bad</entry>
1815 <entry>1</entry>
1816 <entry>Whether there is an accurate exit status.</entry>
1817 </row>
1819 <row>
1820 <entry>reboot_delay</entry>
1821 <entry>10</entry>
1822 <entry>The delay between power off and power on.</entry>
1823 </row>
1825 <row>
1826 <entry>unreliable</entry>
1827 <entry>1</entry>
1828 <entry>Whether communication with the board is unreliable.</entry>
1829 </row>
1831 <row>
1832 <entry>sim</entry>
1833 <entry>[find_sim]</entry>
1834 <entry>The path to the simulator to use.</entry>
1835 </row>
1837 <row>
1838 <entry>objcopy</entry>
1839 <entry>$tempfil</entry>
1840 <entry>The path to the <command>objcopy</command> program.</entry>
1841 </row>
1843 <row>
1844 <entry>support_libs</entry>
1845 <entry>"${prefix_dir}/i386-coff/"</entry>
1846 <entry>Support libraries needed for cross compiling.</entry>
1847 </row>
1849 <row>
1850 <entry>addl_link_flags</entry>
1851 <entry>"-N"</entry>
1852 <entry>Additional link flags, rarely used.</entry>
1853 </row>
1855 </tbody>
1856 </tgroup>
1857 </table>
1858 </para>
1860 <para>These fields are used by the GCC and GDB tests, and are mostly
1861 only useful to somewhat trying to debug a new board file for one of
1862 these tools. Many of these are used only by a few testcases, and their
1863 purpose is esoteric. These are listed with sample values as a guide to
1864 better guessing if you need to change any of these.</para>
1866 <para><table frame=all rowsep=0 colsep=0>
1867 <title>Board Info Fields For GCC & GDB</title>
1869 <tgroup cols=3 align="char" rowsep=1 colsep=0>
1870 <thead><row>
1871 <entry>Field</entry>
1872 <entry>Sample Value</entry>
1873 <entry>Description</entry>
1874 </row></thead>
1875 <tbody>
1877 <row>
1878 <entry>strip</entry>
1879 <entry>$tempfile</entry>
1880 <entry>Strip the executable of symbols.</entry>
1881 </row>
1883 <row>
1884 <entry>gdb_load_offset</entry>
1885 <entry>"0x40050000"</entry>
1886 </row>
1888 <row>
1889 <entry>gdb_protocol</entry>
1890 <entry>"remote"</entry>
1891 <entry>The GDB debugging protocol to use.</entry>
1892 </row>
1894 <row>
1895 <entry>gdb_sect_offset</entry>
1896 <entry>"0x41000000";</entry>
1897 </row>
1899 <row>
1900 <entry>gdb_stub_ldscript</entry>
1901 <entry>"-Wl,-Teva-stub.ld"</entry>
1902 <entry>The linker script to use with a GDB stub.</entry>
1903 </row>
1905 <row>
1906 <entry>gdb_init_command</entry>
1907 <entry>"set mipsfpu none"</entry>
1908 </row>
1910 <row>
1911 <entry>gdb,cannot_call_functions</entry>
1912 <entry>1</entry>
1913 <entry>Whether GDB can call functions on the target,</entry>
1914 </row>
1916 <row>
1917 <entry>gdb,noargs</entry>
1918 <entry>1</entry>
1919 <entry>Whether the target can take command line arguments.</entry>
1920 </row>
1922 <row>
1923 <entry>gdb,nosignals</entry>
1924 <entry>1</entry>
1925 <entry>Whether there are signals on the target.</entry>
1926 </row>
1928 <row>
1929 <entry>gdb,short_int</entry>
1930 <entry>1</entry>
1931 </row>
1933 <row>
1934 <entry>gdb,start_symbol</entry>
1935 <entry>"_start";</entry>
1936 <entry>The starting symbol in the executable.</entry>
1937 </row>
1939 <row>
1940 <entry>gdb,target_sim_options</entry>
1941 <entry>"-sparclite"</entry>
1942 <entry>Special options to pass to the simulator.</entry>
1943 </row>
1945 <row>
1946 <entry>gdb,timeout</entry>
1947 <entry>540</entry>
1948 <entry>Timeout value to use for remote communication.</entry>
1949 </row>
1951 <row>
1952 <entry>gdb_init_command</entry>
1953 <entry>"print/x \$fsr = 0x0"</entry>
1954 </row>
1956 <row>
1957 <entry>gdb_load_offset</entry>
1958 <entry>"0x12020000"</entry>
1959 </row>
1961 <row>
1962 <entry>gdb_opts</entry>
1963 <entry>"--command gdbinit"</entry>
1964 </row>
1966 <row>
1967 <entry>gdb_prompt</entry>
1968 <entry>"\\(gdb960\\)"</entry>
1969 <entry>The prompt GDB is using.</entry>
1970 </row>
1972 <row>
1973 <entry>gdb_run_command</entry>
1974 <entry>"jump start"</entry>
1975 </row>
1977 <row>
1978 <entry>gdb_stub_offset</entry>
1979 <entry>"0x12010000"</entry>
1980 </row>
1982 <row>
1983 <entry>use_gdb_stub</entry>
1984 <entry>1</entry>
1985 <entry>Whether to use a GDB stub.</entry>
1986 </row>
1988 <row>
1989 <entry>use_vma_offset</entry>
1990 <entry>1</entry>
1991 </row>
1993 <row>
1994 <entry>wrap_m68k_aout</entry>
1995 <entry>1</entry>
1996 </row>
1998 <row>
1999 <entry>gcc,no_label_values</entry>
2000 <entry>1</entry>
2001 </row>
2003 <row>
2004 <entry>gcc,no_trampolines</entry>
2005 <entry>1</entry>
2006 </row>
2008 <row>
2009 <entry>gcc,no_varargs</entry>
2010 <entry>1</entry>
2011 </row>
2013 <row>
2014 <entry>gcc,stack_size</entry>
2015 <entry>16384</entry>
2016 <entry>Stack size to use with some GCC testcases.</entry>
2017 </row>
2019 <row>
2020 <entry>ieee_multilib_flags</entry>
2021 <entry>"-mieee";</entry>
2022 </row>
2024 <row>
2025 <entry>is_simulator</entry>
2026 <entry>1</entry>
2027 </row>
2029 <row>
2030 <entry>needs_status_wrapper</entry>
2031 <entry>1</entry>
2032 </row>
2034 <row>
2035 <entry>no_double</entry>
2036 <entry>1</entry>
2037 </row>
2039 <row>
2040 <entry>no_long_long</entry>
2041 <entry>1</entry>
2042 </row>
2044 <row>
2045 <entry>noargs</entry>
2046 <entry>1</entry>
2047 </row>
2049 <row>
2050 <entry>nullstone,lib</entry>
2051 <entry>"mips-clock.c"</entry>
2052 </row>
2054 <row>
2055 <entry>nullstone,ticks_per_sec</entry>
2056 <entry>3782018</entry>
2057 </row>
2059 <row>
2060 <entry>sys_speed_value</entry>
2061 <entry>200</entry>
2062 </row>
2064 <row>
2065 <entry>target_install</entry>
2066 <entry>{sh-hms}</entry>
2067 </row>
2069 </tbody>
2070 </tgroup>
2071 </table>
2072 </para>
2074 </sect1>
2076 <sect1 id=writing xreflabel="Writing A Test Case">
2077 <title>Writing A Test Case</title>
2079 <para>The easiest way to prepare a new test case is to base it
2080 on an existing one for a similar situation. There are two major
2081 categories of tests: batch or interactive. Batch oriented tests
2082 are usually easier to write.</para>
2084 <para>The GCC tests are a good example of batch oriented tests.
2085 All GCC tests consist primarily of a call to a single common
2086 procedure, Since all the tests either have no output, or only
2087 have a few warning messages when successfully compiled. Any
2088 non-warning output is a test failure. All the C code needed is
2089 kept in the test directory. The test driver, written in Tcl,
2090 need only get a listing of all the C files in the directory, and
2091 compile them all using a generic procedure. This procedure and a
2092 few others supporting for these tests are kept in the library
2093 module <filename>lib/c-torture.exp</filename> in the GCC test
2094 suite. Most tests of this kind use very few
2095 <productname>expect</productname> features, and are coded almost
2096 purely in Tcl.</para>
2098 <para>Writing the complete suite of C tests, then, consisted of
2099 these steps:</para>
2101 <itemizedlist mark=bullet>
2102 <listitem><para>Copying all the C code into the test directory.
2103 These tests were based on the C-torture test created by Torbjorn
2104 Granlund (on behalf of the Free Software Foundation) for GCC
2105 development.</para></listitem>
2107 <listitem><para>Writing (and debugging) the generic Tcl procedures for
2108 compilation.</para></listitem>
2110 <listitem><para>Writing the simple test driver: its main task is to
2111 search the directory (using the Tcl procedure
2112 <emphasis>glob</emphasis> for filename expansion with wildcards)
2113 and call a Tcl procedure with each filename. It also checks for
2114 a few errors from the testing procedure.</para></listitem>
2115 </itemizedlist>
2117 <para>Testing interactive programs is intrinsically more
2118 complex. Tests for most interactive programs require some trial
2119 and error before they are complete.</para>
2121 <para>However, some interactive programs can be tested in a
2122 simple fashion reminiscent of batch tests. For example, prior
2123 to the creation of DejaGnu, the GDB distribution already
2124 included a wide-ranging testing procedure. This procedure was
2125 very robust, and had already undergone much more debugging and
2126 error checking than many recent DejaGnu test cases.
2127 Accordingly, the best approach was simply to encapsulate the
2128 existing GDB tests, for reporting purposes. Thereafter, new GDB
2129 tests built up a family of Tcl procedures specialized for GDB
2130 testing.</para>
2132 </sect1>
2134 <sect1 id=debugging xreflabel="Debugging A Test Case">
2135 <title>Debugging A Test Case</title>
2137 <para>These are the kinds of debugging information available
2138 from DejaGnu:</para>
2140 <itemizedlist mark=bullet>
2142 <listitem><para>Output controlled by test scripts themselves,
2143 explicitly allowed for by the test author. This kind of
2144 debugging output appears in the detailed output recorded in the
2145 DejaGnu log file. To do the same for new tests, use the
2146 <command>verbose</command> procedure (which in turn uses the
2147 variable also called <emphasis>verbose</emphasis>) to control
2148 how much output to generate. This will make it easier for other
2149 people running the test to debug it if necessary. Whenever
2150 possible, if <emphasis>$verbose</emphasis> is
2151 <emphasis>0</emphasis>, there should be no output other than the
2152 output from <emphasis>pass</emphasis>,
2153 <emphasis>fail</emphasis>, <emphasis>error</emphasis>, and
2154 <emphasis>warning</emphasis>. Then, to whatever extent is
2155 appropriate for the particular test, allow successively higher
2156 values of <emphasis>$verbose</emphasis> to generate more
2157 information. Be kind to other programmers who use your tests:
2158 provide for a lot of debugging information.</para></listitem>
2160 <listitem><para>Output from the internal debugging functions of
2161 Tcl and <productname>Expect</productname>. There is a command
2162 line options for each; both forms of debugging output are
2163 recorded in the file <filename>dbg.log</filename> in the current
2164 directory.</para>
2166 <para>Use <option>--debug</option> for information from the
2167 expect level; it generates displays of the expect attempts to
2168 match the tool output with the patterns specified. This output
2169 can be very helpful while developing test scripts, since it
2170 shows precisely the characters received. Iterating between the
2171 latest attempt at a new test script and the corresponding
2172 <filename>dbg.log</filename> can allow you to create the final
2173 patterns by ``cut and paste''. This is sometimes the best way
2174 to write a test case.</para></listitem>
2176 <listitem><para>Use <option>--strace</option> to see more
2177 detail at the Tcl level; this shows how Tcl procedure
2178 definitions expand, as they execute. The associated number
2179 controls the depth of definitions expanded.</para></listitem>
2181 <listitem><para>Finally, if the value of
2182 <emphasis>verbose</emphasis> is 3 or greater,DejaGnu turns on
2183 the expect command <command>log_user</command>. This command
2184 prints all expect actions to the expect standard output, to the
2185 detailed log file, and (if <option>--debug</option> is on) to
2186 <filename>dbg.log</filename>.</para></listitem>
2187 </itemizedlist>
2189 </sect1>
2191 <sect1 id=adding xreflabel="Adding A Test Case To A Test Suite">
2192 <title>Adding A Test Case To A Test Suite.</title>
2194 <para>There are two slightly different ways to add a test
2195 case. One is to add the test case to an existing directory. The
2196 other is to create a new directory to hold your test. The
2197 existing test directories represent several styles of testing,
2198 all of which are slightly different; examine the directories for
2199 the tool of interest to see which (if any) is most suitable.</para>
2201 <para>Adding a GCC test can be very simple: just add the C code
2202 to any directory beginning with <filename>gcc</filename>. and it
2203 runs on the next <programlisting>runtest --tool
2204 gcc</programlisting>.</para>
2206 <para>To add a test to GDB, first add any source code you will
2207 need to the test directory. Then you can either create a new
2208 expect file, or add your test to an existing one (any
2209 file with a <emphasis>.exp</emphasis> suffix). Creating a new
2210 .exp file is probably a better idea if the test is significantly
2211 different from existing tests. Adding it as a separate file also
2212 makes upgrading easier. If the C code has to be already compiled
2213 before the test will run, then you'll have to add it to the
2214 <filename>Makefile.in</filename> file for that test directory,
2215 then run <command>configure</command> and
2216 <command>make</command>.</para>
2218 <para>Adding a test by creating a new directory is very
2219 similar:</para>
2221 <itemizedlist mark=bullet>
2223 <listitem><para>Create the new directory. All subdirectory names
2224 begin with the name of the tool to test; e.g. G++ tests might be
2225 in a directory called <filename>g++.other</filename>. There can
2226 be multiple test directories that start with the same tool name
2227 (such as <emphasis>g++</emphasis>).</para></listitem>
2229 <listitem><para>Add the new directory name to the
2230 <symbol>configdirs</symbol> definition in the
2231 <filename>configure.in</filename> file for the test suite
2232 directory. This way when <command>make</command> and
2233 <command>configure</command> next run, they include the new
2234 directory.</para></listitem>
2236 <listitem><para>Add the new test case to the directory, as
2237 above. </para></listitem>
2239 <listitem><para>To add support in the new directory for
2240 configure and make, you must also create a
2241 <filename>Makefile.in</filename> and a
2242 <filename>configure.in</filename>.</para></listitem>
2243 </itemizedlist>
2245 </sect1>
2247 <sect1 id=hints xreflabel="Hints On Writing A Test Case">
2248 <title>Hints On Writing A Test Case</title>
2250 <para>It is safest to write patterns that match all the output
2251 generated by the tested program; this is called closure.
2252 If a pattern does not match the entire output, any output that
2253 remains will be examined by the next <command>expect</command>
2254 command. In this situation, the precise boundary that determines
2255 which <command>expect</command> command sees what is very
2256 sensitive to timing between the Expect task and the task running
2257 the tested tool. As a result, the test may sometimes appear to
2258 work, but is likely to have unpredictable results. (This problem
2259 is particularly likely for interactive tools, but can also
2260 affect batch tools---especially for tests that take a long time
2261 to finish.) The best way to ensure closure is to use the
2262 <option>-re</option> option for the <command>expect</command>
2263 command to write the pattern as a full regular expressions; then
2264 you can match the end of output using a <emphasis>$</emphasis>.
2265 It is also a good idea to write patterns that match all
2266 available output by using <emphasis>.*\</emphasis> after the
2267 text of interest; this will also match any intervening blank
2268 lines. Sometimes an alternative is to match end of line using
2269 <emphasis>\r</emphasis> or <emphasis>\n</emphasis>, but this is
2270 usually too dependent on terminal settings.</para>
2272 <para>Always escape punctuation, such as <emphasis>(</emphasis>
2273 or <emphasis>&quot</emphasis>, in your patterns; for example, write
2274 <emphasis>\(</emphasis>. If you forget to escape punctuation,
2275 you will usually see an error message like <programlisting>extra
2276 characters after close-quote.</programlisting></para>
2278 <para>If you have trouble understanding why a pattern does not
2279 match the program output, try using the <option>--debug</option>
2280 option to <command>runtest</command>, and examine the debug log
2281 carefully.</para>
2283 <para>Be careful not to neglect output generated by setup rather
2284 than by the interesting parts of a test case. For example,
2285 while testing GDB, I issue a send <emphasis>set height
2286 0\n</emphasis> command. The purpose is simply to make sure GDB
2287 never calls a paging program. The <emphasis>set
2288 height</emphasis> command in GDB does not generate any
2289 output; but running any command makes GDB issue a new
2290 <emphasis>(gdb) </emphasis> prompt. If there were no
2291 <command>expect</command> command to match this prompt, the
2292 output <emphasis>(gdb) </emphasis> begins the text seen by the
2293 next <command>expect</command> command---which might make that
2294 pattern fail to match.</para>
2296 <para>To preserve basic sanity, I also recommended that no test
2297 ever pass if there was any kind of problem in the test case. To
2298 take an extreme case, tests that pass even when the tool will
2299 not spawn are misleading. Ideally, a test in this sort of
2300 situation should not fail either. Instead, print an error
2301 message by calling one of the DejaGnu procedures
2302 <command>error</command> or <command>warning</command>.</para>
2304 </sect1>
2306 <sect1 id=tvariables xreflabel="Test Case Variables">
2307 <title>Special variables used by test cases.</title>
2309 <para>There are special variables used by test cases. These contain
2310 other information from DejaGnu. Your test cases can use these variables,
2311 with conventional meanings (as well as the variables saved in
2312 <filename>site.exp</filename>. You can use the value of these variables,
2313 but they should never be changed.</para>
2315 <variablelist>
2316 <varlistentry>
2317 <term>$prms_id</term>
2318 <listitem><para>The tracking system (e.g. GNATS) number identifying
2319 a corresponding bugreport. (<emphasis>0</emphasis>} if you do not
2320 specify it in the test script.)</para></listitem>
2321 </varlistentry>
2323 <varlistentry>
2324 <term>$item bug_id</term>
2325 <listitem><para>An optional bug id; may reflect a bug
2326 identification from another organization. (<emphasis>0</emphasis>
2327 if you do not specify it.)</para></listitem>
2328 </varlistentry>
2330 <varlistentry>
2331 <term>$subdir</term>
2332 <listitem><para>The subdirectory for the current test
2333 case.</para></listitem>
2334 </varlistentry>
2336 <varlistentry>
2337 <term>$expect_out(buffer)</term>
2338 <listitem><para>The output from the last command. This is an
2339 internal variable set by Expect. More information can be found in
2340 the Expect manual.</para></listitem>
2341 </varlistentry>
2343 <varlistentry>
2344 <term>$exec_output</term>
2345 <listitem><para>This is the output from a
2346 <function>${tool}_load</function> command. This only applies to
2347 tools like GCC and GAS which produce an object file that must in
2348 turn be executed to complete a test.</para></listitem>
2349 </varlistentry>
2351 <varlistentry>
2352 <term>$comp_output</term>
2353 <listitem><para>This is the output from a
2354 <function>${tool}_start</function> command. This is conventionally
2355 used for batch oriented programs, like GCC and GAS, that may
2356 produce interesting output (warnings, errors) without further
2357 interaction.</para></listitem>
2358 </varlistentry>
2359 </variablelist>
2361 </sect1>
2363 </chapter>
2365 <!-- Keep this comment at the end of the file
2366 Local variables:
2367 mode: sgml
2368 sgml-omittag:t
2369 sgml-shorttag:t
2370 sgml-namecase-general:t
2371 sgml-general-insert-case:lower
2372 sgml-minimize-attributes:nil
2373 sgml-always-quote-attributes:t
2374 sgml-indent-step:1
2375 sgml-indent-data:nil
2376 sgml-parent-document:nil
2377 sgml-exposed-tags:nil
2378 sgml-local-catalogs:nil
2379 sgml-local-ecat-files:nil
2380 End: