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