Next:Directives used within DejaGnu tests, Up:Testsuites [Contents][Index]
In general, C testcases have a trailing-n.c, startingwith-1.c, in case other testcases with similar names are addedlater. If the test is a test of some well-defined feature, it shouldhave a name referring to that feature such asfeature-1.c. If it does not test a well-defined featurebut just happens to exercise a bug somewhere in the compiler, and abug report has been filed for this bug in the GCC bug database,prbug-number-1.c is the appropriate form of name.Otherwise (for miscellaneous bugs not filed in the GCC bug database),and previously more generally, test cases are named after the date onwhich they were added. This allows people to tell at a glance whethera test failure is because of a recently found bug that has not yetbeen fixed, or whether it may be a regression, but does not give anyother information about the bug or where discussion of it may befound. Some other language testsuites follow similar conventions.
In thegcc.dg testsuite, it is often necessary to test that anerror is indeed a hard error and not just a warning—for example,where it is a constraint violation in the C standard, which mustbecome an error with-pedantic-errors. The following idiom,where the first line shown is lineline of the file and the linethat generates the error, is used for this:
/* { dg-bogus "warning" "warning in place of error" } *//* { dg-error "regexp" "message" { target *-*-* }line } */It may be necessary to check that an expression is an integer constantexpression and has a certain value. To check thatE hasvalueV, an idiom similar to the following is used:
char x[((E) == (V) ? 1 : -1)];
Ingcc.dg tests,__typeof__ is sometimes used to makeassertions about the types of expressions. See, for example,gcc.dg/c99-condexpr-1.c. The more subtle uses depend on theexact rules for the types of conditional expressions in the Cstandard; see, for example,gcc.dg/c99-intconst-1.c.
It is useful to be able to test that optimizations are being madeproperly. This cannot be done in all cases, but it can be done wherethe optimization will lead to code being optimized away (for example,where flow analysis or alias analysis should show that certain codecannot be called) or to functions not being called because they havebeen expanded as built-in functions. Such tests go ingcc.c-torture/execute. Where code should be optimized away, acall to a nonexistent function such aslink_failure () may beinserted; a definition
#ifndef __OPTIMIZE__voidlink_failure (void){ abort ();}#endifwill also be needed so that linking still succeeds when the test isrun without optimization. When all calls to a built-in functionshould have been optimized and no calls to the non-built-in version ofthe function should remain, that function may be defined asstatic to callabort () (although redeclaring a functionas static may not work on all targets).
All testcases must be portable. Target-specific testcases must haveappropriate code to avoid causing failures on unsupported systems;unfortunately, the mechanisms for this differ by directory.
FIXME: discuss non-C testsuites here.
Next:Directives used within DejaGnu tests, Up:Testsuites [Contents][Index]