xref: /freebsd/contrib/kyua/doc/kyuafile.5.in (revision 550cb4ab85c7e514629c8bacbbb07085b81d916b)
1.\" Copyright 2012 The Kyua Authors.
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions are
6.\" met:
7.\"
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.
16.\"
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.
28.Dd July 3, 2015
29.Dt KYUAFILE 5
30.Os
31.Sh NAME
32.Nm Kyuafile
33.Nd Test suite description files
34.Sh SYNOPSIS
35.Fn atf_test_program "string name" "[string metadata]"
36.Fn current_kyuafile
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"
48.Sh DESCRIPTION
49A test suite is a collection of test programs and is represented by a
50hierarchical layout of test binaries on the file system.
51Any subtree of the file system can represent a test suite, provided that it
52includes one or more
53.Nm Ns s ,
54which are the test suite definition files.
55.Pp
56A
57.Nm
58is a Lua script whose purpose is to describe the structure of the test
59suite it belongs to.
60To do so, the script has access to a collection of special functions provided
61by
62.Xr kyua 1
63as described in
64.Sx Helper functions .
65.Ss File versioning
66Every
67.Nm
68file starts with a call to
69.Fn syntax "int version" .
70This call determines the specific schema used by the file so that future
71backwards-incompatible modifications to the file can be introduced.
72.Pp
73Any new
74.Nm
75file should set
76.Fa version
77to
78.Sq 2 .
79.Ss Test suite definition
80If the
81.Nm
82registers any test programs,
83the
84.Nm
85must define the name of the test suite the test programs belong to by using the
86.Fn test_suite
87function at the very beginning of the file.
88.Pp
89The test suite name provided in the
90.Fn test_suite
91call tells
92.Xr kyua 1
93which set of configuration variables from
94.Xr kyua.conf 5
95to pass to the test programs at run time.
96.Ss Test program registration
97A
98.Nm
99can register test programs by means of a variety of
100.Fn *_test_program
101functions, all of which take the name of a test program and a set of
102optional metadata properties that describe such test program.
103.Pp
104The test programs to be registered must live in the current directory; in
105other words, the various
106.Fn *_test_program
107calls cannot reference test programs in other directories.
108The rationale for this is to force all
109.Nm
110files to be self-contained, and to simplify their internal representation.
111.Pp
112.Em ATF test programs
113are those that use the
114.Xr atf 7
115libraries.
116They can be registered with the
117.Fn atf_test_program
118table constructor.
119This function takes the
120.Fa name
121of the test program and a collection of optional metadata settings for all
122the test cases in the test program.
123Any metadata properties defined by the test cases themselves override the
124metadata values defined here.
125.Pp
126.Em Plain test programs
127are those that return 0 on success and non-0 on failure; in general, most test
128programs (even those that use fancy unit-testing libraries) behave this way and
129thus also qualify as plain test programs.
130They can be registered with the
131.Fn plain_test_program
132table constructor.
133This function takes the
134.Fa name
135of the test program, an optional
136.Fa test_suite
137name that overrides the global test suite name, and a collection of optional
138metadata settings for the test program.
139.Pp
140.Em TAP test programs
141are those that implement the Test Anything Protocol.
142They can be registered with the
143.Fn tap_test_program
144table constructor.
145This function takes the
146.Fa name
147of the test program and a collection of optional metadata settings for the
148test program.
149.Pp
150The following metadata properties can be passed to any test program definition:
151.Bl -tag -width XX -offset indent
152.It Va allowed_architectures
153Whitespace-separated list of machine architecture names allowed by the test.
154If empty or not defined, the test is allowed to run on any machine
155architecture.
156.It Va allowed_platforms
157Whitespace-separated list of machine platform names allowed by the test.
158If empty or not defined, the test is allowed to run on any machine
159platform.
160.It Va custom.NAME
161Custom variable defined by the test where
162.Sq NAME
163denotes the name of the variable.
164These variables are useful to tag your tests with information specific to
165your project.
166The values of such variables are propagated all the way from the tests to the
167results files and later to any generated reports.
168.Pp
169Note that if the name happens to have dashes or any other special characters
170in it, you will have to use a special Lua syntax to define the property.
171Refer to the
172.Sx EXAMPLES
173section below for clarification.
174.It Va description
175Textual description of the test.
176.It Va is_exclusive
177If true, indicates that this test program cannot be executed along any other
178programs at the same time.
179Test programs that affect global system state, such as those that modify the
180value of a
181.Xr sysctl 8
182setting, must set themselves as exclusive to prevent failures due to race
183conditions.
184Defaults to false.
185.It Va required_configs
186Whitespace-separated list of configuration variables that the test requires
187to be defined before it can run.
188.It Va required_disk_space
189Amount of available disk space that the test needs to run successfully.
190.It Va required_files
191Whitespace-separated list of paths that the test requires to exist before
192it can run.
193.It Va required_memory
194Amount of physical memory that the test needs to run successfully.
195.It Va required_programs
196Whitespace-separated list of basenames or absolute paths pointing to executable
197binaries that the test requires to exist before it can run.
198.It Va required_user
199If empty, the test has no restrictions on the calling user for it to run.
200If set to
201.Sq unprivileged ,
202the test needs to not run as root.
203If set to
204.Sq root ,
205the test must run as root.
206.It Va timeout
207Amount of seconds that the test is allowed to execute before being killed.
208.El
209.Ss Recursion
210To reference test programs in another subdirectory, a different
211.Nm
212must be created in that directory and it must be included into the original
213.Nm
214by means of the
215.Fn include
216function.
217.Pp
218.Fn include
219may only be called with a relative path and with at most one directory
220component.
221This is by design: Kyua uses the file system structure as the layout of the
222test suite definition.
223Therefore, each subdirectory in a test suite must include its own
224.Nm
225and each
226.Nm
227can only descend into the
228.Nm Ns s
229of immediate subdirectories.
230.Pp
231If you need to source a
232.Nm
233located in disjoint parts of your file system namespace, you will have to
234create a
235.Sq shadow tree
236using symbolic links and possibly helper
237.Nm Ns s
238to plug the various subdirectories together.
239See the
240.Sx EXAMPLES
241section below for details.
242.Pp
243Note that each file is processed in its own Lua environment: there is no
244mechanism to pass state from one file to the other.
245The reason for this is that there is no such thing as a
246.Dq top-level
247.Nm
248in a test suite: the user has to be able to run the test suite from any
249directory in a given hierarchy, and this execution must not depend on files
250that live in parent directories.
251.Ss Top-level Kyuafile
252Every system has a top directory into which test suites get installed.
253The default is
254.Pa __TESTSDIR__ .
255Within this directory live test suites, each of which is in an independent
256subdirectory.
257Each subdirectory can be provided separately by independent third-party
258packages.
259.Pp
260Kyua allows running all the installed test suites at once in order to
261provide comprehensive cross-component reports.
262In order to do this, there is a special file in the top directory that knows
263how to inspect the subdirectories in search for other Kyuafiles and include
264them.
265.Pp
266The
267.Sx FILES
268section includes more details on where this file lives.
269.Ss Helper functions
270The
271.Sq base ,
272.Sq string ,
273and
274.Sq table
275Lua modules are fully available in the context of a
276.Nm .
277.Pp
278The following extra functions are provided by Kyua:
279.Bl -tag -width XX -offset indent
280.It Ft string Fn current_kyuafile
281Returns the absolute path to the current
282.Nm .
283.It Ft string Fn fs.basename "string path"
284Returns the last component of the given path.
285.It Ft string Fn fs.dirname "string path"
286Returns the given path without its last component or a dot if the path has
287a single component.
288.It Ft bool Fn fs.exists "string path"
289Checks if the given path exists.
290If the path is not absolute, it is relative to the directory containing the
291.Nm
292in which the call to this function occurs.
293.It Ft iterator Fn fs.files "string path"
294Opens a directory for scanning of its entries.
295The returned iterator yields an entry on each call, and the entry is simply
296the filename.
297If the path is not absolute, it is relative to the directory containing the
298.Nm
299in which the call to this function occurs.
300.It Ft is_absolute Fn fs.is_absolute "string path"
301Returns true if the given path is absolute; false otherwise.
302.It Ft join Fn fs.join "string path" "string path"
303Concatenates the two paths.
304The second path cannot be absolute.
305.El
306.Sh FILES
307.Bl -tag -width XX
308.It Pa __TESTSDIR__/Kyuafile .
309Top-level
310.Nm
311for the current system.
312.It Pa __EGDIR__/Kyuafile.top .
313Sample file to serve as a top-level
314.Nm .
315.El
316.Sh EXAMPLES
317The following
318.Nm
319is the simplest you can define.
320It provides a test suite definition and registers a couple of different test
321programs using different interfaces:
322.Bd -literal -offset indent
323syntax(2)
324
325test_suite('first')
326
327atf_test_program{name='integration_test'}
328plain_test_program{name='legacy_test'}
329.Ed
330.Pp
331The following example is a bit more elaborate.
332It introduces some metadata properties to the test program definitions and
333recurses into a couple of subdirectories:
334.Bd -literal -offset indent
335syntax(2)
336
337test_suite('second')
338
339plain_test_program{name='legacy_test',
340                   allowed_architectures='amd64 i386',
341                   required_files='/bin/ls',
342                   timeout=30}
343
344tap_test_program{name='privileged_test',
345                 required_user='root'}
346
347include('module-1/Kyuafile')
348include('module-2/Kyuafile')
349.Ed
350.Pp
351The syntax to define custom properties may be not obvious if their names
352have any characters that make the property name not be a valid Lua identifier.
353Dashes are just one example.
354To set such properties, do something like this:
355.Bd -literal -offset indent
356syntax(2)
357
358test_suite('FreeBSD')
359
360plain_test_program{name='the_test',
361                   ['custom.FreeBSD-Bug-Id']='category/12345'}
362.Ed
363.Ss Connecting disjoint test suites
364Now suppose you had various test suites on your file system and you would
365like to connect them together so that they could be executed and treated as
366a single unit.
367The test suites we would like to connect live under
368.Pa /usr/tests ,
369.Pa /usr/local/tests
370and
371.Pa ~/local/tests .
372.Pp
373We cannot create a
374.Nm
375that references these because the
376.Fn include
377directive does not support absolute paths.
378Instead, what we can do is create a shadow tree using symbolic links:
379.Bd -literal -offset indent
380$ mkdir ~/everything
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
384.Ed
385.Pp
386And then we create an
387.Pa ~/everything/Kyuafile
388file to drive the execution of the integrated test suite:
389.Bd -literal -offset indent
390syntax(2)
391
392test_suite('test-all-the-things')
393
394include('system-tests/Kyuafile')
395include('local-tests/Kyuafile')
396include('home-tests/Kyuafile')
397.Ed
398.Pp
399Or, simply, you could reuse the sample top-level
400.Nm
401to avoid having to manually craft the list of directories into which to
402recurse:
403.Bd -literal -offset indent
404$ cp __EGDIR__/Kyuafile.top ~/everything/Kyuafile
405.Ed
406.Sh SEE ALSO
407.Xr kyua 1
408