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