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