OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [gdb/] [testsuite/] [gdb.gdbtk/] [README] - Blame information for rev 1767

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
                        The Insight Testsuite
2
                        ---------------------
3
                   Keith Seitz (keiths@cygnus.com)
4
                             May 1, 2001
5
 
6
RUNNING THE TESTSUITE
7
 
8
The Insight testsuite is run in much the same way that gdb's testsuites
9
are run. The one big difference is the environment variable GDB_DISPLAY,
10
which governs what display should be used for the tests.
11
 
12
When GDB_DISPLAY is not set in the user's environment, the Insight testsuite
13
will attempt to run Xvfb, an X server with a virtual frame buffer. Using
14
Xvfb, the testsuite can run without interuppting the user.
15
 
16
When Xvfb is not available, the testsuite will mark the Insight tests
17
"untested" and print out some appropriate warning to the testsuite log
18
file.
19
 
20
If GDB_DISPLAY is set in the user's environment, the testsuite will attempt
21
to use this display for the tests. If this display is a desktop display,
22
it is very likely that any interaction between the user and his desktop
23
will interfere with the tests. Some tests warp the cursor, i.e., they
24
force the mouse to move on the screen. If you don't want this to happen to
25
you, put Xvfb in your path.
26
 
27
On Cygwin systems, Xvfb is not supported. Only two choices are available in
28
this environment: run the testsuites using the desktop or do not run the
29
testsuite. To run the testsuite on Cygwin, just define the environment
30
variable GDB_DISPLAY to anything.
31
 
32
The examples below summarize the usage of the environment variable GDB_DISPLAY
33
on unix/X-Windows hosts and Cygwin hosts. In all examples, assume that DISPLAY
34
set to the local workstation's main display (:0).
35
 
36
To run the testsuite using Xvfb -- unix only (Xvfb must be in PATH):
37
$ make check
38
 
39
To run the testsuite using a given display (either the desktop or a peviously
40
started Xvfb):
41
$ GDB_DISPLAY=$DISPLAY make check
42
 
43
To run the testsuite on Cygwin:
44
$ GDB_DISPLAY=foo make check
45
 
46
 
47
TESTSUITE INFRASTRUCTURE
48
 
49
The rest of this document deals with writing tests for Insight. This reading
50
is only noteworthy for developers and contributors.
51
 
52
The Insight testsuite consists of two large portions of code: code which is
53
run in dejagnu and code which runs in Insight's built-in Tcl interpreter. Files
54
containing dejagnu code (those files ending in ".exp" in the testsuite directory)
55
are "glue code" between gdb's dejagnu testsuite and Insight's Tcl testsuite.
56
 
57
Dejagnu testsuite files are considered "drivers" for any particular set of
58
tests, since they allow dejagnu to control Insight's Tcl testsuite.
59
 
60
 
61
Dejagnu Testsuite Infrastructure
62
 
63
The dejagnu code is responsible for doing several things. Some of the more
64
important responsibilities include:
65
 
66
o Initializing the display
67
o Determining if tests should be run
68
o Results accounting
69
o Compiling testcases in various languages
70
o Repoting results to gdb's testsuite
71
 
72
There are various functions defined to facilitate the writing of tests. These
73
functions currently reside in gdb's gdb.exp (src/gdb/testsuite/lib/gdb.exp) and
74
include:
75
 
76
Pulic functions:
77
proc gdbtk_initialize_display {}
78
 
79
  gdbtk_initialize_display should be the first function called from the
80
  (dejagnu) test file. It initializes the DISPLAY variable on unix systems
81
  and determines (for all host systems) whether or not the testsuite should
82
  run. It returns 1 if the test should run. If tests should not run, it
83
  marks the test as "untested" and leaves a suitable message about why
84
  the test should not run. If gdbtk_initialize_display returns zero, a test
85
  should simply exit.
86
 
87
proc gdbtk_start {test}
88
 
89
  This function marks the start of a test and will execute Insight for
90
  testing. The TEST parameter should be the file name of the Tcl test
91
  file to load into Insight's Tcl interpreter. It returns a list of
92
  test results suitable for passing to gdbtk_done or gdbtk_analyze_results.
93
  See gdbtk_analyze_results for more information on the format of results.
94
 
95
  gdbtk_start is responsible for communicating target startup information
96
  to Insight, so that Insight's testsuite may be run on any target supported
97
  by gdb. It does this by setting several environment variables just before
98
  it starts Insight. These environment variables are:
99
 
100
  OBJDIR
101
    The object directory of the dejagnu testsuite (i.e.,
102
    objdir/gdb/testsuite).
103
  SRCDIR
104
    The dejagnu source directory in which the tests are located (i.e,
105
    src/gdb/testsuite)
106
  SUBDIR
107
    The dejagnu testsuite subdirectory for the test (i.e., gdb.gdbtk)
