chiark / gitweb /
@@@ more mess
[mLib] / test / tvec.3.in
1 .\" -*-nroff-*-
2 .\"
3 .\" Manual for the test vector framework
4 .\"
5 .\" (c) 2024 Straylight/Edgeware
6 .\"
7 .
8 .\"----- Licensing notice ---------------------------------------------------
9 .\"
10 .\" This file is part of the mLib utilities library.
11 .\"
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.
16 .\"
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.
21 .\"
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,
25 .\" USA.
26 .
27 .\"--------------------------------------------------------------------------
28 .so ../defs.man \" @@@PRE@@@
29 .
30 .\"--------------------------------------------------------------------------
31 .TH tvec 3mLib "11 March 2024" "Straylight/Edgeware" "mLib utilities library"
32 .\" TVMISC_PTR
33 .\" TVMISC_INT
34 .\" TVMISC_UINT
35 .\" TVMISC_FLT
36 .\" TVMISC_LIMIT
37 .
38 .\" @TVEC_REGSLOTS
39 .\" @TVRF_UNSET
40 .\" @TVRF_OPT
41 .\" @TVRF_ID
42 .\" @TVEC_ENDREGS
43 .
44 .\" @tvec_begin
45 .\" @tvec_end
46 .\" @tvec_read
47 .\" @tvec_humanoutput
48 .\" @tvec_tapoutput
49 .\" @tvec_dfltoutput
50 .
51 .\"--------------------------------------------------------------------------
52 .SH NAME
53 tvec \- test vector framework
54 .
55 .\"--------------------------------------------------------------------------
56 .SH SYNOPSIS
57 .nf
58 .B "#include <mLib/tvec.h>"
59 .PP
60 .ta 2n
61 .B "union tvec_misc {"
62 .B "    const void *p;"
63 .B "    long i;"
64 .B "    unsigned long u;"
65 .B "    double f;"
66 .B "};"
67 .B "enum {"
68 .B "    TVMISC_PTR,"
69 .B "    TVMISC_INT,"
70 .B "    TVMISC_UINT,"
71 .B "    TVMISC_FLT,"
72 .B "    ...,"
73 .B "    TVMISC_LIMIT,"
74 .B "};"
75 .PP
76 .ta 2n +2n
77 .B "union tvec_regval {"
78 .B "    long i;"
79 .B "    unsigned long u;"
80 .B "    void *p;"
81 .B "    double f;"
82 .B "    struct { char *p; size_t sz; } text;"
83 .B "    struct { unsigned char *p; size_t sz; } bytes;"
84 .B "    struct {"
85 .B "            unsigned char *p; size_t sz;"
86 .B "            size_t a, m;"
87 .B "            size_t off;"
88 .B "    } buf;"
89 .B "    TVEC_REGSLOTS"
90 .B "};"
91 .B "struct tvec_reg {"
92 .B "    unsigned f;"
93 .B "    union tvec_regval v;"
94 .B "};"
95 .B "#define TVRF_SEEN ..."
96 .B "#define TVRF_LIVE ..."
97 .PP
98 .ta 2n
99 .B "struct tvec_regdef {"
100 .B "    const char *name;"
101 .B "    const struct tvec_regty *ty;"
102 .B "    unsigned i;"
103 .B "    unsigned f;"
104 .B "    union tvec_misc arg;"
105 .B "};"
106 .B "#define TVRF_UNSET ..."
107 .B "#define TVRF_OPT ..."
108 .B "#define TVRF_SYNTH ..."
109 .B "#define TVRF_ID ..."
110 .B "#define TVEC_ENDREGS ..."
111 .PP
112 .B "struct tvec_state;"
113 .PP
114 .B "struct tvec_env;"
115 .ta \w'\fBtypedef void tvec_testfn('u
116 .BI "typedef void tvec_testfn(const struct tvec_reg *" in ,
117 .BI "   struct tvec_reg *" out ,
118 .BI "   void *" ctx );
119 .ta 2n
120 .B "struct tvec_test {"
121 .B "    const char *name;"
122 .B "    const struct tvec_regdef *regs;"
123 .B "    const struct tvec_env *env;"
124 .B "    tvec_testfn *fn;"
125 .B "};"
126 .PP
127 .ta 2n
128 .B "struct tvec_config {"
129 .B "    const struct tvec_test *const *tests;"
130 .B "    unsigned nrout, nreg;"
131 .B "    size_t regsz;"
132 .B "};"
133 .B "struct tvec_output;"
134 .PP
135 .ta \w'\fBvoid tvec_begin('u
136 .BI "void tvec_begin(struct tvec_state *" tv_out ,
137 .BI "   const struct tvec_config *" config ,
138 .BI "   struct tvec_output *" o );
139 .BI "int tvec_end(struct tvec_state *" tv );
140 .BI "int tvec_read(struct tvec_state *" tv ", const char *" infile ", FILE *" fp );
141 .PP
142 .B "#define TVHF_TTY ..."
143 .B "#define TVHF_COLOUR ..."
144 .ta \w'\fBstruct tvec_output *tvec_humanoutput('u
145 .BI "struct tvec_output *tvec_humanoutput(FILE *" fp ,
146 .BI "   unsigned " f ", unsigned " m );
147 .BI "struct tvec_output *tvec_machineoutput(FILE *" fp );
148 .BI "struct tvec_output *tvec_tapoutput(FILE *" fp );
149 .BI "struct tvec_output *tvec_dfltoutput(FILE *" fp );
150 .PP
151 .ta 2n
152 .B "struct tvec_amargs {"
153 .B "    unsigned f;"
154 .B "    const char *name;"
155 .B "    FILE *log;"
156 .B "    FILE *trs;"
157 .B "};"
158 .BI "struct tvec_output *tvec_amoutput(const struct tvec_amargs *" a );
159 .fi
160 .
161 .\"--------------------------------------------------------------------------
162 .SH DESCRIPTION
163 .
164 The
165 .B <mLib/tvec.h>
166 header file provides definitions and declarations
167 for the core of mLib's
168 .IR "test vector framework" .
169 .PP
170 The test vector framework is rather large and complicated,
171 so the documentation for it is split into multiple manual pages.
172 This one provides a conceptual overview
173 and describes the essentials for using it to build simple tests.
174 .
175 .SS Conceptual overview
176 A
177 .I "test session"
178 runs a collection of tests
179 and reports on the outcome.
180 .PP
181 A
182 .I test
183 involves exercising some functionality
184 and checking that it behaves properly.
185 A test can have four
186 .IR outcomes .
187 It can
188 .IR pass :
189 the functionality behaved properly.
190 It can
191 .IR fail :
192 the functionality did not behave properly.
193 It can experience an
194 .IR "expected failure" :
195 the functionality behaved as expected,
196 but the expected behaviour is known to be incorrect.
197 Or it can be
198 .IR skipped :
199 for some reason, the test couldn't be performed.
200 .PP
201 Tests are gathered together into
202 .IR "test groups" .
203 Each test group has a name.
204 Like a individual tests, test groups also have outcomes:
205 they can pass, fail, or be skipped.
206 A test group cannot experience expected failure.
207 .PP
208 A session may also encounter
209 .IR errors ,
210 e.g., as a result of malformed input
211 or failures reported by system facilities,
212 which prevent proper testing from proceeding.
213 The framework attempts to recover from errors,
214 so as to provide as useful a result as possible;
215 but, fundamentally,
216 an error means that the test results are inconclusive.
217 .PP
218 A test session can either
219 be driven from data provided by an input file,
220 or it can be driven by the program alone.
221 The latter case is called
222 .I "ad-hoc testing",
223 and is described in
224 .BR tvec-adhoc (3).
225 This manual page describes file-driven testing.
226 .PP
227 When it begins a session for file-directed testing,
228 the program provides a table of
229 .IR "test definitions" .
230 A test definition has a
231 .IR name ,
232 and also specifies a
233 .IR "test function" ,
234 a
235 .IR "test environment" ,
236 and a table of
237 .IR "register definitions" .
238 Test environments are explained further below.
239 .PP
240 A
241 .I register
242 is a place which can store a single item of test data;
243 registers are the means
244 by which input test data is provided to a test function,
245 and by which a test function returns its results.
246 A test definition's register definitions
247 establish a collection of
248 .I active
249 registers.
250 Each active register has a
251 .IR name ,
252 an
253 .IR index ,
254 and a
255 .IR type ,
256 which are established by its register definition.
257 The register's name is used to refer to the register in the test data file,
258 and its index is used to refer to it
259 in the test function and test environments.
260 The register's type describes the acceptable values for the register,
261 and how they are to be compared,
262 read from the input file,
263 and dumped in diagnostic output.
264 New register types can be defined fairly easily: see
265 .BR tvec_tyimpl (3)
266 for the details.
267 A register definition may describe an
268 .I input
269 register or an
270 .I output
271 register:
272 input registers provide input data to the test function, while
273 output registers collect output data from the test function.
274 The data file provides values for both input and output registers:
275 the values for the input registers are passed to the test function;
276 the values for the output registers are
277 .I reference
278 values against which the test function's outputs are to be checked.
279 .PP
280 The test function is called with two vectors of registers,
281 one containing input values for the test function to read
282 and also reference values,
283 and another for output values that the test function should write;
284 and a
285 .I context
286 provided by the test environment.
287 The test function's task is to exercise the functionality to be tested,
288 providing it the input data from its input registers,
289 and collecting the output in its output registers.
290 It is the responsibility of the test environment or the framework
291 to compare the output register values against reference
292 provided in the input data.
293 .PP
294 The input file syntax is described in full below.
295 In overview, it is a
296 .BR .ini -style
297 file.
298 Comments begin with a semicolon character
299 .RB ` ; ',
300 and extend to the end of the line.
301 It is divided into
302 .I sections
303 by headings in square brackets:
304 .IP
305 .BI [ test ]
306 .PP
307 Each section contains a number of
308 .I paragraphs
309 separated by blank lines.
310 Each paragraph consists of one or more
311 .I assignments
312 of the form
313 .IP
314 .IB reg " = " value
315 .PP
316 or
317 .IP
318 .IB reg ": " value
319 .PP
320 When the framework encounters a section heading,
321 it finishes any test group currently in progress,
322 and searches for a test definition whose name matches the
323 .I test
324 name in the section heading.
325 If it finds a match,
326 it begins a new test group with the same name.
327 Each paragraph of assignments is used to provide
328 input and reference values
329 for a single test.
330 The
331 .I reg
332 name in an assignment must match the name
333 of an active register or a
334 .I "special variable" ;
335 the corresponding
336 .I value
337 is stored in the named register or variable.
338 .PP
339 A register which has been assigned a value is said to be
340 .IR live ;
341 otherwise, it is
342 .IR dead .
343 By default, every active register must be live for a test to proceed;
344 but a register definition can mark its register as
345 .I optional
346 or
347 .IR may-be-unset .
348 An optional register need not be assigned a value explicitly;
349 instead, the register is left dead.
350 A may-be-unset register must be mentioned,
351 but a distinctive syntax
352 .IP
353 .IB reg " *"
354 .PP
355 (with no colon or equals sign)
356 says that the register should be left dead.
357 Optional registers are suitable for cases where
358 there is an obvious default value
359 which would otherwise be mentioned frequently in input files.
360 May-be-unset registers are mostly useful as outputs,
361 where the output is not always set,
362 e.g., in error cases,
363 but where omitting a value in the usual case is likely a mistake.
364 .PP
365 A test environment fits in between
366 the framework and the test function.
367 It can establish hook functions which are called
368 at various points throughout a test group
369 (at the start and and, and before and after each test).
370 It can define special variables
371 which can be set from the input file using assignments.
372 And, finally, it can take on the responsibility
373 of running the test function.
374 The registers will have been set up already,
375 based on the assignments in the input file,
376 but the environment can modify them.
377 It must also check the test function's output
378 against the reference values,
379 though there are functions provided for doing this.
380 The environment can choose to run the test function once,
381 multiple times, or, indeed, not at all.
382 When it calls the test function, it can provide a context pointer,
383 with whatever additional information might be useful:
384 this usually involves coordination
385 between the environment and the test function.
386 It is the test environment's responsibility
387 to check the outputs returned by the test function
388 and to report on mismatches,
389 but there are functions provided by the framework
390 to do the heavy lifting.
391 .PP
392 The following are examples of what test environments can do.
393 .hP \*o
394 It can fill in default values for optional dead registers.
395 For example, if a function returnns error codes,
396 then you can save reptition in the input file
397 by marking the error-code output register optional
398 and letting it default to the `success' value in a test environment.
399 .hP \*o
400 It can run the test function mulitple times.
401 For example, a test of functions like
402 .BR strcmp (3)
403 might run the test twice,
404 first with its operands as supplied by the input file,
405 and then again with the operands swapped
406 and the opposite expected result.
407 A test for bignum addition could verify commutativity
408 by checking both that
409 .IR x "\ + \ " y "\ =\ " z
410 and that
411 .IR y "\ + \ " x "\ =\ " z \fR.
412 Similarly, a subtraction test could check both that
413 .IR x "\ \- \ " y "\ =\ " z
414 and that
415 .IR y "\ \- \ " x "\ =\ \-" z \fR.
416 .hP \*o
417 The
418 .BR tvec-remote (3),
419 .BR tvec-timeout (3),
420 and
421 .BR tvec-bench (3)
422 extensions all slot in as test environments,
423 with no extensions to the core API.
424 .PP
425 The framework includes a simple command-line front-end
426 described in
427 .BR tvec-main (3).
428 In particular, the
429 .B tvec_main
430 function provides all of the necessary command-line
431 option and argument processing,
432 and handles the test session lifecycle,
433 given a pointer to the static tables
434 describing the supported test groups.
435 .
436 .SS Input file format
437 The file format is inspired by Windows
438 .B .ini
439 files.
440 .PP
441 Comments begin with a semicolon
442 .RB ` ; '
443 and continue to the end of the line;
444 a comment may be placed on a line by itself,
445 optionally preceded by whitespace;
446 or following other contents on a line.
447 .PP
448 Indentation and blank lines are significant;
449 trailing whitespace on a line is generally ignored.
450 Blank lines serve to separate groups of assignments into `paragraphs'
451 as explained  below.
452 A line containing only a comment,
453 possibly preceded by whitespace,
454 is ignored,
455 and does not separate paragraphs.
456 An indented line is a
457 .IR "continuation line" ,
458 used to continue values over multiple lines.
459 .PP
460 A line beginning with an opening square bracket
461 .RB ` [ '
462 is a
463 .IR "section heading" ,
464 and has the form
465 .IP
466 .BI [ name ]
467 .PP
468 optionally followed by a comment.
469 The
470 .I name
471 may consist of any non-whitespace characters
472 other than the closing square bracket
473 .RB ` ] '.
474 Whitespace is permitted
475 (though not recommended)
476 between the brackets and the
477 .IR name .
478 The
479 .I name
480 must match the name of a test group
481 defined by the test configuration;
482 see below.
483 .PP
484 A section heading marks the start of a
485 .IR section ,
486 which continues until the next section heading
487 or to the end of the file.
488 .PP
489 Each section consists of
490 .I assignments
491 divided into
492 .I paragraphs
493 by groups of one or more blank lines.
494 A line containing only a comment is
495 .I not
496 considered to be `blank' for the purposes of separating paragraphs.
497 There need not be blank lines
498 before the first paragraph in a section;
499 nor after the last.
500 .PP
501 A paragraph consists of one or more
502 .IR assignments ,
503 each of which begins with an unindented
504 .I initial line
505 followed by zero or more indented
506 .IR "continuation lines" .
507 .PP
508 An initial line begins with a
509 .I name
510 followed by an
511 .IR "assignment operator" ;
512 the remaining contents, if any,
513 are determined by the name and operator.
514 A name is a sequence of non-whitespace characters
515 other than assignment operators, which are
516 colon
517 .RB ` : ',
518 equals sign
519 .RB ` = ',
520 or asterisk
521 .RB ` * '.
522 There may be whitespace separating the name and operator.
523 .PP
524 A
525 .I "value assignment"
526 has the colon
527 .RB ` : '
528 or equals sign
529 .RB ` = '
530 as its operator;
531 there is no difference in meaning between the two.
532 The operator is followed by optional whitespace and a
533 .IR value .
534 The
535 .I name
536 must match the name of a register or special variable
537 defined by the test group,
538 and the register or special variable definition determines
539 a register type for the assignment;
540 the syntax of the value is determined by the register type;
541 see
542 .BR tvec-types (3)
543 for the descriptions of the built-in types,
544 and
545 .BR tvec-tyimpl (3)
546 for how to define new register types.
547 The
548 .I value
549 may continue over multiple continuation lines,
550 each beginning with one or more whitespace characters.
551 The effect is to set the named register or special variable
552 to the specified value.
553 .PP
554 An
555 .I unassignment
556 has the asterisk
557 .RB `*'
558 as its operator.
559 The
560 .I name
561 must match the name of a regsiter defined by the test group.
562 Only registers defined with the
563 .B TVRF_UNSET
564 or
565 .B TVRF_OPT
566 flags (see below) can be unassigned;
567 special variables cannot be unassigned.
568 .PP
569 An error is reported if
570 the same register or special variable
571 is the subject of more than one assignment
572 within a paragraph,
573 or if there is no assignment for
574 a register defined by the test group
575 without the
576 .B TVRF_OPT
577 flag.
578 .
579 .SS Miscellaneous values
580 The
581 .B "union tvec_misc"
582 is a small union used
583 to pass a simple but opaque parameter
584 to an extension.
585 It consists of
586 an untyped pointer
587 .BR p ,
588 signed and unsigned integers
589 .B i
590 and
591 .BR u ,
592 and a floating-point number
593 .BR f .
594 The pointer member is listed first,
595 because this is the most common (and general) case,
596 and the first member of a union
597 is the only member that can be initialized statically
598 in dialects (e.g., C89, C++14) which lack designated initializers.
599 .PP
600 There is an associated collection of constants,
601 .BR TVMISC_PTR ,
602 .BR TVMISC_INT ,
603 .BR TVMISC_UINT ,
604 and
605 .BR TVMISC_FLT ,
606 which can be used to keep track of which member of a
607 .B union tvec_misc
608 is `active'.
609 These constants are currently not used by the framework.
610 .
611 .SS Registers
612 A
613 .I register
614 is essentially a `slot' capable of holding a value.
615 Registers primarily occur as inputs and outputs for test functions,
616 but they also appear in other contexts.
617 .PP
618 The values that a particular register can hold
619 are determined by the register's
620 .IR type .
621 Register values are held in a
622 .BR "union tvec_regval" .
623 Unmodified,
624 this union contains a number of useful C-level data types
625 corresponding to the provided register types;
626 see the synopsis above, and
627 .BR tvec-types (3)
628 for the specifics.
629 More members can added by defining the macro
630 .B TVEC_REGSLOTS
631 to the list of member declarations
632 before including
633 .BR <mLib/tvec.h> .
634 .PP
635 A register value can hold resources,
636 such as allocated memory,
637 or even network connections or files.
638 A register value must be
639 .I initialized
640 before use,
641 and should be
642 .I released
643 when it is no longer required.
644 The life-cycle for register values is described in detail in
645 .BR tvec-tyimpl (3).
646 .PP
647 The state of a register is maintained in
648 .BR "struct tvec_reg" ,
649 which contains a flags word
650 .B f
651 as well as a
652 .B "union tvec_regval"
653 to hold the value.
654 .PP
655 At the start of the test session,
656 the framework allocates two vectors of
657 .B "struct tvec_reg" ,
658 conventionally named
659 .I in
660 and
661 .IR out ,
662 with the lengths
663 .B nreg
664 and
665 .B nrout
666 specified in the test configuration.
667 The
668 .I in
669 vector must be at least as long as the
670 .I out
671 vector, i.e.,
672 .BR nreg "\ \*(>=\ " nrout .
673 Within the framework,
674 registers are identified by their indices in these vectors.
675 An index
676 .BI \fR0 "\ \*(<=\ " i "\ <\ " nrout
677 identifies an
678 .IR "output value" ;
679 an index
680 .BI nrout "\ \*(<=\ " i "\ <\ " nreg
681 identifies an
682 .IR "input value";
683 other indices are invalid.
684 .PP
685 A
686 .I "register definition"
687 associates a name, type, and some flags, with a register index.
688 A register definitions is represented as a
689 .B "struct tvec_regdef"
690 structure, which has five members.
691 .TP
692 .B "const char *name"
693 The register name.
694 This is used in input files to refer to the register.
695 .TP
696 .B "const struct tvec_regty *ty"
697 The register's type.
698 This can be the address one of the supplied
699 .B tvty_...\&
700 type structures described in
701 .BR tvec-types (3),
702 or a custom type;
703 see
704 .BR tvec-tyimpl (3)
705 for how to implement new types.
706 .TP
707 .B "unsigned i"
708 The index of the register.
709 .TP
710 .B "unsigned f"
711 Flags defining additional special behaviour for the register.
712 The flags are described below.
713 .TP
714 .B "union tvec_misc arg"
715 An argument for the register type.
716 .PP
717 A test definition (see below) includes
718 a vector of register definitions.
719 The vector is terminated by an entry whose
720 .B name
721 member is a null pointer.
722 The
723 .B TVEC_ENDREGS
724 macro expands to a suitable static initializer.
725 .PP
726 The names and indices of register definitions
727 for a single test definition
728 must be dinstinct.
729 A test definition need not include
730 a register definition for every register index;
731 the registers with associated definitions
732 in a particular test
733 are said to be
734 .IR active ;
735 those without a definition are said to be
736 .IR inactive .
737 Nothing useful can be done with inactive register indices:
738 inactive register don't even have an associated type.
739 .PP
740 The flags which can be set are as follows.
741 .TP
742 .B TVRF_UNSET
743 It is permitted to
744 .I unassign
745 the register in input file paragraph
746 using the
747 .RB ` * '
748 assignment operator.
749 .TP
750 .B TVRF_OPT
751 It is permitted for an input file paragraph
752 to have no assignment for the register.
753 It is also permitted for an input file paragraph
754 to unassign the register explicitly,
755 i.e.,
756 .B TVRF_OPT
757 additionally implies the behaviour of
758 .BR TVRF_UNSET .
759 .TP
760 .B TVRF_ID
761 The register value constitutes part of
762 the `identity' of the test case.
763 For example, the
764 .BR tvec-bench (3)
765 uses the values of the registers whose
766 .B TVRF_ID
767 flag is set to label its performence results.
768 .PP
769 The
770 .I in
771 vector receives data from the input file.
772 When the framework processes an assignment,
773 it looks up the
774 .I name
775 in the register definitions:
776 if it finds a match,
777 it uses the associated index to locate the register.
778 In the case of a value assignment,
779 the framework invokes the register type's
780 .B parse
781 function to read the value from the input file
782 (see
783 .BR tvec-tyimpl (3)
784 for details on this)
785 and store it in the register.
786 If this is successful, then the framework sets the
787 .B TVRF_SEEN
788 and
789 .B TVRF_LIVE
790 flags on the register.
791 In the case of an unassignment,
792 the framework sets only the
793 .B TVRF_SEEN
794 flag.
795 Registers with indicess equal or greater than
796 .B nrout
797 provide input data to the test function.
798 Registers with indices less than
799 .B nrout
800 hold reference values:
801 a test function won't usually inspect these,
802 though it might,
803 e.g., to determine an output buffer size.
804 .PP
805 Once the end of the paragraph is found,
806 the framework checks that
807 all of the necessary register have been assigned:
808 every register listed in the test group's register definitions
809 must have the
810 .B TVRF_SEEN
811 flag set, unless the definition sets the
812 .B TVRF_OPT
813 flag.
814 It invokes the test function,
815 via the test environment, if one is defined.
816 See below for details on how the test function is invoked.
817 .
818 .SS Test definitions
819 A
820 .I "test definition"
821 describes a test group.
822 Test definitions are represented as a
823 .B "struct tvec_test"
824 structure.
825 This has four members.
826 .TP
827 .B "const char *name"
828 The test group name.
829 This is used in input files to refer to the test group.
830 .TP
831 .B "const struct tvec_regdef *regs"
832 Pointer to the vector of register definitions.
833 The vector is terminated by an entry whose
834 .B name
835 member is null.
836 .TP
837 .B "const struct tvec_env *env"
838 Pointer to the test environment for this test group.
839 Test environments are described in
840 .BR tvec-env (3).
841 Specific uses are discussed in
842 .BR tvec-bench (3),
843 .BR tvec-remote (3),
844 and
845 .BR tvec-timeout (3).
846 .TP
847 .B "tvec_testfn *fn"
848 The test function.
849 .
850 .SS Test functions
851 The signature for test functions is
852 .IP
853 .nf
854 .ta \w'\fBvoid \,\fItestfn\/\fB('u
855 .BI "void " testfn "(const struct tvec_reg *" in ,
856 .BI "   struct tvec_rec_reg *" out ", void *" ctx );
857 .fi
858 .PP
859 The
860 .I in
861 and
862 .I out
863 arguments are the two register vectors discussed above,
864 the former holding the input and reference values,
865 and the latter for the outputs.
866 The
867 .I ctx
868 pointer is provided by the test environment.
869 If there is no test environment,
870 then this is null.
871 .PP
872 On entry to the test function,
873 all of the active registers are initialized,
874 both
875 .I in
876 and
877 .IR out ;
878 the
879 .I out
880 registers corresponding to
881 live reference registers in the
882 .I in vector
883 additionally have their
884 .B TVRF_LIVE
885 flags set.
886 .PP
887 Recall that an input-file paragraph can provide
888 a value assignment for a register,
889 an unassignment,
890 or none at all.
891 A test function or test environment
892 can distinguish the three cases using the register flags:
893 .hP \*o
894 A register which has been assigned a value
895 has both
896 .B TVRF_SEEN
897 and
898 .B TVRF_LIVE
899 flags.
900 .hP \*o
901 A register which has been explicitly unassigned has only the
902 .B TVRF_SEEN
903 flag.
904 Such a register's definition must have had either
905 .B TVRF_UNSET
906 or
907 .B TVRF_OPT
908 set.
909 .hP \*o
910 A register which has not been assigned has neither flag set.
911 Such a register's definition must have had the
912 .B TVRF_OPT
913 flag set.
914 .PP
915 The test function will usually set the
916 .I out
917 registers corresponding to at least the live reference registers;
918 it may set additional active output registers
919 (and set their
920 .B TVRF_LIVE
921 flags).
922 .PP
923 The caller will check the outputs
924 against the reference values from the input file.
925 A
926 .I mismatch
927 occurs when a reference-value register is live and
928 either the corresponding output register is not live
929 or the output register value is not equal to the reference value
930 (as determined by the register type).
931 In the event of a mismatch,
932 the framework dumps the values of of the registers
933 and reports a failure.
934 .PP
935 The test function is
936 .I not
937 passed a pointer to the
938 .B "struct tvec_state"
939 structure which is pretty much ubiquitous
940 in the test-vector framework interface.
941 A test function is not expected to `fail'
942 in the sense that it encounters a problem
943 that prevents it from performing the test.
944 Failure-prone setup can be performed by the test environment,
945 which can force a skip if necessary;
946 successfully acquired resources can be passed on
947 to the test function via the context pointer.
948 Errors encountered by the test function itself
949 should usually be reported by setting an output register.
950 If a test function really needs access to the test state,
951 an environment can arrange to pass it in via the context pointer.
952 .
953 .SS Test configurations
954 A
955 .IR "test configuration" ,
956 represented by the
957 .B "struct tvec_config"
958 structure,
959 describes the global information required for a test session.
960 It has four members.
961 .TP
962 .B "const struct tvec_test *const *tests"
963 A pointer to a vector of pointers to test definitions,
964 terminated by a null pointer.
965 (Having pointers to the test definitions here,
966 rather than the definitions themselves,
967 allows the actual definitions to be kept alongside
968 the rest of the machinery required for the test group.)
969 .TP
970 .B "unsigned nrout"
971 The number of output registers.
972 .TP
973 .B "unsigned nreg"
974 The number of registers total.
975 (There are therefore
976 .BR nreg "\ \-\ " nrout
977 input registers.)
978 .TP
979 .B "size_t regsz"
980 The size of a
981 .BR "struct tvec_reg" .
982 The fact that a test program can add
983 additional members to the
984 .B "union tvec_regval"
985 by setting
986 .B TVEC_REGSLOTS
987 means that the true size of the union
988 was unknown when the framework
989 and application-agnostic extensions
990 were compiled.
991 They therefore need to learn the true size at runtime.
992 Since the main motivation is to be able to index the
993 .I in
994 and
995 .I out
996 register vectors,
997 it's the size of
998 .BR "struct tvec_reg" ,
999 rather than
1000 .B "union tvec_regval"
1001 itself,
1002 that's of critical importance.
1003 .
1004 .SS Output drivers
1005 The framework core does no output itself.
1006 Instead, all output is performed by an
1007 .IR "output driver" ,
1008 represented with the
1009 .B "struct tvec_output"
1010 structure.
1011 See
1012 .BR tvec-output (3)
1013 for details about this structure
1014 and how to write new output drivers.
1015 This section describes the output drivers
1016 provided with the framework.
1017 .PP
1018 The
1019 .B tvec_dfltoutput
1020 function is given a
1021 .B stdio
1022 stream
1023 .I fp
1024 and returns an output driver chosen in some unspecified way.
1025 Currently, if
1026 .I fp
1027 refers to an `interactive device'
1028 then the `human' driver is chosen;
1029 otherwise, the `machine' driver is chosen.
1030 This behaviour may change in the future.
1031 If your program depends on a specific driver being chosen,
1032 then use it explicitly.
1033 .PP
1034 The predefined drivers are as follows.
1035 .IP The `human' driver
1036 .RS
1037 The `human' driver produces output expected to be useful to humans,
1038 but, despite being
1039 .I technically
1040 unambiguous (I think)
1041 is probably rather difficult to parse.
1042 Moreover, the details of the output are subject to change.
1043 .PP
1044 The `human' driver prints a line when a test or test group is skipped;
1045 where a reason for the skip is given, this is also printed.
1046 A line is also printed for each error encountered,
1047 describing the situtation;
1048 errors are
1049 .I also
1050 written to the standard error stream if (heurstically)
1051
1052
1053
1054 .
1055 .SS Test session lifecycle