ATF-TEST-CASE(4) | Kernel Interfaces Manual | ATF-TEST-CASE(4) |
A test case is defined by three components regardless of the language it is implemented in: a header, a body and a cleanup routine. The header is, basically, a declarative piece of code that defines several properties to describe what the test case does and how it behaves. In other words: it defines the test case's meta-data, further described in the Meta-data section. The body is the test case itself. It executes all actions needed to reproduce the test, and checks for failures. This body is only executed if the abstract conditions specified by the header are met. The cleanup routine routine is a piece of code always executed after the body, regardless of the exit status of the test case. It can be used to undo side-effects of the test case. Note that almost all side-effects of a test case are automatically cleaned up by the library; this is explained in more detail in the rest of this document.
It is extremely important to keep the separation between a test case's header and body well-defined, because the header is always parsed, whereas the body is only executed when the conditions defined in the header are met and when the user specifies that test case.
At last, test cases are always contained into test programs. The test programs act as a front-end to them, providing a consistent interface to the user and several APIs to ease their implementation.
The possible exit status of a test case are one of the following:
The usefulness of the ‘expected_*' results comes when writing test cases that verify known failures caused, in general, due to programming errors (aka bugs). Whenever the faulty condition that the expectation is trying to convery is fixed, then the test case will be reported as ‘failed' and the developer will have to adjust it to match its new condition.
It is important to note that all ‘expected_*' results are only provided as a hint to the caller; the caller must verify that the test case did actually terminate as the expected condition says.
Test cases will log their results to an auxiliary file, which is then collected by the test program they are contained in. The developer need not care about this as long as he uses the correct APIs to implement the test cases.
The standard input of the test cases is unconditionally connected to ‘/dev/zero'.
A brief textual description of the test case's purpose. Will be shown to the user in reports. Also good for documentation purposes.
If set to true, specifies that the test case has a cleanup routine that has to be executed by atf-run(1) during the cleanup phase of the execution. This property is automatically set by the framework when defining a test case with a cleanup routine, so it should never be set by hand.
The test case's identifier. Must be unique inside the test program and should be short but descriptive.
A whitespace separated list of architectures that the test case can be run under without causing errors due to an architecture mismatch.
A whitespace separated list of configuration variables that must be defined to execute the test case. If any of the required variables is not defined, the test case is skipped.
A whitespace separated list of files that must be present to execute the test case. The names of these files must be absolute paths. If any of the required files is not found, the test case is skipped.
A whitespace separated list of machine types that the test case can be run under without causing errors due to a machine type mismatch.
A whitespace separated list of programs that must be present to execute the test case. These can be given as plain names, in which case they are looked in the user's PATH, or as absolute paths. If any of the required programs is not found, the test case is skipped.
The required privileges to execute the test case. Can be one of ‘root' or ‘unprivileged'.
If the test case is running as a regular user and this property is ‘root', the test case is skipped.
If the test case is running as root and this property is ‘unprivileged', atf-run(1) will automatically drop the privileges if the ‘unprivileged-user' configuration property is set; otherwise the test case is skipped.
Specifies the maximum amount of time the test case can run. This is particularly useful because some tests can stall either because they are incorrectly coded or because they trigger an anomalous behavior of the program. It is not acceptable for these tests to stall the whole execution of the test program.
Can optionally be set to zero, in which case the test case has no run-time limit. This is discouraged.
January 13, 2011 | NetBSD 6.1 |