1e2207522Sjmmv.\" 2e2207522Sjmmv.\" Automated Testing Framework (atf) 3e2207522Sjmmv.\" 436b886feSjmmv.\" Copyright (c) 2007 The NetBSD Foundation, Inc. 5e2207522Sjmmv.\" All rights reserved. 6e2207522Sjmmv.\" 7e2207522Sjmmv.\" Redistribution and use in source and binary forms, with or without 8e2207522Sjmmv.\" modification, are permitted provided that the following conditions 9e2207522Sjmmv.\" are met: 10e2207522Sjmmv.\" 1. Redistributions of source code must retain the above copyright 11e2207522Sjmmv.\" notice, this list of conditions and the following disclaimer. 12e2207522Sjmmv.\" 2. Redistributions in binary form must reproduce the above copyright 13e2207522Sjmmv.\" notice, this list of conditions and the following disclaimer in the 14e2207522Sjmmv.\" documentation and/or other materials provided with the distribution. 15e2207522Sjmmv.\" 16e2207522Sjmmv.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 17e2207522Sjmmv.\" CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 18e2207522Sjmmv.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19e2207522Sjmmv.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20e2207522Sjmmv.\" IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 21e2207522Sjmmv.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22e2207522Sjmmv.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 23e2207522Sjmmv.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24e2207522Sjmmv.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25e2207522Sjmmv.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 26e2207522Sjmmv.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27e2207522Sjmmv.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28e2207522Sjmmv.\" 29*227e5be6Sgutteridge.Dd August 27, 2023 30edebbb8eSjmmv.Dt ATF-TEST-CASE 4 31e2207522Sjmmv.Os 32e2207522Sjmmv.Sh NAME 33e2207522Sjmmv.Nm atf-test-case 34e2207522Sjmmv.Nd generic description of test cases 35e2207522Sjmmv.Sh DESCRIPTION 36e2207522SjmmvA 37e2207522Sjmmv.Em test case 38e2207522Sjmmvis a piece of code that stress-tests a specific feature of the software. 39e2207522SjmmvThis feature is typically self-contained enough, either in the amount of 40e2207522Sjmmvcode that implements it or in the general idea that describes it, to 41e2207522Sjmmvwarrant its independent testing. 42e2207522SjmmvGiven this, test cases are very fine-grained, but they attempt to group 43e2207522Sjmmvsimilar smaller tests which are semantically related. 44e2207522Sjmmv.Pp 45e2207522SjmmvA test case is defined by three components regardless of the language it is 46e2207522Sjmmvimplemented in: a header, a body and a cleanup routine. 47e2207522SjmmvThe 48e2207522Sjmmv.Em header 49e2207522Sjmmvis, basically, a declarative piece of code that defines several 50e2207522Sjmmvproperties to describe what the test case does and how it behaves. 51e2207522SjmmvIn other words: it defines the test case's 52e2207522Sjmmv.Em meta-data , 53e2207522Sjmmvfurther described in the 54e2207522Sjmmv.Sx Meta-data 55e2207522Sjmmvsection. 56e2207522SjmmvThe 57e2207522Sjmmv.Em body 58e2207522Sjmmvis the test case itself. 59e2207522SjmmvIt executes all actions needed to reproduce the test, and checks for 60e2207522Sjmmvfailures. 61e2207522SjmmvThis body is only executed if the abstract conditions specified by the 62e2207522Sjmmvheader are met. 63e2207522SjmmvThe 646f587c98Sjmmv.Em cleanup 65e2207522Sjmmvroutine is a piece of code always executed after the body, regardless of 66e2207522Sjmmvthe exit status of the test case. 67e2207522SjmmvIt can be used to undo side-effects of the test case. 68e2207522SjmmvNote that almost all side-effects of a test case are automatically cleaned 69e2207522Sjmmvup by the library; this is explained in more detail in the rest of this 70e2207522Sjmmvdocument. 71e2207522Sjmmv.Pp 72e2207522SjmmvIt is extremely important to keep the separation between a test case's 73e2207522Sjmmvheader and body well-defined, because the header is 74e2207522Sjmmv.Em always 75e2207522Sjmmvparsed, whereas the body is only executed when the conditions defined in 76e2207522Sjmmvthe header are met and when the user specifies that test case. 77e2207522Sjmmv.Pp 78e2207522SjmmvAt last, test cases are always contained into test programs. 79e2207522SjmmvThe test programs act as a front-end to them, providing a consistent 80e2207522Sjmmvinterface to the user and several APIs to ease their implementation. 81e2207522Sjmmv.Ss Results 82edebbb8eSjmmvUpon termination, a test case reports a status and, optionally, a textual 83edebbb8eSjmmvreason describing why the test reported such status. 84edebbb8eSjmmvThe caller must ensure that the test case really performed the task that its 85edebbb8eSjmmvstatus describes, as the test program may be bogus and therefore providing a 86edebbb8eSjmmvmisleading result (e.g. providing a result that indicates success but the 87edebbb8eSjmmverror code of the program says otherwise). 88edebbb8eSjmmv.Pp 89edebbb8eSjmmvThe possible exit status of a test case are one of the following: 90edebbb8eSjmmv.Bl -tag -width expectedXfailureXX 91edebbb8eSjmmv.It expected_death 92edebbb8eSjmmvThe test case expects to terminate abruptly. 93edebbb8eSjmmv.It expected_exit 94edebbb8eSjmmvThe test case expects to exit cleanly. 95edebbb8eSjmmv.It expected_failure 96edebbb8eSjmmvThe test case expects to exit with a controller fatal/non-fatal failure. 97edebbb8eSjmmvIf this happens, the test program exits with a success error code. 98edebbb8eSjmmv.It expected_signal 99edebbb8eSjmmvThe test case expects to receive a signal that makes it terminate. 100edebbb8eSjmmv.It expected_timeout 101edebbb8eSjmmvThe test case expects to execute for longer than its timeout. 102e2207522Sjmmv.It passed 103e2207522SjmmvThe test case was executed successfully. 104edebbb8eSjmmvThe test program exits with a success error code. 105e2207522Sjmmv.It skipped 106e2207522SjmmvThe test case could not be executed because some preconditions were not 107e2207522Sjmmvmet. 108e2207522SjmmvThis is not a failure because it can typically be resolved by adjusting 109e2207522Sjmmvthe system to meet the necessary conditions. 110e2207522SjmmvThis is always accompanied by a 111e2207522Sjmmv.Em reason , 112e2207522Sjmmva message describing why the test was skipped. 113edebbb8eSjmmvThe test program exits with a success error code. 114e2207522Sjmmv.It failed 115e2207522SjmmvAn error appeared during the execution of the test case. 116e2207522SjmmvThis is always accompanied by a 117e2207522Sjmmv.Em reason , 118e2207522Sjmmva message describing why the test failed. 119edebbb8eSjmmvThe test program exits with a failure error code. 120e2207522Sjmmv.El 121edebbb8eSjmmv.Pp 122edebbb8eSjmmvThe usefulness of the 123edebbb8eSjmmv.Sq expected_* 124edebbb8eSjmmvresults comes when writing test cases that verify known failures caused, 125edebbb8eSjmmvin general, due to programming errors (aka bugs). 12697bff204SjmmvWhenever the faulty condition that the 12797bff204Sjmmv.Sq expected_* 12897bff204Sjmmvresult is trying to cover is fixed, then the test case will be reported as 129edebbb8eSjmmv.Sq failed 130edebbb8eSjmmvand the developer will have to adjust it to match its new condition. 131edebbb8eSjmmv.Pp 132edebbb8eSjmmvIt is important to note that all 133edebbb8eSjmmv.Sq expected_* 134edebbb8eSjmmvresults are only provided as a 135edebbb8eSjmmv.Em hint 136edebbb8eSjmmvto the caller; the caller must verify that the test case did actually terminate 137edebbb8eSjmmvas the expected condition says. 138e2207522Sjmmv.Ss Input/output 139e2207522SjmmvTest cases are free to print whatever they want to their 140e2207522Sjmmv.Xr stdout 4 141e2207522Sjmmvand 142e2207522Sjmmv.Xr stderr 4 143e2207522Sjmmvfile descriptors. 144e2207522SjmmvThey are, in fact, encouraged to print status information as they execute 145e2207522Sjmmvto keep the user informed of their actions. 146e2207522SjmmvThis is specially important for long test cases. 147e2207522Sjmmv.Pp 148e2207522SjmmvTest cases will log their results to an auxiliary file, which is then 149e2207522Sjmmvcollected by the test program they are contained in. 150e2207522SjmmvThe developer need not care about this as long as he uses the correct 151e2207522SjmmvAPIs to implement the test cases. 1521d706b81Sjmmv.Pp 1531d706b81SjmmvThe standard input of the test cases is unconditionally connected to 1541d706b81Sjmmv.Sq /dev/zero . 155e2207522Sjmmv.Ss Meta-data 156*227e5be6SgutteridgeThe following meta-data properties can be exposed via the test case's head: 157e2207522Sjmmv.Bl -tag -width requireXmachineXX 158e2207522Sjmmv.It descr 159e2207522SjmmvType: textual. 160e2207522SjmmvRequired. 161e2207522Sjmmv.Pp 162e2207522SjmmvA brief textual description of the test case's purpose. 163e2207522SjmmvWill be shown to the user in reports. 164e2207522SjmmvAlso good for documentation purposes. 165edebbb8eSjmmv.It has.cleanup 166edebbb8eSjmmvType: boolean. 167edebbb8eSjmmvOptional. 168edebbb8eSjmmv.Pp 169edebbb8eSjmmvIf set to true, specifies that the test case has a cleanup routine that has 170edebbb8eSjmmvto be executed by 171edebbb8eSjmmv.Xr atf-run 1 172edebbb8eSjmmvduring the cleanup phase of the execution. 173edebbb8eSjmmvThis property is automatically set by the framework when defining a test case 174edebbb8eSjmmvwith a cleanup routine, so it should never be set by hand. 175e2207522Sjmmv.It ident 176e2207522SjmmvType: textual. 177e2207522SjmmvRequired. 178e2207522Sjmmv.Pp 179e2207522SjmmvThe test case's identifier. 180e2207522SjmmvMust be unique inside the test program and should be short but descriptive. 181e2207522Sjmmv.It require.arch 1821d706b81SjmmvType: textual. 183e2207522SjmmvOptional. 18412aa0b5aSjmmv.Pp 185e2207522SjmmvA whitespace separated list of architectures that the test case can be run 186e2207522Sjmmvunder without causing errors due to an architecture mismatch. 187e2207522Sjmmv.It require.config 188e2207522SjmmvType: textual. 189e2207522SjmmvOptional. 190e2207522Sjmmv.Pp 191e2207522SjmmvA whitespace separated list of configuration variables that must be defined 192e2207522Sjmmvto execute the test case. 193e2207522SjmmvIf any of the required variables is not defined, the test case is 194e2207522Sjmmv.Em skipped . 1951d706b81Sjmmv.It require.files 1961d706b81SjmmvType: textual. 1971d706b81SjmmvOptional. 1981d706b81Sjmmv.Pp 1991d706b81SjmmvA whitespace separated list of files that must be present to execute the 2001d706b81Sjmmvtest case. 2011d706b81SjmmvThe names of these files must be absolute paths. 2021d706b81SjmmvIf any of the required files is not found, the test case is 2031d706b81Sjmmv.Em skipped . 204e2207522Sjmmv.It require.machine 2051d706b81SjmmvType: textual. 206e2207522SjmmvOptional. 20712aa0b5aSjmmv.Pp 208e2207522SjmmvA whitespace separated list of machine types that the test case can be run 209e2207522Sjmmvunder without causing errors due to a machine type mismatch. 21036b886feSjmmv.It require.memory 21136b886feSjmmvType: integer. 21236b886feSjmmvOptional. 21336b886feSjmmvSpecifies the minimum amount of physical memory needed by the test. 21436b886feSjmmvThe value can have a size suffix such as 21536b886feSjmmv.Sq K , 21636b886feSjmmv.Sq M , 21736b886feSjmmv.Sq G 21836b886feSjmmvor 21936b886feSjmmv.Sq T 22036b886feSjmmvto make the amount of bytes easier to type and read. 221e2207522Sjmmv.It require.progs 222e2207522SjmmvType: textual. 223e2207522SjmmvOptional. 224e2207522Sjmmv.Pp 225e2207522SjmmvA whitespace separated list of programs that must be present to execute 226e2207522Sjmmvthe test case. 227e2207522SjmmvThese can be given as plain names, in which case they are looked in the 228e2207522Sjmmvuser's 229e2207522Sjmmv.Ev PATH , 230e2207522Sjmmvor as absolute paths. 231e2207522SjmmvIf any of the required programs is not found, the test case is 232e2207522Sjmmv.Em skipped . 233e2207522Sjmmv.It require.user 234e2207522SjmmvType: textual. 235e2207522SjmmvOptional. 236e2207522Sjmmv.Pp 237e2207522SjmmvThe required privileges to execute the test case. 238e2207522SjmmvCan be one of 239e2207522Sjmmv.Sq root 240e2207522Sjmmvor 241e2207522Sjmmv.Sq unprivileged . 2421d706b81Sjmmv.Pp 2431d706b81SjmmvIf the test case is running as a regular user and this property is 2441d706b81Sjmmv.Sq root , 2451d706b81Sjmmvthe test case is 246e2207522Sjmmv.Em skipped . 247e2207522Sjmmv.Pp 2481d706b81SjmmvIf the test case is running as root and this property is 2491d706b81Sjmmv.Sq unprivileged , 2501d706b81Sjmmv.Xr atf-run 1 2511d706b81Sjmmvwill automatically drop the privileges if the 2521d706b81Sjmmv.Sq unprivileged-user 2531d706b81Sjmmvconfiguration property is set; otherwise the test case is 2541d706b81Sjmmv.Em skipped . 255e2207522Sjmmv.It timeout 256e2207522SjmmvType: integral. 2579b3149ccSjmmvOptional; defaults to 2589e95dfadSjmmv.Sq 300 . 25912aa0b5aSjmmv.Pp 260e2207522SjmmvSpecifies the maximum amount of time the test case can run. 261e2207522SjmmvThis is particularly useful because some tests can stall either because they 262e2207522Sjmmvare incorrectly coded or because they trigger an anomalous behavior of the 263e2207522Sjmmvprogram. 264e2207522SjmmvIt is not acceptable for these tests to stall the whole execution of the 265e2207522Sjmmvtest program. 266e2207522Sjmmv.Pp 267e2207522SjmmvCan optionally be set to zero, in which case the test case has no run-time 268e2207522Sjmmvlimit. 269e2207522SjmmvThis is discouraged. 270*227e5be6Sgutteridge.It X- Ns Sq NAME 271*227e5be6SgutteridgeType: textual. 272*227e5be6SgutteridgeOptional. 273*227e5be6Sgutteridge.Pp 274*227e5be6SgutteridgeA user-defined property named 275*227e5be6Sgutteridge.Sq NAME . 276*227e5be6SgutteridgeThese properties are free form, have no special meaning within ATF, and can 277*227e5be6Sgutteridgebe specified at will by the test case. 278*227e5be6SgutteridgeThe runtime engine should propagate these properties from the test case to 279*227e5be6Sgutteridgethe end user so that the end user can rely on custom properties for test case 280*227e5be6Sgutteridgetagging and classification. 281e2207522Sjmmv.El 282e2207522Sjmmv.Ss Environment 283e2207522SjmmvEvery time a test case is executed, several environment variables are 284e2207522Sjmmvcleared or reseted to sane values to ensure they do not make the test fail 285e2207522Sjmmvdue to unexpected conditions. 286e2207522SjmmvThese variables are: 287e2207522Sjmmv.Bl -tag -width LCXMESSAGESXX 288e2207522Sjmmv.It Ev HOME 289e2207522SjmmvSet to the work directory's path. 290e2207522Sjmmv.It Ev LANG 291e2207522SjmmvUndefined. 292e2207522Sjmmv.It Ev LC_ALL 293e2207522SjmmvUndefined. 294e2207522Sjmmv.It Ev LC_COLLATE 295e2207522SjmmvUndefined. 296e2207522Sjmmv.It Ev LC_CTYPE 297e2207522SjmmvUndefined. 298e2207522Sjmmv.It Ev LC_MESSAGES 299e2207522SjmmvUndefined. 300e2207522Sjmmv.It Ev LC_MONETARY 301e2207522SjmmvUndefined. 302e2207522Sjmmv.It Ev LC_NUMERIC 303e2207522SjmmvUndefined. 304e2207522Sjmmv.It Ev LC_TIME 305e2207522SjmmvUndefined. 306e2207522Sjmmv.It Ev TZ 3071d706b81SjmmvHardcoded to 3081d706b81Sjmmv.Sq UTC . 309e2207522Sjmmv.El 310e2207522Sjmmv.Ss Work directories 311e2207522SjmmvThe test program always creates a temporary directory 312e2207522Sjmmvand switches to it before running the test case's body. 313e2207522SjmmvThis way the test case is free to modify its current directory as it 314e7183a79Sjmmvwishes, and the runtime engine will be able to clean it up later on in a 315e2207522Sjmmvsafe way, removing any traces of its execution from the system. 316e7183a79SjmmvTo do so, the runtime engine will perform a recursive removal of the work 317e7183a79Sjmmvdirectory without crossing mount points; if a mount point is found, the 318e7183a79Sjmmvfile system will be unmounted (if possible). 319e2207522Sjmmv.Ss File creation mode mask (umask) 320e2207522SjmmvTest cases are always executed with a file creation mode mask (umask) of 321e2207522Sjmmv.Sq 0022 . 322e2207522SjmmvThe test case's code is free to change this during execution. 323e2207522Sjmmv.Sh SEE ALSO 3241d706b81Sjmmv.Xr atf-run 1 , 325e2207522Sjmmv.Xr atf-test-program 1 , 326e2207522Sjmmv.Xr atf-formats 5 , 327e2207522Sjmmv.Xr atf 7 328