This page was produced by an automated import process, and may have formatting errors; feel free to fix.

Writing Tests

In many areas, the GDB tests are already quite comprehensive; you should be able to copy existing tests to handle new cases.

You should try to use gdb_test whenever possible, since it includes cases to handle all the unexpected errors that might happen. However, it doesn’t cost anything to add new test procedures; for instance, gdb.base/exprs.exp defines a test_expr that calls gdb_test multiple times.

Only use send_gdb and gdb_expect when absolutely necessary. Even if GDB has several valid responses to a command, you can use gdb_test_multiple. Like gdb_test, gdb_test_multiple recognizes internal errors and unexpected prompts.

Do not write tests which expect a literal tab character from GDB. On some operating systems (e.g. OpenBSD) the TTY layer expands tabs to spaces, so by the time GDB’s output reaches expect the tab is gone.

The source language programs do not need to be in a consistent style. Since GDB is used to debug programs written in many different styles, it’s worth having a mix of styles in the testsuite; for instance, some GDB bugs involving the display of source lines would never manifest themselves if the programs used GNU coding style uniformly.

Some testcase results need more detailed explanation:

Known problem of GDB itself. You must specify the GDB bug report number like in these sample tests:

kfail "gdb/13392" "continue to marker 2"

or

setup_kfail gdb/13392 "*-*-*"
kfail "continue to marker 2"

Known problem of environment. This typically includes GCC but it includes also many other system components which cannot be fixed in the GDB project. Sample test with sanity check not knowing the specific cause of the problem:

# On x86_64 it is commonly about 4MB.
if {$stub_size > 25000000} {
    xfail "stub size $stub_size is too large"
    return
}

You should provide bug report number for the failing component of the environment, if such bug report is available:

if {[test_compiler_info {gcc-[0-3]-*}]
   || [test_compiler_info {gcc-4-[0-5]-*}]} {
   setup_xfail "gcc/46955" *-*-*
}
gdb_test "python print ttype.template_argument(2)" "&C::c"

None: Internals Writing-Tests (last edited 2013-08-20 23:41:49 by StanShebs)

All content (C) 2008 Free Software Foundation. For terms of use, redistribution, and modification, please see the WikiLicense page.