1 .\" Copyright 2012 Google Inc.
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions are
8 .\" * Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" * Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
13 .\" * Neither the name of Google Inc. nor the names of its contributors
14 .\" may be used to endorse or promote products derived from this software
15 .\" without specific prior written permission.
17 .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 .\" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 .\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 .\" A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 .\" OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 .\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 .\" OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 .Dt KYUA-ATF-INTERFACE 1
33 .Nd Description of the ATF test program interface
35 The interface of ATF test programs is the interface of the test
36 programs linked to the
41 libraries provided by ATF.
43 The ATF interface can be understood as the mechanisms used by test programs
44 to communicate with the runtime engine as well as the assumptions that test
45 programs and test cases can make while running.
47 A test case is the most basic part of a test suite. A test case is
48 supposed to reproduce one, and only one, scenario. For example: if the
49 item under test was a function, the test case would provide a single set of
50 input parameters to the function and check its output; If the item under
51 test was a binary, the test case would provide a single set of arguments to
52 the program and check its behavior.
54 Test cases have three parts:
55 .Bl -tag -width cleanupXX
57 Programmatically defines metadata properties. The head must not perform
58 any other thing than defining such properties. In particular, no testing
59 whatsoever can happen in the head. (Ideally the definition of metadata
60 properties would not happen programmatically.)
62 The actual test case which performs any desired testing and reports a
63 result. The body is executed by the runtime engine in a deterministic way;
64 see the isolation section below.
66 An optional cleanup routine. Note that the runtime engine will attempt to
67 clean up the work directory automatically, so this routine should only be
68 provided in cases where the test modifies system-wide state not known by
69 the runtime engine. The cleanup part is executed in the same directory as
70 the body. However, the body and the cleanup parts
71 .Em do not share the same process space ;
72 the only way to pass data around from the body to the cleanup is by means
73 of files in the work directory.
75 .Ss Metadata properties
76 The following test case metadata properties must be exported in the test
77 case list for every test case:
80 Single-word string. The name of the test case. Must be unique within the
84 The following test case metadata properties may be exported in the
85 test case list for every test case:
88 Multi-word string. A textual description for the test case. Usually,
89 providing a descriptive identifier is better than providing a textual
92 Boolean. Whether the test case defines a cleanup routine or not.
94 Whitespace separated list of the architectures required by the test case.
95 If defined, the test case is skipped unless the host architecture matches
96 any of the values defined in this property.
98 Whitespace separated list of configuration variable names. The list of
99 configuration variables that must be defined. The test is skipped if any
102 Whitespace separated list of absolute paths to installed files. If any of
103 these files is not found, the test case is skipped.
104 .It Va require.machine
105 Whitespace separated list of the machine types required by the test case.
106 If defined, the test case is skipped unless the host machine type matches
107 any of the values defined in this property.
109 Whitespace separated list of program names (either absolute names or base
110 names). If any of these programs is not found, the test case is skipped.
118 the test case must be run as the superuser or otherwise it is skipped. If
120 the test case must be run as an unprivileged user or else it is skipped.
122 Integer. The amount of seconds the test case can run for before it is
123 killed by the runtime engine.
125 .Ss Configuration properties
126 The following properties may be defined by the runtime engine and are
127 propagated to the test cases:
129 .It Va unprivileged-user
130 String, optional. Specifies the name of the user under which tests that
132 .Sq require.user=unprivileged
136 A test case must always report a result by creating the results file
137 specified through the
139 flag. For convenience when running test cases without the runtime engine,
140 this file may point to
144 in which case the file must not be created (because the creation will
147 Aside from creating the results file, the process in which the test case
148 runs must terminate in particular ways for the test result to be considered
151 If the test case fails to create the test result, if the test result is
152 created but contains an invalid syntax, or if the termination status of the
153 process does not match the requirements of the test result, the runtime
154 engine marks the test case as
158 state is decided by the runtime engine; a test case cannot report itself as
161 The general syntax for the results file is as follows:
162 .Bd -literal -offset indent
163 <status>[[(int)]: reason]
166 The following results are allowed:
169 The process is expected to terminate either due to a clean call to
171 or due to the reception of a signal. The contents of the file are
172 .Sq expected_death: <reason>\\n .
174 .Sq expected_death: Calling libdofoo breaks due to bug xyz .
176 The process is expected to terminate cleanly. The contents of the file are
177 .Sq expected_exit: <reason>
178 if the exit code is irrelevant or
179 .Sq expected_exit(<exitcode>): <reason>
180 if the process must terminate with a given exit code. Examples:
181 .Sq expected_exit: Calling bar exits but it should not
183 .Sq expected_exit(123): Calling bar exits with an unexpected code .
185 The process must exit cleanly with an
187 exit code. The contents of the file are
188 .Sq expected_failure: <reason>\\n
190 .Sq expected_failure: 2 + 2 = 3 .
192 The process is expected to terminate due to the reception of a signal. The
193 contents of the file are
194 .Sq expected_signal: <reason>
195 if the signal number is irrelevant or
196 .Sq expected_signal(<signalno>): <reason>
197 if the process must terminate due to a particular signal. Examples:
198 .Sq expected_signal: Calling bar crashes
200 .Sq expected_signal(1): Calling bar kills ourselves due to unhandled SIGHUP .
202 The process is expected to hang for longer than its
204 metadata property. Only the runtime engine can control this situation
205 because the runtime engine is the one implementing the timeout
208 The process must exit cleanly with an
210 exit code. The contents of the file are
211 .Sq failed: <reason>\\n .
213 .Sq failed: Failed on purpose\\n .
215 The process must exit cleanly with an
217 exit code. The contents of the file are
220 The process must exit cleanly with an
222 exit code. The contents of the file are
223 .Sq skipped: <reason>\\n .
225 .Sq skipped: Skipped because the foo is not present\\n .
228 The runtime engine attempts to isolate test cases from other test cases in
229 the same test program and from the rest of the system by performing what is
231 .Em test case isolation .
233 Whenever the user runs a test program binary by hand (i.e. not through
235 the test program will print a warning message stating that test case
236 isolation does not work and therefore the program may cause side-effects
237 and/or report invalid values.
239 The runtime engine must set the
240 .Va __RUNNING_INSIDE_ATF_RUN
241 environment variable to the magic value
242 .Sq internal-yes-value
243 to tell the test programs that they are being run with isolation enabled.
245 The test case isolation performs the following:
248 Each test case body and cleanup routines are executed in independent
249 processes. Corollary: the test case can do whatever it wants to the
250 current process (such as modifying global variables) without having to undo
253 The test case body and cleanup are executed in their own process groups.
254 Should they spawn any children, such children should maintain the same
255 process group. This is done to allow the runtime engine to kill the whole
256 process subtree once the test case finishes (or if the test case hangs).
258 The test case body and its cleanup (if any) are executed in a temporary
259 directory automatically created by the runtime engine. This temporary
260 directory is shared among the body and cleanup parts of a single test case
261 but is completely separate from the temporary directories of other tests.
262 Corollary: the test case body and cleanup routines can write to their
263 current directory without bothering to clean any files and/or directories
264 they create. The runtime engine takes care to recursively delete the
265 temporary directories after the execution of a test case. Any file systems
266 mounted within the temporary directory will be unmounted if possible.
270 environment variable is set to the absolute path of the work directory.
272 The value of the umask is set to 0022.
284 variables are unset. The
289 The maximum soft core size limit is raised to its corresponding hard limit.
290 This is a simple, best-effort attempt at allowing test cases to dump core
291 for further diagnostic purposes.
294 A test program is, simply put, a collection of related test cases. The
295 test program can be seen as a command-line dispatcher for the test cases.
296 A test program must provide one or more test cases. If it does not contain
297 any test case, the runtime system will report it as invalid.
299 Test programs expose their list of test cases in a machine parseable
300 format. The runtime engine obtains the list of test cases to know what
301 tests to run and to know how to set up the environment of each test prior
302 execution. The test program must not do any test when asked to dump its
305 The generic syntax to obtain the list of test cases included in a test
307 .Bd -literal -offset indent
311 The list of test cases follows the following format:
312 .Bd -literal -offset indent
313 LIST ::= HEADER NEWLINE TEST_CASES
315 HEADER ::= 'Content-Type: application/X-atf-tp; version="1"'
317 TEST_CASES ::= TEST_CASE | TEST_CASE NEWLINE TEST_CASES
319 TEST_CASE ::= IDENT_PROPERTY PROPERTIES
320 IDENT_PROPERTY ::= 'ident' DELIM STRING NEWLINE
323 PROPERTIES ::= PROPERTY | PROPERTY PROPERTIES
324 PROPERTY ::= PROPERTY_NAME DELIM STRING NEWLINE
325 PROPERTY_NAME ::= (see below)
329 .Bd -literal -offset indent
330 Content-Type: application/X-atf-tp; version="1"
333 descr: Tests that the addition function works
336 descr: Tests that the subtraction function works
339 descr: Tests removing files
345 The syntax to run a test case body part is:
346 .Bd -literal -offset indent
347 <test-program> [-r resfile] [-s srcdir] [-v var=value]* <test-case>[:body]
350 This must run the test case body
352 without any attempt of isolating it from the rest of the system. It is the
353 responsibility of the runtime engine to do such isolation.
355 The runtime engine always passes the path of a nonexistent file to
357 which must be created by the test case; and always passes an absolute path
360 flag pointing to the directory containing the test program executable.
362 The runtime engine shall pass any configuration variables it wants through
365 flag, and these can be later inspected by the test case at will.
367 A note to users: if you run the test case by hand (not through
370 from the command line, none of the isolation features described in the
371 isolation section apply. This means that the test case can (and probably
372 will) write to the current directory and leave garbage behind. Also, given
373 that the test case is executed without e.g. clearing the environment, the
374 results of the test case may differ from those obtained when running the
375 test case inside the runtime engine.
376 .Em Only use this for debugging purposes
377 (i.e. to run the test case code under GDB).
379 The syntax to run a test case cleanup part is:
380 .Bd -literal -offset indent
381 <test-program> [-s srcdir] [-v var=value]* <test-case>:cleanup
384 This can only be performed if and only if the test case sets the
386 property to true. Otherwise the behavior of executing the cleanup part is
393 apply as to when running the body.
395 The cleanup part must be executed in the same directory as the body but in
396 a separate process space. The only way for test cases to transfer state
397 (if any) from the body to the cleanup routine is by means of files in the
400 The cleanup part does not have to worry about deleting temporary files
401 created in the current directory. The runtime engine does this