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