1 .\" Copyright 2012 The Kyua Authors.
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.
33 .Nd Test suite description files
35 .Fn atf_test_program "string name" "[string metadata]"
37 .Fn fs.basename "string path"
38 .Fn fs.dirname "string path"
39 .Fn fs.exists "string path"
40 .Fn fs.files "string path"
41 .Fn fs.is_absolute "string path"
42 .Fn fs.join "string path" "string path"
43 .Fn include "string path"
44 .Fn plain_test_program "string name" "[string metadata]"
45 .Fn syntax "int version"
46 .Fn tap_test_program "string name" "[string metadata]"
47 .Fn test_suite "string name"
49 A test suite is a collection of test programs and is represented by a
50 hierarchical layout of test binaries on the file system.
51 Any subtree of the file system can represent a test suite, provided that it
54 which are the test suite definition files.
58 is a Lua script whose purpose is to describe the structure of the test
60 To do so, the script has access to a collection of special functions provided
64 .Sx Helper functions .
68 file starts with a call to
69 .Fn syntax "int version" .
70 This call determines the specific schema used by the file so that future
71 backwards-incompatible modifications to the file can be introduced.
79 .Ss Test suite definition
82 registers any test programs,
85 must define the name of the test suite the test programs belong to by using the
87 function at the very beginning of the file.
89 The test suite name provided in the
93 which set of configuration variables from
95 to pass to the test programs at run time.
96 .Ss Test program registration
99 can register test programs by means of a variety of
101 functions, all of which take the name of a test program and a set of
102 optional metadata properties that describe such test program.
104 The test programs to be registered must live in the current directory; in
105 other words, the various
107 calls cannot reference test programs in other directories.
108 The rationale for this is to force all
110 files to be self-contained, and to simplify their internal representation.
112 .Em ATF test programs
113 are those that use the
116 They can be registered with the
119 This function takes the
121 of the test program and a collection of optional metadata settings for all
122 the test cases in the test program.
123 Any metadata properties defined by the test cases themselves override the
124 metadata values defined here.
126 .Em Plain test programs
127 are those that return 0 on success and non-0 on failure; in general, most test
128 programs (even those that use fancy unit-testing libraries) behave this way and
129 thus also qualify as plain test programs.
130 They can be registered with the
131 .Fn plain_test_program
133 This function takes the
135 of the test program, an optional
137 name that overrides the global test suite name, and a collection of optional
138 metadata settings for the test program.
140 .Em TAP test programs
141 are those that implement the Test Anything Protocol.
142 They can be registered with the
145 This function takes the
147 of the test program and a collection of optional metadata settings for the
150 The following metadata properties can be passed to any test program definition:
151 .Bl -tag -width XX -offset indent
152 .It Va allowed_architectures
153 Whitespace-separated list of machine architecture names allowed by the test.
154 If empty or not defined, the test is allowed to run on any machine
156 .It Va allowed_platforms
157 Whitespace-separated list of machine platform names allowed by the test.
158 If empty or not defined, the test is allowed to run on any machine
161 Custom variable defined by the test where
163 denotes the name of the variable.
164 These variables are useful to tag your tests with information specific to
166 The values of such variables are propagated all the way from the tests to the
167 results files and later to any generated reports.
169 Note that if the name happens to have dashes or any other special characters
170 in it, you will have to use a special Lua syntax to define the property.
173 section below for clarification.
175 Textual description of the test.
177 If true, indicates that this test program cannot be executed along any other
178 programs at the same time.
179 Test programs that affect global system state, such as those that modify the
182 setting, must set themselves as exclusive to prevent failures due to race
185 .It Va required_configs
186 Whitespace-separated list of configuration variables that the test requires
187 to be defined before it can run.
188 .It Va required_disk_space
189 Amount of available disk space that the test needs to run successfully.
190 .It Va required_files
191 Whitespace-separated list of paths that the test requires to exist before
193 .It Va required_memory
194 Amount of physical memory that the test needs to run successfully.
195 .It Va required_programs
196 Whitespace-separated list of basenames or absolute paths pointing to executable
197 binaries that the test requires to exist before it can run.
199 If empty, the test has no restrictions on the calling user for it to run.
202 the test needs to not run as root.
205 the test must run as root.
207 Amount of seconds that the test is allowed to execute before being killed.
210 To reference test programs in another subdirectory, a different
212 must be created in that directory and it must be included into the original
219 may only be called with a relative path and with at most one directory
221 This is by design: Kyua uses the file system structure as the layout of the
222 test suite definition.
223 Therefore, each subdirectory in a test suite must include its own
227 can only descend into the
229 of immediate subdirectories.
231 If you need to source a
233 located in disjoint parts of your file system namespace, you will have to
236 using symbolic links and possibly helper
238 to plug the various subdirectories together.
241 section below for details.
243 Note that each file is processed in its own Lua environment: there is no
244 mechanism to pass state from one file to the other.
245 The reason for this is that there is no such thing as a
248 in a test suite: the user has to be able to run the test suite from any
249 directory in a given hierarchy, and this execution must not depend on files
250 that live in parent directories.
251 .Ss Top-level Kyuafile
252 Every system has a top directory into which test suites get installed.
255 Within this directory live test suites, each of which is in an independent
257 Each subdirectory can be provided separately by independent third-party
260 Kyua allows running all the installed test suites at once in order to
261 provide comprehensive cross-component reports.
262 In order to do this, there is a special file in the top directory that knows
263 how to inspect the subdirectories in search for other Kyuafiles and include
268 section includes more details on where this file lives.
275 Lua modules are fully available in the context of a
278 The following extra functions are provided by Kyua:
279 .Bl -tag -width XX -offset indent
280 .It Ft string Fn current_kyuafile
281 Returns the absolute path to the current
283 .It Ft string Fn fs.basename "string path"
284 Returns the last component of the given path.
285 .It Ft string Fn fs.dirname "string path"
286 Returns the given path without its last component or a dot if the path has
288 .It Ft bool Fn fs.exists "string path"
289 Checks if the given path exists.
290 If the path is not absolute, it is relative to the directory containing the
292 in which the call to this function occurs.
293 .It Ft iterator Fn fs.files "string path"
294 Opens a directory for scanning of its entries.
295 The returned iterator yields an entry on each call, and the entry is simply
297 If the path is not absolute, it is relative to the directory containing the
299 in which the call to this function occurs.
300 .It Ft is_absolute Fn fs.is_absolute "string path"
301 Returns true if the given path is absolute; false otherwise.
302 .It Ft join Fn fs.join "string path" "string path"
303 Concatenates the two paths.
304 The second path cannot be absolute.
308 .It Pa __TESTSDIR__/Kyuafile .
311 for the current system.
312 .It Pa __EGDIR__/Kyuafile.top .
313 Sample file to serve as a top-level
319 is the simplest you can define.
320 It provides a test suite definition and registers a couple of different test
321 programs using different interfaces:
322 .Bd -literal -offset indent
327 atf_test_program{name='integration_test'}
328 plain_test_program{name='legacy_test'}
331 The following example is a bit more elaborate.
332 It introduces some metadata properties to the test program definitions and
333 recurses into a couple of subdirectories:
334 .Bd -literal -offset indent
339 plain_test_program{name='legacy_test',
340 allowed_architectures='amd64 i386',
341 required_files='/bin/ls',
344 tap_test_program{name='privileged_test',
345 required_user='root'}
347 include('module-1/Kyuafile')
348 include('module-2/Kyuafile')
351 The syntax to define custom properties may be not obvious if their names
352 have any characters that make the property name not be a valid Lua identifier.
353 Dashes are just one example.
354 To set such properties, do something like this:
355 .Bd -literal -offset indent
358 test_suite('FreeBSD')
360 plain_test_program{name='the_test',
361 ['custom.FreeBSD-Bug-Id']='category/12345'}
363 .Ss Connecting disjoint test suites
364 Now suppose you had various test suites on your file system and you would
365 like to connect them together so that they could be executed and treated as
367 The test suites we would like to connect live under
375 that references these because the
377 directive does not support absolute paths.
378 Instead, what we can do is create a shadow tree using symbolic links:
379 .Bd -literal -offset indent
381 $ ln -s /usr/tests ~/everything/system-tests
382 $ ln -s /usr/local/tests ~/everything/local-tests
383 $ ln -s ~/local/tests ~/everything/home-tests
386 And then we create an
387 .Pa ~/everything/Kyuafile
388 file to drive the execution of the integrated test suite:
389 .Bd -literal -offset indent
392 test_suite('test-all-the-things')
394 include('system-tests/Kyuafile')
395 include('local-tests/Kyuafile')
396 include('home-tests/Kyuafile')
399 Or, simply, you could reuse the sample top-level
401 to avoid having to manually craft the list of directories into which to
403 .Bd -literal -offset indent
404 $ cp __EGDIR__/Kyuafile.top ~/everything/Kyuafile