108
  GDBTK_LIBRARY
109
    The location of the Insight tcl library (i.e., src/gdb/gdbtk/library)
110
  TCL_LIBRARY
111
    The location of the Tcl library (i.e., src/tcl/library)
112
  TK_LIBRARY
113
    The location of the Tk library (i.e., src/tk/library)
114
  TIX_LIBRARY
115
    The location of the Tix library (i.e., src/tix/library)
116
  ITCL_LIBRARY
117
    The location fo the Itcl librarry (i.e., src/itcl/itcl/library)
118
  CYGNUS_GUI_LIBRARY
119
    The location of libgui (i.e., src/libgui/library)
120
  DEFS
121
    The location of the testsuite definitions file (i.e.,
122
    src/gdb/testsuite/gdb.gdbtk/defs)
123
 
124
  Note that *_LIBRARY and DEFS are converted to absolute tcl-style
125
  paths. On unix, this means that GDBTK_LIBRARY would point to, for example,
126
  /home/keiths/insight/src/gdb/gdbtk/library. On Cygwin it would point to
127
  C:/cygwin/home/keiths/insight/src/gdb/gdbtk/library. This is because of
128
  a descrepency between Cygwin's posix paths and Tcl's not-quite-posix
129
  paths.
130
 
131
proc gdbtk_analyze_results {results}
132
  This function translates the list of results in RESULTS into dejagnu
133
  results, reporting the number of failures, errors, passes, and expected
134
  failures and passes. It currently does not deal with "untested" and other
135
  test statuses from dejagnu since Insight's tcl testsuite does not
136
  issue such results.
137
 
138
  The format of the results expected by gdbtk_analyze_results is simple:
139
  it is a list of {status name description msg}. "status" is the execution
140
  status of one of the tcl tests run. This can be "PASS", "FAIL", "ERROR",
141
  "XFAIL", or "XPASS".
142
 
143
  "name" is the name of the test, and it is reported in all testsuite
144
  results in dejagnu. This speeds location of the failing test. This
145
  "name" may also be given to Insight's testsuite, telling it to
146
  only run this test. See "do_tests" in Tcl Testsuite Infrastructure
147
  for more information.
148
 
149
  "description" is a textual description of the test given by "name".
150
 
151
  "msg" is currently not used.
152
 
153
proc gdbtk_done {{results {}}}
154
  gdbtk_done takes any RESULTS and passes it gdbtk_analyze_results for
155
  outputting to the dejagnu part of the testsuite. It may be called
156
  without an argument, in which case it will only terminate Xvfb if it
157
  was started. Tests must call gdbtk_done _once_ at the end of their
158
  test drivers.
159
 
160
Private functions:
161
proc _gdbtk_export_target_info
162
  This functin exports information about the target into the environment
163
  so that Insight's testsuite may run programs on any supported gdb
164
  target. This target information is passed into the Tcl testsuite
165
  via an environment variable, TARGET_INFO, which is really a Tcl array,
166
  i.e., the array is constructed in tcl and exported into the environment
167
  with Tcl's "array get" command).
168
 
169
  There are four elements to the array:
170
  TARGET_INFO(init)   - (optional) A list of commands to execute in gdb
171
                        to initialize the session. This usually includes
172
                        setting baud rates and remote protocol options.
173
  TARGET_INFO(target) - (required) The complete "target" command to connect
174
                        to the given target.
175
  TARGET_INFO(load)   - (optional) The complete "load" command to load an
176
                        executable into a target.
177
  TARGET_INFO(run)    - (required) The complete "run" command, sans arguments,
178
                        to start a process on the target. For remote targets,
179
                        this is usually just "continue".
180
 
181
proc _gdbtk_xvfb_init
182
  This procedure actually determines whether the an Insight test should
183
  run and what DISPLAY it should use for that test. It is called by
184
  gdbtk_initialize_display to do most of the dirty work.
185
 
186
  It has a simple heuristic: If GDB_DISPLAY is not set and Xvfb is available
187
  (on unix), it starts Xvfb, using the current process id as the screen number.
188
  If Xvfb is not available and GDB_DISPLAY was not set, it skips the tests.
189
 
190
proc _gdbtk_xvfb_exit
191
  _gdbtk_xvfb_exit will kill any previously started Xvfb.
192
 
193
Private globals:
194
global _xvfb_spawn_id
195
  This variable holds the spawn_id of any Xvfb process started
196
  by the testsuite (or it is left undefined).
197
 
198
global _using_windows
199
  A global variable which indicates whether the testsuite is running
200
  on cygwin. Unfortunately, as of writing, the global variable
201
  tcl_platform(platform) is "unix" on Cygwin, so it is not possible
202
  to rely on this for platform-dependent operations.
203
 
204
  Instead, this variable is set by gdbtk_initialize_display. The test
