14 .TH testrig 3 "5 June 1999" "Straylight/Edgeware" "mLib utilities library"
16 testrig \- generic test rig
20 .B "#include <mLib/testrig.h>"
22 .B "#define TEST_FIELDMAX ..."
26 .B " unsigned tests, failed;"
30 .BI " void (*cvt)(const char *" buf ", dstr *" d );
31 .BI " void (*dump)(dstr *" d ", FILE *" fp );
35 .B " const char *name;"
36 .BI " void (*test)(dstr " dv "[]);"
37 .B " const test_type *f[TEST_FIELDMAX];"
41 .B " const char *name;"
42 .B " const test_chunk *chunks;"
45 .B "const test_type type_hex;"
46 .B "const test_type type_string;"
47 .B "const test_type type_int;"
48 .B "const test_type type_long;"
49 .B "const test_type type_ulong;"
50 .B "const test_type type_uint32;"
52 .ta \w'\fBint test_do('u
53 .BI "int test_do(const test_suite " suite [],
54 .BI " FILE *" fp ", test_results *" results );
55 .ta \w'\fBvoid test_run('u
56 .BI "void test_run(int " argc ", char *" argv [],
57 .BI " const test_chunk " chunk "[], const char *" def );
61 Test vectors are gathered together into
63 which should be processed in the same way. Chunks, in turn, are grouped
69 function runs a collection of tests, as defined by
71 given the test vectors in the file
73 It returns results in the
77 which has two members:
80 counts the number of tests carried out, and
83 counts the number of tests which failed.
85 The function returns negative if there was a system error or the test
86 vector file was corrupt in some way, zero if all the tests were
87 successful, or positive if some tests failed.
91 provides a simple command-line interface to the test system. It is
92 intended to be called from the
94 function of a test rig program to check that a particular function or
95 suite of functions are running properly. It does not return. The arguments
99 should just be the arguments given to
103 argument gives the name of the default file of test vectors to read.
104 This can be overridden at run-time by passing the program a
106 command-line option. The
108 argument is (the address of) an array of
109 .I "chunk definitions"
110 describing the layout of the test vector file.
111 .SS "Test vector file syntax"
112 Test vector files are mostly free-form. Comments begin with a hash
114 and extend to the end of the line. Apart from that, newline characters
115 are just considered to be whitespace.
117 Test vector files have the following syntax:
121 .RI [ suite-header | chunk " ...]"
132 .RI [ test-vector " ...]"
140 Briefly in English: a test vector file is divided into chunks, each of
141 which consists of a textual name and a brace-enclosed list of test
142 vectors. Each test vector consists of a number of values terminated by
145 A value is either a sequence of
147 (alphanumerics and some other characters)
148 or a string enclosed in quote marks (double or single). Quoted strings
149 may contain newlines. In either type of value, a backslash escapes the
151 .SS "Suite definitions"
160 is a pointer to an array of these structures, terminated by one with a
163 .SS "Chunk definitions"
165 .I "chunk definition"
166 describes the format of a named chunk: the number and type of the values
167 required and the function to call in order to test the system against
168 that test vector. The array is terminated by a chunk definition whose
169 name field is a null pointer.
171 A chunk definition is described by the
173 structure. The members of this structure are as follows:
175 .B "const char *name"
176 The name of the chunk described by this chunk definition, or null if
177 this is the termination marker.
179 .BI "int (*test)(dstr " dv "[])"
180 The test function. It is passed an array of dynamic strings, one for
181 each field, and must return nonzero if the test succeeded or zero if the
182 test failed. On success, the function should not write anything to
183 stdout or stderr; on failure, a report of the test arguments should be
186 .B "test_type *f[TEST_FIELDMAX]"
187 Definitions of the fields. This is an array of pointers to
189 (see below), terminated by a null pointer.
191 When the test driver encounters a chunk it has a definition for, it
192 reads test vectors one by one, translating each value according to the
193 designated field type, and then passing the completed array of fields to
196 A field type describes how a field is to be read and written. A field
197 type is described by a
201 member is a function called to read an input string stored in
203 and output internal-format data in the dynamic string
205 The testrig driver has already stripped of quotes and dealt with
209 member is called to write the internal-format data in dynamic string
216 There are three predefined field types:
219 The simplest type. The string contents is not interpreted at all.
222 The string is interpreted as binary data encoded as hexadecimal.
225 The string is interpreted as a textual representation of an integer.
226 The integer is written to the dynamic string, and can be read out again
231 which isn't pretty but does the job.
236 but reads and stores a
243 but reads and stores an
250 but reads and stores a
258 Mark Wooding, <mdw@distorted.org.uk>