14 .TH testrig 3 "5 June 1999" "Straylight/Edgeware" "mLib utilities library"
16 testrig \- generic test rig
20 .B "#include <mLib/testrig.h>"
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 );
33 Test vectors are gathered together into
35 which should be processed in the same way. Chunks, in turn, are grouped
41 function runs a collection of tests, as defined by
43 given the test vectors in the file
45 It returns results in the
49 which has two members:
52 counts the number of tests carried out, and
55 counts the number of tests which failed.
57 The function returns negative if there was a system error or the test
58 vector file was corrupt in some way, zero if all the tests were
59 successful, or positive if some tests failed.
63 provides a simple command-line interface to the test system. It is
64 intended to be called from the
66 function of a test rig program to check that a particular function or
67 suite of functions are running properly. It does not return. The arguments
71 should just be the arguments given to
75 argument gives the name of the default file of test vectors to read.
76 This can be overridden at run-time by passing the program a
78 command-line option. The
80 argument is (the address of) an array of
81 .I "chunk definitions"
82 describing the layout of the test vector file.
83 .SS "Test vector file syntax"
84 Test vector files are mostly free-form. Comments begin with a hash
86 and extend to the end of the line. Apart from that, newline characters
87 are just considered to be whitespace.
89 Test vector files have the following syntax:
93 .RI [ suite-header | chunk " ...]"
104 .RI [ test-vector " ...]"
112 Briefly in English: a test vector file is divided into chunks, each of
113 which consists of a textual name and a brace-enclosed list of test
114 vectors. Each test vector consists of a number of values terminated by
117 A value is either a sequence of
119 (alphanumerics and some other characters)
120 or a string enclosed in quote marks (double or single). Quoted strings
121 may contain newlines. In either type of value, a backslash escapes the
123 .SS "Suite definitions"
126 is described by the structure
128 typedef struct test_suite {
129 const char *name; /* Name of this suite */
130 const test_chunk *chunks; /* Pointer to chunks */
137 is a pointer to an array of these structures, terminated by one with a
140 .SS "Chunk definitions"
142 .I "chunk definition"
143 describes the format of a named chunk: the number and type of the values
144 required and the function to call in order to test the system against
145 that test vector. The array is terminated by a chunk definition whose
146 name field is a null pointer.
148 A chunk definition is described by the following structure:
150 typedef 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 */
156 The members of this structure are as follows:
158 .B "const char *name"
159 The name of the chunk described by this chunk definition, or null if
160 this is the termination marker.
162 .B "int (*test)(dstr dv[])"
163 The test function. It is passed an array of dynamic strings, one for
164 each field, and must return nonzero if the test succeeded or zero if the
165 test failed. On success, the function should not write anything to
166 stdout or stderr; on failure, a report of the test arguments should be
169 .B "test_type *f[TEST_FIELDMAX]"
170 Definitions of the fields. This is an array of pointers to
172 (see below), terminated by a null pointer.
174 When the test driver encounters a chunk it has a definition for, it
175 reads test vectors one by one, translating each value according to the
176 designated field type, and then passing the completed array of fields to
179 A field type describes how a field is to be read and written. A field
180 type is described by a structure:
182 typedef struct test_type {
183 void (*cvt)(const char *buf, dstr *d);
184 void (*dump)(dstr *d, FILE *fp);
189 member is a function called to read an input string stored in
191 and output internal-format data in the dynamic string
193 The testrig driver has already stripped of quotes and dealt with
197 member is called to write the internal-format data in dynamic string
204 There are three predefined field types:
207 The simplest type. The string contents is not interpreted at all.
210 The string is interpreted as binary data encoded as hexadecimal.
213 The string is interpreted as a textual representation of an integer.
214 The integer is written to the dynamic string, and can be read out again
219 which isn't pretty but does the job.
224 but reads and stores a
231 but reads and stores an
238 but reads and stores a
246 Mark Wooding, <mdw@distorted.org.uk>