3 .\" Manual for old-fashioned testing
5 .\" (c) 1999, 2001, 2005, 2008, 2009, 2023, 2024 Straylight/Edgeware
8 .\"----- Licensing notice ---------------------------------------------------
10 .\" This file is part of the mLib utilities library.
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.
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.
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,
27 .\"--------------------------------------------------------------------------
28 .so ../defs.man \" @@@PRE@@@
30 .\"--------------------------------------------------------------------------
31 .TH testrig 3mLib "5 June 1999" "Straylight/Edgeware" "mLib utilities library"
35 .\"--------------------------------------------------------------------------
37 testrig \- generic test rig
39 .\"--------------------------------------------------------------------------
43 .B "#include <mLib/testrig.h>"
45 .B "#define TEST_FIELDMAX ..."
49 .B " unsigned tests, failed;"
53 .BI " void (*cvt)(const char *" buf ", dstr *" d );
54 .BI " void (*dump)(dstr *" d ", FILE *" fp );
58 .B " const char *name;"
59 .BI " void (*test)(dstr " dv "[]);"
60 .B " const test_type *f[TEST_FIELDMAX];"
64 .B " const char *name;"
65 .B " const test_chunk *chunks;"
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;"
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 );
83 .\"--------------------------------------------------------------------------
87 Test vectors are gathered together into
89 which should be processed in the same way. Chunks, in turn, are grouped
96 function runs a collection of tests, as defined by
98 given the test vectors in the file
100 It returns results in the
104 which has two members:
107 counts the number of tests carried out, and
110 counts the number of tests which failed.
112 The function returns negative if there was a system error or the test
113 vector file was corrupt in some way, zero if all the tests were
114 successful, or positive if some tests failed.
118 provides a simple command-line interface to the test system. It is
119 intended to be called from the
121 function of a test rig program to check that a particular function or
122 suite of functions are running properly. It does not return. The arguments
126 should just be the arguments given to
130 argument gives the name of the default file of test vectors to read.
131 This can be overridden at run-time by passing the program a
133 command-line option. The
135 argument is (the address of) an array of
136 .I "chunk definitions"
137 describing the layout of the test vector file.
139 .SS "Test vector file syntax"
140 Test vector files are mostly free-form. Comments begin with a hash
142 and extend to the end of the line. Apart from that, newline characters
143 are just considered to be whitespace.
145 Test vector files have the following syntax:
149 .RI [ suite-header | chunk " ...]"
160 .RI [ test-vector " ...]"
168 Briefly in English: a test vector file is divided into chunks, each of
169 which consists of a textual name and a brace-enclosed list of test
170 vectors. Each test vector consists of a number of values terminated by
173 A value is either a sequence of
175 (alphanumerics and some other characters)
176 or a string enclosed in quote marks (double or single). Quoted strings
177 may contain newlines. In either type of value, a backslash escapes the
180 .SS "Suite definitions"
189 is a pointer to an array of these structures, terminated by one with a
193 .SS "Chunk definitions"
195 .I "chunk definition"
196 describes the format of a named chunk: the number and type of the values
197 required and the function to call in order to test the system against
198 that test vector. The array is terminated by a chunk definition whose
199 name field is a null pointer.
201 A chunk definition is described by the
203 structure. The members of this structure are as follows:
205 .B "const char *name"
206 The name of the chunk described by this chunk definition, or null if
207 this is the termination marker.
209 .BI "int (*test)(dstr " dv "[])"
210 The test function. It is passed an array of dynamic strings, one for
211 each field, and must return nonzero if the test succeeded or zero if the
212 test failed. On success, the function should not write anything to
213 stdout or stderr; on failure, a report of the test arguments should be
216 .B "test_type *f[TEST_FIELDMAX]"
217 Definitions of the fields. This is an array of pointers to
219 (see below), terminated by a null pointer.
221 When the test driver encounters a chunk it has a definition for, it
222 reads test vectors one by one, translating each value according to the
223 designated field type, and then passing the completed array of fields to
227 A field type describes how a field is to be read and written. A field
228 type is described by a
232 member is a function called to read an input string stored in
234 and output internal-format data in the dynamic string
236 The testrig driver has already stripped of quotes and dealt with
240 member is called to write the internal-format data in dynamic string
247 There are three predefined field types:
250 The simplest type. The string contents is not interpreted at all.
253 The string is interpreted as binary data encoded as hexadecimal.
256 The string is interpreted as a textual representation of an integer.
257 The integer is written to the dynamic string, and can be read out again
262 which isn't pretty but does the job.
267 but reads and stores a
274 but reads and stores an
281 but reads and stores a
287 .\"--------------------------------------------------------------------------
293 .\"--------------------------------------------------------------------------
296 Mark Wooding, <mdw@distorted.org.uk>
298 .\"----- That's all, folks --------------------------------------------------