]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/atf/doc/atf-test-case.4
Import atf-0.20.
[FreeBSD/stable/10.git] / contrib / atf / doc / atf-test-case.4
1 .\"
2 .\" Automated Testing Framework (atf)
3 .\"
4 .\" Copyright (c) 2007 The NetBSD Foundation, Inc.
5 .\" All rights reserved.
6 .\"
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
9 .\" are met:
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\"    notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\"    notice, this list of conditions and the following disclaimer in the
14 .\"    documentation and/or other materials provided with the distribution.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 .\" CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 .\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 .\" IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 .\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 .\"
29 .Dd January 13, 2011
30 .Dt ATF-TEST-CASE 4
31 .Os
32 .Sh NAME
33 .Nm atf-test-case
34 .Nd generic description of test cases
35 .Sh DESCRIPTION
36 A
37 .Em test case
38 is a piece of code that stress-tests a specific feature of the software.
39 This feature is typically self-contained enough, either in the amount of
40 code that implements it or in the general idea that describes it, to
41 warrant its independent testing.
42 Given this, test cases are very fine-grained, but they attempt to group
43 similar smaller tests which are semantically related.
44 .Pp
45 A test case is defined by three components regardless of the language it is
46 implemented in: a header, a body and a cleanup routine.
47 The
48 .Em header
49 is, basically, a declarative piece of code that defines several
50 properties to describe what the test case does and how it behaves.
51 In other words: it defines the test case's
52 .Em meta-data ,
53 further described in the
54 .Sx Meta-data
55 section.
56 The
57 .Em body
58 is the test case itself.
59 It executes all actions needed to reproduce the test, and checks for
60 failures.
61 This body is only executed if the abstract conditions specified by the
62 header are met.
63 The
64 .Em cleanup
65 routine is a piece of code always executed after the body, regardless of
66 the exit status of the test case.
67 It can be used to undo side-effects of the test case.
68 Note that almost all side-effects of a test case are automatically cleaned
69 up by the library; this is explained in more detail in the rest of this
70 document.
71 .Pp
72 It is extremely important to keep the separation between a test case's
73 header and body well-defined, because the header is
74 .Em always
75 parsed, whereas the body is only executed when the conditions defined in
76 the header are met and when the user specifies that test case.
77 .Pp
78 At last, test cases are always contained into test programs.
79 The test programs act as a front-end to them, providing a consistent
80 interface to the user and several APIs to ease their implementation.
81 .Ss Results
82 Upon termination, a test case reports a status and, optionally, a textual
83 reason describing why the test reported such status.
84 The caller must ensure that the test case really performed the task that its
85 status describes, as the test program may be bogus and therefore providing a
86 misleading result (e.g. providing a result that indicates success but the
87 error code of the program says otherwise).
88 .Pp
89 The possible exit status of a test case are one of the following:
90 .Bl -tag -width expectedXfailureXX
91 .It expected_death
92 The test case expects to terminate abruptly.
93 .It expected_exit
94 The test case expects to exit cleanly.
95 .It expected_failure
96 The test case expects to exit with a controller fatal/non-fatal failure.
97 If this happens, the test program exits with a success error code.
98 .It expected_signal
99 The test case expects to receive a signal that makes it terminate.
100 .It expected_timeout
101 The test case expects to execute for longer than its timeout.
102 .It passed
103 The test case was executed successfully.
104 The test program exits with a success error code.
105 .It skipped
106 The test case could not be executed because some preconditions were not
107 met.
108 This is not a failure because it can typically be resolved by adjusting
109 the system to meet the necessary conditions.
110 This is always accompanied by a
111 .Em reason ,
112 a message describing why the test was skipped.
113 The test program exits with a success error code.
114 .It failed
115 An error appeared during the execution of the test case.
116 This is always accompanied by a
117 .Em reason ,
118 a message describing why the test failed.
119 The test program exits with a failure error code.
120 .El
121 .Pp
122 The usefulness of the
123 .Sq expected_*
124 results comes when writing test cases that verify known failures caused,
125 in general, due to programming errors (aka bugs).
126 Whenever the faulty condition that the
127 .Sq expected_*
128 result is trying to cover is fixed, then the test case will be reported as
129 .Sq failed
130 and the developer will have to adjust it to match its new condition.
131 .Pp
132 It is important to note that all
133 .Sq expected_*
134 results are only provided as a
135 .Em hint
136 to the caller; the caller must verify that the test case did actually terminate
137 as the expected condition says.
138 .Ss Input/output
139 Test cases are free to print whatever they want to their
140 .Xr stdout 4
141 and
142 .Xr stderr 4
143 file descriptors.
144 They are, in fact, encouraged to print status information as they execute
145 to keep the user informed of their actions.
146 This is specially important for long test cases.
147 .Pp
148 Test cases will log their results to an auxiliary file, which is then
149 collected by the test program they are contained in.
150 The developer need not care about this as long as he uses the correct
151 APIs to implement the test cases.
152 .Pp
153 The standard input of the test cases is unconditionally connected to
154 .Sq /dev/zero .
155 .Ss Meta-data
156 The following list describes all meta-data properties interpreted
157 internally by ATF.
158 You are free to define new properties in your test cases and use them as
159 you wish, but non-standard properties must be prefixed by
160 .Sq X- .
161 .Bl -tag -width requireXmachineXX
162 .It descr
163 Type: textual.
164 Required.
165 .Pp
166 A brief textual description of the test case's purpose.
167 Will be shown to the user in reports.
168 Also good for documentation purposes.
169 .It has.cleanup
170 Type: boolean.
171 Optional.
172 .Pp
173 If set to true, specifies that the test case has a cleanup routine that has
174 to be executed by
175 .Xr atf-run 1
176 during the cleanup phase of the execution.
177 This property is automatically set by the framework when defining a test case
178 with a cleanup routine, so it should never be set by hand.
179 .It ident
180 Type: textual.
181 Required.
182 .Pp
183 The test case's identifier.
184 Must be unique inside the test program and should be short but descriptive.
185 .It require.arch
186 Type: textual.
187 Optional.
188 .Pp
189 A whitespace separated list of architectures that the test case can be run
190 under without causing errors due to an architecture mismatch.
191 .It require.config
192 Type: textual.
193 Optional.
194 .Pp
195 A whitespace separated list of configuration variables that must be defined
196 to execute the test case.
197 If any of the required variables is not defined, the test case is
198 .Em skipped .
199 .It require.files
200 Type: textual.
201 Optional.
202 .Pp
203 A whitespace separated list of files that must be present to execute the
204 test case.
205 The names of these files must be absolute paths.
206 If any of the required files is not found, the test case is
207 .Em skipped .
208 .It require.machine
209 Type: textual.
210 Optional.
211 .Pp
212 A whitespace separated list of machine types that the test case can be run
213 under without causing errors due to a machine type mismatch.
214 .It require.memory
215 Type: integer.
216 Optional.
217 Specifies the minimum amount of physical memory needed by the test.
218 The value can have a size suffix such as
219 .Sq K ,
220 .Sq M ,
221 .Sq G
222 or
223 .Sq T
224 to make the amount of bytes easier to type and read.
225 .It require.progs
226 Type: textual.
227 Optional.
228 .Pp
229 A whitespace separated list of programs that must be present to execute
230 the test case.
231 These can be given as plain names, in which case they are looked in the
232 user's
233 .Ev PATH ,
234 or as absolute paths.
235 If any of the required programs is not found, the test case is
236 .Em skipped .
237 .It require.user
238 Type: textual.
239 Optional.
240 .Pp
241 The required privileges to execute the test case.
242 Can be one of
243 .Sq root
244 or
245 .Sq unprivileged .
246 .Pp
247 If the test case is running as a regular user and this property is
248 .Sq root ,
249 the test case is
250 .Em skipped .
251 .Pp
252 If the test case is running as root and this property is
253 .Sq unprivileged ,
254 .Xr atf-run 1
255 will automatically drop the privileges if the
256 .Sq unprivileged-user
257 configuration property is set; otherwise the test case is
258 .Em skipped .
259 .It timeout
260 Type: integral.
261 Optional; defaults to
262 .Sq 300 .
263 .Pp
264 Specifies the maximum amount of time the test case can run.
265 This is particularly useful because some tests can stall either because they
266 are incorrectly coded or because they trigger an anomalous behavior of the
267 program.
268 It is not acceptable for these tests to stall the whole execution of the
269 test program.
270 .Pp
271 Can optionally be set to zero, in which case the test case has no run-time
272 limit.
273 This is discouraged.
274 .El
275 .Ss Environment
276 Every time a test case is executed, several environment variables are
277 cleared or reseted to sane values to ensure they do not make the test fail
278 due to unexpected conditions.
279 These variables are:
280 .Bl -tag -width LCXMESSAGESXX
281 .It Ev HOME
282 Set to the work directory's path.
283 .It Ev LANG
284 Undefined.
285 .It Ev LC_ALL
286 Undefined.
287 .It Ev LC_COLLATE
288 Undefined.
289 .It Ev LC_CTYPE
290 Undefined.
291 .It Ev LC_MESSAGES
292 Undefined.
293 .It Ev LC_MONETARY
294 Undefined.
295 .It Ev LC_NUMERIC
296 Undefined.
297 .It Ev LC_TIME
298 Undefined.
299 .It Ev TZ
300 Hardcoded to
301 .Sq UTC .
302 .El
303 .Ss Work directories
304 The test program always creates a temporary directory
305 and switches to it before running the test case's body.
306 This way the test case is free to modify its current directory as it
307 wishes, and the runtime engine will be able to clean it up later on in a
308 safe way, removing any traces of its execution from the system.
309 To do so, the runtime engine will perform a recursive removal of the work
310 directory without crossing mount points; if a mount point is found, the
311 file system will be unmounted (if possible).
312 .Ss File creation mode mask (umask)
313 Test cases are always executed with a file creation mode mask (umask) of
314 .Sq 0022 .
315 The test case's code is free to change this during execution.
316 .Sh SEE ALSO
317 .Xr atf-run 1 ,
318 .Xr atf-test-program 1 ,
319 .Xr atf-formats 5 ,
320 .Xr atf 7