14 .TH testrig 3 "5 June 1999" "Straylight/Edgeware" "mLib utilities library"
16 testrig \- generic test rig
20 .B "#include <mLib/testrig.h>"
22 .BI "int test_do(const test_suite " suite [],
24 .BI " test_results *" results );
25 .BI "void test_run(int " argc ", char *" argv [],
26 .BI " const test_chunk " chunk [],
27 .BI " const char *" def );
31 Test vectors are gathered together into
33 which should be processed in the same way. Chunks, in turn, are grouped
39 function runs a collection of tests, as defined by
41 given the test vectors in the file
43 It returns results in the
47 which has two members:
50 counts the number of tests carried out, and
53 counts the number of tests which failed.
55 The function returns negative if there was a system error or the test
56 vector file was corrupt in some way, zero if all the tests were
57 successful, or positive if some tests failed.
61 provides a simple command-line interface to the test system. It is
62 intended to be called from the
64 function of a test rig program to check that a particular function or
65 suite of functions are running properly. It does not return. The arguments
69 should just be the arguments given to
73 argument gives the name of the default file of test vectors to read.
74 This can be overridden at run-time by passing the program a
76 command-line option. The
78 argument is (the address of) an array of
79 .I "chunk definitions"
80 describing the layout of the test vector file.
81 .SS "Test vector file syntax"
82 Test vector files are mostly free-form. Comments begin with a hash
84 and extend to the end of the line. Apart from that, newline characters
85 are just considered to be whitespace.
87 Test vector files have the following syntax:
91 .RI [ suite-header | chunk " ...]"
102 .RI [ test-vector " ...]"
110 Briefly in English: a test vector file is divided into chunks, each of
111 which consists of a textual name and a brace-enclosed list of test
112 vectors. Each test vector consists of a number of values terminated by
115 A value is either a sequence of
117 (alphanumerics and some other characters)
118 or a string enclosed in quote marks (double or single). Quoted strings
119 may contain newlines. In either type of value, a backslash escapes the
121 .SS "Suite definitions"
124 is described by the structure
126 typedef struct test_suite {
127 const char *name; /* Name of this suite */
128 const test_chunk *chunks; /* Pointer to chunks */
135 is a pointer to an array of these structures, terminated by one with a
138 .SS "Chunk definitions"
140 .I "chunk definition"
141 describes the format of a named chunk: the number and type of the values
142 required and the function to call in order to test the system against
143 that test vector. The array is terminated by a chunk definition whose
144 name field is a null pointer.
146 A chunk definition is described by the following structure:
148 typedef struct test_chunk {
149 const char *name; /* Name of this chunk */
150 int (*test)(dstr dv[]); /* Test verification function */
151 test_type *f[TEST_FIELDMAX]; /* Field definitions */
154 The members of this structure are as follows:
156 .B "const char *name"
157 The name of the chunk described by this chunk definition, or null if
158 this is the termination marker.
160 .B "int (*test)(dstr dv[])"
161 The test function. It is passed an array of dynamic strings, one for
162 each field, and must return nonzero if the test succeeded or zero if the
163 test failed. On success, the function should not write anything to
164 stdout or stderr; on failure, a report of the test arguments should be
167 .B "test_type *f[TEST_FIELDMAX]"
168 Definitions of the fields. This is an array of pointers to
170 (see below), terminated by a null pointer.
172 When the test driver encounters a chunk it has a definition for, it
173 reads test vectors one by one, translating each value according to the
174 designated field type, and then passing the completed array of fields to
177 A field type describes how a field is to be read and written. A field
178 type is described by a structure:
180 typedef struct test_type {
181 void (*cvt)(const char *buf, dstr *d);
182 void (*dump)(dstr *d, FILE *fp);
187 member is a function called to read an input string stored in
189 and output internal-format data in the dynamic string
191 The testrig driver has already stripped of quotes and dealt with
195 member is called to write the internal-format data in dynamic string
202 There are three predefined field types:
205 The simplest type. The string contents is not interpreted at all.
208 The string is interpreted as binary data encoded as hexadecimal.
211 The string is interpreted as a textual representation of an integer.
212 The integer is written to the dynamic string, and can be read out again
217 which isn't pretty but does the job.
222 but reads and stores a
229 but reads and stores an
236 but reads and stores a
244 Mark Wooding, <mdw@distorted.org.uk>