205
  it uses to determine if Cygwin is being used: it looks for the program
206
  cygpath in the PATH. Therefore, cygpath is REQUIRED to run the testsuite
207
  on Cygwin. (gdbtk_start also uses cygpath to determine Windows
208
  pathnames for Cygwin.)
209
 
210
 
211
Testsuite Driver Basics
212
 
213
Given the above interfaces for connecting Insight's Tcl testsuite and
214
gdb's dejagnu testsuite, the basic testsuite driver file should look
215
(minimally) like this:
216
 
217
File: mytest.exp
218
1   if {[gdbtk_initialize_display]} {
219
2     # We found a display to use
220
3     gdb_exit;   # Make sure any previous gdb is gone
221
4     set results [gdbtk_start mytest.test]
222
5
223
6     # Done!
224
7     gdbtk_done [split $results \n]
225
8   }
226
 
227
Line 1 calls gdbtk_initialize_display to ascertain whether there is a display
228
to use for the test. This could use an existing display (if GDB_DISPLAY is
229
set in the environment) or gdbk_initialize_display could startup an Xvfb
230
for use by the testsuite.
231
 
232
Line 3 forces any previously executing gdb to terminate.
233
 
234
Line 4 signals the start of the test run. "mytest.test" is the name of the
235
Tcl test file to execute in Insight's built-in Tcl interpreter. The output
236
of gdbtk_start_test is all of the results of the Tcl test from Insight, which
237
is subsequently passed to gdbk_analyze_results via gdbtk_done on Line 7.
238
 
239
Note how nothing happens if gdbtk_initialize_display returns false.
240
 
241
 
242
Tcl Testsuite Infrastructure
243
 
244
The heart of Insight's testsuite is its Tcl testsuite. It is these tests
245
which run directly in Insight's Tcl interpreter and allow test writers
246
access to Insight's internals. Tcl testsuite files have the filename suffix
247
".test" to distinguish them from their driver files, which end in ".exp".
248
 
249
The design of the Insight Tcl testsuite parallels Tcl's testsuite. It has
250
many powerful features, including the ability to run ANY test in a given
251
Tcl test file. See the description of utility routines below for more
252
information about running any set of tests from a file.
253
 
254
The bulk of the code implementing the Tcl testsuite infrastructure in
255
Insight is contained in the testsuite definitions file, "defs", located
256
in src/gdb/testsuite/gdb.gdbtk. This file contains routines necessary
257
to write tests for Insight.
258
 
259
Public functions:
260
proc gdbtk_read_defs {}
261
  This function, located in Insight's core Tcl library, attempts to load
262
  the testsuite definitions file. If it fails, it will either pop up
263
  a dialog box with the error (if running interactively) or it will
264
  print the error to stderr and exit (if running non-interactively).
265
 
266
  If successful, it will return true.
267
 
268
proc gdbtk_test_file {filename}
269
  This function is used to load the file given by FILENAME into
270
  Insight. It will automatically append ".exe" to any FILENAME
271
  on Cygwin-hosted systems.
272
 
273
  If successful, it will load the given file into Insight and
274
  return the output of gdb's file command. It will call "error"
275
  if it was succesful, therefore all calls to "gdbtk_test_file"
276
  should be called using "catch".
277
 
278
  Test authors should not use "gdb_cmd {file FILENAME}" to load
279
  files into gdb unless they are testing interface code between
280
  gdb and Insight.
281
 
282
proc gdbtk_test_run {{prog_args {}}}
283
  gdbtk_test_run runs the previoiusly loaded executable, passing
284
  the given arguments to the inferior. Like Insight's Run button,
285
  it will do whatever is necessary to get the executable running,
286
  including any target initialization (setting baud rate and remote
287
  protocol options), downloading the executable to the target, and
288
  finally starting execution.
289
 
290
  Test authors should NEVER use "gdb_cmd {run ARGUMENTS}" to run an
291
  executable. Doing so will insure that your tests will only run on
292
  a native debugger.
293
 
294
  It returns true if successful or false otherwise. It will report
295
  the error in a dialog box (if running interactively) or it will
296
  print the error to stderr.
297
 
298
proc gdbtk_test {name description script answer}
299
  This is Tcl testsuite equivalent of "expect". "name" is a canonical
300
  name of the test, usually of the form "shortname-major.minor". This is
301
  the name that is used when running selected tests from a given file.
302
  If "name" starts with an asterisk (*), it designates that the test
303
  is expected to fail.
304
 
305
  "description" is a short textual description of the test to help
306
  humans understand what it does.
307
 
308
  "script" is the actual test script to run. The result of this script
309
  will be compared against "answer" to determine if the test passed
310
  or failed.
311
 
312
  It calls gdbtk_print_verbose to print out the results to the terminal
313
  (if running interactively) or to the log file.
