chiark / gitweb /
*/*.3: Align arguments properly to the right of the opening `('.
[mLib] / test / testrig.3
CommitLineData
05fbeb03 1.\" -*-nroff-*-
2.de VS
3.sp 1
4.in +5
5.nf
6.ft B
7..
8.de VE
9.ft R
10.fi
11.in -5
12.sp 1
13..
fbf20b5b 14.TH testrig 3 "5 June 1999" "Straylight/Edgeware" "mLib utilities library"
05fbeb03 15.SH NAME
16testrig \- generic test rig
17.\" @test_run
18.SH SYNOPSIS
19.nf
20.B "#include <mLib/testrig.h>"
21
2b1924c2
MW
22.ds mT \fBint test_do(
23.BI "\*(mTconst test_suite " suite [],
24.BI "\h'\w'\*(mT'u'FILE *" fp ,
25.BI "\h'\w'\*(mT'u'test_results *" results );
26.ds mT \fBvoid test_run(
27.BI "\*(mTint " argc ", char *" argv [],
28.BI "\h'\w'\*(mT'u'const test_chunk " chunk [],
29.BI "\h'\w'\*(mT'u'const char *" def );
05fbeb03 30.fi
31.SH DESCRIPTION
9fcce036
MW
32.SS Structure
33Test vectors are gathered together into
34.I chunks
35which should be processed in the same way. Chunks, in turn, are grouped
36into
37.IR suites .
38.SS Functions
39The
40.B test_do
41function runs a collection of tests, as defined by
42.IR suite ,
43given the test vectors in the file
44.IR fp .
45It returns results in the
46.B test_results
47structure
48.IR results ,
49which has two members:
50.TP
51.B "unsigned tests"
52counts the number of tests carried out, and
53.TP
54.B "unsigned failed"
55counts the number of tests which failed.
56.PP
57The function returns negative if there was a system error or the test
58vector file was corrupt in some way, zero if all the tests were
59successful, or positive if some tests failed.
60.PP
05fbeb03 61The
62.B test_run
9fcce036
MW
63provides a simple command-line interface to the test system. It is
64intended to be called from the
05fbeb03 65.B main
66function of a test rig program to check that a particular function or
9fcce036 67suite of functions are running properly. It does not return. The arguments
05fbeb03 68.I argc
69and
70.I argv
71should just be the arguments given to
72.BR main .
73The
74.I def
75argument gives the name of the default file of test vectors to read.
76This can be overridden at run-time by passing the program a
77.B \-f
78command-line option. The
79.I chunk
80argument is (the address of) an array of
81.I "chunk definitions"
82describing the layout of the test vector file.
83.SS "Test vector file syntax"
84Test vector files are mostly free-form. Comments begin with a hash
85.RB (` # ')
86and extend to the end of the line. Apart from that, newline characters
87are just considered to be whitespace.
88.PP
89Test vector files have the following syntax:
90.PP
91.I file
92::=
9fcce036
MW
93.RI [ suite-header | chunk " ...]"
94.br
95.I suite-header
96::=
97.B suite
98.I name
05fbeb03 99.br
100.I chunk
101::=
102.I name
103.B {
9fcce036 104.RI [ test-vector " ...]"
05fbeb03 105.B }
106.br
107.I test-vector
108::=
109.RI [ value ...]
110.B ;
111.PP
112Briefly in English: a test vector file is divided into chunks, each of
113which consists of a textual name and a brace-enclosed list of test
114vectors. Each test vector consists of a number of values terminated by
115a semicolon.
116.PP
117A value is either a sequence of
118.I "word characters"
119(alphanumerics and some other characters)
120or a string enclosed in quote marks (double or single). Quoted strings
121may contain newlines. In either type of value, a backslash escapes the
122following character.
9fcce036
MW
123.SS "Suite definitions"
124A
125.I suite definition
126is described by the structure
127.VS
128typedef struct test_suite {
129 const char *name; /* Name of this suite */
130 const test_chunk *chunks; /* Pointer to chunks */
131} test_suite;
132.VE
133The
134.I suite
135argument to
136.B test_do
137is a pointer to an array of these structures, terminated by one with a
138null
139.BR name .
05fbeb03 140.SS "Chunk definitions"
9fcce036
MW
141A
142.I "chunk definition"
143describes the format of a named chunk: the number and type of the values
144required and the function to call in order to test the system against
145that test vector. The array is terminated by a chunk definition whose
146name field is a null pointer.
05fbeb03 147.PP
148A chunk definition is described by the following structure:
149.VS
150typedef struct test_chunk {
151 const char *name; /* Name of this chunk */
152 int (*test)(dstr dv[]); /* Test verification function */
153 test_type *f[TEST_FIELDMAX]; /* Field definitions */
154} test_chunk;
155.VE
156The members of this structure are as follows:
157.TP
ff76c38f 158.B "const char *name"
05fbeb03 159The name of the chunk described by this chunk definition, or null if
160this is the termination marker.
161.TP
ff76c38f 162.B "int (*test)(dstr dv[])"
05fbeb03 163The test function. It is passed an array of dynamic strings, one for
164each field, and must return nonzero if the test succeeded or zero if the
165test failed. On success, the function should not write anything to
166stdout or stderr; on failure, a report of the test arguments should be
167emitted to stderr.
168.TP
ff76c38f 169.B "test_type *f[TEST_FIELDMAX]"
05fbeb03 170Definitions of the fields. This is an array of pointers to
171.I "field types"
172(see below), terminated by a null pointer.
173.PP
174When the test driver encounters a chunk it has a definition for, it
175reads test vectors one by one, translating each value according to the
176designated field type, and then passing the completed array of fields to
177the test function.
178.SS "Field types"
179A field type describes how a field is to be read and written. A field
180type is described by a structure:
181.VS
182typedef struct test_type {
183 void (*cvt)(const char *buf, dstr *d);
184 void (*dump)(dstr *d, FILE *fp);
185} test_type;
186.VE
187The
ff76c38f 188.B cvt
05fbeb03 189member is a function called to read an input string stored in
ff76c38f 190.B buf
05fbeb03 191and output internal-format data in the dynamic string
192.IR d .
193The testrig driver has already stripped of quotes and dealt with
194backslash escapes.
195The
ff76c38f 196.B dump
05fbeb03 197member is called to write the internal-format data in dynamic string
198.I d
199to the
200.B stdio
201stream
202.IR fp .
203.PP
204There are three predefined field types:
205.TP
206.B "type_string"
207The simplest type. The string contents is not interpreted at all.
208.TP
209.B "type_hex"
210The string is interpreted as binary data encoded as hexadecimal.
211.TP
212.B "type_int"
213The string is interpreted as a textual representation of an integer.
214The integer is written to the dynamic string, and can be read out again
215with the expression
216.VS
217*(int *)d.buf
218.VE
219which isn't pretty but does the job.
dadc1afb 220.TP
221.B "type_long"
222As for
223.B type_int
224but reads and stores a
225.B long
226instead.
227.TP
228.B "type_ulong"
229As for
230.B type_long
231but reads and stores an
232.B "unsigned long"
233instead.
234.TP
235.B "type_uint32"
236As for
237.B type_int
238but reads and stores a
239.B uint32
240(see
241.BR bits (3))
242instead.
05fbeb03 243.SH "SEE ALSO"
244.BR mLib (3).
245.SH "AUTHOR"
9b5ac6ff 246Mark Wooding, <mdw@distorted.org.uk>