xref: /openbsd-src/gnu/lib/libstdc++/libstdc++/testsuite/README (revision 03a78d155d6fff5698289342b62759a75b20d130)
1*03a78d15SespieWe're in the process of converting the existing testsuite machinery to
2*03a78d15Sespieuse the new style DejaGnu framework.  Eventually, we'll abandon
3*03a78d15Sespie../mkcheck.in in favor of this new testsuite framework.
4*03a78d15Sespie
5*03a78d15Sespie// 1: Thoughts on naming test cases, and structuring them.
6*03a78d15SespieThe testsuite directory has been divided into 11 directories, directly
7*03a78d15Sespiecorrelated to the relevant chapters in the standard. For example, the
8*03a78d15Sespiedirectory testsuite/21_strings contains tests related to "Chapter 21,
9*03a78d15SespieStrings library" in the C++ standard.
10*03a78d15Sespie
11*03a78d15SespieSo, the first step in making a new test case is to choose the correct
12*03a78d15Sespiedirectory. The second item is seeing if a test file exists that tests
13*03a78d15Sespiethe item in question. Generally, within chapters test files are named
14*03a78d15Sespieafter the section headings in ISO 14882, the C++ standard. For instance,
15*03a78d15Sespie
16*03a78d15Sespie21.3.7.9 Inserters and Extractors
17*03a78d15Sespie
18*03a78d15SespieHas a related test case:
19*03a78d15Sespie21_strings/inserters_extractors.cc
20*03a78d15Sespie
21*03a78d15SespieNot so hard. Some time, the words "ctor" and "dtor" are used instead
22*03a78d15Sespieof "construct", "constructor", "cons", "destructor", etc. Other than
23*03a78d15Sespiethat, the naming seems mostly consistent. If the file exists, add a
24*03a78d15Sespietest to it. If it does not, then create a new file. All files are
25*03a78d15Sespiecopyright the FSF, and GPL'd: this is very important.
26*03a78d15Sespie
27*03a78d15SespieIn addition, some of the locale and io code tests different
28*03a78d15Sespieinstantiating types: thus, 'char' or 'wchar_t' is appended to the name
29*03a78d15Sespieas constructed above.
30*03a78d15Sespie
31*03a78d15SespieAlso, some test files are negative tests. That is, they are supposed
32*03a78d15Sespieto fail (usually this involves making sure some kind of construct gets
33*03a78d15Sespiean error when it's compiled.) These test files have 'neg' appended to
34*03a78d15Sespiethe name as constructed above.
35*03a78d15Sespie
36*03a78d15SespieInside a test file, the plan is to test the relevant parts of the
37*03a78d15Sespiestandard, and then add specific regressions as additional test
38*03a78d15Sespiefunctions, ie test04() can represent a specific regression noted in
39*03a78d15SespieGNATS. Once test files get unwieldy or too big, then they should be
40*03a78d15Sespiebroken up into multiple sub-categories, hopefully intelligently named
41*03a78d15Sespieafter the relevant (and more specific) part of the standard.
42*03a78d15Sespie
43*03a78d15Sespie
44*03a78d15Sespie// 2: How to write a test case, from a dejagnu perspective
45*03a78d15SespieAs per the dejagnu instructions, always return 0 from main to indicate
46*03a78d15Sespiesuccess.
47*03a78d15Sespie
48*03a78d15SespieBasically, a test case contains dg-keywords (see dg.exp) indicating
49*03a78d15Sespiewhat to do and what kinds of behaviour are to be expected.  New
50*03a78d15Sespietestcases should be written with the new style DejaGnu framework in
51*03a78d15Sespiemind.
52*03a78d15Sespie
53*03a78d15SespieTo ease transition, here is the list of dg-keyword documentation
54*03a78d15Sespielifted from dg.exp -- eventually we should improve DejaGnu
55*03a78d15Sespiedocumentation, but getting checkin account currently demands Pyrrhic
56*03a78d15Sespieeffort.
57*03a78d15Sespie
58*03a78d15Sespie# The currently supported options are:
59*03a78d15Sespie#
60*03a78d15Sespie# dg-prms-id N
61*03a78d15Sespie#	set prms_id to N
62*03a78d15Sespie#
63*03a78d15Sespie# dg-options "options ..." [{ target selector }]
64*03a78d15Sespie#	specify special options to pass to the tool (eg: compiler)
65*03a78d15Sespie#
66*03a78d15Sespie# dg-do do-what-keyword [{ target/xfail selector }]
67*03a78d15Sespie#	`do-what-keyword' is tool specific and is passed unchanged to
68*03a78d15Sespie#	${tool}-dg-test.  An example is gcc where `keyword' can be any of:
69*03a78d15Sespie#	preprocess|compile|assemble|link|run
70*03a78d15Sespie#	and will do one of: produce a .i, produce a .s, produce a .o,
71*03a78d15Sespie#	produce an a.out, or produce an a.out and run it (the default is
72*03a78d15Sespie#	compile).
73*03a78d15Sespie#
74*03a78d15Sespie# dg-error regexp comment [{ target/xfail selector } [{.|0|linenum}]]
75*03a78d15Sespie#	indicate an error message <regexp> is expected on this line
76*03a78d15Sespie#	(the test fails if it doesn't occur)
77*03a78d15Sespie#	Linenum=0 for general tool messages (eg: -V arg missing).
78*03a78d15Sespie#	"." means the current line.
79*03a78d15Sespie#
80*03a78d15Sespie# dg-warning regexp comment [{ target/xfail selector } [{.|0|linenum}]]
81*03a78d15Sespie#	indicate a warning message <regexp> is expected on this line
82*03a78d15Sespie#	(the test fails if it doesn't occur)
83*03a78d15Sespie#
84*03a78d15Sespie# dg-bogus regexp comment [{ target/xfail selector } [{.|0|linenum}]]
85*03a78d15Sespie#	indicate a bogus error message <regexp> use to occur here
86*03a78d15Sespie#	(the test fails if it does occur)
87*03a78d15Sespie#
88*03a78d15Sespie# dg-build regexp comment [{ target/xfail selector }]
89*03a78d15Sespie#	indicate the build use to fail for some reason
90*03a78d15Sespie#	(errors covered here include bad assembler generated, tool crashes,
91*03a78d15Sespie#	and link failures)
92*03a78d15Sespie#	(the test fails if it does occur)
93*03a78d15Sespie#
94*03a78d15Sespie# dg-excess-errors comment [{ target/xfail selector }]
95*03a78d15Sespie#	indicate excess errors are expected (any line)
96*03a78d15Sespie#	(this should only be used sparingly and temporarily)
97*03a78d15Sespie#
98*03a78d15Sespie# dg-output regexp [{ target selector }]
99*03a78d15Sespie#	indicate the expected output of the program is <regexp>
100*03a78d15Sespie#	(there may be multiple occurrences of this, they are concatenated)
101*03a78d15Sespie#
102*03a78d15Sespie# dg-final { tcl code }
103*03a78d15Sespie#	add some tcl code to be run at the end
104*03a78d15Sespie#	(there may be multiple occurrences of this, they are concatenated)
105*03a78d15Sespie#	(unbalanced braces must be \-escaped)
106*03a78d15Sespie#
107*03a78d15Sespie# "{ target selector }" is a list of expressions that determine whether the
108*03a78d15Sespie# test succeeds or fails for a particular target, or in some cases whether the
109*03a78d15Sespie# option applies for a particular target.  If the case of `dg-do' it specifies
110*03a78d15Sespie# whether the testcase is even attempted on the specified target.
111*03a78d15Sespie#
112*03a78d15Sespie# The target selector is always optional.  The format is one of:
113*03a78d15Sespie#
114*03a78d15Sespie# { xfail *-*-* ... } - the test is expected to fail for the given targets
115*03a78d15Sespie# { target *-*-* ... } - the option only applies to the given targets
116*03a78d15Sespie#
117*03a78d15Sespie# At least one target must be specified, use *-*-* for "all targets".
118*03a78d15Sespie# At present it is not possible to specify both `xfail' and `target'.
119*03a78d15Sespie# "native" may be used in place of "*-*-*".
120*03a78d15Sespie
121*03a78d15SespieExample 1: Testing compilation only
122*03a78d15Sespie(to just have a testcase do compile testing, without linking and executing)
123*03a78d15Sespie// { dg-do compile }
124*03a78d15Sespie
125*03a78d15SespieExample 2: Testing for expected warings on line 36
126*03a78d15Sespie// { dg-warning "string literals" "" { xfail *-*-* } 36
127*03a78d15Sespie
128*03a78d15SespieExample 3: Testing for compilation errors on line 41
129*03a78d15Sespie// { dg-do compile }
130*03a78d15Sespie// { dg-error "no match for" "" { xfail *-*-* } 41 }
131*03a78d15Sespie
132*03a78d15SespieMore examples can be found in the libstdc++-v3/testsuite/*/*.cc files.
133*03a78d15Sespie
134*03a78d15Sespie
135*03a78d15Sespie// 3: Test harness notes, invocation, and debugging.
136*03a78d15SespieConfiguring the dejagnu harness to work with libstdc++-v3 in a cross
137*03a78d15Sespiecompilation environment has been maddening. However, it does work now,
138*03a78d15Sespieand on a variety of platforms. Including solaris, linux, and cygwin.
139*03a78d15Sespie
140*03a78d15SespieTo debug the test harness during runs, try invoking with
141*03a78d15Sespie
142*03a78d15Sespiemake check-target-libstdc++-v3 RUNTESTFLAGS="-v"
143*03a78d15Sespieor
144*03a78d15Sespiemake check-target-libstdc++-v3 RUNTESTFLAGS="-v -v"
145*03a78d15Sespie
146*03a78d15SespieThere are two ways to run on a simulator: set up DEJAGNU to point to a
147*03a78d15Sespiespecially crafted site.exp, or pass down --target_board flags.
148*03a78d15Sespie
149*03a78d15SespieExample flags to pass down for various embedded builds are as follows:
150*03a78d15Sespie
151*03a78d15Sespie--target=powerpc-eabism (libgloss/sim)
152*03a78d15Sespiemake check-target-libstdc++-v3 RUNTESTFLAGS="--target_board=powerpc-sim"
153*03a78d15Sespie
154*03a78d15Sespie--target=calmrisc32 (libgloss/sid)
155*03a78d15Sespiemake check-target-libstdc++-v3 RUNTESTFLAGS="--target_board=calmrisc32-sid"
156*03a78d15Sespie
157*03a78d15Sespie--target=xscale-elf (newlib/sim)
158*03a78d15Sespiemake check-target-libstdc++-v3 RUNTESTFLAGS="--target_board=arm-sim"
159*03a78d15Sespie
160*03a78d15Sespie
161*03a78d15Sespie// 4: Future plans, to be done
162*03a78d15SespieShared runs need to be implemented, for targets that support shared libraries.
163*03a78d15Sespie
164*03a78d15SespieDiffing of expected output to standard streams needs to be finished off.
165*03a78d15Sespie
166*03a78d15SespieThe V3 testing framework supports, or will eventually support,
167*03a78d15Sespieadditional keywords for the purpose of easing the job of writing
168*03a78d15Sespietestcases.  All V3-keywords are of the form @xxx@.  Currently plans
169*03a78d15Sespiefor supported keywords include:
170*03a78d15Sespie
171*03a78d15Sespie  @require@ <files>
172*03a78d15Sespie      The existence of <files> is essential for the test to complete
173*03a78d15Sespie      successfully.  For example, a testcase foo.C using bar.baz as
174*03a78d15Sespie      input file could say
175*03a78d15Sespie	    // @require@ bar.baz
176*03a78d15Sespie      The special variable % stands for the rootname, e.g. the
177*03a78d15Sespie      file-name without its `.C' extension.  Example of use (taken
178*03a78d15Sespie      verbatim from 27_io/filebuf.cc)
179*03a78d15Sespie	   // @require@ %-*.tst %-*.txt
180*03a78d15Sespie
181*03a78d15Sespie  @diff@ <first-list> <second-list>
182*03a78d15Sespie      After the testcase compiles and ran successfully, diff
183*03a78d15Sespie      <first-list> against <second-list>, these lists should have the
184*03a78d15Sespie      same length.  The test fails if diff returns non-zero a pair of
185*03a78d15Sespie      files.
186*03a78d15Sespie
187*03a78d15SespieCurrent testing problems with cygwin-hosted tools:
188*03a78d15Sespie
189*03a78d15SespieThere are two known problems which I have not addressed.  The first is
190*03a78d15Sespiethat when testing cygwin hosted tools from the unix build dir, it does
191*03a78d15Sespiethe wrong thing building the wrapper program (testglue.c) because host
192*03a78d15Sespieand target are the same in site.exp (host and target are the same from
193*03a78d15Sespiethe perspective of the target libraries)
194*03a78d15Sespie
195*03a78d15SespieProblem number two is a little more annoying.  In order for me to make
196*03a78d15Sespiev3 testing work on Windows, I had to tell dejagnu to copy over the
197*03a78d15Sespiedebug_assert.h file to the remote host and then set the includes to
198*03a78d15Sespie-I./.  This is how all the other tests like this are done so I didn't
199*03a78d15Sespiethink much of it.  However, this had some unfortunate results due to
200*03a78d15Sespiegcc having a testcase called "limits" and C++ having an include file
201*03a78d15Sespiecalled "limits".  The gcc "limits" binary was in the temporary dir
202*03a78d15Sespiewhen the v3 tests were being built.  As a result, the gcc "limits"
203*03a78d15Sespiebinary was being #included rather than the intended one.  The only way
204*03a78d15Sespieto fix this is to go through the testsuites and make sure binaries are
205*03a78d15Sespiedeleted on the remote host when testing is done with them.  That is a
206*03a78d15Sespielot more work than I want to do so I worked around it by cleaning out
207*03a78d15SespieD:\kermit on compsognathus and rerunning tests.
208