xref: /freebsd/contrib/atf/doc/atf-test-case.4 (revision c203bd70b5957f85616424b6fa374479372d06e3)
1c243e490SMarcel Moolenaar.\" Copyright (c) 2007 The NetBSD Foundation, Inc.
2c243e490SMarcel Moolenaar.\" All rights reserved.
3c243e490SMarcel Moolenaar.\"
4c243e490SMarcel Moolenaar.\" Redistribution and use in source and binary forms, with or without
5c243e490SMarcel Moolenaar.\" modification, are permitted provided that the following conditions
6c243e490SMarcel Moolenaar.\" are met:
7c243e490SMarcel Moolenaar.\" 1. Redistributions of source code must retain the above copyright
8c243e490SMarcel Moolenaar.\"    notice, this list of conditions and the following disclaimer.
9c243e490SMarcel Moolenaar.\" 2. Redistributions in binary form must reproduce the above copyright
10c243e490SMarcel Moolenaar.\"    notice, this list of conditions and the following disclaimer in the
11c243e490SMarcel Moolenaar.\"    documentation and/or other materials provided with the distribution.
12c243e490SMarcel Moolenaar.\"
13c243e490SMarcel Moolenaar.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
14c243e490SMarcel Moolenaar.\" CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15c243e490SMarcel Moolenaar.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16c243e490SMarcel Moolenaar.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17c243e490SMarcel Moolenaar.\" IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
18c243e490SMarcel Moolenaar.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19c243e490SMarcel Moolenaar.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20c243e490SMarcel Moolenaar.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21c243e490SMarcel Moolenaar.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22c243e490SMarcel Moolenaar.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23c243e490SMarcel Moolenaar.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24c243e490SMarcel Moolenaar.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25e5bab279SEnji Cooper.Dd March 6, 2017
26c243e490SMarcel Moolenaar.Dt ATF-TEST-CASE 4
27c243e490SMarcel Moolenaar.Os
28c243e490SMarcel Moolenaar.Sh NAME
29c243e490SMarcel Moolenaar.Nm atf-test-case
30c243e490SMarcel Moolenaar.Nd generic description of test cases
31c243e490SMarcel Moolenaar.Sh DESCRIPTION
32c243e490SMarcel MoolenaarA
33c243e490SMarcel Moolenaar.Em test case
34c243e490SMarcel Moolenaaris a piece of code that stress-tests a specific feature of the software.
35c243e490SMarcel MoolenaarThis feature is typically self-contained enough, either in the amount of
36c243e490SMarcel Moolenaarcode that implements it or in the general idea that describes it, to
37c243e490SMarcel Moolenaarwarrant its independent testing.
38c243e490SMarcel MoolenaarGiven this, test cases are very fine-grained, but they attempt to group
39c243e490SMarcel Moolenaarsimilar smaller tests which are semantically related.
40c243e490SMarcel Moolenaar.Pp
41c243e490SMarcel MoolenaarA test case is defined by three components regardless of the language it is
42c243e490SMarcel Moolenaarimplemented in: a header, a body and a cleanup routine.
43c243e490SMarcel MoolenaarThe
44c243e490SMarcel Moolenaar.Em header
45c243e490SMarcel Moolenaaris, basically, a declarative piece of code that defines several
46c243e490SMarcel Moolenaarproperties to describe what the test case does and how it behaves.
47c243e490SMarcel MoolenaarIn other words: it defines the test case's
48c243e490SMarcel Moolenaar.Em meta-data ,
49c243e490SMarcel Moolenaarfurther described in the
50c243e490SMarcel Moolenaar.Sx Meta-data
51c243e490SMarcel Moolenaarsection.
52c243e490SMarcel MoolenaarThe
53c243e490SMarcel Moolenaar.Em body
54c243e490SMarcel Moolenaaris the test case itself.
55c243e490SMarcel MoolenaarIt executes all actions needed to reproduce the test, and checks for
56c243e490SMarcel Moolenaarfailures.
57c243e490SMarcel MoolenaarThis body is only executed if the abstract conditions specified by the
58c243e490SMarcel Moolenaarheader are met.
59c243e490SMarcel MoolenaarThe
60a4fb74f1SMarcel Moolenaar.Em cleanup
61c243e490SMarcel Moolenaarroutine is a piece of code always executed after the body, regardless of
62c243e490SMarcel Moolenaarthe exit status of the test case.
63c243e490SMarcel MoolenaarIt can be used to undo side-effects of the test case.
64c243e490SMarcel MoolenaarNote that almost all side-effects of a test case are automatically cleaned
65c243e490SMarcel Moolenaarup by the library; this is explained in more detail in the rest of this
66c243e490SMarcel Moolenaardocument.
67c243e490SMarcel Moolenaar.Pp
68c243e490SMarcel MoolenaarIt is extremely important to keep the separation between a test case's
69c243e490SMarcel Moolenaarheader and body well-defined, because the header is
70c243e490SMarcel Moolenaar.Em always
71c243e490SMarcel Moolenaarparsed, whereas the body is only executed when the conditions defined in
72c243e490SMarcel Moolenaarthe header are met and when the user specifies that test case.
73c243e490SMarcel Moolenaar.Pp
74c243e490SMarcel MoolenaarAt last, test cases are always contained into test programs.
75c243e490SMarcel MoolenaarThe test programs act as a front-end to them, providing a consistent
76c243e490SMarcel Moolenaarinterface to the user and several APIs to ease their implementation.
77c243e490SMarcel Moolenaar.Ss Results
78c243e490SMarcel MoolenaarUpon termination, a test case reports a status and, optionally, a textual
79c243e490SMarcel Moolenaarreason describing why the test reported such status.
80c243e490SMarcel MoolenaarThe caller must ensure that the test case really performed the task that its
81c243e490SMarcel Moolenaarstatus describes, as the test program may be bogus and therefore providing a
82e5bab279SEnji Coopermisleading result, e.g., providing a result that indicates success but the
83e5bab279SEnji Coopererror code of the program says otherwise.
84c243e490SMarcel Moolenaar.Pp
85c243e490SMarcel MoolenaarThe possible exit status of a test case are one of the following:
86c243e490SMarcel Moolenaar.Bl -tag -width expectedXfailureXX
87c243e490SMarcel Moolenaar.It expected_death
88c243e490SMarcel MoolenaarThe test case expects to terminate abruptly.
89c243e490SMarcel Moolenaar.It expected_exit
90c243e490SMarcel MoolenaarThe test case expects to exit cleanly.
91c243e490SMarcel Moolenaar.It expected_failure
92c243e490SMarcel MoolenaarThe test case expects to exit with a controller fatal/non-fatal failure.
93c243e490SMarcel MoolenaarIf this happens, the test program exits with a success error code.
94c243e490SMarcel Moolenaar.It expected_signal
95c243e490SMarcel MoolenaarThe test case expects to receive a signal that makes it terminate.
96c243e490SMarcel Moolenaar.It expected_timeout
97c243e490SMarcel MoolenaarThe test case expects to execute for longer than its timeout.
98c243e490SMarcel Moolenaar.It passed
99c243e490SMarcel MoolenaarThe test case was executed successfully.
100c243e490SMarcel MoolenaarThe test program exits with a success error code.
101c243e490SMarcel Moolenaar.It skipped
102c243e490SMarcel MoolenaarThe test case could not be executed because some preconditions were not
103c243e490SMarcel Moolenaarmet.
104c243e490SMarcel MoolenaarThis is not a failure because it can typically be resolved by adjusting
105c243e490SMarcel Moolenaarthe system to meet the necessary conditions.
106c243e490SMarcel MoolenaarThis is always accompanied by a
107c243e490SMarcel Moolenaar.Em reason ,
108c243e490SMarcel Moolenaara message describing why the test was skipped.
109c243e490SMarcel MoolenaarThe test program exits with a success error code.
110c243e490SMarcel Moolenaar.It failed
111c243e490SMarcel MoolenaarAn error appeared during the execution of the test case.
112c243e490SMarcel MoolenaarThis is always accompanied by a
113c243e490SMarcel Moolenaar.Em reason ,
114c243e490SMarcel Moolenaara message describing why the test failed.
115c243e490SMarcel MoolenaarThe test program exits with a failure error code.
116c243e490SMarcel Moolenaar.El
117c243e490SMarcel Moolenaar.Pp
118c243e490SMarcel MoolenaarThe usefulness of the
119c243e490SMarcel Moolenaar.Sq expected_*
120c243e490SMarcel Moolenaarresults comes when writing test cases that verify known failures caused,
121c243e490SMarcel Moolenaarin general, due to programming errors (aka bugs).
1221a61beb0SJulio MerinoWhenever the faulty condition that the
1231a61beb0SJulio Merino.Sq expected_*
1241a61beb0SJulio Merinoresult is trying to cover is fixed, then the test case will be reported as
125c243e490SMarcel Moolenaar.Sq failed
126c243e490SMarcel Moolenaarand the developer will have to adjust it to match its new condition.
127c243e490SMarcel Moolenaar.Pp
128c243e490SMarcel MoolenaarIt is important to note that all
129c243e490SMarcel Moolenaar.Sq expected_*
130c243e490SMarcel Moolenaarresults are only provided as a
131c243e490SMarcel Moolenaar.Em hint
132c243e490SMarcel Moolenaarto the caller; the caller must verify that the test case did actually terminate
133c243e490SMarcel Moolenaaras the expected condition says.
134c243e490SMarcel Moolenaar.Ss Input/output
135c243e490SMarcel MoolenaarTest cases are free to print whatever they want to their
136c243e490SMarcel Moolenaar.Xr stdout 4
137c243e490SMarcel Moolenaarand
138c243e490SMarcel Moolenaar.Xr stderr 4
139c243e490SMarcel Moolenaarfile descriptors.
140c243e490SMarcel MoolenaarThey are, in fact, encouraged to print status information as they execute
141c243e490SMarcel Moolenaarto keep the user informed of their actions.
142c243e490SMarcel MoolenaarThis is specially important for long test cases.
143c243e490SMarcel Moolenaar.Pp
144c243e490SMarcel MoolenaarTest cases will log their results to an auxiliary file, which is then
145c243e490SMarcel Moolenaarcollected by the test program they are contained in.
146c243e490SMarcel MoolenaarThe developer need not care about this as long as he uses the correct
147c243e490SMarcel MoolenaarAPIs to implement the test cases.
148c243e490SMarcel Moolenaar.Pp
149c243e490SMarcel MoolenaarThe standard input of the test cases is unconditionally connected to
150c243e490SMarcel Moolenaar.Sq /dev/zero .
151c243e490SMarcel Moolenaar.Ss Meta-data
152*c203bd70SAlex RichardsonThe following metadata properties can be exposed via the test case's head:
153c243e490SMarcel Moolenaar.Bl -tag -width requireXmachineXX
154c243e490SMarcel Moolenaar.It descr
155c243e490SMarcel MoolenaarType: textual.
156c243e490SMarcel MoolenaarRequired.
157c243e490SMarcel Moolenaar.Pp
158c243e490SMarcel MoolenaarA brief textual description of the test case's purpose.
159c243e490SMarcel MoolenaarWill be shown to the user in reports.
160c243e490SMarcel MoolenaarAlso good for documentation purposes.
161c243e490SMarcel Moolenaar.It has.cleanup
162c243e490SMarcel MoolenaarType: boolean.
163c243e490SMarcel MoolenaarOptional.
164c243e490SMarcel Moolenaar.Pp
165c243e490SMarcel MoolenaarIf set to true, specifies that the test case has a cleanup routine that has
166b9306c04SCraig Rodriguesto be executed by the runtime engine during the cleanup phase of the execution.
167c243e490SMarcel MoolenaarThis property is automatically set by the framework when defining a test case
168c243e490SMarcel Moolenaarwith a cleanup routine, so it should never be set by hand.
169c243e490SMarcel Moolenaar.It ident
170c243e490SMarcel MoolenaarType: textual.
171c243e490SMarcel MoolenaarRequired.
172c243e490SMarcel Moolenaar.Pp
173c243e490SMarcel MoolenaarThe test case's identifier.
174c243e490SMarcel MoolenaarMust be unique inside the test program and should be short but descriptive.
175c243e490SMarcel Moolenaar.It require.arch
176c243e490SMarcel MoolenaarType: textual.
177c243e490SMarcel MoolenaarOptional.
178c243e490SMarcel Moolenaar.Pp
179c243e490SMarcel MoolenaarA whitespace separated list of architectures that the test case can be run
180c243e490SMarcel Moolenaarunder without causing errors due to an architecture mismatch.
181c243e490SMarcel Moolenaar.It require.config
182c243e490SMarcel MoolenaarType: textual.
183c243e490SMarcel MoolenaarOptional.
184c243e490SMarcel Moolenaar.Pp
185c243e490SMarcel MoolenaarA whitespace separated list of configuration variables that must be defined
186c243e490SMarcel Moolenaarto execute the test case.
187c243e490SMarcel MoolenaarIf any of the required variables is not defined, the test case is
188c243e490SMarcel Moolenaar.Em skipped .
1890677dfd1SJulio Merino.It require.diskspace
1900677dfd1SJulio MerinoType: integer.
1910677dfd1SJulio MerinoOptional.
1920677dfd1SJulio MerinoSpecifies the minimum amount of available disk space needed by the test.
1930677dfd1SJulio MerinoThe value can have a size suffix such as
1940677dfd1SJulio Merino.Sq K ,
1950677dfd1SJulio Merino.Sq M ,
1960677dfd1SJulio Merino.Sq G
1970677dfd1SJulio Merinoor
1980677dfd1SJulio Merino.Sq T
1990677dfd1SJulio Merinoto make the amount of bytes easier to type and read.
200c243e490SMarcel Moolenaar.It require.files
201c243e490SMarcel MoolenaarType: textual.
202c243e490SMarcel MoolenaarOptional.
203c243e490SMarcel Moolenaar.Pp
204c243e490SMarcel MoolenaarA whitespace separated list of files that must be present to execute the
205c243e490SMarcel Moolenaartest case.
206c243e490SMarcel MoolenaarThe names of these files must be absolute paths.
207c243e490SMarcel MoolenaarIf any of the required files is not found, the test case is
208c243e490SMarcel Moolenaar.Em skipped .
209c243e490SMarcel Moolenaar.It require.machine
210c243e490SMarcel MoolenaarType: textual.
211c243e490SMarcel MoolenaarOptional.
212c243e490SMarcel Moolenaar.Pp
213c243e490SMarcel MoolenaarA whitespace separated list of machine types that the test case can be run
214c243e490SMarcel Moolenaarunder without causing errors due to a machine type mismatch.
215c243e490SMarcel Moolenaar.It require.memory
216c243e490SMarcel MoolenaarType: integer.
217c243e490SMarcel MoolenaarOptional.
218c243e490SMarcel MoolenaarSpecifies the minimum amount of physical memory needed by the test.
219c243e490SMarcel MoolenaarThe value can have a size suffix such as
220c243e490SMarcel Moolenaar.Sq K ,
221c243e490SMarcel Moolenaar.Sq M ,
222c243e490SMarcel Moolenaar.Sq G
223c243e490SMarcel Moolenaaror
224c243e490SMarcel Moolenaar.Sq T
225c243e490SMarcel Moolenaarto make the amount of bytes easier to type and read.
226c243e490SMarcel Moolenaar.It require.progs
227c243e490SMarcel MoolenaarType: textual.
228c243e490SMarcel MoolenaarOptional.
229c243e490SMarcel Moolenaar.Pp
230c243e490SMarcel MoolenaarA whitespace separated list of programs that must be present to execute
231c243e490SMarcel Moolenaarthe test case.
232c243e490SMarcel MoolenaarThese can be given as plain names, in which case they are looked in the
233c243e490SMarcel Moolenaaruser's
234c243e490SMarcel Moolenaar.Ev PATH ,
235c243e490SMarcel Moolenaaror as absolute paths.
236c243e490SMarcel MoolenaarIf any of the required programs is not found, the test case is
237c243e490SMarcel Moolenaar.Em skipped .
238c243e490SMarcel Moolenaar.It require.user
239c243e490SMarcel MoolenaarType: textual.
240c243e490SMarcel MoolenaarOptional.
241c243e490SMarcel Moolenaar.Pp
242c243e490SMarcel MoolenaarThe required privileges to execute the test case.
243c243e490SMarcel MoolenaarCan be one of
244c243e490SMarcel Moolenaar.Sq root
245c243e490SMarcel Moolenaaror
246c243e490SMarcel Moolenaar.Sq unprivileged .
247c243e490SMarcel Moolenaar.Pp
248c243e490SMarcel MoolenaarIf the test case is running as a regular user and this property is
249c243e490SMarcel Moolenaar.Sq root ,
250c243e490SMarcel Moolenaarthe test case is
251c243e490SMarcel Moolenaar.Em skipped .
252c243e490SMarcel Moolenaar.Pp
253c243e490SMarcel MoolenaarIf the test case is running as root and this property is
254c243e490SMarcel Moolenaar.Sq unprivileged ,
255b9306c04SCraig Rodriguesthe runtime engine will automatically drop the privileges if the
256c243e490SMarcel Moolenaar.Sq unprivileged-user
257c243e490SMarcel Moolenaarconfiguration property is set; otherwise the test case is
258c243e490SMarcel Moolenaar.Em skipped .
259c243e490SMarcel Moolenaar.It timeout
260c243e490SMarcel MoolenaarType: integral.
261c243e490SMarcel MoolenaarOptional; defaults to
262c243e490SMarcel Moolenaar.Sq 300 .
263c243e490SMarcel Moolenaar.Pp
264c243e490SMarcel MoolenaarSpecifies the maximum amount of time the test case can run.
265c243e490SMarcel MoolenaarThis is particularly useful because some tests can stall either because they
266c243e490SMarcel Moolenaarare incorrectly coded or because they trigger an anomalous behavior of the
267c243e490SMarcel Moolenaarprogram.
268c243e490SMarcel MoolenaarIt is not acceptable for these tests to stall the whole execution of the
269c243e490SMarcel Moolenaartest program.
270c243e490SMarcel Moolenaar.Pp
271c243e490SMarcel MoolenaarCan optionally be set to zero, in which case the test case has no run-time
272c243e490SMarcel Moolenaarlimit.
273c243e490SMarcel MoolenaarThis is discouraged.
274*c203bd70SAlex Richardson.It X- Ns Sq NAME
275*c203bd70SAlex RichardsonType: textual.
276*c203bd70SAlex RichardsonOptional.
277*c203bd70SAlex Richardson.Pp
278*c203bd70SAlex RichardsonA user-defined property named
279*c203bd70SAlex Richardson.Sq NAME .
280*c203bd70SAlex RichardsonThese properties are free form, have no special meaning within ATF, and can
281*c203bd70SAlex Richardsonbe specified at will by the test case.
282*c203bd70SAlex RichardsonThe runtime engine should propagate these properties from the test case to
283*c203bd70SAlex Richardsonthe end user so that the end user can rely on custom properties for test case
284*c203bd70SAlex Richardsontagging and classification.
285c243e490SMarcel Moolenaar.El
286c243e490SMarcel Moolenaar.Ss Environment
287c243e490SMarcel MoolenaarEvery time a test case is executed, several environment variables are
288c243e490SMarcel Moolenaarcleared or reseted to sane values to ensure they do not make the test fail
289c243e490SMarcel Moolenaardue to unexpected conditions.
290c243e490SMarcel MoolenaarThese variables are:
291c243e490SMarcel Moolenaar.Bl -tag -width LCXMESSAGESXX
292c243e490SMarcel Moolenaar.It Ev HOME
293c243e490SMarcel MoolenaarSet to the work directory's path.
294c243e490SMarcel Moolenaar.It Ev LANG
295c243e490SMarcel MoolenaarUndefined.
296c243e490SMarcel Moolenaar.It Ev LC_ALL
297c243e490SMarcel MoolenaarUndefined.
298c243e490SMarcel Moolenaar.It Ev LC_COLLATE
299c243e490SMarcel MoolenaarUndefined.
300c243e490SMarcel Moolenaar.It Ev LC_CTYPE
301c243e490SMarcel MoolenaarUndefined.
302c243e490SMarcel Moolenaar.It Ev LC_MESSAGES
303c243e490SMarcel MoolenaarUndefined.
304c243e490SMarcel Moolenaar.It Ev LC_MONETARY
305c243e490SMarcel MoolenaarUndefined.
306c243e490SMarcel Moolenaar.It Ev LC_NUMERIC
307c243e490SMarcel MoolenaarUndefined.
308c243e490SMarcel Moolenaar.It Ev LC_TIME
309c243e490SMarcel MoolenaarUndefined.
310c243e490SMarcel Moolenaar.It Ev TZ
311c243e490SMarcel MoolenaarHardcoded to
312c243e490SMarcel Moolenaar.Sq UTC .
313c243e490SMarcel Moolenaar.El
314c243e490SMarcel Moolenaar.Ss Work directories
315c243e490SMarcel MoolenaarThe test program always creates a temporary directory
316c243e490SMarcel Moolenaarand switches to it before running the test case's body.
317c243e490SMarcel MoolenaarThis way the test case is free to modify its current directory as it
318c243e490SMarcel Moolenaarwishes, and the runtime engine will be able to clean it up later on in a
319c243e490SMarcel Moolenaarsafe way, removing any traces of its execution from the system.
320c243e490SMarcel MoolenaarTo do so, the runtime engine will perform a recursive removal of the work
321c243e490SMarcel Moolenaardirectory without crossing mount points; if a mount point is found, the
322c243e490SMarcel Moolenaarfile system will be unmounted (if possible).
323c243e490SMarcel Moolenaar.Ss File creation mode mask (umask)
324c243e490SMarcel MoolenaarTest cases are always executed with a file creation mode mask (umask) of
325c243e490SMarcel Moolenaar.Sq 0022 .
326c243e490SMarcel MoolenaarThe test case's code is free to change this during execution.
327c243e490SMarcel Moolenaar.Sh SEE ALSO
328b9306c04SCraig Rodrigues.Xr atf-test-program 1
329