@@@ much mess, mostly manpages
[mLib] / test / testrig.3.in
CommitLineData
05fbeb03 1.\" -*-nroff-*-
c4ccbbf9
MW
2.\"
3.\" Manual for old-fashioned testing
4.\"
5.\" (c) 1999, 2001, 2005, 2008, 2009, 2023, 2024 Straylight/Edgeware
6.\"
7.
8.\"----- Licensing notice ---------------------------------------------------
9.\"
10.\" This file is part of the mLib utilities library.
11.\"
12.\" mLib is free software: you can redistribute it and/or modify it under
13.\" the terms of the GNU Library General Public License as published by
14.\" the Free Software Foundation; either version 2 of the License, or (at
15.\" your option) any later version.
16.\"
17.\" mLib is distributed in the hope that it will be useful, but WITHOUT
18.\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19.\" FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
20.\" License for more details.
21.\"
22.\" You should have received a copy of the GNU Library General Public
23.\" License along with mLib. If not, write to the Free Software
24.\" Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
25.\" USA.
26.
27.\"--------------------------------------------------------------------------
28.so ../defs.man \" @@@PRE@@@
29.
30.\"--------------------------------------------------------------------------
31.TH testrig 3mLib "5 June 1999" "Straylight/Edgeware" "mLib utilities library"
32.\" @test_do
33.\" @test_run
34.
35.\"--------------------------------------------------------------------------
05fbeb03 36.SH NAME
37testrig \- generic test rig
c4ccbbf9
MW
38.
39.\"--------------------------------------------------------------------------
05fbeb03 40.SH SYNOPSIS
c4ccbbf9 41.
05fbeb03 42.nf
43.B "#include <mLib/testrig.h>"
d056fbdf 44.PP
4729aa69 45.B "#define TEST_FIELDMAX ..."
d056fbdf 46.PP
adec5584 47.ta 2n
4729aa69 48.B "typedef struct {"
adec5584 49.B " unsigned tests, failed;"
4729aa69 50.B "} test_results";
d056fbdf 51.PP
4729aa69 52.B "typedef struct {"
adec5584
MW
53.BI " void (*cvt)(const char *" buf ", dstr *" d );
54.BI " void (*dump)(dstr *" d ", FILE *" fp );
4729aa69 55.B "} test_type";
d056fbdf 56.PP
4729aa69 57.B "typedef struct {"
adec5584
MW
58.B " const char *name;"
59.BI " void (*test)(dstr " dv "[]);"
60.B " const test_type *f[TEST_FIELDMAX];"
4729aa69 61.B "} test_chunk";
d056fbdf 62.PP
4729aa69 63.B "typedef struct {"
adec5584
MW
64.B " const char *name;"
65.B " const test_chunk *chunks;"
4729aa69 66.B "} test_suite";
d056fbdf 67.PP
4729aa69
MW
68.B "const test_type type_hex;"
69.B "const test_type type_string;"
70.B "const test_type type_int;"
71.B "const test_type type_long;"
72.B "const test_type type_ulong;"
73.B "const test_type type_uint32;"
d056fbdf 74.PP
adec5584
MW
75.ta \w'\fBint test_do('u
76.BI "int test_do(const test_suite " suite [],
77.BI " FILE *" fp ", test_results *" results );
78.ta \w'\fBvoid test_run('u
79.BI "void test_run(int " argc ", char *" argv [],
80.BI " const test_chunk " chunk "[], const char *" def );
05fbeb03 81.fi
c4ccbbf9
MW
82.
83.\"--------------------------------------------------------------------------
05fbeb03 84.SH DESCRIPTION
c4ccbbf9 85.
9fcce036
MW
86.SS Structure
87Test vectors are gathered together into
88.I chunks
89which should be processed in the same way. Chunks, in turn, are grouped
90into
91.IR suites .
c4ccbbf9 92.
9fcce036
MW
93.SS Functions
94The
95.B test_do
96function runs a collection of tests, as defined by
97.IR suite ,
98given the test vectors in the file
99.IR fp .
100It returns results in the
101.B test_results
102structure
103.IR results ,
104which has two members:
105.TP
106.B "unsigned tests"
107counts the number of tests carried out, and
108.TP
109.B "unsigned failed"
110counts the number of tests which failed.
111.PP
112The function returns negative if there was a system error or the test
113vector file was corrupt in some way, zero if all the tests were
114successful, or positive if some tests failed.
115.PP
05fbeb03 116The
117.B test_run
9fcce036
MW
118provides a simple command-line interface to the test system. It is
119intended to be called from the
05fbeb03 120.B main
121function of a test rig program to check that a particular function or
9fcce036 122suite of functions are running properly. It does not return. The arguments
05fbeb03 123.I argc
124and
125.I argv
126should just be the arguments given to
127.BR main .
128The
129.I def
130argument gives the name of the default file of test vectors to read.
131This can be overridden at run-time by passing the program a
132.B \-f
133command-line option. The
134.I chunk
135argument is (the address of) an array of
136.I "chunk definitions"
137describing the layout of the test vector file.
c4ccbbf9 138.
05fbeb03 139.SS "Test vector file syntax"
140Test vector files are mostly free-form. Comments begin with a hash
141.RB (` # ')
142and extend to the end of the line. Apart from that, newline characters
143are just considered to be whitespace.
144.PP
145Test vector files have the following syntax:
146.PP
147.I file
148::=
9fcce036
MW
149.RI [ suite-header | chunk " ...]"
150.br
151.I suite-header
152::=
153.B suite
154.I name
05fbeb03 155.br
156.I chunk
157::=
158.I name
159.B {
9fcce036 160.RI [ test-vector " ...]"
05fbeb03 161.B }
162.br
163.I test-vector
164::=
165.RI [ value ...]
166.B ;
167.PP
168Briefly in English: a test vector file is divided into chunks, each of
169which consists of a textual name and a brace-enclosed list of test
170vectors. Each test vector consists of a number of values terminated by
171a semicolon.
172.PP
173A value is either a sequence of
174.I "word characters"
175(alphanumerics and some other characters)
176or a string enclosed in quote marks (double or single). Quoted strings
177may contain newlines. In either type of value, a backslash escapes the
178following character.
c4ccbbf9 179.
9fcce036
MW
180.SS "Suite definitions"
181A
182.I suite definition
4729aa69
MW
183is described by the
184.B test_suite
185structure. The
9fcce036
MW
186.I suite
187argument to
188.B test_do
189is a pointer to an array of these structures, terminated by one with a
190null
191.BR name .
c4ccbbf9 192.
05fbeb03 193.SS "Chunk definitions"
9fcce036
MW
194A
195.I "chunk definition"
196describes the format of a named chunk: the number and type of the values
197required and the function to call in order to test the system against
198that test vector. The array is terminated by a chunk definition whose
199name field is a null pointer.
05fbeb03 200.PP
4729aa69
MW
201A chunk definition is described by the
202.B test_chunk
203structure. The members of this structure are as follows:
05fbeb03 204.TP
ff76c38f 205.B "const char *name"
05fbeb03 206The name of the chunk described by this chunk definition, or null if
207this is the termination marker.
208.TP
4729aa69 209.BI "int (*test)(dstr " dv "[])"
05fbeb03 210The test function. It is passed an array of dynamic strings, one for
211each field, and must return nonzero if the test succeeded or zero if the
212test failed. On success, the function should not write anything to
213stdout or stderr; on failure, a report of the test arguments should be
214emitted to stderr.
215.TP
ff76c38f 216.B "test_type *f[TEST_FIELDMAX]"
05fbeb03 217Definitions of the fields. This is an array of pointers to
218.I "field types"
219(see below), terminated by a null pointer.
220.PP
221When the test driver encounters a chunk it has a definition for, it
222reads test vectors one by one, translating each value according to the
223designated field type, and then passing the completed array of fields to
224the test function.
c4ccbbf9 225.
05fbeb03 226.SS "Field types"
227A field type describes how a field is to be read and written. A field
4729aa69
MW
228type is described by a
229.B test_type
230structure. The
ff76c38f 231.B cvt
05fbeb03 232member is a function called to read an input string stored in
ff76c38f 233.B buf
05fbeb03 234and output internal-format data in the dynamic string
235.IR d .
236The testrig driver has already stripped of quotes and dealt with
237backslash escapes.
238The
ff76c38f 239.B dump
05fbeb03 240member is called to write the internal-format data in dynamic string
241.I d
242to the
243.B stdio
244stream
245.IR fp .
246.PP
247There are three predefined field types:
248.TP
249.B "type_string"
250The simplest type. The string contents is not interpreted at all.
251.TP
252.B "type_hex"
253The string is interpreted as binary data encoded as hexadecimal.
254.TP
255.B "type_int"
256The string is interpreted as a textual representation of an integer.
257The integer is written to the dynamic string, and can be read out again
258with the expression
259.VS
260*(int *)d.buf
261.VE
262which isn't pretty but does the job.
dadc1afb 263.TP
264.B "type_long"
265As for
266.B type_int
267but reads and stores a
268.B long
269instead.
270.TP
271.B "type_ulong"
272As for
273.B type_long
274but reads and stores an
275.B "unsigned long"
276instead.
277.TP
278.B "type_uint32"
279As for
280.B type_int
281but reads and stores a
282.B uint32
283(see
284.BR bits (3))
285instead.
c4ccbbf9
MW
286.
287.\"--------------------------------------------------------------------------
05fbeb03 288.SH "SEE ALSO"
c4ccbbf9
MW
289.
290.BR tvec (3),
05fbeb03 291.BR mLib (3).
c4ccbbf9
MW
292.
293.\"--------------------------------------------------------------------------
05fbeb03 294.SH "AUTHOR"
c4ccbbf9 295.
9b5ac6ff 296Mark Wooding, <mdw@distorted.org.uk>
c4ccbbf9
MW
297.
298.\"----- That's all, folks --------------------------------------------------