xref: /netbsd-src/external/bsd/atf/dist/doc/atf-test-case.4 (revision c2f76ff004a2cb67efe5b12d97bd3ef7fe89e18d)
1.\"
2.\" Automated Testing Framework (atf)
3.\"
4.\" Copyright (c) 2007, 2008, 2010 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 November 16, 2010
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
36A
37.Em test case
38is a piece of code that stress-tests a specific feature of the software.
39This feature is typically self-contained enough, either in the amount of
40code that implements it or in the general idea that describes it, to
41warrant its independent testing.
42Given this, test cases are very fine-grained, but they attempt to group
43similar smaller tests which are semantically related.
44.Pp
45A test case is defined by three components regardless of the language it is
46implemented in: a header, a body and a cleanup routine.
47The
48.Em header
49is, basically, a declarative piece of code that defines several
50properties to describe what the test case does and how it behaves.
51In other words: it defines the test case's
52.Em meta-data ,
53further described in the
54.Sx Meta-data
55section.
56The
57.Em body
58is the test case itself.
59It executes all actions needed to reproduce the test, and checks for
60failures.
61This body is only executed if the abstract conditions specified by the
62header are met.
63The
64.Em cleanup routine
65routine is a piece of code always executed after the body, regardless of
66the exit status of the test case.
67It can be used to undo side-effects of the test case.
68Note that almost all side-effects of a test case are automatically cleaned
69up by the library; this is explained in more detail in the rest of this
70document.
71.Pp
72It is extremely important to keep the separation between a test case's
73header and body well-defined, because the header is
74.Em always
75parsed, whereas the body is only executed when the conditions defined in
76the header are met and when the user specifies that test case.
77.Pp
78At last, test cases are always contained into test programs.
79The test programs act as a front-end to them, providing a consistent
80interface to the user and several APIs to ease their implementation.
81.Ss Results
82Upon termination, a test case reports a status and, optionally, a textual
83reason describing why the test reported such status.
84The caller must ensure that the test case really performed the task that its
85status describes, as the test program may be bogus and therefore providing a
86misleading result (e.g. providing a result that indicates success but the
87error code of the program says otherwise).
88.Pp
89The possible exit status of a test case are one of the following:
90.Bl -tag -width expectedXfailureXX
91.It expected_death
92The test case expects to terminate abruptly.
93.It expected_exit
94The test case expects to exit cleanly.
95.It expected_failure
96The test case expects to exit with a controller fatal/non-fatal failure.
97If this happens, the test program exits with a success error code.
98.It expected_signal
99The test case expects to receive a signal that makes it terminate.
100.It expected_timeout
101The test case expects to execute for longer than its timeout.
102.It passed
103The test case was executed successfully.
104The test program exits with a success error code.
105.It skipped
106The test case could not be executed because some preconditions were not
107met.
108This is not a failure because it can typically be resolved by adjusting
109the system to meet the necessary conditions.
110This is always accompanied by a
111.Em reason ,
112a message describing why the test was skipped.
113The test program exits with a success error code.
114.It failed
115An error appeared during the execution of the test case.
116This is always accompanied by a
117.Em reason ,
118a message describing why the test failed.
119The test program exits with a failure error code.
120.El
121.Pp
122The usefulness of the
123.Sq expected_*
124results comes when writing test cases that verify known failures caused,
125in general, due to programming errors (aka bugs).
126Whenever the faulty condition that the expectation is trying to convery is
127fixed, then the test case will be reported as
128.Sq failed
129and the developer will have to adjust it to match its new condition.
130.Pp
131It is important to note that all
132.Sq expected_*
133results are only provided as a
134.Em hint
135to the caller; the caller must verify that the test case did actually terminate
136as the expected condition says.
137.Ss Input/output
138Test cases are free to print whatever they want to their
139.Xr stdout 4
140and
141.Xr stderr 4
142file descriptors.
143They are, in fact, encouraged to print status information as they execute
144to keep the user informed of their actions.
145This is specially important for long test cases.
146.Pp
147Test cases will log their results to an auxiliary file, which is then
148collected by the test program they are contained in.
149The developer need not care about this as long as he uses the correct
150APIs to implement the test cases.
151.Ss Meta-data
152The following list describes all meta-data properties interpreted
153internally by ATF.
154You are free to define new properties in your test cases and use them as
155you wish, but non-standard properties must be prefixed by
156.Sq X- .
157.Bl -tag -width requireXmachineXX
158.It descr
159Type: textual.
160Required.
161.Pp
162A brief textual description of the test case's purpose.
163Will be shown to the user in reports.
164Also good for documentation purposes.
165.It has.cleanup
166Type: boolean.
167Optional.
168.Pp
169If set to true, specifies that the test case has a cleanup routine that has
170to be executed by
171.Xr atf-run 1
172during the cleanup phase of the execution.
173This property is automatically set by the framework when defining a test case
174with a cleanup routine, so it should never be set by hand.
175.It ident
176Type: textual.
177Required.
178.Pp
179The test case's identifier.
180Must be unique inside the test program and should be short but descriptive.
181.It require.arch
182Type textual.
183Optional.
184.Pp
185A whitespace separated list of architectures that the test case can be run
186under without causing errors due to an architecture mismatch.
187.It require.config
188Type: textual.
189Optional.
190.Pp
191A whitespace separated list of configuration variables that must be defined
192to execute the test case.
193If any of the required variables is not defined, the test case is
194.Em skipped .
195.It require.machine
196Type textual.
197Optional.
198.Pp
199A whitespace separated list of machine types that the test case can be run
200under without causing errors due to a machine type mismatch.
201.It require.progs
202Type: textual.
203Optional.
204.Pp
205A whitespace separated list of programs that must be present to execute
206the test case.
207These can be given as plain names, in which case they are looked in the
208user's
209.Ev PATH ,
210or as absolute paths.
211If any of the required programs is not found, the test case is
212.Em skipped .
213.It require.user
214Type: textual.
215Optional.
216.Pp
217The required privileges to execute the test case.
218Can be one of
219.Sq root
220or
221.Sq unprivileged .
222If the requested privileges do not match the current user, the test case is
223.Em skipped .
224.Pp
225.Em NOTE :
226In the future, it is expected that the test case will attempt to gain the
227necessary privileges on its own before failing.
228At the very least, lowering the privileges from the super-user to an
229unprivileged user will be supported.
230.It timeout
231Type: integral.
232Optional; defaults to
233.Sq 300 .
234.Pp
235Specifies the maximum amount of time the test case can run.
236This is particularly useful because some tests can stall either because they
237are incorrectly coded or because they trigger an anomalous behavior of the
238program.
239It is not acceptable for these tests to stall the whole execution of the
240test program.
241.Pp
242Can optionally be set to zero, in which case the test case has no run-time
243limit.
244This is discouraged.
245.El
246.Ss Environment
247Every time a test case is executed, several environment variables are
248cleared or reseted to sane values to ensure they do not make the test fail
249due to unexpected conditions.
250These variables are:
251.Bl -tag -width LCXMESSAGESXX
252.It Ev HOME
253Set to the work directory's path.
254.It Ev LANG
255Undefined.
256.It Ev LC_ALL
257Undefined.
258.It Ev LC_COLLATE
259Undefined.
260.It Ev LC_CTYPE
261Undefined.
262.It Ev LC_MESSAGES
263Undefined.
264.It Ev LC_MONETARY
265Undefined.
266.It Ev LC_NUMERIC
267Undefined.
268.It Ev LC_TIME
269Undefined.
270.It Ev TZ
271Undefined.
272.El
273.Ss Work directories
274The test program always creates a temporary directory
275and switches to it before running the test case's body.
276This way the test case is free to modify its current directory as it
277wishes, and the test program will be able to clean it up later on in a
278safe way, removing any traces of its execution from the system.
279.Ss File creation mode mask (umask)
280Test cases are always executed with a file creation mode mask (umask) of
281.Sq 0022 .
282The test case's code is free to change this during execution.
283.Sh SEE ALSO
284.Xr atf-test-program 1 ,
285.Xr atf-formats 5 ,
286.Xr atf 7
287