3 * Test vector processing framework
5 * (c) 2023 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,
35 /* Here's the overall flow for a testing session.
38 * -> output @bsession@
43 * -> type @init@ (input and output)
44 * -> type @parse@ (input)
48 * -> output @skipgroup@
83 * -> output @skipgroup@
88 * -> output @esession@
92 * -> type @dump@ (compact style)
97 * -> @tvec_benchreport@
99 * The output functions @error@ and @notice@ can be called at arbitrary
103 /*----- Header files ------------------------------------------------------*/
114 #ifndef MLIB_CONTROL_H
115 # include "control.h"
122 #ifndef MLIB_GPRINTF_H
123 # include "gprintf.h"
130 #ifndef MLIB_MACROS_H
134 /*----- Miscellaneous values ----------------------------------------------*/
136 /* These are attached to structures which represent extension points, as a
137 * way to pass an opaque parameter to whatever things are hooked onto them.
140 #define TVEC_MISCSLOTS(_) \
141 _(PTR, const void *, p) /* arbitrary pointer */ \
142 _(INT, long, i) /* signed integer */ \
143 _(UINT, unsigned long, u) /* signed integer */ \
144 _(FLT, double, f) /* floating point */
147 #define TVEC_DEFSLOT(tag, ty, slot) ty slot;
148 TVEC_MISCSLOTS(TVEC_DEFSLOT)
152 #define TVEC_DEFCONST(tag, ty, slot) TVMISC_##tag,
153 TVEC_MISCSLOTS(TVEC_DEFCONST)
157 /*----- Register values ---------------------------------------------------*/
159 /* The framework doesn't have a preconceived idea about what's in a register
160 * value: it just allocates them and accesses them through the register type
161 * functions. It doesn't even have a baked-in idea of how big a register
162 * value is: instead, it gets that via the `regsz' slot in `struct
163 * tvec_testinfo'. So, as far as the framework is concerned, it's safe to
164 * add new slots to this union, even if they make the overall union larger.
165 * This can be done by defining the preprocessor macro `TVEC_REGSLOTS' to be
166 * a `union' fragment defining any additional union members.
168 * This creates a distinction between code which does and doesn't know the
169 * size of a register value. Code which does, which typically means the test
170 * functions, benchmarking setup and teardown functions, and tightly-bound
171 * runner functions, is free to index the register vectors directly. Code
172 * which doesn't, which means the framework core itself and output formatting
173 * machinery, must use the `TVEC_REG' macro (or its more general `TVEC_GREG'
174 * companion) for indexing register vectors. (In principle, register type
175 * handlers also fit into this category, but they have no business peering
176 * into register values other than the one's they're given.)
180 /* The actual register value. This is what the type handler sees.
181 * Additional members can be added by setting `TVEC_REGSLOTS' before
182 * including this file.
184 * A register value can be /initialized/, which simply means that its
185 * contents represent a valid value according to its type -- the register
186 * can be compared, dumped, serialized, parsed into, etc. You can't do
187 * anything safely to an uninitialized register value other than initialize
191 long i; /* signed integer */
192 unsigned long u; /* unsigned integer */
193 void *p; /* pointer */
194 double f; /* floating point */
195 struct { unsigned char *p; size_t sz; } bytes; /* binary string of bytes */
196 struct { char *p; size_t sz; } str; /* text string */
205 * Note that all of the registers listed as being used by a particular test
206 * group are initialized at all times[1] while that test group is being
207 * processed. (The other register slots don't even have types associated
208 * with them, so there's nothing useful we could do with them.)
210 * The `TVRF_LIVE' flag indicates that the register was assigned a value by
211 * the test vector file: it's the right thing to use to check whether an
212 * optional register is actually present. Even `dead' registers are still
213 * initialized, though.
215 * [1] This isn't quite true. Between individual tests, the registers are
216 * released and reinitialized in order to reset them to known values
217 * ready for the next test. But you won't see them at this point.
220 unsigned f; /* flags */
221 #define TVRF_LIVE 1u /* used in current test */
222 union tvec_regval v; /* register value */
226 /* A register definition. Register definitions list the registers which
227 * are used by a particular test group (see `struct tvec_test' below).
229 * A vector of register definitions is terminated by a definition whose
230 * `name' slot is null.
233 const char *name; /* register name (for input files) */
234 unsigned i; /* register index */
235 const struct tvec_regty *ty; /* register type descriptor */
236 unsigned f; /* flags */
237 #define TVRF_OPT 1u /* optional register */
238 #define TVRF_ID 2u /* part of test identity */
239 union tvec_misc arg; /* extra detail for the type */
241 #define TVEC_ENDREGS { 0, 0, 0, 0, { 0 } }
243 /* @TVEC_GREG(vec, i, regsz)@
245 * If @vec@ is a data pointer which happens to contain the address of a
246 * vector of @struct tvec_reg@ objects, @i@ is an integer, and @regsz@ is the
247 * size of a @struct tvec_reg@, then this evaluates to the address of the
248 * @i@th element of the vector.
250 * This is the general tool you need for accessing register vectors when you
251 * don't have absolute knowledge of the size of a @union tvec_regval@.
252 * Usually you want to access one of the register vectors in a @struct
253 * tvec_state@, and @TVEC_REG@ will be more convenient.
255 #define TVEC_GREG(vec, i, regsz) \
256 ((struct tvec_reg *)((unsigned char *)(vec) + (i)*(regsz)))
258 /*----- Register types ----------------------------------------------------*/
260 struct tvec_state; /* forward declaration */
263 /* A register type. */
265 void (*init)(union tvec_regval */*rv*/, const struct tvec_regdef */*rd*/);
266 /* Initialize the value in @*rv@. This will be called before any other
267 * function acting on the value, including @release@.
270 void (*release)(union tvec_regval */*rv*/,
271 const struct tvec_regdef */*rd*/);
272 /* Release any resources associated with the value in @*rv@. */
274 int (*eq)(const union tvec_regval */*rv0*/,
275 const union tvec_regval */*rv1*/,
276 const struct tvec_regdef */*rd*/);
277 /* Return nonzero if @*rv0@ and @*rv1@ are equal values. Asymmetric
278 * criteria are permitted: @tvec_checkregs@ calls @eq@ with the input
279 * register as @rv0@ and the output as @rv1@.
282 int (*tobuf)(buf */*b*/, const union tvec_regval */*rv*/,
283 const struct tvec_regdef */*rd*/);
284 /* Serialize the value @*rv@, writing the result to @b@. Return zero on
285 * success, or %$-1$% on error.
288 int (*frombuf)(buf */*b*/, union tvec_regval */*rv*/,
289 const struct tvec_regdef */*rd*/);
290 /* Deserialize a value from @b@, storing it in @*rv@. Return zero on
291 * success, or %$-1$% on error.
294 int (*parse)(union tvec_regval */*rv*/, const struct tvec_regdef */*rd*/,
295 struct tvec_state */*tv*/);
296 /* Parse a value from @tv->fp@, storing it in @*rv@. Return zero on
297 * success, or %$-1$% on error, having reported one or more errors via
298 * @tvec_error@ or @tvec_syntax@. A successful return should leave the
299 * input position at the start of the next line; the caller will flush
300 * the remainder of the line itself.
303 void (*dump)(const union tvec_regval */*rv*/,
304 const struct tvec_regdef */*rd*/,
306 const struct gprintf_ops */*gops*/, void */*go*/);
307 #define TVSF_COMPACT 1u
308 /* Write a human-readable representation of the value @*rv@ using
309 * @gprintf@ on @gops@ and @go@. The @style@ is a collection of flags:
310 * if @TVSF_COMPACT@ is set, then output should be minimal, and must fit
311 * on a single line; otherwise, output may consist of multiple lines and
312 * may contain redundant information if that is likely to be useful to a
317 /*----- Test descriptions -------------------------------------------------*/
319 typedef void tvec_testfn(const struct tvec_reg */*in*/,
320 struct tvec_reg */*out*/,
322 /* A test function. It should read inputs from @in@ and write outputs to
323 * @out@. The @TVRF_LIVE@ is set on inputs which are actually present, and
324 * on outputs which are wanted to test. A test function can set additional
325 * `gratuitous outputs' by setting @TVRF_LIVE@ on them; clearing
326 * @TVRF_LIVE@ on a wanted output causes a mismatch.
328 * A test function may be called zero or more times by the environment. In
329 * particular, it may be called multiple times, though usually by prior
330 * arrangement with the environment.
332 * The @ctx@ is supplied by the environment's @run@ function (see below).
333 * The default environment calls the test function once, with a null
334 * @ctx@. There is no expectation that the environment's context has
335 * anything to do with the test function's context.
340 typedef void tvec_envsetupfn(struct tvec_state */*tv*/,
341 const struct tvec_env */*env*/,
342 void */*pctx*/, void */*ctx*/);
343 /* Initialize the context; called at the start of a test group; @pctx@ is
344 * null for environments called by the core, but may be non-null for
345 * subordinate environments. If setup fails, the function should call
346 * @tvec_skipgroup@ with a suitable excuse. The @set@, @after@, and
347 * @teardown@ entry points will still be called, but @before@ and @run@
351 typedef int tvec_envsetfn(struct tvec_state */*tv*/,
352 const char */*var*/, void */*ctx*/);
353 /* Called when the parser finds a %|@var|%' setting to parse and store the
354 * value. If @setup@ failed, this is still called (so as to skip the
355 * value), but @ctx@ is null.
358 typedef void tvec_envbeforefn(struct tvec_state */*tv*/, void */*ctx*/);
359 /* Called prior to running a test. This is the right place to act on any
360 * `%|@var|%' settings. If preparation fails, the function should call
361 * @tvec_skip@ with a suitable excuse. This function is never called if
362 * the test group is skipped.
365 typedef void tvec_envrunfn(struct tvec_state */*tv*/,
366 tvec_testfn */*fn*/, void */*ctx*/);
367 /* Run the test. It should either call @tvec_skip@, or run @fn@ one or
368 * more times. In the latter case, it is responsible for checking the
369 * outputs, and calling @tvec_fail@ as necessary; @tvec_checkregs@ will
370 * check the register values against the supplied test vector, while
371 * @tvec_check@ does pretty much everything necessary. This function is
372 * never called if the test group is skipped.
375 typedef void tvec_envafterfn(struct tvec_state */*tv*/, void */*ctx*/);
376 /* Called after running or skipping a test. Typical actions involve
377 * resetting whatever things were established by @set@. This function
378 * %%\emph{is}%% called if the test group is skipped, so that the test
379 * environment can reset variables set by the @set@ entry point. It should
380 * check the @TVSF_SKIP@ flag if necessary.
383 typedef void tvec_envteardownfn(struct tvec_state */*tv*/, void */*ctx*/);
384 /* Tear down the environment: called at the end of a test group. */
388 /* A test environment sets things up for and arranges to run the test.
390 * The caller is responsible for allocating storage for the environment's
391 * context, based on the @ctxsz@ slot, and freeing it later; this space is
392 * passed in as the @ctx@ parameter to the remaining functions; if @ctxsz@
393 * is zero then @ctx@ is null.
396 size_t ctxsz; /* environment context size */
398 tvec_envsetupfn *setup; /* setup for group */
399 tvec_envsetfn *set; /* set variable */
400 tvec_envbeforefn *before; /* prepare for test */
401 tvec_envrunfn *run; /* run test function */
402 tvec_envafterfn *after; /* clean up after test */
403 tvec_envteardownfn *teardown; /* tear down after group */
407 /* A test description. */
409 const char *name; /* name of the test */
410 const struct tvec_regdef *regs; /* descriptions of the registers */
411 const struct tvec_env *env; /* environment to run test in */
412 tvec_testfn *fn; /* test function */
414 #define TVEC_ENDTESTS { 0, 0, 0, 0 }
417 /* Register output dispositions. */
419 TVRD_INPUT, /* input-only register */
420 TVRD_OUTPUT, /* output-only (input is dead) */
421 TVRD_MATCH, /* matching (equal) registers */
422 TVRD_FOUND, /* mismatching output register */
423 TVRD_EXPECT, /* mismatching input register */
424 TVRD_LIMIT /* (number of dispositions) */
427 /*----- Test state --------------------------------------------------------*/
430 /* Possible test outcomes. */
432 TVOUT_LOSE, /* test failed */
433 TVOUT_SKIP, /* test skipped */
434 TVOUT_WIN, /* test passed */
435 TVOUT_XFAIL, /* test passed, but shouldn't have */
436 TVOUT_LIMIT /* (number of possible outcomes) */
440 /* The primary state structure for the test vector machinery. */
442 unsigned f; /* flags */
443 #define TVSF_SKIP 0x0001u /* skip this test group */
444 #define TVSF_OPEN 0x0002u /* test is open */
445 #define TVSF_ACTIVE 0x0004u /* test is active */
446 #define TVSF_ERROR 0x0008u /* an error occurred */
447 #define TVSF_OUTMASK 0x00f0u /* test outcome (@TVOUT_...@) */
448 #define TVSF_OUTSHIFT 4 /* shift applied to outcome */
449 #define TVSF_XFAIL 0x0100u /* test expected to fail */
450 #define TVSF_MUFFLE 0x0200u /* muffle errors */
452 /* Registers. Available to execution environments. */
453 unsigned nrout, nreg; /* number of output/total registers */
454 size_t regsz; /* size of register entry */
455 struct tvec_reg *in, *out; /* register vectors */
457 /* Test groups state. Available to output formatters. */
458 const struct tvec_test *tests, *test; /* all tests and current test */
460 /* Test scoreboard. Available to output formatters. */
461 unsigned curr[TVOUT_LIMIT], all[TVOUT_LIMIT], grps[TVOUT_LIMIT];
463 /* Output machinery. */
464 struct tvec_output *output; /* output formatter */
466 /* Input machinery. Available to type parsers. */
467 const char *infile; unsigned lno, test_lno; /* input file name, line */
468 FILE *fp; /* input file stream */
471 /* @TVEC_REG(tv, vec, i)@
473 * If @tv@ is a pointer to a @struct tvec_state@, @vec@ is either @in@ or
474 * @out@, and @i@ is an integer, then this evaluates to the address of the
475 * @i@th register in the selected vector.
477 #define TVEC_REG(tv, vec, i) TVEC_GREG((tv)->vec, (i), (tv)->regsz)
480 /* An overall test configuration. */
482 const struct tvec_test *tests; /* the tests to be performed */
483 unsigned nrout, nreg; /* number of output/total regs */
484 size_t regsz; /* size of a register */
487 /*----- Output formatting -------------------------------------------------*/
490 /* An output formatter. */
491 const struct tvec_outops *ops; /* pointer to operations */
494 /* Benchmarking details. */
496 TVBU_OP, /* counting operations of some kind */
497 TVBU_BYTE, /* counting bytes (@rbuf >= 0@) */
498 TVBU_LIMIT /* (number of units) */
500 struct bench_timing; /* forward declaration */
503 /* Output operations. */
505 void (*bsession)(struct tvec_output */*o*/, struct tvec_state */*tv*/);
506 /* Begin a test session. The output driver will probably want to
507 * save @tv@, because this isn't provided to any other methods.
510 int (*esession)(struct tvec_output */*o*/);
511 /* End a session, and return the suggested exit code. */
513 void (*bgroup)(struct tvec_output */*o*/);
514 /* Begin a test group. The test group description is @tv->test@. */
516 void (*skipgroup)(struct tvec_output */*o*/,
517 const char */*excuse*/, va_list */*ap*/);
518 /* The group is being skipped; @excuse@ may be null or a format
519 * string explaining why. The @egroup@ method will not be called
523 void (*egroup)(struct tvec_output */*o*/);
524 /* End a test group. At least one test was attempted or @skipgroup@
525 * would have been called instead. If @tv->curr[TVOUT_LOSE]@ is nonzero
526 * then the test group as a whole failed; otherwise it passed.
529 void (*btest)(struct tvec_output */*o*/);
530 /* Begin a test case. */
532 void (*skip)(struct tvec_output */*o*/,
533 const char */*excuse*/, va_list */*ap*/);
534 /* The test case is being skipped; @excuse@ may be null or a format
535 * string explaining why. The @etest@ function will still be called (so
536 * this works differently from @skipgroup@ and @egroup@). A test case
537 * can be skipped at most once, and, if skipped, it cannot fail.
540 void (*fail)(struct tvec_output */*o*/,
541 const char */*detail*/, va_list */*ap*/);
542 /* The test case failed.
544 * The output driver should preferably report the filename (@infile@) and
545 * line number (@test_lno@, not @lno@) for the failing test.
547 * The @detail@ may be null or a format string describing detail about
548 * how the failing test was run which can't be determined from the
549 * registers; a @detail@ is usually provided when (and only when) the
550 * test environment potentially invokes the test function more than once.
552 * A single test case can fail multiple times!
555 void (*dumpreg)(struct tvec_output */*o*/,
556 unsigned /*disp*/, const union tvec_regval */*rv*/,
557 const struct tvec_regdef */*rd*/);
558 /* Dump a register. The `disposition' @disp@ explains what condition the
559 * register is in; see @tvec_dumpreg@ and the @TVRD_...@ codes. The
560 * register value is at @rv@, and its definition, including its type, at
561 * @rd@. Note that this function may be called on virtual registers
562 * which aren't in either of the register vectors or mentioned by the
563 * test description. It may also be called with @rv@ null, indicating
564 * that the register is not live.
567 void (*etest)(struct tvec_output */*o*/, unsigned /*outcome*/);
568 /* The test case concluded with the given @outcome@ (one of the
572 void (*bbench)(struct tvec_output */*o*/,
573 const char */*ident*/, unsigned /*unit*/);
574 /* Begin a benchmark. The @ident@ is a formatted string identifying the
575 * benchmark based on the values of the input registered marked
576 * @TVRF_ID@; the output driver is free to use this or come up with its
577 * own way to identify the test, e.g., by inspecting the register values
578 * for itself. The @unit@ is one of the @TVBU_...@ constants explaining
579 * what sort of thing is being measured.
582 void (*ebench)(struct tvec_output */*o*/,
583 const char */*ident*/, unsigned /*unit*/,
584 const struct bench_timing */*tm*/);
585 /* End a benchmark. The @ident@ and @unit@ arguments are as for
586 * @bbench@. If @tm@ is zero then the measurement failed; otherwise
587 * @tm->n@ counts total number of things (operations or bytes, as
588 * indicated by @unit@) processed in the indicated time.
591 void (*report)(struct tvec_output */*o*/, unsigned /*level*/,
592 const char */*msg*/, va_list */*ap*/);
593 /* Report a message. The driver should ideally report the filename
594 * (@infile@) and line number (@lno@) prompting the error.
597 void (*destroy)(struct tvec_output */*o*/);
598 /* Release any resources acquired by the driver. */
601 #define TVEC_LEVELS(_) \
602 _(NOTE, "notice", 4) \
606 #define TVEC_DEFLEVEL(tag, name, val) TVLEV_##tag = val,
607 TVEC_LEVELS(TVEC_DEFLEVEL)
612 /*----- Session lifecycle -------------------------------------------------*/
614 /* --- @tvec_begin@ --- *
616 * Arguments: @struct tvec_state *tv_out@ = state structure to fill in
617 * @const struct tvec_config *config@ = test configuration
618 * @struct tvec_output *o@ = output driver
622 * Use: Initialize a state structure ready to do some testing.
625 extern void tvec_begin(struct tvec_state */*tv_out*/,
626 const struct tvec_config */*config*/,
627 struct tvec_output */*o*/);
629 /* --- @tvec_end@ --- *
631 * Arguments: @struct tvec_state *tv@ = test-vector state
633 * Returns: A proposed exit code.
635 * Use: Conclude testing and suggests an exit code to be returned to
636 * the calling program. (The exit code comes from the output
637 * driver's @esession@ method.)
640 extern int tvec_end(struct tvec_state */*tv*/);
642 /* --- @tvec_read@ --- *
644 * Arguments: @struct tvec_state *tv@ = test-vector state
645 * @const char *infile@ = the name of the input file
646 * @FILE *fp@ = stream to read from
648 * Returns: Zero on success, %$-1$% on error.
650 * Use: Read test vector data from @fp@ and exercise test functions.
651 * THe return code doesn't indicate test failures: it's only
652 * concerned with whether there were problems with the input
653 * file or with actually running the tests.
656 extern int tvec_read(struct tvec_state */*tv*/,
657 const char */*infile*/, FILE */*fp*/);
659 /*----- Command-line interface --------------------------------------------*/
661 extern const struct tvec_config tvec_adhocconfig;
662 /* A special @struct tvec_config@ to use for programs which perform ad-hoc
666 /* --- @tvec_parseargs@ --- *
668 * Arguments: @int argc@ = number of command-line arguments
669 * @char *argv[]@ = vector of argument strings
670 * @struct tvec_state *tv_out@ = test vector state to initialize
671 * @int *argpos_out@ = where to leave unread argument index
672 * @const struct tvec_config *cofig@ = test vector configuration
676 * Use: Parse arguments and set up the test vector state @*tv_out@.
677 * If errors occur, print messages to standard error and exit
681 extern void tvec_parseargs(int /*argc*/, char */*argv*/[],
682 struct tvec_state */*tv_out*/,
684 const struct tvec_config */*config*/);
686 /* --- @tvec_readstdin@, @tvec_readfile@, @tvec_readarg@ --- *
688 * Arguments: @struct tvec_state *tv@ = test vector state
689 * @const char *file@ = pathname of file to read
690 * @const char *arg@ = argument to interpret
692 * Returns: Zero on success, %$-1$% on error.
694 * Use: Read test vector data from stdin or a named file. The
695 * @tvec_readarg@ function reads from stdin if @arg@ is `%|-|%',
696 * and from the named file otherwise.
699 extern int tvec_readstdin(struct tvec_state */*tv*/);
700 extern int tvec_readfile(struct tvec_state */*tv*/, const char */*file*/);
701 extern int tvec_readarg(struct tvec_state */*tv*/, const char */*arg*/);
703 /* --- @tvec_readdflt@ --- *
705 * Arguments: @struct tvec_state *tv@ = test vector state
706 * @const char *dflt@ = defsault filename or null
708 * Returns: Zero on success, %$-1$% on error.
710 * Use: Reads from the default test vector data. If @file@ is null,
711 * then read from standard input, unless that's a terminal; if
712 * @file@ is not null, then read the named file, looking in the
713 * directory named by the `%|srcdir|%' environment variable if
714 * that's set, or otherwise in the current directory.
717 extern int tvec_readdflt(struct tvec_state */*tv*/, const char */*file*/);
719 /* --- @tvec_readargs@ --- *
721 * Arguments: @int argc@ = number of command-line arguments
722 * @char *argv[]@ = vector of argument strings
723 * @struct tvec_state *tv@ = test vector state
724 * @int *argpos_inout@ = current argument position (updated)
725 * @const char *dflt@ = default filename or null
727 * Returns: Zero on success, %$-1$% on error.
729 * Use: Reads from the sources indicated by the command-line
730 * arguments, in order, interpreting each as for @tvec_readarg@;
731 * if no arguments are given then read from @dflt@ as for
735 extern int tvec_readargs(int /*argc*/, char */*argv*/[],
736 struct tvec_state */*tv*/,
737 int */*argpos_inout*/, const char */*dflt*/);
739 /* --- @tvec_main@ --- *
741 * Arguments: @int argc@ = number of command-line arguments
742 * @char *argv[]@ = vector of argument strings
743 * @const struct tvec_config *cofig@ = test vector configuration
744 * @const char *dflt@ = default filename or null
746 * Returns: Exit code.
748 * Use: All-in-one test vector front-end. Parse options from the
749 * command-line as for @tvec_parseargs@, and then process the
750 * remaining positional arguments as for @tvec_readargs@. The
751 * function constructs and disposes of a test vector state.
754 extern int tvec_main(int /*argc*/, char */*argv*/[],
755 const struct tvec_config */*config*/,
756 const char */*dflt*/);
758 /*----- Test processing ---------------------------------------------------*/
760 /* --- @tvec_skipgroup@, @tvec_skipgroup_v@ --- *
762 * Arguments: @struct tvec_state *tv@ = test-vector state
763 * @const char *excuse@, @va_list *ap@ = reason why skipped
767 * Use: Skip the current group. This should only be called from a
768 * test environment @setup@ function; a similar effect occurs if
769 * the @setup@ function fails.
772 extern PRINTF_LIKE(2, 3)
773 void tvec_skipgroup(struct tvec_state */*tv*/,
774 const char */*excuse*/, ...);
775 extern void tvec_skipgroup_v(struct tvec_state */*tv*/,
776 const char */*excuse*/, va_list */*ap*/);
778 /* --- @tvec_skip@, @tvec_skip_v@ --- *
780 * Arguments: @struct tvec_state *tv@ = test-vector state
781 * @const char *excuse@, @va_list *ap@ = reason why test skipped
785 * Use: Skip the current test. This should only be called from a
786 * test environment @run@ function; a similar effect occurs if
787 * the @before@ function fails.
790 extern PRINTF_LIKE(2, 3)
791 void tvec_skip(struct tvec_state */*tv*/, const char */*excuse*/, ...);
792 extern void tvec_skip_v(struct tvec_state */*tv*/,
793 const char */*excuse*/, va_list */*ap*/);
795 /* --- @tvec_fail@, @tvec_fail_v@ --- *
797 * Arguments: @struct tvec_state *tv@ = test-vector state
798 * @const char *detail@, @va_list *ap@ = description of test
802 * Use: Report the current test as a failure. This function can be
803 * called multiple times for a single test, e.g., if the test
804 * environment's @run@ function invokes the test function
805 * repeatedly; but a single test that fails repeatedly still
806 * only counts as a single failure in the statistics. The
807 * @detail@ string and its format parameters can be used to
808 * distinguish which of several invocations failed; it can
809 * safely be left null if the test function is run only once.
812 extern PRINTF_LIKE(2, 3)
813 void tvec_fail(struct tvec_state */*tv*/, const char */*detail*/, ...);
814 extern void tvec_fail_v(struct tvec_state */*tv*/,
815 const char */*detail*/, va_list */*ap*/);
817 /* --- @tvec_dumpreg@ --- *
819 * Arguments: @struct tvec_state *tv@ = test-vector state
820 * @unsigned disp@ = the register disposition (@TVRD_...@)
821 * @const union tvec_regval *tv@ = register value, or null
822 * @const struct tvec_regdef *rd@ = register definition
826 * Use: Dump a register value to the output. This is the lowest-
827 * level function for dumping registers, and calls the output
828 * formatter directly.
830 * Usually @tvec_mismatch@ is much more convenient. Low-level
831 * access is required for reporting `virtual' registers
832 * corresponding to test environment settings.
835 extern void tvec_dumpreg(struct tvec_state */*tv*/,
836 unsigned /*disp*/, const union tvec_regval */*rv*/,
837 const struct tvec_regdef */*rd*/);
839 /* --- @tvec_initregs@, @tvec_releaseregs@ --- *
841 * Arguments: @struct tvec_state *tv@ = test-vector state
845 * Use: Initialize or release, respectively, the registers required
846 * by the current test. All of the registers, both input and
847 * output, are effected. Initialized registers are not marked
851 extern void tvec_initregs(struct tvec_state */*tv*/);
852 extern void tvec_releaseregs(struct tvec_state */*tv*/);
854 /* --- @tvec_resetoutputs@ --- *
856 * Arguments: @struct tvec_state *tv@ = test-vector state
860 * Use: Reset (releases and reinitializes) the output registers in
861 * the test state. This is mostly of use to test environment
862 * @run@ functions, between invocations of the test function.
863 * Output registers are marked live if and only if the
864 * corresponding input register is live.
867 extern void tvec_resetoutputs(struct tvec_state */*tv*/);
869 /* --- @tvec_checkregs@ --- *
871 * Arguments: @struct tvec_state *tv@ = test-vector state
873 * Returns: Zero on success, %$-1$% on mismatch.
875 * Use: Compare the active output registers (according to the current
876 * test group definition) with the corresponding input register
877 * values. A mismatch occurs if the two values differ
878 * (according to the register type's @eq@ method), or if the
879 * input is live but the output is dead.
881 * This function only checks for a mismatch and returns the
882 * result; it takes no other action. In particular, it doesn't
883 * report a failure, or dump register values.
886 extern int tvec_checkregs(struct tvec_state */*tv*/);
888 /* --- @tvec_mismatch@ --- *
890 * Arguments: @struct tvec_state *tv@ = test-vector state
891 * @unsigned f@ = flags (@TVMF_...@)
895 * Use: Dumps registers suitably to report a mismatch. The flag bits
896 * @TVMF_IN@ and @TVF_OUT@ select input-only and output
897 * registers. If both are reset then nothing happens.
898 * Suppressing the output registers may be useful, e.g., if the
899 * test function crashed rather than returning outputs.
904 extern void tvec_mismatch(struct tvec_state */*tv*/, unsigned /*f*/);
906 /* --- @tvec_check@, @tvec_check_v@ --- *
908 * Arguments: @struct tvec_state *tv@ = test-vector state
909 * @const char *detail@, @va_list *ap@ = description of test
913 * Use: Check the register values, reporting a failure and dumping
914 * the registers in the event of a mismatch. This just wraps up
915 * @tvec_checkregs@, @tvec_fail@ and @tvec_mismatch@ in the
919 extern PRINTF_LIKE(2, 3)
920 void tvec_check(struct tvec_state */*tv*/, const char */*detail*/, ...);
921 extern void tvec_check_v(struct tvec_state */*tv*/,
922 const char */*detail*/, va_list */*ap*/);
924 /*----- Ad-hoc testing ----------------------------------------------------*/
926 /* --- @tvec_adhoc@ --- *
928 * Arguments: @struct tvec_state *tv@ = test-vector state
929 * @struct tvec_test *t@ = space for a test definition
933 * Use: Begin ad-hoc testing, i.e., without reading a file of
936 * The structure at @t@ will be used to record information about
937 * the tests underway, which would normally come from a static
938 * test definition. The other functions in this section assume
939 * that @tvec_adhoc@ has been called.
942 extern void tvec_adhoc(struct tvec_state */*tv*/, struct tvec_test */*t*/);
944 /* --- @tvec_begingroup@, @TVEC_BEGINGROUP@ --- *
946 * Arguments: @struct tvec_state *tv@ = test-vector state
947 * @const char *name@ = name for this test group
948 * @const char *file@, @unsigned @lno@ = calling file and line
952 * Use: Begin an ad-hoc test group with the given name. The @file@
953 * and @lno@ can be anything, but it's usually best if they
954 * refer to the source code performing the test: the macro
955 * @TVEC_BEGINGROUP@ does this automatically.
958 extern void tvec_begingroup(struct tvec_state */*tv*/, const char */*name*/,
959 const char */*file*/, unsigned /*lno*/);
960 #define TVEC_BEGINGROUP(tv, name) \
961 do tvec_begingroup(tv, name, __FILE__, __LINE__); while (0)
963 /* --- @tvec_endgroup@ --- *
965 * Arguments: @struct tvec_state *tv@ = test-vector state
969 * Use: End an ad-hoc test group. The statistics are updated and the
970 * outcome is reported to the output formatter.
973 extern void tvec_endgroup(struct tvec_state */*tv*/);
975 /* --- @TVEC_TESTGROUP@, @TVEC_TESTGROUP_TAG@ --- *
977 * Arguments: @tag@ = label-disambiguation tag
978 * @const struct tvec_state *tv = test-vector state
979 * @const char *name@ = test-group name
983 * Use: Control-structure macro: @TVEC_TESTGROUP(tv, name) stmt@
984 * establishes a test group with the given @name@ (attributing
985 * it to the source file and lie number), executes @stmt@, and
986 * ends the test group. If @stmt@ invokes @break@ then the test
987 * group is skipped. @TVEC_TESTGROUP_TAG@ is the same, with an
988 * additional @tag@ argument for use in higher-level macros.
991 #define TVEC_TESTGROUP_TAG(tag, tv, name) \
992 MC_WRAP(tag##__around, \
993 { TVEC_BEGINGROUP(tv, name); }, \
994 { tvec_endgroup(tv); }, \
995 { if (!((tv)->f&TVSF_SKIP)) tvec_skipgroup(tv, 0); \
996 tvec_endgroup(tv); })
997 #define TVEC_TESTGROUP(tv, name) TVEC_TESTGROUP_TAG(grp, tv, name)
999 /* --- @tvec_begintest@, @TVEC_BEGINTEST@ --- *
1001 * Arguments: @struct tvec_state *tv@ = test-vector state
1002 * @const char *file@, @unsigned @lno@ = calling file and line
1006 * Use: Begin an ad-hoc test case. The @file@ and @lno@ can be
1007 * anything, but it's usually best if they refer to the source
1008 * code performing the test: the macro @TVEC_BEGINGROUP@ does
1009 * this automatically.
1012 extern void tvec_begintest(struct tvec_state */*tv*/,
1013 const char */*file*/, unsigned /*lno*/);
1014 #define TVEC_BEGINTEST(tv) \
1015 do tvec_begintest(tv, __FILE__, __LINE__); while (0)
1017 /* --- @tvec_endtest@ --- *
1019 * Arguments: @struct tvec_state *tv@ = test-vector state
1023 * Use: End an ad-hoc test case, The statistics are updated and the
1024 * outcome is reported to the output formatter.
1027 extern void tvec_endtest(struct tvec_state */*tv*/);
1029 /* --- @TVEC_TEST@, @TVEC_TEST_TAG@ --- *
1031 * Arguments: @tag@ = label-disambiguation tag
1032 * @struct tvec_test *t@ = space for a test definition
1036 * Use: Control-structure macro: @TVEC_TEST(tv) stmt@ begins a test
1037 * case, executes @stmt@, and ends the test case. If @stmt@
1038 * invokes @break@ then the test case is skipped.
1039 * @TVEC_TEST_TAG@ is the same, with an additional @tag@ argumet
1040 * for use in higher-level macros.
1043 #define TVEC_TEST_TAG(tag, tv) \
1044 MC_WRAP(tag##__around, \
1045 { TVEC_BEGINTEST(tv); }, \
1046 { tvec_endtest(tv); }, \
1047 { if ((tv)->f&TVSF_ACTIVE) tvec_skip((tv), 0); \
1048 tvec_endtest(tv); })
1049 #define TVEC_TEST(tv) TVEC_TEST_TAG(test, tv)
1051 /* --- @tvec_claim@, @tvec_claim_v@, @TVEC_CLAIM@ --- *
1053 * Arguments: @struct tvec_state *tv@ = test-vector state
1055 * @const char *file@, @unsigned @lno@ = calling file and line
1056 * @const char *msg@, @va_list *ap@ = message to report on
1059 * Returns: The value @ok@.
1061 * Use: Check that a claimed condition holds, as (part of) a test.
1062 * If no test case is underway (i.e., if @TVSF_OPEN@ is reset in
1063 * @tv->f@), then a new test case is begun and ended. The
1064 * @file@ and @lno@ are passed to the output formatter to be
1065 * reported in case of a failure. If @ok@ is nonzero, then
1066 * nothing else happens; so, in particular, if @tvec_claim@
1067 * established a new test case, then the test case succeeds. If
1068 * @ok@ is zero, then a failure is reported, quoting @msg@.
1070 * The @TVEC_CLAIM@ macro is similar, only it (a) identifies the
1071 * file and line number of the call site automatically, and (b)
1072 * implicitly quotes the source text of the @ok@ condition in
1073 * the failure message.
1076 extern PRINTF_LIKE(5, 6)
1077 int tvec_claim(struct tvec_state */*tv*/, int /*ok*/,
1078 const char */*file*/, unsigned /*lno*/,
1079 const char */*msg*/, ...);
1080 extern int tvec_claim_v(struct tvec_state */*tv*/, int /*ok*/,
1081 const char */*file*/, unsigned /*lno*/,
1082 const char */*msg*/, va_list */*ap*/);
1083 #define TVEC_CLAIM(tv, cond) \
1084 (tvec_claim(tv, !!(cond), __FILE__, __LINE__, "%s untrue", #cond))
1086 /* --- @tvec_claimeq@ --- *
1088 * Arguments: @struct tvec_state *tv@ = test-vector state
1089 * @const struct tvec_regty *ty@ = register type
1090 * @const union tvec_misc *arg@ = register type argument
1091 * @const char *file@, @unsigned @lno@ = calling file and line
1092 * @const char *expr@ = the expression to quote on failure
1094 * Returns: Nonzero if the input and output values of register 0 are
1095 * equal, zero if they differ.
1097 * Use: Check that the input and output values of register 0 are
1098 * equal (according to the register type @ty@). As for
1099 * @tvec_claim@ above, a test case is automatically begun and
1100 * ended if none is already underway. If the values are
1101 * unequal, then @tvec_fail@ is called, quoting @expr@, and the
1102 * mismatched values are dumped.
1104 * This function is not expected to be called directly, but
1105 * through type-specific wrapper functions or macros such as
1106 * @TVEC_CLAIMEQ_INT@.
1109 extern int tvec_claimeq(struct tvec_state */*tv*/,
1110 const struct tvec_regty */*ty*/,
1111 const union tvec_misc */*arg*/,
1112 const char */*file*/, unsigned /*lno*/,
1113 const char */*expr*/);
1115 /*----- Benchmarking ------------------------------------------------------*/
1117 struct tvec_benchenv {
1118 struct tvec_env _env; /* benchmarking is an environment */
1119 struct bench_state **bst; /* benchmark state anchor or null */
1120 unsigned long niter; /* iterations done per unit */
1121 int riter, rbuf; /* iterations and buffer registers */
1122 const struct tvec_env *env; /* subordinate environment */
1125 struct tvec_benchctx {
1126 const struct tvec_benchenv *be; /* environment configuration */
1127 struct bench_state *bst; /* benchmark state */
1128 double dflt_target; /* default time in seconds */
1129 unsigned f; /* flags */
1130 #define TVBF_SETTRG 1u /* set `@target' */
1131 #define TVBF_SETMASK (TVBF_SETTRG)) /* mask of @TVBF_SET...@ */
1132 void *subctx; /* subsidiary environment context */
1135 extern struct bench_state *tvec_benchstate;
1137 /* --- Environment implementation --- *
1139 * The following special variables are supported.
1141 * * %|@target|% is the (approximate) number of seconds to run the
1144 * Unrecognized variables are passed to the subordinate environment, if there
1145 * is one. Other events are passed through to the subsidiary environment.
1148 extern tvec_envsetupfn tvec_benchsetup;
1149 extern tvec_envsetfn tvec_benchset;
1150 extern tvec_envbeforefn tvec_benchbefore;
1151 extern tvec_envrunfn tvec_benchrun;
1152 extern tvec_envafterfn tvec_benchafter;
1153 extern tvec_envteardownfn tvec_benchteardown;
1155 #define TVEC_BENCHENV \
1156 { sizeof(struct tvec_benchctx), \
1162 tvec_benchteardown }
1163 #define TVEC_BENCHINIT TVEC_BENCHENV, &tvec_benchstate
1165 /* --- @tvec_benchreport@ --- *
1167 * Arguments: @const struct gprintf_ops *gops@ = print operations
1168 * @void *go@ = print destination
1169 * @unsigned unit@ = the unit being measured (~TVBU_...@)
1170 * @const struct bench_timing *tm@ = the benchmark result
1174 * Use: Formats a report about the benchmark performance. This
1175 * function is intended to be called on by an output
1176 * @ebench@ function.
1179 extern void tvec_benchreport
1180 (const struct gprintf_ops */*gops*/, void */*go*/,
1181 unsigned /*unit*/, const struct bench_timing */*tm*/);
1183 /*----- Remote execution --------------------------------------------------*/
1185 struct tvec_remotecomms {
1186 int infd, outfd; /* input and output descriptors */
1187 dbuf bout; /* output buffer */
1188 unsigned char *bin; /* input buffer */
1189 size_t binoff, binlen, binsz; /* input offset, length, and size */
1190 size_t t; /* temporary offset */
1191 unsigned f; /* flags */
1192 #define TVRF_BROKEN 0x0001u /* communications have failed */
1194 #define TVEC_REMOTECOMMS_INIT { -1, -1, DBUF_INIT, 0, 0, 0, 0, 0, 0 }
1196 struct tvec_remotectx {
1197 struct tvec_state *tv; /* test vector state */
1198 struct tvec_remotecomms rc; /* communication state */
1199 const struct tvec_remoteenv *re; /* environment configuration */
1200 unsigned ver; /* protocol version */
1201 pid_t kid; /* child process id */
1202 int errfd; /* child stderr descriptor */
1203 lbuf errbuf; /* child stderr line buffer */
1204 dstr prgwant, progress; /* progress: wanted/reported */
1205 unsigned exwant, exit; /* exit status wanted/reported */
1206 #define TVRF_RCNMASK 0x0300u /* reconnection behaviour: */
1207 #define TVRCN_SKIP 0x0000u /* skip unless connected */
1208 #define TVRCN_DEMAND 0x0100u /* connect on demand */
1209 #define TVRCN_FORCE 0x0200u /* force reconnection */
1210 #define TVRF_MUFFLE 0x0400u /* muffle child stderr */
1211 #define TVRF_SETEXIT 0x0800u /* set `@exit' */
1212 #define TVRF_SETPRG 0x1000u /* set `@progress' */
1213 #define TVRF_SETRCN 0x2000u /* set `@reconnect' */
1214 #define TVRF_SETMASK (TVRF_SETEXIT | TVRF_SETPRG | TVRF_SETRCN)
1215 /* mask of @TVTF_SET...@ */
1218 typedef int tvec_connectfn(pid_t */*kid_out*/, int */*infd_out*/,
1219 int */*outfd_out*/, int */*errfd_out*/,
1220 struct tvec_state */*tv*/,
1221 const struct tvec_remoteenv */*env*/);
1223 struct tvec_remoteenv_slots {
1224 tvec_connectfn *connect; /* connection function */
1225 const struct tvec_env *env; /* subsidiary environment */
1228 struct tvec_remoteenv {
1229 struct tvec_env _env;
1230 struct tvec_remoteenv_slots r;
1233 struct tvec_remotefork_slots {
1234 const struct tvec_test *tests; /* child tests (or null) */
1237 struct tvec_remotefork {
1238 struct tvec_env _env;
1239 struct tvec_remoteenv_slots r;
1240 struct tvec_remotefork_slots f;
1243 struct tvec_remoteexec_slots {
1244 const char *const *args; /* command line to execute */
1247 struct tvec_remoteexec {
1248 struct tvec_env _env;
1249 struct tvec_remoteenv_slots r;
1250 struct tvec_remoteexec_slots x;
1253 union tvec_remoteenv_subclass_kludge {
1254 struct tvec_env _env;
1255 struct tvec_remoteenv renv;
1256 struct tvec_remotefork fork;
1257 struct tvec_remoteexec exec;
1260 extern tvec_envsetupfn tvec_remotesetup;
1261 extern tvec_envsetfn tvec_remoteset;
1262 extern tvec_envrunfn tvec_remoterun;
1263 extern tvec_envafterfn tvec_remoteafter;
1264 extern tvec_envteardownfn tvec_remoteteardown;
1265 #define TVEC_REMOTEENV \
1266 { sizeof(struct tvec_remotectx), \
1272 tvec_remoteteardown }
1274 extern PRINTF_LIKE(1, 2) int tvec_setprogress(const char */*status*/, ...);
1275 extern int tvec_setprogress_v(const char */*status*/, va_list */*ap*/);
1277 extern int tvec_remoteserver(int /*infd*/, int /*outfd*/,
1278 const struct tvec_config */*config*/);
1280 extern tvec_connectfn tvec_fork, tvec_exec;
1282 #define TVEC_REMOTEFORK(subenv, tests) \
1283 TVEC_REMOTEENV, { tvec_fork, subenv }, { tests }
1285 #define TVEC_REMOTEEXEC(subenv, args) \
1286 TVEC_REMOTEENV, { tvec_exec, subenv }, { args }
1288 /*----- Timeouts ----------------------------------------------------------*/
1290 struct tvec_timeoutenv {
1291 struct tvec_env _env;
1294 const struct tvec_env *env;
1297 struct tvec_timeoutctx {
1298 const struct tvec_timeoutenv *te;
1301 unsigned f; /* flags */
1302 #define TVTF_SETTMO 1u /* set `@timeout' */
1303 #define TVTF_SETMASK (TVTF_SETTMO) /* mask of @TVTF_SET...@ */
1307 extern tvec_envsetupfn tvec_timeoutsetup;
1308 extern tvec_envsetfn tvec_timeoutset;
1309 extern tvec_envbeforefn tvec_timeoutbefore;
1310 extern tvec_envrunfn tvec_timeoutrun;
1311 extern tvec_envafterfn tvec_timeoutafter;
1312 extern tvec_envteardownfn tvec_timeoutteardown;
1313 #define TVEC_TIMEOUTENV \
1314 { sizeof(struct tvec_timeoutctx), \
1315 tvec_timeoutsetup, \
1317 tvec_timeoutbefore, \
1319 tvec_timeoutafter, \
1320 tvec_timeoutteardown }
1321 #define TVEC_TIMEOUTINIT(timer, t) TVEC_TIMEOUTENV, timer, t
1323 /*----- Output functions --------------------------------------------------*/
1325 /* --- @tvec_strlevel@ --- *
1327 * Arguments: @unsigned level@ = level code
1329 * Returns: A human-readable description.
1331 * Use: Converts a level code into something that you can print in a
1335 extern const char *tvec_strlevel(unsigned /*level*/);
1337 /* --- @tvec_report@, @tvec_report_v@ --- *
1339 * Arguments: @struct tvec_state *tv@ = test-vector state
1340 * @const char *msg@, @va_list ap@ = error message
1344 * Use: Report an message with a given severity. Messages with level
1345 * @TVLEV_ERR@ or higher force a nonzero exit code.
1348 extern PRINTF_LIKE(3, 4)
1349 void tvec_report(struct tvec_state */*tv*/, unsigned /*level*/,
1350 const char */*msg*/, ...);
1351 extern void tvec_report_v(struct tvec_state */*tv*/, unsigned /*level*/,
1352 const char */*msg*/, va_list */*ap*/);
1354 /* --- @tvec_error@, @tvec_notice@ --- *
1356 * Arguments: @struct tvec_state *tv@ = test-vector state
1357 * @const char *msg@, @va_list ap@ = error message
1359 * Returns: The @tvec_error@ function returns %$-1$% as a trivial
1360 * convenience; @tvec_notice@ does not return a value.
1362 * Use: Report an error or a notice. Errors are distinct from test
1363 * failures, and indicate that a problem was encountered which
1364 * compromised the activity of testing. Notices are important
1365 * information which doesn't fit into any other obvious
1369 extern PRINTF_LIKE(2, 3)
1370 int tvec_error(struct tvec_state */*tv*/, const char */*msg*/, ...);
1371 extern PRINTF_LIKE(2, 3)
1372 void tvec_notice(struct tvec_state */*tv*/, const char */*msg*/, ...);
1374 /* --- @tvec_humanoutput@ --- *
1376 * Arguments: @FILE *fp@ = output file to write on
1378 * Returns: An output formatter.
1380 * Use: Return an output formatter which writes on @fp@ with the
1381 * expectation that a human will be watching and interpreting
1382 * the output. If @fp@ denotes a terminal, the display shows a
1383 * `scoreboard' indicating the outcome of each test case
1384 * attempted, and may in addition use colour and other
1388 extern struct tvec_output *tvec_humanoutput(FILE */*fp*/);
1390 /* --- @tvec_tapoutput@ --- *
1392 * Arguments: @FILE *fp@ = output file to write on
1394 * Returns: An output formatter.
1396 * Use: Return an output formatter which writes on @fp@ in `TAP'
1397 * (`Test Anything Protocol') format.
1399 * TAP comes from the Perl community, but has spread rather
1400 * further. This driver produces TAP version 14, but pretends
1401 * to be version 13. The driver produces a TAP `test point' --
1402 * i.e., a result reported as `ok' or `not ok' -- for each input
1403 * test group. Failure reports and register dumps are produced
1404 * as diagnostic messages before the final group result. (TAP
1405 * permits structuerd YAML data after the test-point result,
1406 * which could be used to report details, but (a) postponing the
1407 * details until after the report is inconvenient, and (b) there
1408 * is no standardization for the YAML anyway, so in practice
1409 * it's no more useful than the unstructured diagnostics.
1412 extern struct tvec_output *tvec_tapoutput(FILE */*fp*/);
1414 /* --- @tvec_dfltoutput@ --- *
1416 * Arguments: @FILE *fp@ = output file to write on
1418 * Returns: An output formatter.
1420 * Use: Selects and instantiates an output formatter suitable for
1421 * writing on @fp@. The policy is subject to change, but
1422 * currently the `human' output format is selected if @fp@ is
1423 * interactive (i.e., if @isatty(fileno(fp))@ is true), and
1424 * otherwise the `tap' format is used.
1427 extern struct tvec_output *tvec_dfltout(FILE */*fp*/);
1429 /*------ Serialization utilities ------------------------------------------*/
1431 /* Serialization format.
1433 * The `candidate register definitions' are those entries @r@ in the @regs@
1434 * vector whose index @r.i@ is strictly less than @nr@. The `selected
1435 * register definitions' are those candidate register definitions @r@ for
1436 * which the indicated register @rv[r.i]@ has the @TVRF_LIVE@ flag set. The
1437 * serialized output begins with a header bitmap: if there are %$n$%
1438 * candidate register definitions then the header bitmap consists of %$\lceil
1439 * n/8 \rceil$% bytes. Bits are ordered starting from the least significant
1440 * bit of the first byte, end ending at the most significant bit of the final
1441 * byte. The bit corresponding to a candidate register definition is set if
1442 * and only if that register defintion is selected. The header bitmap is
1443 * then followed by the serializations of the selected registers -- i.e., for
1444 * each selected register definition @r@, the serialized value of register
1445 * @rv[r.i]@ -- simply concatenated together, with no padding or alignment.
1448 /* --- @tvec_serialize@ --- *
1450 * Arguments: @const struct tvec_reg *rv@ = vector of registers
1451 * @buf *b@ = buffer to write on
1452 * @const struct tvec_regdef *regs@ = vector of register
1453 * descriptions, terminated by an entry with a null
1455 * @unsigned nr@ = number of entries in the @rv@ vector
1456 * @size_t regsz@ = true size of each element of @rv@
1458 * Returns: Zero on success, %$-1$% on failure.
1460 * Use: Serialize a collection of register values.
1462 * The serialized output is written to the buffer @b@. Failure
1463 * can be caused by running out of buffer space, or a failing
1467 extern int tvec_serialize(const struct tvec_reg */*rv*/, buf */*b*/,
1468 const struct tvec_regdef */*regs*/,
1469 unsigned /*nr*/, size_t /*regsz*/);
1471 /* --- @tvec_deserialize@ --- *
1473 * Arguments: @struct tvec_reg *rv@ = vector of registers
1474 * @buf *b@ = buffer to write on
1475 * @const struct tvec_regdef *regs@ = vector of register
1476 * descriptions, terminated by an entry with a null
1478 * @unsigned nr@ = number of entries in the @rv@ vector
1479 * @size_t regsz@ = true size of each element of @rv@
1481 * Returns: Zero on success, %$-1$% on failure.
1483 * Use: Deserialize a collection of register values.
1485 * The size of the register vector @nr@ and the register
1486 * definitions @regs@ must match those used when producing the
1487 * serialization. For each serialized register value,
1488 * deserialize and store the value into the appropriate register
1489 * slot, and set the @TVRF_LIVE@ flag on the register. See
1490 * @tvec_serialize@ for a description of the format.
1492 * Failure results only from a failing register type handler.
1495 extern int tvec_deserialize(struct tvec_reg */*rv*/, buf */*b*/,
1496 const struct tvec_regdef */*regs*/,
1497 unsigned /*nr*/, size_t /*regsz*/);
1499 /*----- Input utilities ---------------------------------------------------*/
1501 /* These are provided by the core for the benefit of type @parse@ methods,
1502 * and test-environment @set@ functions, which get to read from the test
1503 * input file. The latter are usually best implemented by calling on the
1506 * The two main rules are as follows.
1508 * * Leave the file position at the beginning of the line following
1509 * whatever it was that you read.
1511 * * When you read and consume a newline (which you do at least once, by
1512 * the previous rule), then increment @tv->lno@ to keep track of the
1513 * current line number.
1516 /* --- @tvec_syntax@, @tvec_syntax_v@ --- *
1518 * Arguments: @struct tvec_state *tv@ = test-vector state
1519 * @int ch@ = the character found (in @fgetc@ format)
1520 * @const char *expect@, @va_list ap@ = what was expected
1524 * Use: Report a syntax error quoting @ch@ and @expect@. If @ch@ is
1525 * a newline, then back up so that it can be read again (e.g.,
1526 * by @tvec_flushtoeol@ or @tvec_nexttoken@, which will also
1527 * advance the line number).
1530 extern PRINTF_LIKE(3, 4)
1531 int tvec_syntax(struct tvec_state */*tv*/, int /*ch*/,
1532 const char */*expect*/, ...);
1533 extern int tvec_syntax_v(struct tvec_state */*tv*/, int /*ch*/,
1534 const char */*expect*/, va_list */*ap*/);
1536 /* --- @tvec_dupreg@ --- *
1538 * Arguments: @struct tvec_state *tv@ = test-vector state
1539 * @const char *name@ = register or pseudoregister name
1543 * Use: Reports an error that the register or pseudoregister has been
1544 * assigned already in the current test.
1547 extern int tvec_dupreg(struct tvec_state */*tv*/, const char */*name*/);
1549 /* --- @tvec_skipspc@ --- *
1551 * Arguments: @struct tvec_state *tv@ = test-vector state
1555 * Use: Advance over any whitespace characters other than newlines.
1556 * This will stop at `;', end-of-file, or any other kind of
1557 * non-whitespace; and it won't consume a newline.
1560 extern void tvec_skipspc(struct tvec_state */*tv*/);
1562 /* --- @tvec_flushtoeol@ --- *
1564 * Arguments: @struct tvec_state *tv@ = test-vector state
1565 * @unsigned f@ = flags (@TVFF_...@)
1567 * Returns: Zero on success, %$-1$% on error.
1569 * Use: Advance to the start of the next line, consuming the
1570 * preceding newline.
1572 * A syntax error is reported if no newline character is found,
1573 * i.e., the file ends in mid-line. A syntax error is also
1574 * reported if material other than whitespace or a comment is
1575 * found before the end of the line end, and @TVFF_ALLOWANY@ is
1576 * not set in @f@. The line number count is updated
1580 #define TVFF_ALLOWANY 1u
1581 extern int tvec_flushtoeol(struct tvec_state */*tv*/, unsigned /*f*/);
1583 /* --- @tvec_nexttoken@ --- *
1585 * Arguments: @struct tvec_state *tv@ = test-vector state
1587 * Returns: Zero if there is a next token which can be read; %$-1$% if no
1588 * token is available.
1590 * Use: Advance to the next whitespace-separated token, which may be
1593 * Tokens are separated by non-newline whitespace, comments, and
1594 * newlines followed by whitespace; a newline /not/ followed by
1595 * whitespace instead begins the next assignment, and two
1596 * newlines separated only by whitespace terminate the data for
1599 * If this function returns zero, then the next character in the
1600 * file begins a suitable token which can be read and
1601 * processed. If it returns %$-1$% then there is no such token,
1602 * and the file position is left correctly. The line number
1603 * count is updated appropriately.
1606 extern int tvec_nexttoken(struct tvec_state */*tv*/);
1608 /* --- @tvec_readword@, @tvec_readword_v@ --- *
1610 * Arguments: @struct tvec_state *tv@ = test-vector state
1611 * @dstr *d@ = string to append the word to
1612 * @const char *delims@ = additional delimiters to stop at
1613 * @const char *expect@, @va_list ap@ = what was expected
1615 * Returns: Zero on success, %$-1$% on failure.
1617 * Use: A `word' consists of characters other than whitespace, null
1618 * characters, and other than those listed in @delims@;
1619 * furthermore, a word does not begin with a `;'. (If you want
1620 * reading to stop at comments not preceded by whitespace, then
1621 * include `;' in @delims@. This is a common behaviour.)
1623 * If there is no word beginning at the current file position,
1624 * then return %$-1$%; furthermore, if @expect@ is not null,
1625 * then report an appropriate error via @tvec_syntax@.
1627 * Otherwise, the word is accumulated in @d@ and zero is
1628 * returned; if @d@ was not empty at the start of the call, the
1629 * newly read word is separated from the existing material by a
1630 * single space character. Since null bytes are never valid
1631 * word constituents, a null terminator is written to @d@, and
1632 * it is safe to treat the string in @d@ as being null-
1636 extern PRINTF_LIKE(4, 5)
1637 int tvec_readword(struct tvec_state */*tv*/, dstr */*d*/,
1638 const char */*delims*/, const char */*expect*/, ...);
1639 extern int tvec_readword_v(struct tvec_state */*tv*/, dstr */*d*/,
1640 const char */*delims*/, const char */*expect*/,
1643 /*----- Integer types: signed and unsigned --------------------------------*/
1645 /* Integers may be input in decimal, hex, binary, or octal, following
1646 * approximately usual conventions.
1648 * * Signed integers may be preceded with a `+' or `-' sign.
1650 * * Decimal integers are just a sequence of decimal digits `0' ... `9'.
1652 * * Octal integers are a sequence of digits `0' ... `7', preceded by `0o'
1655 * * Hexadecimal integers are a sequence of digits `0' ... `9', `a'
1656 * ... `f', or `A' ... `F', preceded by `0x' or `0X'.
1658 * * Radix-B integers are a sequence of digits `0' ... `9', `a' ... `f', or
1659 * `A' ... `F', each with value less than B, preceded by `Br' or `BR',
1660 * where 0 < B < 36 is expressed in decimal without any leading `0' or
1661 * internal underscores `_'.
1663 * * A digit sequence may contain internal underscore `_' separators, but
1664 * not before or after all of the digits; and two consecutive `_'
1665 * characters are not permitted.
1668 extern const struct tvec_regty tvty_int, tvty_uint;
1670 /* The @arg.p@ slot may be null or a pointer to @struct tvec_irange@ or
1671 * @struct tvec_urange@ as appropriate. The bounds are inclusive; use, e.g.,
1672 * @LONG_MAX@ explicitly if one or the other bound is logically inapplicable.
1674 struct tvec_irange { long min, max; };
1675 struct tvec_urange { unsigned long min, max; };
1677 /* Bounds corresponding to common integer types. */
1678 extern const struct tvec_irange
1679 tvrange_schar, tvrange_short, tvrange_int, tvrange_long,
1680 tvrange_sbyte, tvrange_i16, tvrange_i32;
1681 extern const struct tvec_urange
1682 tvrange_uchar, tvrange_ushort, tvrange_uint, tvrange_ulong, tvrange_size,
1683 tvrange_byte, tvrange_u16, tvrange_u32;
1685 /* --- @tvec_claimeq_int@, @TVEC_CLAIMEQ_INT@ --- *
1687 * Arguments: @struct tvec_state *tv@ = test-vector state
1688 * @long i0, i1@ = two signed integers
1689 * @const char *file@, @unsigned @lno@ = calling file and line
1690 * @const char *expr@ = the expression to quote on failure
1692 * Returns: Nonzero if @i0@ and @i1@ are equal, otherwise zero.
1694 * Use: Check that values of @i0@ and @i1@ are equal. As for
1695 * @tvec_claim@ above, a test case is automatically begun and
1696 * ended if none is already underway. If the values are
1697 * unequal, then @tvec_fail@ is called, quoting @expr@, and the
1698 * mismatched values are dumped: @i0@ is printed as the output
1699 * value and @i1@ is printed as the input reference.
1701 * The @TVEC_CLAIM_INT@ macro is similar, only it (a) identifies
1702 * the file and line number of the call site automatically, and
1703 * (b) implicitly quotes the source text of the @i0@ and @i1@
1704 * arguments in the failure message.
1707 extern int tvec_claimeq_int(struct tvec_state */*tv*/,
1708 long /*i0*/, long /*i1*/,
1709 const char */*file*/, unsigned /*lno*/,
1710 const char */*expr*/);
1711 #define TVEC_CLAIMEQ_INT(tv, i0, i1) \
1712 (tvec_claimeq_int(tv, i0, i1, __FILE__, __LINE__, #i0 " /= " #i1))
1714 /* --- @tvec_claimeq_uint@, @TVEC_CLAIMEQ_UINT@ --- *
1716 * Arguments: @struct tvec_state *tv@ = test-vector state
1717 * @unsigned long u0, u1@ = two unsigned integers
1718 * @const char *file@, @unsigned @lno@ = calling file and line
1719 * @const char *expr@ = the expression to quote on failure
1721 * Returns: Nonzero if @u0@ and @u1@ are equal, otherwise zero.
1723 * Use: Check that values of @u0@ and @u1@ are equal. As for
1724 * @tvec_claim@ above, a test case is automatically begun and
1725 * ended if none is already underway. If the values are
1726 * unequal, then @tvec_fail@ is called, quoting @expr@, and the
1727 * mismatched values are dumped: @u0@ is printed as the output
1728 * value and @u1@ is printed as the input reference.
1730 * The @TVEC_CLAIM_UINT@ macro is similar, only it (a)
1731 * identifies the file and line number of the call site
1732 * automatically, and (b) implicitly quotes the source text of
1733 * the @u0@ and @u1@ arguments in the failure message.
1736 extern int tvec_claimeq_uint(struct tvec_state */*tv*/,
1737 unsigned long /*u0*/, unsigned long /*u1*/,
1738 const char */*file*/, unsigned /*lno*/,
1739 const char */*expr*/);
1740 #define TVEC_CLAIMEQ_UINT(tv, u0, u1) \
1741 (tvec_claimeq_uint(tv, u0, u1, __FILE__, __LINE__, #u0 " /= " #u1))
1743 /*----- Floating-point type -----------------------------------------------*/
1745 /* Floating-point are either NaN (`#nan', if supported by the platform);
1746 * positive or negative infinity (`#inf', `+#inf', or, preferred, `#+inf',
1747 * and `-#inf' or, preferred, `#-inf', if supported by the platform), or a
1748 * number in strtod(3) syntax.
1750 * The comparison rules for floating-point numbers are complex: see
1751 * @tvec_claimeqish_float@ for details.
1754 extern const struct tvec_regty tvty_float;
1756 struct tvec_floatinfo {
1757 /* Details about acceptable floating-point values. */
1759 unsigned f; /* flags (@TVFF_...@ bits) */
1760 #define TVFF_NOMIN 1u /* ignore @min@ (allow -inf) */
1761 #define TVFF_NOMAX 2u /* ignore @max@ (allow +inf) */
1762 #define TVFF_NANOK 4u /* permit NaN */
1763 #define TVFF_EQMASK 0xf0 /* how to compare */
1764 #define TVFF_EXACT 0x00 /* must equal exactly */
1765 #define TVFF_ABSDELTA 0x10 /* must be within @delta@ */
1766 #define TVFF_RELDELTA 0x20 /* diff < @delta@ fraction */
1767 double min, max; /* smallest/largest value allowed */
1768 double delta; /* maximum tolerable difference */
1771 /* --- @tvec_claimeqish_float@, @TVEC_CLAIMEQISH_FLOAT@ --- *
1773 * Arguments: @struct tvec_state *tv@ = test-vector state
1774 * @double f0, f1@ = two floating-point numbers
1775 * @unsigned f@ = flags (@TVFF_...@)
1776 * @double delta@ = maximum tolerable difference
1777 * @const char *file@, @unsigned @lno@ = calling file and line
1778 * @const char *expr@ = the expression to quote on failure
1780 * Returns: Nonzero if @f0@ and @u1@ are sufficiently close, otherwise
1783 * Use: Check that values of @f0@ and @f1@ are sufficiently close.
1784 * As for @tvec_claim@ above, a test case is automatically begun
1785 * and ended if none is already underway. If the values are
1786 * too far apart, then @tvec_fail@ is called, quoting @expr@,
1787 * and the mismatched values are dumped: @f0@ is printed as the
1788 * output value and @f1@ is printed as the input reference.
1790 * The details for the comparison are as follows.
1792 * * A NaN value matches any other NaN, and nothing else.
1794 * * An infinity matches another infinity of the same sign,
1797 * * If @f&TVFF_EQMASK@ is @TVFF_EXACT@, then any
1798 * representable number matches only itself: in particular,
1799 * positive and negative zero are considered distinct.
1800 * (This allows tests to check that they land on the correct
1801 * side of branch cuts, for example.)
1803 * * If @f&TVFF_EQMASK@ is @TVFF_ABSDELTA@, then %$x$% matches
1804 * %$y$% when %$|x - y| < \delta$%.
1806 * * If @f&TVFF_EQMASK@ is @TVFF_RELDELTA@, then %$x$% matches
1807 * %$y$% when %$|1 - y/x| < \delta$%. (Note that this
1808 * criterion is asymmetric FIXME
1810 * The @TVEC_CLAIM_FLOAT@ macro is similar, only it (a)
1811 * identifies the file and line number of the call site
1812 * automatically, and (b) implicitly quotes the source text of
1813 * the @f0@ and @f1@ arguments (and @delta@) in the failure
1817 extern int tvec_claimeqish_float(struct tvec_state */*tv*/,
1818 double /*f0*/, double /*f1*/,
1819 unsigned /*f*/, double /*delta*/,
1820 const char */*file*/, unsigned /*lno*/,
1821 const char */*expr*/);
1822 #define TVEC_CLAIMEQISH_FLOAT(tv, f0, f1, f, delta) \
1823 (tvec_claimeqish_float(tv, f0, f1, f, delta, , __FILE__, __LINE__, \
1824 #f0 " /= " #f1 " (+/- " #delta ")"))
1826 /* --- @tvec_claimeq_float@, @TVEC_CLAIMEQ_FLOAT@ --- *
1828 * Arguments: @struct tvec_state *tv@ = test-vector state
1829 * @double f0, f1@ = two floating-point numbers
1830 * @const char *file@, @unsigned @lno@ = calling file and line
1831 * @const char *expr@ = the expression to quote on failure
1833 * Returns: Nonzero if @f0@ and @u1@ are identical, otherwise zero.
1835 * Use: Check that values of @f0@ and @f1@ are identical. The
1836 * function is exactly equivalent to @tvec_claimeqish_float@
1837 * with @f == TVFF_EXACT@; the macro is similarly like
1838 * @TVEC_CLAIMEQISH_FLOAT@ with @f == TVFF_EXACT@, except that
1839 * it doesn't bother to quote a delta.
1842 extern int tvec_claimeq_float(struct tvec_state */*tv*/,
1843 double /*f0*/, double /*f1*/,
1844 const char */*file*/, unsigned /*lno*/,
1845 const char */*expr*/);
1846 #define TVEC_CLAIMEQ_FLOAT(tv, f0, f1) \
1847 (tvec_claimeq_float(tv, f0, f1, __FILE__, __LINE__, #f0 " /= " #f1))
1849 extern const struct tvec_floatinfo tvflt_finite, tvflt_nonneg;
1851 /*----- Enumerated types --------------------------------------------------*/
1853 /* An enumeration describes a set of values of some underlying type, each of
1854 * which has a symbolic name. Values outside of the defined set can occur --
1855 * on output, because of bugs in the tested code, or on input to test
1856 * handling of unexpected values.
1858 * There is a distinct enumerated type for each of the branches of
1859 * @tvec_misc@. In the following, we write @t@ for the type code, which is
1860 * @i@ for signed integer, @u@ for unsigned integer, @f@ for floating-point,
1861 * and @p@ for pointer.
1863 * On input, an enumerated value may be given by name or as a literal value.
1864 * For enumerations based on numeric types, the literal values can be written
1865 * in the same syntax as the underlying values. For enumerations based on
1866 * pointers, the only permitted literal is `#nil', which denotes a null
1867 * pointer. On output, names are preferred (with the underlying value given
1871 #define DEFENUMTY(tag, ty, slot) \
1872 extern const struct tvec_regty tvty_##slot##enum;
1873 TVEC_MISCSLOTS(DEFENUMTY)
1876 /* A @struct tvec_tassoc@ associates a string tag with a value. */
1877 #define DEFASSOC(tag_, ty, slot) \
1878 struct tvec_##slot##assoc { const char *tag; ty slot; };
1879 TVEC_MISCSLOTS(DEFASSOC)
1882 #define TVEC_ENDENUM { 0, 0 }
1884 /* Information about an enumerated type. */
1885 #define DEFINFO(tag, ty, slot) \
1886 struct tvec_##slot##enuminfo { \
1887 const char *name; /* type name for diagnostics */ \
1888 const struct tvec_##slot##assoc *av; /* name/value mappings */ \
1889 EXTRA_##tag##_INFOSLOTS /* type-specific extra info */ \
1892 #define EXTRA_INT_INFOSLOTS \
1893 const struct tvec_irange *ir; /* allowed range of raw values */
1895 #define EXTRA_UINT_INFOSLOTS \
1896 const struct tvec_urange *ur; /* allowed range of raw values */
1898 #define EXTRA_FLT_INFOSLOTS \
1899 const struct tvec_floatinfo *fi; /* range and matching policy */
1901 #define EXTRA_PTR_INFOSLOTS /* (nothing) */
1903 TVEC_MISCSLOTS(DEFINFO)
1905 #undef EXTRA_INT_INFOSLOTS
1906 #undef EXTRA_UINT_INFOSLOTS
1907 #undef EXTRA_FLT_INFOSLOTS
1908 #undef EXTRA_PTR_INFOSLOTS
1912 /* Standard enumerations. */
1913 extern const struct tvec_ienuminfo tvenum_bool;
1914 extern const struct tvec_ienuminfo tvenum_cmp;
1916 /* --- @tvec_claimeq_tenum@, @TVEC_CLAIMEQ_TENUM@ --- *
1918 * Arguments: @struct tvec_state *tv@ = test-vector state
1919 * @const struct tvec_typeenuminfo *ei@ = enumeration type info
1920 * @ty t0, t1@ = two values
1921 * @const char *file@, @unsigned @lno@ = calling file and line
1922 * @const char *expr@ = the expression to quote on failure
1924 * Returns: Nonzero if @t0@ and @t1@ are equal, otherwise zero.
1926 * Use: Check that values of @t0@ and @t1@ are equal. As for
1927 * @tvec_claim@ above, a test case is automatically begun and
1928 * ended if none is already underway. If the values are
1929 * unequal, then @tvec_fail@ is called, quoting @expr@, and the
1930 * mismatched values are dumped: @t0@ is printed as the output
1931 * value and @t1@ is printed as the input reference.
1933 * The @TVEC_CLAIM_TENUM@ macro is similar, only it (a)
1934 * identifies the file and line number of the call site
1935 * automatically, and (b) implicitly quotes the source text of
1936 * the @t0@ and @t1@ arguments in the failure message.
1939 #define DECLCLAIM(tag, ty, slot) \
1940 extern int tvec_claimeq_##slot##enum \
1941 (struct tvec_state */*tv*/, \
1942 const struct tvec_##slot##enuminfo */*ei*/, \
1943 ty /*t0*/, ty /*t1*/, \
1944 const char */*file*/, unsigned /*lno*/, const char */*expr*/);
1945 TVEC_MISCSLOTS(DECLCLAIM)
1947 #define TVEC_CLAIMEQ_IENUM(tv, ei, i0, i1) \
1948 (tvec_claimeq_ienum(tv, ei, i0, i1, \
1949 __FILE__, __LINE__, #i0 " /= " #i1))
1950 #define TVEC_CLAIMEQ_UENUM(tv, ei, u0, u1) \
1951 (tvec_claimeq_uenum(tv, ei, u0, u1, \
1952 __FILE__, __LINE__, #u0 " /= " #u1))
1953 #define TVEC_CLAIMEQ_FENUM(tv, ei, f0, f1) \
1954 (tvec_claimeq_fenum(tv, ei, f0, f1, \
1955 __FILE__, __LINE__, #f0 " /= " #f1))
1956 #define TVEC_CLAIMEQ_PENUM(tv, ei, p0, p1) \
1957 (tvec_claimeq_penum(tv, ei, p0, p1, \
1958 __FILE__, __LINE__, #p0 " /= " #p1))
1960 /*----- Flags type --------------------------------------------------------*/
1962 /* A flags value packs a number of fields into a single nonnegative integer.
1963 * Symbolic names are associated with the possible values of the various
1964 * fields; more precisely, each name is associated with a value and a
1967 * The input syntax is a sequence of items separated by `|' signs. Each item
1968 * may be the symbolic name of a field value, or a literal unsigned integer.
1969 * The masks associated with the given symbolic names must be disjoint. The
1970 * resulting numerical value is simply the bitwise OR of the given values.
1972 * On output, the table of symbolic names and their associated values and
1973 * masks is repeatedly scanned, in order, to find disjoint matches -- i.e.,
1974 * entries whose value matches the target value in the bit positions
1975 * indicated by the mask, and whose mask doesn't overlap with any previously
1976 * found matches; the names are then output, separated by `|'. Any remaining
1977 * nonzero bits not covered by any of the matching masks are output as a
1978 * single literal integer, in hex.
1981 extern const struct tvec_regty tvty_flags;
1984 /* Definition of a single flag or bitfield value.
1986 * Each named setting comes with a value @v@ and a mask @m@; the mask
1987 * should cover all of the value bits, i.e., @(v&~m) == 0@.
1990 const char *tag; /* name */
1991 unsigned long m, v; /* mask and value */
1994 #define TVEC_ENDFLAGS { 0, 0, 0 }
1996 struct tvec_flaginfo {
1997 /* Information about a flags type. */
1999 const char *name; /* type name for diagnostics */
2000 const struct tvec_flag *fv; /* name/mask/value mappings */
2001 const struct tvec_urange *range; /* permitted range for literals */
2004 /* --- @tvec_claimeq_flags@, @TVEC_CLAIMEQ_FLAGS@ --- *
2006 * Arguments: @struct tvec_state *tv@ = test-vector state
2007 * @const struct tvec_flaginfo *fi@ = flags type info
2008 * @unsigned long f0, f1@ = two values
2009 * @const char *file@, @unsigned @lno@ = calling file and line
2010 * @const char *expr@ = the expression to quote on failure
2012 * Returns: Nonzero if @f0@ and @f1@ are equal, otherwise zero.
2014 * Use: Check that values of @f0@ and @f1@ are equal. As for
2015 * @tvec_claim@ above, a test case is automatically begun and
2016 * ended if none is already underway. If the values are
2017 * unequal, then @tvec_fail@ is called, quoting @expr@, and the
2018 * mismatched values are dumped: @f0@ is printed as the output
2019 * value and @f1@ is printed as the input reference.
2021 * The @TVEC_CLAIM_FLAGS@ macro is similar, only it (a)
2022 * identifies the file and line number of the call site
2023 * automatically, and (b) implicitly quotes the source text of
2024 * the @f0@ and @f1@ arguments in the failure message.
2027 extern int tvec_claimeq_flags(struct tvec_state */*tv*/,
2028 const struct tvec_flaginfo */*fi*/,
2029 unsigned long /*f0*/, unsigned long /*f1*/,
2030 const char */*file*/, unsigned /*lno*/,
2031 const char */*expr*/);
2032 #define TVEC_CLAIMEQ_FLAGS(tv, fi, f0, f1) \
2033 (tvec_claimeq_flags(tv, fi, f0, f1, \
2034 __FILE__, __LINE__, #f0 " /= " #f1))
2036 /*----- Character type ----------------------------------------------------*/
2038 /* A character value holds a character, as read by @fgetc@. The special
2039 * @EOF@ value can also be represented.
2041 * On input, a character value can be given by name, with a leading `%|#|%';
2042 * or a character or `%|\|%'-escape sequence, optionally in single quotes.
2044 * The following escape sequences and character names are recognized.
2046 * * `%|#eof|%' is the special end-of-file marker.
2048 * * `%|#nul|%' is the NUL character, sometimes used to terminate strings.
2050 * * `%|bell|%', `%|bel|%', `%|ding|%', or `%|\a|%' is the BEL character
2051 * used to ring the terminal bell (or do some other thing to attract the
2052 * user's attention).
2054 * * %|#backspace|%, %|#bs|%, or %|\b|% is the backspace character, used to
2055 * move the cursor backwords by one cell.
2057 * * %|#escape|% %|#esc|%, or%|\e|% is the escape character, used to
2058 * introduce special terminal commands.
2060 * * %|#formfeed|%, %|#ff|%, or %|\f|% is the formfeed character, used to
2061 * separate pages of text.
2063 * * %|#newline|%, %|#linefeed|%, %|#lf|%, %|#nl|%, or %|\n|% is the
2064 * newline character, used to terminate lines of text or advance the
2065 * cursor to the next line (perhaps without returning it to the start of
2068 * * %|#return|%, %|#carriage-return|%, %|#cr|%, or %|\r|% is the
2069 * carriage-return character, used to return the cursor to the start of
2072 * * %|#tab|%, %|#horizontal-tab|%, %|#ht|%, or %|\t|% is the tab
2073 * character, used to advance the cursor to the next tab stop on the
2076 * * %|#vertical-tab|%, %|#vt|%, %|\v|% is the vertical tab character.
2078 * * %|#space|%, %|#spc|% is the space character.
2080 * * %|#delete|%, %|#del|% is the delete character, used to erase the most
2083 * * %|\'|% is the single-quote character.
2085 * * %|\\|% is the backslash character.
2087 * * %|\"|% is the double-quote character.
2089 * * %|\NNN|% or %|\{NNN}|% is the character with code NNN in octal. The
2090 * NNN may be up to three digits long.
2092 * * %|\xNN|% or %|\x{NN}|% is the character with code NNN in hexadecimal.
2095 extern const struct tvec_regty tvty_char;
2097 /* --- @tvec_claimeq_char@, @TVEC_CLAIMEQ_CHAR@ --- *
2099 * Arguments: @struct tvec_state *tv@ = test-vector state
2100 * @int ch0, ch1@ = two character codes
2101 * @const char *file@, @unsigned @lno@ = calling file and line
2102 * @const char *expr@ = the expression to quote on failure
2104 * Returns: Nonzero if @ch0@ and @ch1@ are equal, otherwise zero.
2106 * Use: Check that values of @ch0@ and @ch1@ are equal. As for
2107 * @tvec_claim@ above, a test case is automatically begun and
2108 * ended if none is already underway. If the values are
2109 * unequal, then @tvec_fail@ is called, quoting @expr@, and the
2110 * mismatched values are dumped: @ch0@ is printed as the output
2111 * value and @ch1@ is printed as the input reference.
2113 * The @TVEC_CLAIM_CHAR@ macro is similar, only it (a)
2114 * identifies the file and line number of the call site
2115 * automatically, and (b) implicitly quotes the source text of
2116 * the @ch0@ and @ch1@ arguments in the failure message.
2119 extern int tvec_claimeq_char(struct tvec_state */*tv*/,
2120 int /*ch0*/, int /*ch1*/,
2121 const char */*file*/, unsigned /*lno*/,
2122 const char */*expr*/);
2123 #define TVEC_CLAIMEQ_CHAR(tv, c0, c1) \
2124 (tvec_claimeq_char(tv, c0, c1, __FILE__, __LINE__, #c0 " /= " #c1))
2126 /*----- Text and binary string types --------------------------------------*/
2128 /* A string is a sequence of octets. Text and binary strings differ
2129 * primarily in presentation: text strings are shown as raw characters where
2130 * possible; binary strings are shown as hex dumps with an auxiliary text
2133 * The input format for both kinds of strings is basically the same: a
2134 * `compound string', consisting of
2136 * * single-quoted strings, which are interpreted entirely literally, but
2137 * can't contain single quotes or newlines;
2139 * * double-quoted strings, in which `%|\|%'-escapes are interpreted as for
2142 * * character names, marked by an initial `%|#|%' sign;
2144 * * special tokens marked by an initial `%|!|%' sign; or
2146 * * barewords interpreted according to the current coding scheme.
2148 * The special tokens are
2150 * * `%|!bare|%', which causes subsequent sequences of barewords to be
2151 * treated as plain text;
2153 * * `%|!hex|%', `%|!base32|%', `%|!base64|%', which cause subsequent
2154 * barewords to be decoded in the requested manner.
2156 * * `%|!repeat|% %$n$% %|{|% %%\textit{string}%% %|}|%', which includes
2157 * %$n$% copies of the (compound) string.
2159 * Either kind of string can contain internal nul characters. A trailing nul
2160 * is appended -- beyond the stated input length -- to input strings as a
2161 * convenience to test functions. Test functions may include such a nul
2162 * character on output but this is not checked by the equality test.
2164 * A @struct tvec_urange@ may be supplied as an argument: the length of the
2165 * string (in bytes) will be checked against the permitted range.
2168 extern const struct tvec_regty tvty_string, tvty_bytes;
2170 /* --- @tvec_claimeq_string@, @TVEC_CLAIMEQ_STRING@ --- *
2172 * Arguments: @struct tvec_state *tv@ = test-vector state
2173 * @const char *p0@, @size_t sz0@ = first string with length
2174 * @const char *p1@, @size_t sz1@ = second string with length
2175 * @const char *file@, @unsigned @lno@ = calling file and line
2176 * @const char *expr@ = the expression to quote on failure
2178 * Returns: Nonzero if the strings at @p0@ and @p1@ are equal, otherwise
2181 * Use: Check that strings at @p0@ and @p1@ are equal. As for
2182 * @tvec_claim@ above, a test case is automatically begun and
2183 * ended if none is already underway. If the values are
2184 * unequal, then @tvec_fail@ is called, quoting @expr@, and the
2185 * mismatched values are dumped: @p0@ is printed as the output
2186 * value and @p1@ is printed as the input reference.
2188 * The @TVEC_CLAIM_STRING@ macro is similar, only it (a)
2189 * identifies the file and line number of the call site
2190 * automatically, and (b) implicitly quotes the source text of
2191 * the @ch0@ and @ch1@ arguments in the failure message.
2194 extern int tvec_claimeq_string(struct tvec_state */*tv*/,
2195 const char */*p0*/, size_t /*sz0*/,
2196 const char */*p1*/, size_t /*sz1*/,
2197 const char */*file*/, unsigned /*lno*/,
2198 const char */*expr*/);
2199 #define TVEC_CLAIMEQ_STRING(tv, p0, sz0, p1, sz1) \
2200 (tvec_claimeq_string(tv, p0, sz0, p1, sz1, __FILE__, __LINE__, \
2201 #p0 "[" #sz0 "] /= " #p1 "[" #sz1 "]"))
2203 /* --- @tvec_claimeq_strz@, @TVEC_CLAIMEQ_STRZ@ --- *
2205 * Arguments: @struct tvec_state *tv@ = test-vector state
2206 * @const char *p0, *p1@ = two strings to compare
2207 * @const char *file@, @unsigned @lno@ = calling file and line
2208 * @const char *expr@ = the expression to quote on failure
2210 * Returns: Nonzero if the strings at @p0@ and @p1@ are equal, otherwise
2213 * Use: Check that strings at @p0@ and @p1@ are equal, as for
2214 * @tvec_claimeq_string@, except that the strings are assumed
2215 * null-terminated, so their lengths don't need to be supplied
2216 * explicitly. The macro is similarly like
2217 * @TVEC_CLAIMEQ_STRING@.
2220 extern int tvec_claimeq_strz(struct tvec_state */*tv*/,
2221 const char */*p0*/, const char */*p1*/,
2222 const char */*file*/, unsigned /*lno*/,
2223 const char */*expr*/);
2224 #define TVEC_CLAIMEQ_STRZ(tv, p0, p1) \
2225 (tvec_claimeq_strz(tv, p0, p1, __FILE__, __LINE__, #p0 " /= " #p1))
2227 /* --- @tvec_claimeq_bytes@, @TVEC_CLAIMEQ_BYTES@ --- *
2229 * Arguments: @struct tvec_state *tv@ = test-vector state
2230 * @const void *p0@, @size_t sz0@ = first string with length
2231 * @const void *p1@, @size_t sz1@ = second string with length
2232 * @const char *file@, @unsigned @lno@ = calling file and line
2233 * @const char *expr@ = the expression to quote on failure
2235 * Returns: Nonzero if the strings at @p0@ and @p1@ are equal, otherwise
2238 * Use: Check that binary strings at @p0@ and @p1@ are equal. As for
2239 * @tvec_claim@ above, a test case is automatically begun and
2240 * ended if none is already underway. If the values are
2241 * unequal, then @tvec_fail@ is called, quoting @expr@, and the
2242 * mismatched values are dumped: @p0@ is printed as the output
2243 * value and @p1@ is printed as the input reference.
2245 * The @TVEC_CLAIM_STRING@ macro is similar, only it (a)
2246 * identifies the file and line number of the call site
2247 * automatically, and (b) implicitly quotes the source text of
2248 * the @ch0@ and @ch1@ arguments in the failure message.
2251 extern int tvec_claimeq_bytes(struct tvec_state */*tv*/,
2252 const void */*p0*/, size_t /*sz0*/,
2253 const void */*p1*/, size_t /*sz1*/,
2254 const char */*file*/, unsigned /*lno*/,
2255 const char */*expr*/);
2256 #define TVEC_CLAIMEQ_BYTES(tv, p0, sz0, p1, sz1) \
2257 (tvec_claimeq(tv, p0, sz0, p1, sz1, __FILE__, __LINE__, \
2258 #p0 "[" #sz0 "] /= " #p1 "[" #sz1 "]"))
2260 /* --- @tvec_allocstring@, @tvec_allocbytes@ --- *
2262 * Arguments: @union tvec_regval *rv@ = register value
2263 * @size_t sz@ = required size
2267 * Use: Allocated space in a text or binary string register. If the
2268 * current register size is sufficient, its buffer is left
2269 * alone; otherwise, the old buffer, if any, is freed and a
2270 * fresh buffer allocated. These functions are not intended to
2271 * be used to adjust a buffer repeatedly, e.g., while building
2272 * output incrementally: (a) they will perform badly, and (b)
2273 * the old buffer contents are simply discarded if reallocation
2274 * is necessary. Instead, use a @dbuf@ or @dstr@.
2276 * The @tvec_allocstring@ function sneakily allocates an extra
2277 * byte for a terminating zero. The @tvec_allocbytes@ function
2281 extern void tvec_allocstring(union tvec_regval */*rv*/, size_t /*sz*/);
2282 extern void tvec_allocbytes(union tvec_regval */*rv*/, size_t /*sz*/);
2284 /*----- Buffer type -------------------------------------------------------*/
2286 /* Buffer registers are primarily used for benchmarking. Only a buffer's
2287 * size is significant: its contents are ignored on comparison and output,
2288 * and unspecified on input.
2290 * The input is simply the buffer size, as an integer, optionally suffixed
2291 * with a unit `kB', `MB', `GB', `TB', `PB', `EB', `ZB', `YB' (with or
2292 * without the `B') denoting a power of 1024. Units are used on output only
2293 * when the size would be expressed exactly.
2296 extern const struct tvec_regty tvty_buffer;
2298 /*----- That's all, folks -------------------------------------------------*/