314
 
315
proc gdbtk_test_done {}
316
  gdbtk_test_done is called at the very end of all tcl tests. It is used
317
  to exit Insight and return control back to the dejagnu driver which
318
  started the tests.
319
 
320
proc gdbtk_dotests {file args}
321
  Obsolete.
322
 
323
proc do_test {{file {}} {verbose {}} {tests {}}}
324
  This procedure is used to invoke the Insight test(s) given in FILE
325
  which match the regular expression(s) in TESTS. This is invoked
326
  from Insight's console window to run tests interactively.
327
 
328
  VERBOSE sets the verbosity of the test run. When set to one,
329
  the testsuite will report all results in human readable form.
330
  When set  greater than one, it will print out results as a list,
331
  i.e., for passing to gdbtk_analyze_results. If zero, it will only
332
  print errors and failures in human readable form.
333
 
334
Public global variables:
335
objdir   - The objdir from dejagnu. See gdbtk_start for more information.
336
srcdir   - The srcdir from dejagnu. See gdbtk_start for more information.
337
test_ran - Indicates whether the last test ran or not. See example below.
338
 
339
Private functions:
340
proc gdbtk_test_error {desc}
341
  An internal function used to report a framework error in the testsuite.
342
  "desc" is a description of the error. It calls gdbtk_test_done.
343
 
344
proc gdbtk_print_verbose {status name description script code answer}
345
  A helper procedure to gdbtk_test which prints out results to the terminal
346
  or the logfile (or both or none).
347
 
348
Private global variables:
349
_test - An array used by the testsuite internals.
350
 
351
 
352
Tcl Test Basics
353
 
354
Armed with the basic interface described above, it is possible to test Insight's
355
GUI. Please do not write tests which attempt to imitate a user (moving the
356
mouse and clicking buttons), unless there is no other way to test the functionality.
357
 
358
The basic test file (with one test) looks like this (nonsensical one):
359
File: mytest.exp
360
1  if {![gdbtk_read_defs]} {
361
2    break
362
3  }
363
4
364
5  global objdir test_ran
365
6  set program [file join $objdir mytest]
366
7  if {[catch {gdbtk_test_file $program} t]} {
367
8    gdbtk_test_error "loading \"$program\": $t"
368
9  }
369
10 if {![gdbtk_test_run]} { exit 1 }
370
11
371
12 global foo
372
13 set foo 1
373
14
374
15 # Test:  mytest-1.1
375
16 # Desc:  check if a source window was created
376
17 gdbtk_test mytest-1.1 {source window created} {
377
18   set window [ManagedWin::find SrcWin]
378
19   llength $window
379
20   set foo 13
380
21 } {1}
381
22
382
23 if {$test_ran} {
383
24   set foo 1
384
25 }
385
26
386
27 # Done
387
28 gdbtk_test_done
388
 
389
Line 1 calls the Inisght function gdbtk_read_defs to read in the testsuite
390
definitions file.
391
 
392
Line 6 then specifies the name of a file (mytest) in the object directory
393
which is loaded into gdb on Line 7. If loading the file into Insight
394
failed, gdbtk_test_error is called to publish the error (and terminate the
395
test run for this file).
396
 
397
Line 10 runs the executable on the target, and exits if it was unable
398
to do so.
399
 
400
Line 13 simply sets a global variable foo to illustrate the purpose
401
of the global "test_ran". Before the test "mytest-1.1" runs, foo is set to
402
one. In order to support running specific tests, the state of the debugger
403
cannot be altered INSIDE gdbtk_test scripts, since the contents of the
404
script may not be run if the user requested only a specific test to run.
405
 
406
Line 20 in the middle of the test modifies the global foo. If subsequent
407
test relied on foo being one, we would have a state violation, since
408
mytest-1.1 may have (or may have not) run.
409
 
410
Therefore, we can check if a test ran and reset foo by checking the
411
global "test_ran". If set, we know that the previous test (mytest-1.1)
412
was run, and that foo is now thirteen. We reset the result back to one.
413
 
414
(Aside: Some tests do not follow this rule explicitly: they can assume
415
that all tests run sequentially. In these cases, running a specific
416
test in the file will probably fail, since the debugger is not brought
417
to a known state along the way.)
418
 
419
Lines 17-21 contain the actual test. The test's name is "mytest-1.1". It
420
is this name that may be referred to when asking the testsuite to run
421
a specific test. The description of this test is "source window created",
422
indicating that mytest-1.1's purpose is to check whether a source window
423
was created.
424
 
425
If gdbtk_test determines that this test is to run, it will execute the
426
next part, lines 18-20, and compare the output of that script (llength
427
$window) with "1". If the result is not "1", a failure is recorded. If
428
it is "1", a pass is recorded.
429
 
430
Finally, the test file is done and exits on line 28.

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.