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 { char *p; size_t sz; } text; /* text string */
196 struct { unsigned char *p; size_t sz; } bytes; /* binary string of bytes */
197 struct { /* buffer */
198 unsigned char *p; size_t sz; /* binary string */
199 size_t a, m; /* residue and modulus */
200 size_t off; /* offset into full buffer */
210 * Note that all of the registers listed as being used by a particular test
211 * group are initialized at all times[1] while that test group is being
212 * processed. (The other register slots don't even have types associated
213 * with them, so there's nothing useful we could do with them.)
215 * The `TVRF_LIVE' flag indicates that the register was assigned a value by
216 * the test vector file: it's the right thing to use to check whether an
217 * optional register is actually present. Even `dead' registers are still
218 * initialized, though.
220 * [1] This isn't quite true. Between individual tests, the registers are
221 * released and reinitialized in order to reset them to known values
222 * ready for the next test. But you won't see them at this point.
225 unsigned f; /* flags */
226 #define TVRF_SEEN 1u /* assignment seen in file */
227 #define TVRF_LIVE 2u /* used in current test */
228 union tvec_regval v; /* register value */
232 /* A register definition. Register definitions list the registers which
233 * are used by a particular test group (see `struct tvec_test' below).
235 * A vector of register definitions is terminated by a definition whose
236 * `name' slot is null.
239 const char *name; /* register name (for input files) */
240 const struct tvec_regty *ty; /* register type descriptor */
241 unsigned i; /* register index */
242 unsigned f; /* flags */
243 #define TVRF_UNSET 1u /* register may be marked unset */
244 #define TVRF_OPT 2u /* register need not be assigned */
245 #define TVRF_ID 4u /* part of test identity */
246 union tvec_misc arg; /* extra detail for the type */
248 #define TVEC_ENDREGS { 0, 0, 0, 0, { 0 } }
250 /* @TVEC_GREG(vec, i, regsz)@
252 * If @vec@ is a data pointer which happens to contain the address of a
253 * vector of @struct tvec_reg@ objects, @i@ is an integer, and @regsz@ is the
254 * size of a @struct tvec_reg@, then this evaluates to the address of the
255 * @i@th element of the vector.
257 * This is the general tool you need for accessing register vectors when you
258 * don't have absolute knowledge of the size of a @union tvec_regval@.
259 * Usually you want to access one of the register vectors in a @struct
260 * tvec_state@, and @TVEC_REG@ will be more convenient.
262 #define TVEC_GREG(vec, i, regsz) \
263 ((struct tvec_reg *)((unsigned char *)(vec) + (i)*(regsz)))
265 /*----- Register types ----------------------------------------------------*/
267 struct tvec_state; /* forward declaration */
270 /* A register type. */
272 void (*init)(union tvec_regval */*rv*/, const struct tvec_regdef */*rd*/);
273 /* Initialize the value in @*rv@. This will be called before any other
274 * function acting on the value, including @release@. Following @init@,
275 * the register value must be valid to use for all other type entry
279 void (*release)(union tvec_regval */*rv*/,
280 const struct tvec_regdef */*rd*/);
281 /* Release any resources associated with the value in @*rv@. The
282 * register value may be left in an invalid state.
285 int (*eq)(const union tvec_regval */*rv0*/,
286 const union tvec_regval */*rv1*/,
287 const struct tvec_regdef */*rd*/);
288 /* Return nonzero if @*rv0@ and @*rv1@ are equal values. Asymmetric
289 * criteria are permitted: @tvec_checkregs@ calls @eq@ with the input
290 * register as @rv0@ and the output as @rv1@.
293 int (*tobuf)(buf */*b*/, const union tvec_regval */*rv*/,
294 const struct tvec_regdef */*rd*/);
295 /* Serialize the value @*rv@, writing the result to @b@. Return zero on
296 * success, or %$-1$% on error.
299 int (*frombuf)(buf */*b*/, union tvec_regval */*rv*/,
300 const struct tvec_regdef */*rd*/);
301 /* Deserialize a value from @b@, storing it in @*rv@. Return zero on
302 * success, or %$-1$% on error.
305 int (*parse)(union tvec_regval */*rv*/, const struct tvec_regdef */*rd*/,
306 struct tvec_state */*tv*/);
307 /* Parse a value from @tv->fp@, storing it in @*rv@. Return zero on
308 * success, or %$-1$% on error, having reported one or more errors via
309 * @tvec_error@ or @tvec_syntax@. A successful return should leave the
310 * input position at the start of the next line; the caller will flush
311 * the remainder of the line itself.
314 void (*dump)(const union tvec_regval */*rv*/,
315 const struct tvec_regdef */*rd*/,
317 const struct gprintf_ops */*gops*/, void */*go*/);
318 #define TVSF_COMPACT 1u
319 /* Write a human-readable representation of the value @*rv@ using
320 * @gprintf@ on @gops@ and @go@. The @style@ is a collection of flags:
321 * if @TVSF_COMPACT@ is set, then output should be minimal, and must fit
322 * on a single line; otherwise, output may consist of multiple lines and
323 * may contain redundant information if that is likely to be useful to a
328 /*----- Test descriptions -------------------------------------------------*/
332 typedef void tvec_testfn(const struct tvec_reg */*in*/,
333 struct tvec_reg */*out*/,
335 /* A test function. It should read inputs from @in@ and write outputs to
336 * @out@. The @TVRF_LIVE@ is set on inputs which are actually present, and
337 * on outputs which are wanted to test. A test function can set additional
338 * `gratuitous outputs' by setting @TVRF_LIVE@ on them; clearing
339 * @TVRF_LIVE@ on a wanted output causes a mismatch.
341 * A test function may be called zero or more times by the environment. In
342 * particular, it may be called multiple times, though usually by prior
343 * arrangement with the environment.
345 * The @ctx@ is supplied by the environment's @run@ function (see below).
346 * The default environment calls the test function once, with a null
347 * @ctx@. There is no expectation that the environment's context has
348 * anything to do with the test function's context.
351 typedef int tvec_setvarfn(struct tvec_state */*tv*/, const char */*var*/,
352 const union tvec_regval */*rv*/, void */*ctx*/);
353 /* Called after a variable is read. Return zero on success or %$-1$% on
354 * error. This function is never called if the test group is skipped.
358 size_t regsz; /* (minimum) register size */
359 tvec_setvarfn *setvar; /* function to set variable */
360 struct tvec_regdef def; /* register definition */
363 typedef void tvec_envsetupfn(struct tvec_state */*tv*/,
364 const struct tvec_env */*env*/,
365 void */*pctx*/, void */*ctx*/);
366 /* Initialize the context; called at the start of a test group; @pctx@ is
367 * null for environments called by the core, but may be non-null for
368 * subordinate environments. If setup fails, the function should call
369 * @tvec_skipgroup@ with a suitable excuse. The @set@, @after@, and
370 * @teardown@ entry points will still be called, but @before@ and @run@
374 typedef const struct tvec_vardef *tvec_envfindvarfn
375 (struct tvec_state */*tv*/, const char */*name*/,
376 void **/*ctx_out*/, void */*ctx*/);
377 /* Called when the parser finds a %|@var|%' special variable. If a
378 * suitable variable was found, set @*ctx_out@ to a suitable context and
379 * return the variable definition; the context will be passed to the
380 * variable definition's @setvar@ function. If no suitable variable was
381 * found, then return null.
384 typedef void tvec_envbeforefn(struct tvec_state */*tv*/, void */*ctx*/);
385 /* Called prior to running a test. This is the right place to act on any
386 * `%|@var|%' settings. If preparation fails, the function should call
387 * @tvec_skip@ with a suitable excuse. This function is never called if
388 * the test group is skipped. It %%\emph{is}%% called if the test will be
389 * skipped due to erroneous test data. It should check the @TVSF_ACTIVE@
393 typedef void tvec_envrunfn(struct tvec_state */*tv*/,
394 tvec_testfn */*fn*/, void */*ctx*/);
395 /* Run the test. It should either call @tvec_skip@, or run @fn@ one or
396 * more times. In the latter case, it is responsible for checking the
397 * outputs, and calling @tvec_fail@ as necessary; @tvec_checkregs@ will
398 * check the register values against the supplied test vector, while
399 * @tvec_check@ does pretty much everything necessary. This function is
400 * never called if the test group is skipped.
403 typedef void tvec_envafterfn(struct tvec_state */*tv*/, void */*ctx*/);
404 /* Called after running or skipping a test. Typical actions involve
405 * resetting whatever things were established by @set@. This function
406 * %%\emph{is}%% called if the test group is skipped or the test data is
407 * erroneous, so that the test environment can reset variables set by the
408 * @set@ entry point. It should check the @TVSF_SKIP@ flag if necessary.
411 typedef void tvec_envteardownfn(struct tvec_state */*tv*/, void */*ctx*/);
412 /* Tear down the environment: called at the end of a test group. */
416 /* A test environment sets things up for and arranges to run the test.
418 * The caller is responsible for allocating storage for the environment's
419 * context, based on the @ctxsz@ slot, and freeing it later; this space is
420 * passed in as the @ctx@ parameter to the remaining functions; if @ctxsz@
421 * is zero then @ctx@ is null.
424 size_t ctxsz; /* environment context size */
426 tvec_envsetupfn *setup; /* setup for group */
427 tvec_envfindvarfn *findvar; /* find variable */
428 tvec_envbeforefn *before; /* prepare for test */
429 tvec_envrunfn *run; /* run test function */
430 tvec_envafterfn *after; /* clean up after test */
431 tvec_envteardownfn *teardown; /* tear down after group */
435 /* A test description. */
437 const char *name; /* name of the test */
438 const struct tvec_regdef *regs; /* descriptions of the registers */
439 const struct tvec_env *env; /* environment to run test in */
440 tvec_testfn *fn; /* test function */
442 #define TVEC_ENDTESTS { 0, 0, 0, 0 }
444 /*----- Test state --------------------------------------------------------*/
447 /* Possible test outcomes. */
449 TVOUT_LOSE, /* test failed */
450 TVOUT_SKIP, /* test skipped */
451 TVOUT_WIN, /* test passed */
452 TVOUT_XFAIL, /* test passed, but shouldn't have */
453 TVOUT_LIMIT /* (number of possible outcomes) */
457 /* An overall test configuration. */
459 const struct tvec_test *tests; /* the tests to be performed */
460 unsigned nrout, nreg; /* number of output/total regs */
461 size_t regsz; /* size of a register */
465 /* The primary state structure for the test vector machinery. */
467 /* Flags. Read-only for all callers. */
468 unsigned f; /* flags */
469 #define TVSF_SKIP 0x0001u /* skip this test group */
470 #define TVSF_OPEN 0x0002u /* test is open */
471 #define TVSF_ACTIVE 0x0004u /* test is active */
472 #define TVSF_ERROR 0x0008u /* an error occurred */
473 #define TVSF_OUTMASK 0x00f0u /* test outcome (@TVOUT_...@) */
474 #define TVSF_OUTSHIFT 4 /* shift applied to outcome */
475 #define TVSF_XFAIL 0x0100u /* test expected to fail */
476 #define TVSF_MUFFLE 0x0200u /* muffle errors */
478 /* Test configuration. Read-only for all callers. */
479 struct tvec_config cfg; /* test configuration */
481 /* Registers. Available to execution environments, which may modify the
482 * contents of the active registers, as defined by the current test group,
483 * but not the vector pointers themselves or inactive registers.
485 struct tvec_reg *in, *out; /* register vectors */
487 /* Test group state. Read-only for all callers. */
488 const struct tvec_test *test; /* current test */
490 /* Test scoreboard. Available to output formatters. */
491 unsigned curr[TVOUT_LIMIT], all[TVOUT_LIMIT], grps[TVOUT_LIMIT];
493 /* Output machinery. */
494 struct tvec_output *output; /* output formatter */
496 /* Input machinery. Available to type parsers. */
497 const char *infile; unsigned lno, test_lno; /* input file name, line */
498 FILE *fp; /* input file stream */
501 /* @TVEC_REG(tv, vec, i)@
503 * If @tv@ is a pointer to a @struct tvec_state@, @vec@ is either @in@ or
504 * @out@, and @i@ is an integer, then this evaluates to the address of the
505 * @i@th register in the selected vector.
507 #define TVEC_REG(tv, vec, i) TVEC_GREG((tv)->vec, (i), (tv)->cfg.regsz)
509 /*----- Output formatting -------------------------------------------------*/
512 /* An output formatter. */
513 const struct tvec_outops *ops; /* pointer to operations */
517 /* Register output dispositions. */
519 TVRD_INPUT, /* input-only register */
520 TVRD_OUTPUT, /* output-only (input is dead) */
521 TVRD_MATCH, /* matching (equal) registers */
522 TVRD_FOUND, /* mismatching output register */
523 TVRD_EXPECT, /* mismatching input register */
524 TVRD_LIMIT /* (number of dispositions) */
527 #define TVEC_LEVELS(_) \
528 _(NOTE, "notice", 4) \
531 #define TVEC_DEFLEVEL(tag, name, val) TVLEV_##tag = val,
532 TVEC_LEVELS(TVEC_DEFLEVEL)
537 /* Benchmarking details. */
539 TVBU_OP, /* counting operations of some kind */
540 TVBU_BYTE, /* counting bytes (@rbuf >= 0@) */
541 TVBU_LIMIT /* (number of units) */
543 struct bench_timing; /* include <mLib/bench.h> for the real definition */
546 /* Output operations. */
548 void (*bsession)(struct tvec_output */*o*/, struct tvec_state */*tv*/);
549 /* Begin a test session. The output driver will probably want to
550 * save @tv@, because this isn't provided to any other methods.
553 int (*esession)(struct tvec_output */*o*/);
554 /* End a session, and return the suggested exit code. */
556 void (*bgroup)(struct tvec_output */*o*/);
557 /* Begin a test group. The test group description is @tv->test@. */
559 void (*skipgroup)(struct tvec_output */*o*/,
560 const char */*excuse*/, va_list */*ap*/);
561 /* The group is being skipped; @excuse@ may be null or a format
562 * string explaining why. The @egroup@ method will not be called
566 void (*egroup)(struct tvec_output */*o*/);
567 /* End a test group. At least one test was attempted or @skipgroup@
568 * would have been called instead. If @tv->curr[TVOUT_LOSE]@ is nonzero
569 * then the test group as a whole failed; otherwise it passed.
572 void (*btest)(struct tvec_output */*o*/);
573 /* Begin a test case. */
575 void (*skip)(struct tvec_output */*o*/,
576 const char */*excuse*/, va_list */*ap*/);
577 /* The test case is being skipped; @excuse@ may be null or a format
578 * string explaining why. The @etest@ function will still be called (so
579 * this works differently from @skipgroup@ and @egroup@). A test case
580 * can be skipped at most once, and, if skipped, it cannot fail.
583 void (*fail)(struct tvec_output */*o*/,
584 const char */*detail*/, va_list */*ap*/);
585 /* The test case failed.
587 * The output driver should preferably report the filename (@infile@) and
588 * line number (@test_lno@, not @lno@) for the failing test.
590 * The @detail@ may be null or a format string describing detail about
591 * how the failing test was run which can't be determined from the
592 * registers; a @detail@ is usually provided when (and only when) the
593 * test environment potentially invokes the test function more than once.
595 * A single test case can fail multiple times!
598 void (*dumpreg)(struct tvec_output */*o*/,
599 unsigned /*disp*/, const union tvec_regval */*rv*/,
600 const struct tvec_regdef */*rd*/);
601 /* Dump a register. The `disposition' @disp@ explains what condition the
602 * register is in; see @tvec_dumpreg@ and the @TVRD_...@ codes. The
603 * register value is at @rv@, and its definition, including its type, at
604 * @rd@. Note that this function may be called on virtual registers
605 * which aren't in either of the register vectors or mentioned by the
606 * test description. It may also be called with @rv@ null, indicating
607 * that the register is not live.
610 void (*etest)(struct tvec_output */*o*/, unsigned /*outcome*/);
611 /* The test case concluded with the given @outcome@ (one of the
615 void (*bbench)(struct tvec_output */*o*/,
616 const char */*ident*/, unsigned /*unit*/);
617 /* Begin a benchmark. The @ident@ is a formatted string identifying the
618 * benchmark based on the values of the input registered marked
619 * @TVRF_ID@; the output driver is free to use this or come up with its
620 * own way to identify the test, e.g., by inspecting the register values
621 * for itself. The @unit@ is one of the @TVBU_...@ constants explaining
622 * what sort of thing is being measured.
625 void (*ebench)(struct tvec_output */*o*/,
626 const char */*ident*/, unsigned /*unit*/,
627 const struct bench_timing */*tm*/);
628 /* End a benchmark. The @ident@ and @unit@ arguments are as for
629 * @bbench@. If @tm@ is zero then the measurement failed; otherwise
630 * @tm->n@ counts total number of things (operations or bytes, as
631 * indicated by @unit@) processed in the indicated time.
634 void (*report)(struct tvec_output */*o*/, unsigned /*level*/,
635 const char */*msg*/, va_list */*ap*/);
636 /* Report a message. The driver should ideally report the filename
637 * (@infile@) and line number (@lno@) prompting the error.
640 void (*destroy)(struct tvec_output */*o*/);
641 /* Release any resources acquired by the driver. */
644 /*----- Session lifecycle -------------------------------------------------*/
646 /* --- @tvec_begin@ --- *
648 * Arguments: @struct tvec_state *tv_out@ = state structure to fill in
649 * @const struct tvec_config *config@ = test configuration
650 * @struct tvec_output *o@ = output driver
654 * Use: Initialize a state structure ready to do some testing.
657 extern void tvec_begin(struct tvec_state */*tv_out*/,
658 const struct tvec_config */*config*/,
659 struct tvec_output */*o*/);
661 /* --- @tvec_end@ --- *
663 * Arguments: @struct tvec_state *tv@ = test-vector state
665 * Returns: A proposed exit code.
667 * Use: Conclude testing and suggests an exit code to be returned to
668 * the calling program. (The exit code comes from the output
669 * driver's @esession@ method.)
672 extern int tvec_end(struct tvec_state */*tv*/);
674 /* --- @tvec_read@ --- *
676 * Arguments: @struct tvec_state *tv@ = test-vector state
677 * @const char *infile@ = the name of the input file
678 * @FILE *fp@ = stream to read from
680 * Returns: Zero on success, %$-1$% on error.
682 * Use: Read test vector data from @fp@ and exercise test functions.
683 * THe return code doesn't indicate test failures: it's only
684 * concerned with whether there were problems with the input
685 * file or with actually running the tests.
688 extern int tvec_read(struct tvec_state */*tv*/,
689 const char */*infile*/, FILE */*fp*/);
691 /*----- Command-line interface --------------------------------------------*/
693 extern const struct tvec_config tvec_adhocconfig;
694 /* A special @struct tvec_config@ to use for programs which perform ad-hoc
698 /* --- @tvec_parseargs@ --- *
700 * Arguments: @int argc@ = number of command-line arguments
701 * @char *argv[]@ = vector of argument strings
702 * @struct tvec_state *tv_out@ = test vector state to initialize
703 * @int *argpos_out@ = where to leave unread argument index
704 * @const struct tvec_config *cofig@ = test vector configuration
708 * Use: Parse arguments and set up the test vector state @*tv_out@.
709 * If errors occur, print messages to standard error and exit
713 extern void tvec_parseargs(int /*argc*/, char */*argv*/[],
714 struct tvec_state */*tv_out*/,
716 const struct tvec_config */*config*/);
718 /* --- @tvec_readstdin@, @tvec_readfile@, @tvec_readarg@ --- *
720 * Arguments: @struct tvec_state *tv@ = test vector state
721 * @const char *file@ = pathname of file to read
722 * @const char *arg@ = argument to interpret
724 * Returns: Zero on success, %$-1$% on error.
726 * Use: Read test vector data from stdin or a named file. The
727 * @tvec_readarg@ function reads from stdin if @arg@ is `%|-|%',
728 * and from the named file otherwise.
731 extern int tvec_readstdin(struct tvec_state */*tv*/);
732 extern int tvec_readfile(struct tvec_state */*tv*/, const char */*file*/);
733 extern int tvec_readarg(struct tvec_state */*tv*/, const char */*arg*/);
735 /* --- @tvec_readdflt@ --- *
737 * Arguments: @struct tvec_state *tv@ = test vector state
738 * @const char *dflt@ = defsault filename or null
740 * Returns: Zero on success, %$-1$% on error.
742 * Use: Reads from the default test vector data. If @file@ is null,
743 * then read from standard input, unless that's a terminal; if
744 * @file@ is not null, then read the named file, looking in the
745 * directory named by the `%|srcdir|%' environment variable if
746 * that's set, or otherwise in the current directory.
749 extern int tvec_readdflt(struct tvec_state */*tv*/, const char */*file*/);
751 /* --- @tvec_readargs@ --- *
753 * Arguments: @int argc@ = number of command-line arguments
754 * @char *argv[]@ = vector of argument strings
755 * @struct tvec_state *tv@ = test vector state
756 * @int *argpos_inout@ = current argument position (updated)
757 * @const char *dflt@ = default filename or null
759 * Returns: Zero on success, %$-1$% on error.
761 * Use: Reads from the sources indicated by the command-line
762 * arguments, in order, interpreting each as for @tvec_readarg@;
763 * if no arguments are given then read from @dflt@ as for
767 extern int tvec_readargs(int /*argc*/, char */*argv*/[],
768 struct tvec_state */*tv*/,
769 int */*argpos_inout*/, const char */*dflt*/);
771 /* --- @tvec_main@ --- *
773 * Arguments: @int argc@ = number of command-line arguments
774 * @char *argv[]@ = vector of argument strings
775 * @const struct tvec_config *cofig@ = test vector configuration
776 * @const char *dflt@ = default filename or null
778 * Returns: Exit code.
780 * Use: All-in-one test vector front-end. Parse options from the
781 * command-line as for @tvec_parseargs@, and then process the
782 * remaining positional arguments as for @tvec_readargs@. The
783 * function constructs and disposes of a test vector state.
786 extern int tvec_main(int /*argc*/, char */*argv*/[],
787 const struct tvec_config */*config*/,
788 const char */*dflt*/);
790 /*----- Test processing ---------------------------------------------------*/
792 /* --- @tvec_skipgroup@, @tvec_skipgroup_v@ --- *
794 * Arguments: @struct tvec_state *tv@ = test-vector state
795 * @const char *excuse@, @va_list *ap@ = reason why skipped
799 * Use: Skip the current group. This should only be called from a
800 * test environment @setup@ function; a similar effect occurs if
801 * the @setup@ function fails.
804 extern PRINTF_LIKE(2, 3)
805 void tvec_skipgroup(struct tvec_state */*tv*/,
806 const char */*excuse*/, ...);
807 extern void tvec_skipgroup_v(struct tvec_state */*tv*/,
808 const char */*excuse*/, va_list */*ap*/);
810 /* --- @tvec_skip@, @tvec_skip_v@ --- *
812 * Arguments: @struct tvec_state *tv@ = test-vector state
813 * @const char *excuse@, @va_list *ap@ = reason why test skipped
817 * Use: Skip the current test. This should only be called from a
818 * test environment @run@ function; a similar effect occurs if
819 * the @before@ function fails.
822 extern PRINTF_LIKE(2, 3)
823 void tvec_skip(struct tvec_state */*tv*/, const char */*excuse*/, ...);
824 extern void tvec_skip_v(struct tvec_state */*tv*/,
825 const char */*excuse*/, va_list */*ap*/);
827 /* --- @tvec_fail@, @tvec_fail_v@ --- *
829 * Arguments: @struct tvec_state *tv@ = test-vector state
830 * @const char *detail@, @va_list *ap@ = description of test
834 * Use: Report the current test as a failure. This function can be
835 * called multiple times for a single test, e.g., if the test
836 * environment's @run@ function invokes the test function
837 * repeatedly; but a single test that fails repeatedly still
838 * only counts as a single failure in the statistics. The
839 * @detail@ string and its format parameters can be used to
840 * distinguish which of several invocations failed; it can
841 * safely be left null if the test function is run only once.
844 extern PRINTF_LIKE(2, 3)
845 void tvec_fail(struct tvec_state */*tv*/, const char */*detail*/, ...);
846 extern void tvec_fail_v(struct tvec_state */*tv*/,
847 const char */*detail*/, va_list */*ap*/);
849 /* --- @tvec_dumpreg@ --- *
851 * Arguments: @struct tvec_state *tv@ = test-vector state
852 * @unsigned disp@ = the register disposition (@TVRD_...@)
853 * @const union tvec_regval *tv@ = register value, or null
854 * @const struct tvec_regdef *rd@ = register definition
858 * Use: Dump a register value to the output. This is the lowest-
859 * level function for dumping registers, and calls the output
860 * formatter directly.
862 * Usually @tvec_mismatch@ is much more convenient. Low-level
863 * access is required for reporting `virtual' registers
864 * corresponding to test environment settings.
867 extern void tvec_dumpreg(struct tvec_state */*tv*/,
868 unsigned /*disp*/, const union tvec_regval */*rv*/,
869 const struct tvec_regdef */*rd*/);
871 /* --- @tvec_initregs@, @tvec_releaseregs@ --- *
873 * Arguments: @struct tvec_state *tv@ = test-vector state
877 * Use: Initialize or release, respectively, the registers required
878 * by the current test. All of the registers, both input and
879 * output, are effected. Initialized registers are not marked
883 extern void tvec_initregs(struct tvec_state */*tv*/);
884 extern void tvec_releaseregs(struct tvec_state */*tv*/);
886 /* --- @tvec_resetoutputs@ --- *
888 * Arguments: @struct tvec_state *tv@ = test-vector state
892 * Use: Reset (releases and reinitializes) the output registers in
893 * the test state. This is mostly of use to test environment
894 * @run@ functions, between invocations of the test function.
895 * Output registers are marked live if and only if the
896 * corresponding input register is live.
899 extern void tvec_resetoutputs(struct tvec_state */*tv*/);
901 /* --- @tvec_checkregs@ --- *
903 * Arguments: @struct tvec_state *tv@ = test-vector state
905 * Returns: Zero on success, %$-1$% on mismatch.
907 * Use: Compare the active output registers (according to the current
908 * test group definition) with the corresponding input register
909 * values. A mismatch occurs if the two values differ
910 * (according to the register type's @eq@ method), or if the
911 * input is live but the output is dead.
913 * This function only checks for a mismatch and returns the
914 * result; it takes no other action. In particular, it doesn't
915 * report a failure, or dump register values.
918 extern int tvec_checkregs(struct tvec_state */*tv*/);
920 /* --- @tvec_mismatch@ --- *
922 * Arguments: @struct tvec_state *tv@ = test-vector state
923 * @unsigned f@ = flags (@TVMF_...@)
927 * Use: Dumps registers suitably to report a mismatch. The flag bits
928 * @TVMF_IN@ and @TVF_OUT@ select input-only and output
929 * registers. If both are reset then nothing happens.
930 * Suppressing the output registers may be useful, e.g., if the
931 * test function crashed rather than returning outputs.
936 extern void tvec_mismatch(struct tvec_state */*tv*/, unsigned /*f*/);
938 /* --- @tvec_check@, @tvec_check_v@ --- *
940 * Arguments: @struct tvec_state *tv@ = test-vector state
941 * @const char *detail@, @va_list *ap@ = description of test
945 * Use: Check the register values, reporting a failure and dumping
946 * the registers in the event of a mismatch. This just wraps up
947 * @tvec_checkregs@, @tvec_fail@ and @tvec_mismatch@ in the
951 extern PRINTF_LIKE(2, 3)
952 void tvec_check(struct tvec_state */*tv*/, const char */*detail*/, ...);
953 extern void tvec_check_v(struct tvec_state */*tv*/,
954 const char */*detail*/, va_list */*ap*/);
956 /*----- Ad-hoc testing ----------------------------------------------------*/
958 /* --- @tvec_adhoc@ --- *
960 * Arguments: @struct tvec_state *tv@ = test-vector state
961 * @struct tvec_test *t@ = space for a test definition
965 * Use: Begin ad-hoc testing, i.e., without reading a file of
968 * The structure at @t@ will be used to record information about
969 * the tests underway, which would normally come from a static
970 * test definition. The other functions in this section assume
971 * that @tvec_adhoc@ has been called.
974 extern void tvec_adhoc(struct tvec_state */*tv*/, struct tvec_test */*t*/);
976 /* --- @tvec_begingroup@, @TVEC_BEGINGROUP@ --- *
978 * Arguments: @struct tvec_state *tv@ = test-vector state
979 * @const char *name@ = name for this test group
980 * @const char *file@, @unsigned @lno@ = calling file and line
984 * Use: Begin an ad-hoc test group with the given name. The @file@
985 * and @lno@ can be anything, but it's usually best if they
986 * refer to the source code performing the test: the macro
987 * @TVEC_BEGINGROUP@ does this automatically.
990 extern void tvec_begingroup(struct tvec_state */*tv*/, const char */*name*/,
991 const char */*file*/, unsigned /*lno*/);
992 #define TVEC_BEGINGROUP(tv, name) \
993 do tvec_begingroup(tv, name, __FILE__, __LINE__); while (0)
995 /* --- @tvec_endgroup@ --- *
997 * Arguments: @struct tvec_state *tv@ = test-vector state
1001 * Use: End an ad-hoc test group. The statistics are updated and the
1002 * outcome is reported to the output formatter.
1005 extern void tvec_endgroup(struct tvec_state */*tv*/);
1007 /* --- @TVEC_TESTGROUP@, @TVEC_TESTGROUP_TAG@ --- *
1009 * Arguments: @tag@ = label-disambiguation tag
1010 * @const struct tvec_state *tv = test-vector state
1011 * @const char *name@ = test-group name
1015 * Use: Control-structure macro: @TVEC_TESTGROUP(tv, name) stmt@
1016 * establishes a test group with the given @name@ (attributing
1017 * it to the source file and lie number), executes @stmt@, and
1018 * ends the test group. If @stmt@ invokes @break@ then the test
1019 * group is skipped. @TVEC_TESTGROUP_TAG@ is the same, with an
1020 * additional @tag@ argument for use in higher-level macros.
1023 #define TVEC_TESTGROUP_TAG(tag, tv, name) \
1024 MC_WRAP(tag##__around, \
1025 { TVEC_BEGINGROUP(tv, name); }, \
1026 { tvec_endgroup(tv); }, \
1027 { if (!((tv)->f&TVSF_SKIP)) tvec_skipgroup(tv, 0); \
1028 tvec_endgroup(tv); })
1029 #define TVEC_TESTGROUP(tv, name) TVEC_TESTGROUP_TAG(grp, tv, name)
1031 /* --- @tvec_begintest@, @TVEC_BEGINTEST@ --- *
1033 * Arguments: @struct tvec_state *tv@ = test-vector state
1034 * @const char *file@, @unsigned @lno@ = calling file and line
1038 * Use: Begin an ad-hoc test case. The @file@ and @lno@ can be
1039 * anything, but it's usually best if they refer to the source
1040 * code performing the test: the macro @TVEC_BEGINGROUP@ does
1041 * this automatically.
1044 extern void tvec_begintest(struct tvec_state */*tv*/,
1045 const char */*file*/, unsigned /*lno*/);
1046 #define TVEC_BEGINTEST(tv) \
1047 do tvec_begintest(tv, __FILE__, __LINE__); while (0)
1049 /* --- @tvec_endtest@ --- *
1051 * Arguments: @struct tvec_state *tv@ = test-vector state
1055 * Use: End an ad-hoc test case, The statistics are updated and the
1056 * outcome is reported to the output formatter.
1059 extern void tvec_endtest(struct tvec_state */*tv*/);
1061 /* --- @TVEC_TEST@, @TVEC_TEST_TAG@ --- *
1063 * Arguments: @tag@ = label-disambiguation tag
1064 * @struct tvec_test *t@ = space for a test definition
1068 * Use: Control-structure macro: @TVEC_TEST(tv) stmt@ begins a test
1069 * case, executes @stmt@, and ends the test case. If @stmt@
1070 * invokes @break@ then the test case is skipped.
1071 * @TVEC_TEST_TAG@ is the same, with an additional @tag@ argumet
1072 * for use in higher-level macros.
1075 #define TVEC_TEST_TAG(tag, tv) \
1076 MC_WRAP(tag##__around, \
1077 { TVEC_BEGINTEST(tv); }, \
1078 { tvec_endtest(tv); }, \
1079 { if ((tv)->f&TVSF_ACTIVE) tvec_skip((tv), 0); \
1080 tvec_endtest(tv); })
1081 #define TVEC_TEST(tv) TVEC_TEST_TAG(test, tv)
1083 /* --- @tvec_claim@, @tvec_claim_v@, @TVEC_CLAIM@ --- *
1085 * Arguments: @struct tvec_state *tv@ = test-vector state
1087 * @const char *file@, @unsigned @lno@ = calling file and line
1088 * @const char *msg@, @va_list *ap@ = message to report on
1091 * Returns: The value @ok@.
1093 * Use: Check that a claimed condition holds, as (part of) a test.
1094 * If no test case is underway (i.e., if @TVSF_OPEN@ is reset in
1095 * @tv->f@), then a new test case is begun and ended. The
1096 * @file@ and @lno@ are passed to the output formatter to be
1097 * reported in case of a failure. If @ok@ is nonzero, then
1098 * nothing else happens; so, in particular, if @tvec_claim@
1099 * established a new test case, then the test case succeeds. If
1100 * @ok@ is zero, then a failure is reported, quoting @msg@.
1102 * The @TVEC_CLAIM@ macro is similar, only it (a) identifies the
1103 * file and line number of the call site automatically, and (b)
1104 * implicitly quotes the source text of the @ok@ condition in
1105 * the failure message.
1108 extern PRINTF_LIKE(5, 6)
1109 int tvec_claim(struct tvec_state */*tv*/, int /*ok*/,
1110 const char */*file*/, unsigned /*lno*/,
1111 const char */*msg*/, ...);
1112 extern int tvec_claim_v(struct tvec_state */*tv*/, int /*ok*/,
1113 const char */*file*/, unsigned /*lno*/,
1114 const char */*msg*/, va_list */*ap*/);
1115 #define TVEC_CLAIM(tv, cond) \
1116 (tvec_claim(tv, !!(cond), __FILE__, __LINE__, "%s untrue", #cond))
1118 /* --- @tvec_claimeq@ --- *
1120 * Arguments: @struct tvec_state *tv@ = test-vector state
1121 * @const struct tvec_regty *ty@ = register type
1122 * @const union tvec_misc *arg@ = register type argument
1123 * @const char *file@, @unsigned @lno@ = calling file and line
1124 * @const char *expr@ = the expression to quote on failure
1126 * Returns: Nonzero if the input and output values of register 0 are
1127 * equal, zero if they differ.
1129 * Use: Check that the input and output values of register 0 are
1130 * equal (according to the register type @ty@). As for
1131 * @tvec_claim@ above, a test case is automatically begun and
1132 * ended if none is already underway. If the values are
1133 * unequal, then @tvec_fail@ is called, quoting @expr@, and the
1134 * mismatched values are dumped.
1136 * This function is not expected to be called directly, but
1137 * through type-specific wrapper functions or macros such as
1138 * @TVEC_CLAIMEQ_INT@.
1141 extern int tvec_claimeq(struct tvec_state */*tv*/,
1142 const struct tvec_regty */*ty*/,
1143 const union tvec_misc */*arg*/,
1144 const char */*file*/, unsigned /*lno*/,
1145 const char */*expr*/);
1147 /*----- Benchmarking ------------------------------------------------------*/
1149 struct tvec_benchenv {
1150 struct tvec_env _env; /* benchmarking is an environment */
1151 struct bench_state **bst; /* benchmark state anchor or null */
1152 unsigned long niter; /* iterations done per unit */
1153 int riter, rbuf; /* iterations and buffer registers */
1154 const struct tvec_env *env; /* subordinate environment */
1157 struct tvec_benchctx {
1158 const struct tvec_benchenv *be; /* environment configuration */
1159 struct bench_state *bst; /* benchmark state */
1160 double dflt_target; /* default time in seconds */
1161 unsigned f; /* flags */
1162 #define TVBF_SETTRG 1u /* set `@target' */
1163 #define TVBF_SETMASK (TVBF_SETTRG)) /* mask of @TVBF_SET...@ */
1164 void *subctx; /* subsidiary environment context */
1167 extern struct bench_state *tvec_benchstate;
1169 /* --- Environment implementation --- *
1171 * The following special variables are supported.
1173 * * %|@target|% is the (approximate) number of seconds to run the
1176 * Unrecognized variables are passed to the subordinate environment, if there
1177 * is one. Other events are passed through to the subsidiary environment.
1180 extern tvec_envsetupfn tvec_benchsetup;
1181 extern tvec_envfindvarfn tvec_benchfindvar;
1182 extern tvec_envbeforefn tvec_benchbefore;
1183 extern tvec_envrunfn tvec_benchrun;
1184 extern tvec_envafterfn tvec_benchafter;
1185 extern tvec_envteardownfn tvec_benchteardown;
1187 #define TVEC_BENCHENV \
1188 { sizeof(struct tvec_benchctx), \
1190 tvec_benchfindvar, \
1194 tvec_benchteardown }
1195 #define TVEC_BENCHINIT TVEC_BENCHENV, &tvec_benchstate
1197 /* --- @tvec_benchreport@ --- *
1199 * Arguments: @const struct gprintf_ops *gops@ = print operations
1200 * @void *go@ = print destination
1201 * @unsigned unit@ = the unit being measured (~TVBU_...@)
1202 * @const struct bench_timing *tm@ = the benchmark result
1206 * Use: Formats a report about the benchmark performance. This
1207 * function is intended to be called on by an output
1208 * @ebench@ function.
1211 extern void tvec_benchreport
1212 (const struct gprintf_ops */*gops*/, void */*go*/,
1213 unsigned /*unit*/, const struct bench_timing */*tm*/);
1215 /*----- Remote execution --------------------------------------------------*/
1217 struct tvec_remoteenv;
1219 struct tvec_remotecomms {
1220 int infd, outfd; /* input and output descriptors */
1221 dbuf bout; /* output buffer */
1222 unsigned char *bin; /* input buffer */
1223 size_t binoff, binlen, binsz; /* input offset, length, and size */
1224 size_t t; /* temporary offset */
1225 unsigned f; /* flags */
1226 #define TVRF_BROKEN 0x0001u /* communications have failed */
1228 #define TVEC_REMOTECOMMS_INIT { -1, -1, DBUF_INIT, 0, 0, 0, 0, 0, 0 }
1230 struct tvec_remotectx {
1231 struct tvec_state *tv; /* test vector state */
1232 struct tvec_remotecomms rc; /* communication state */
1233 const struct tvec_remoteenv *re; /* environment configuration */
1234 void *subctx; /* subenvironment context */
1235 struct tvec_vardef vd; /* temporary variable definition */
1236 unsigned ver; /* protocol version */
1237 pid_t kid; /* child process id */
1238 int errfd; /* child stderr descriptor */
1239 lbuf errbuf; /* child stderr line buffer */
1240 dstr prgwant, progress; /* progress: wanted/reported */
1241 unsigned exwant, exit; /* exit status wanted/reported */
1242 #define TVRF_RCNMASK 0x0300u /* reconnection behaviour: */
1243 #define TVRCN_DEMAND 0x0000u /* connect on demand */
1244 #define TVRCN_SKIP 0x0100u /* skip unless connected */
1245 #define TVRCN_FORCE 0x0200u /* force reconnection */
1246 #define TVRF_MUFFLE 0x0400u /* muffle child stderr */
1247 #define TVRF_SETEXIT 0x0800u /* set `@exit' */
1248 #define TVRF_SETPRG 0x1000u /* set `@progress' */
1249 #define TVRF_SETRCN 0x2000u /* set `@reconnect' */
1250 #define TVRF_SETMASK (TVRF_SETEXIT | TVRF_SETPRG | TVRF_SETRCN)
1251 /* mask of @TVTF_SET...@ */
1254 typedef int tvec_connectfn(pid_t */*kid_out*/, int */*infd_out*/,
1255 int */*outfd_out*/, int */*errfd_out*/,
1256 struct tvec_state */*tv*/,
1257 const struct tvec_remoteenv */*env*/);
1258 /* A connection function. On entry, @tv@ holds the test-vector state, and
1259 * @env@ is the test group's remote environment structure, which will
1260 * typically really be some subclass of @struct tvec_remoteenv@ containing
1261 * additional parameters for establishing the child process.
1263 * On successful completion, the function stores input and output
1264 * descriptors (which need not be distinct) in @*infd_out@ and
1265 * @*outfd_out@, and returns zero; if it creates a child process, it should
1266 * additionally store the child's process-id in @*kid_out@ and store in
1267 * @*errfd_out@ a descriptor from which the child's error output can be
1268 * read. On error, the function should report an appropriate message via
1269 * @tvec_error@ and return %$-1$%.
1272 struct tvec_remoteenv_slots {
1273 tvec_connectfn *connect; /* connection function */
1274 const struct tvec_env *env; /* subsidiary environment */
1275 unsigned dflt_reconn; /* default reconnection */
1278 struct tvec_remoteenv {
1279 struct tvec_env _env;
1280 struct tvec_remoteenv_slots r;
1283 struct tvec_remotefork_slots {
1284 const struct tvec_test *tests; /* child tests (or null) */
1287 struct tvec_remotefork {
1288 struct tvec_env _env;
1289 struct tvec_remoteenv_slots r;
1290 struct tvec_remotefork_slots f;
1293 struct tvec_remoteexec_slots {
1294 const char *const *args; /* command line to execute */
1297 struct tvec_remoteexec {
1298 struct tvec_env _env;
1299 struct tvec_remoteenv_slots r;
1300 struct tvec_remoteexec_slots x;
1303 union tvec_remoteenv_subclass_kludge {
1304 struct tvec_env _env;
1305 struct tvec_remoteenv renv;
1306 struct tvec_remotefork fork;
1307 struct tvec_remoteexec exec;
1312 * We don't use the conventional encoding returned by the @wait@(2) family of
1313 * system calls because it's too hard for our flags type to decode. Instead,
1314 * we use our own encoding.
1316 * The exit code or signal number ends up in the `value' field in the low 12
1317 * bits; bit 12 is set if the value field holds a signal, and it if holds an
1318 * exit code. Bits 13--15 hold a code which describes the status of a child
1319 * process or connection.
1321 #define TVXF_VALMASK 0x0fffu /* value (exit code or signal) */
1322 #define TVXF_SIG 0x1000u /* value is signal, not exit code */
1323 #define TVXF_CAUSEMASK 0xe000u /* mask for cause bits */
1324 #define TVXST_RUN 0x0000u /* still running */
1325 #define TVXST_EXIT 0x2000u /* child exited */
1326 #define TVXST_KILL 0x4000u /* child killed by signal */
1327 #define TVXST_CONT 0x6000u /* child continued (?) */
1328 #define TVXST_STOP 0x8000u /* child stopped (?) */
1329 #define TVXST_DISCONN 0xa000u /* disconnected */
1330 #define TVXST_UNK 0xc000u /* unknown */
1331 #define TVXST_ERR 0xe000u /* local error prevented diagnosis */
1333 /* Remote environment. */
1334 extern tvec_envsetupfn tvec_remotesetup;
1335 extern tvec_envfindvarfn tvec_remotefindvar;
1336 extern tvec_envbeforefn tvec_remotebefore;
1337 extern tvec_envrunfn tvec_remoterun;
1338 extern tvec_envafterfn tvec_remoteafter;
1339 extern tvec_envteardownfn tvec_remoteteardown;
1340 #define TVEC_REMOTEENV \
1341 { sizeof(struct tvec_remotectx), \
1343 tvec_remotefindvar, \
1344 tvec_remotebefore, \
1347 tvec_remoteteardown }
1349 /* --- @tvec_setprogress@, @tvec_setprogress_v@ --- *
1351 * Arguments: @const char *status@ = progress status token format
1352 * @va_list ap@ = argument tail
1356 * Use: Reports the progress of a test execution to the client.
1358 * The framework makes use of tokens beginning with %|%|%:
1360 * * %|%IDLE|%: during the top-level server code;
1362 * * %|%SETUP|%: during the enclosing environment's @before@
1365 * * %|%RUN|%: during the environment's @run@ function, or the
1366 * test function; and
1368 * * %|%DONE|%: during the enclosing environment's @after@
1371 * The intent is that a test can use the progress token to check
1372 * that a function which is expected to crash does so at the
1373 * correct point, so it's expected that more complex test
1374 * functions and/or environments will set their own progress
1375 * tokens to reflect what's going on.
1378 extern PRINTF_LIKE(1, 2) int tvec_setprogress(const char */*status*/, ...);
1379 extern int tvec_setprogress_v(const char */*status*/, va_list */*ap*/);
1381 /* --- @tvec_remoteserver@ --- *
1383 * Arguments: @int infd@, @int outfd@ = input and output file descriptors
1384 * @const struct tvec_config *config@ = test configuration
1386 * Returns: Suggested exit code.
1388 * Use: Run a test server, reading packets from @infd@ and writing
1389 * responses and notifications to @outfd@, and invoking tests as
1390 * described by @config@.
1392 * This function is not particularly general purpose. It
1393 * expects to `take over' the process, and makes use of private
1397 extern int tvec_remoteserver(int /*infd*/, int /*outfd*/,
1398 const struct tvec_config */*config*/);
1400 extern tvec_connectfn tvec_fork, tvec_exec;
1402 #define TVEC_REMOTEFORK(subenv, tests) \
1403 TVEC_REMOTEENV, { tvec_fork, subenv }, { tests }
1405 #define TVEC_REMOTEEXEC(subenv, args) \
1406 TVEC_REMOTEENV, { tvec_exec, subenv }, { args }
1408 /*----- Timeouts ----------------------------------------------------------*/
1410 struct tvec_timeoutenv {
1411 struct tvec_env _env;
1412 int timer; /* the timer (@ITIMER_...@) */
1413 double t; /* time to wait (in seconds) */
1414 const struct tvec_env *env; /* subsidiary environment */
1417 struct tvec_timeoutctx {
1418 const struct tvec_timeoutenv *te; /* saved environment description */
1419 int timer; /* timer code (as overridden) */
1420 double t; /* time to wait (as overridden) */
1421 unsigned f; /* flags */
1422 #define TVTF_SETTMO 1u /* set `@timeout' */
1423 #define TVTF_SETTMR 2u /* set `@timer' */
1424 #define TVTF_SETMASK (TVTF_SETTMO | TVTF_SETTMR)
1425 /* mask of @TVTF_SET...@ */
1429 extern tvec_envsetupfn tvec_timeoutsetup;
1430 extern tvec_envfindvarfn tvec_timeoutfindvar;
1431 extern tvec_envbeforefn tvec_timeoutbefore;
1432 extern tvec_envrunfn tvec_timeoutrun;
1433 extern tvec_envafterfn tvec_timeoutafter;
1434 extern tvec_envteardownfn tvec_timeoutteardown;
1435 #define TVEC_TIMEOUTENV \
1436 { sizeof(struct tvec_timeoutctx), \
1437 tvec_timeoutsetup, \
1438 tvec_timeoutfindvar, \
1439 tvec_timeoutbefore, \
1441 tvec_timeoutafter, \
1442 tvec_timeoutteardown }
1443 #define TVEC_TIMEOUTINIT(timer, t) TVEC_TIMEOUTENV, timer, t
1445 /*----- Output functions --------------------------------------------------*/
1447 /* --- @tvec_strlevel@ --- *
1449 * Arguments: @unsigned level@ = level code
1451 * Returns: A human-readable description.
1453 * Use: Converts a level code into something that you can print in a
1457 extern const char *tvec_strlevel(unsigned /*level*/);
1459 /* --- @tvec_report@, @tvec_report_v@ --- *
1461 * Arguments: @struct tvec_state *tv@ = test-vector state
1462 * @const char *msg@, @va_list ap@ = error message
1466 * Use: Report an message with a given severity. Messages with level
1467 * @TVLEV_ERR@ or higher force a nonzero exit code.
1470 extern PRINTF_LIKE(3, 4)
1471 void tvec_report(struct tvec_state */*tv*/, unsigned /*level*/,
1472 const char */*msg*/, ...);
1473 extern void tvec_report_v(struct tvec_state */*tv*/, unsigned /*level*/,
1474 const char */*msg*/, va_list */*ap*/);
1476 /* --- @tvec_error@, @tvec_notice@ --- *
1478 * Arguments: @struct tvec_state *tv@ = test-vector state
1479 * @const char *msg@, @va_list ap@ = error message
1481 * Returns: The @tvec_error@ function returns %$-1$% as a trivial
1482 * convenience; @tvec_notice@ does not return a value.
1484 * Use: Report an error or a notice. Errors are distinct from test
1485 * failures, and indicate that a problem was encountered which
1486 * compromised the activity of testing. Notices are important
1487 * information which doesn't fit into any other obvious
1491 extern PRINTF_LIKE(2, 3)
1492 int tvec_error(struct tvec_state */*tv*/, const char */*msg*/, ...);
1493 extern PRINTF_LIKE(2, 3)
1494 void tvec_notice(struct tvec_state */*tv*/, const char */*msg*/, ...);
1496 /* --- @tvec_unkreg@ --- *
1498 * Arguments: @struct tvec_state *tv@ = test-vector state
1499 * @const char *name@ = register or pseudoregister name
1503 * Use: Reports an error that the register or pseudoregister is
1507 extern int tvec_unkreg(struct tvec_state */*tv*/, const char */*name*/);
1509 /* --- @tvec_dupreg@ --- *
1511 * Arguments: @struct tvec_state *tv@ = test-vector state
1512 * @const char *name@ = register or pseudoregister name
1516 * Use: Reports an error that the register or pseudoregister has been
1517 * assigned already in the current test.
1520 extern int tvec_dupreg(struct tvec_state */*tv*/, const char */*name*/);
1522 /* --- @tvec_humanoutput@ --- *
1524 * Arguments: @FILE *fp@ = output file to write on
1526 * Returns: An output formatter.
1528 * Use: Return an output formatter which writes on @fp@ with the
1529 * expectation that a human will be watching and interpreting
1530 * the output. If @fp@ denotes a terminal, the display shows a
1531 * `scoreboard' indicating the outcome of each test case
1532 * attempted, and may in addition use colour and other
1536 extern struct tvec_output *tvec_humanoutput(FILE */*fp*/);
1538 /* --- @tvec_tapoutput@ --- *
1540 * Arguments: @FILE *fp@ = output file to write on
1542 * Returns: An output formatter.
1544 * Use: Return an output formatter which writes on @fp@ in `TAP'
1545 * (`Test Anything Protocol') format.
1547 * TAP comes from the Perl community, but has spread rather
1548 * further. This driver produces TAP version 14, but pretends
1549 * to be version 13. The driver produces a TAP `test point' --
1550 * i.e., a result reported as `ok' or `not ok' -- for each input
1551 * test group. Failure reports and register dumps are produced
1552 * as diagnostic messages before the final group result. (TAP
1553 * permits structuerd YAML data after the test-point result,
1554 * which could be used to report details, but (a) postponing the
1555 * details until after the report is inconvenient, and (b) there
1556 * is no standardization for the YAML anyway, so in practice
1557 * it's no more useful than the unstructured diagnostics.
1560 extern struct tvec_output *tvec_tapoutput(FILE */*fp*/);
1562 /* --- @tvec_dfltoutput@ --- *
1564 * Arguments: @FILE *fp@ = output file to write on
1566 * Returns: An output formatter.
1568 * Use: Selects and instantiates an output formatter suitable for
1569 * writing on @fp@. The policy is subject to change, but
1570 * currently the `human' output format is selected if @fp@ is
1571 * interactive (i.e., if @isatty(fileno(fp))@ is true), and
1572 * otherwise the `tap' format is used.
1575 extern struct tvec_output *tvec_dfltout(FILE */*fp*/);
1577 /*------ Serialization utilities ------------------------------------------*/
1579 /* Serialization format.
1581 * The `candidate register definitions' are those entries @r@ in the @regs@
1582 * vector whose index @r.i@ is strictly less than @nr@. The `selected
1583 * register definitions' are those candidate register definitions @r@ for
1584 * which the indicated register @rv[r.i]@ has the @TVRF_LIVE@ flag set. The
1585 * serialized output begins with a header bitmap: if there are %$n$%
1586 * candidate register definitions then the header bitmap consists of %$\lceil
1587 * n/8 \rceil$% bytes. Bits are ordered starting from the least significant
1588 * bit of the first byte, end ending at the most significant bit of the final
1589 * byte. The bit corresponding to a candidate register definition is set if
1590 * and only if that register defintion is selected. The header bitmap is
1591 * then followed by the serializations of the selected registers -- i.e., for
1592 * each selected register definition @r@, the serialized value of register
1593 * @rv[r.i]@ -- simply concatenated together, with no padding or alignment.
1596 /* --- @tvec_serialize@ --- *
1598 * Arguments: @const struct tvec_reg *rv@ = vector of registers
1599 * @buf *b@ = buffer to write on
1600 * @const struct tvec_regdef *regs@ = vector of register
1601 * descriptions, terminated by an entry with a null
1603 * @unsigned nr@ = number of entries in the @rv@ vector
1604 * @size_t regsz@ = true size of each element of @rv@
1606 * Returns: Zero on success, %$-1$% on failure.
1608 * Use: Serialize a collection of register values.
1610 * The serialized output is written to the buffer @b@. Failure
1611 * can be caused by running out of buffer space, or a failing
1615 extern int tvec_serialize(const struct tvec_reg */*rv*/, buf */*b*/,
1616 const struct tvec_regdef */*regs*/,
1617 unsigned /*nr*/, size_t /*regsz*/);
1619 /* --- @tvec_deserialize@ --- *
1621 * Arguments: @struct tvec_reg *rv@ = vector of registers
1622 * @buf *b@ = buffer to write on
1623 * @const struct tvec_regdef *regs@ = vector of register
1624 * descriptions, terminated by an entry with a null
1626 * @unsigned nr@ = number of entries in the @rv@ vector
1627 * @size_t regsz@ = true size of each element of @rv@
1629 * Returns: Zero on success, %$-1$% on failure.
1631 * Use: Deserialize a collection of register values.
1633 * The size of the register vector @nr@ and the register
1634 * definitions @regs@ must match those used when producing the
1635 * serialization. For each serialized register value,
1636 * deserialize and store the value into the appropriate register
1637 * slot, and set the @TVRF_LIVE@ flag on the register. See
1638 * @tvec_serialize@ for a description of the format.
1640 * Failure results only from a failing register type handler.
1643 extern int tvec_deserialize(struct tvec_reg */*rv*/, buf */*b*/,
1644 const struct tvec_regdef */*regs*/,
1645 unsigned /*nr*/, size_t /*regsz*/);
1647 /*----- Input utilities ---------------------------------------------------*/
1649 /* These are provided by the core for the benefit of type @parse@ methods,
1650 * and test-environment @set@ functions, which get to read from the test
1651 * input file. The latter are usually best implemented by calling on the
1654 * The two main rules are as follows.
1656 * * Leave the file position at the beginning of the line following
1657 * whatever it was that you read.
1659 * * When you read and consume a newline (which you do at least once, by
1660 * the previous rule), then increment @tv->lno@ to keep track of the
1661 * current line number.
1664 /* --- @tvec_syntax@, @tvec_syntax_v@ --- *
1666 * Arguments: @struct tvec_state *tv@ = test-vector state
1667 * @int ch@ = the character found (in @fgetc@ format)
1668 * @const char *expect@, @va_list ap@ = what was expected
1672 * Use: Report a syntax error quoting @ch@ and @expect@. If @ch@ is
1673 * a newline, then back up so that it can be read again (e.g.,
1674 * by @tvec_flushtoeol@ or @tvec_nexttoken@, which will also
1675 * advance the line number).
1678 extern PRINTF_LIKE(3, 4)
1679 int tvec_syntax(struct tvec_state */*tv*/, int /*ch*/,
1680 const char */*expect*/, ...);
1681 extern int tvec_syntax_v(struct tvec_state */*tv*/, int /*ch*/,
1682 const char */*expect*/, va_list */*ap*/);
1684 /* --- @tvec_skipspc@ --- *
1686 * Arguments: @struct tvec_state *tv@ = test-vector state
1690 * Use: Advance over any whitespace characters other than newlines.
1691 * This will stop at `;', end-of-file, or any other kind of
1692 * non-whitespace; and it won't consume a newline.
1695 extern void tvec_skipspc(struct tvec_state */*tv*/);
1697 /* --- @tvec_flushtoeol@ --- *
1699 * Arguments: @struct tvec_state *tv@ = test-vector state
1700 * @unsigned f@ = flags (@TVFF_...@)
1702 * Returns: Zero on success, %$-1$% on error.
1704 * Use: Advance to the start of the next line, consuming the
1705 * preceding newline.
1707 * A syntax error is reported if no newline character is found,
1708 * i.e., the file ends in mid-line. A syntax error is also
1709 * reported if material other than whitespace or a comment is
1710 * found before the end of the line end, and @TVFF_ALLOWANY@ is
1711 * not set in @f@. The line number count is updated
1715 #define TVFF_ALLOWANY 1u
1716 extern int tvec_flushtoeol(struct tvec_state */*tv*/, unsigned /*f*/);
1718 /* --- @tvec_nexttoken@ --- *
1720 * Arguments: @struct tvec_state *tv@ = test-vector state
1722 * Returns: Zero if there is a next token which can be read; %$-1$% if no
1723 * token is available.
1725 * Use: Advance to the next whitespace-separated token, which may be
1728 * Tokens are separated by non-newline whitespace, comments, and
1729 * newlines followed by whitespace; a newline /not/ followed by
1730 * whitespace instead begins the next assignment, and two
1731 * newlines separated only by whitespace terminate the data for
1734 * If this function returns zero, then the next character in the
1735 * file begins a suitable token which can be read and
1736 * processed. If it returns %$-1$% then there is no such token,
1737 * and the file position is left correctly. The line number
1738 * count is updated appropriately.
1741 extern int tvec_nexttoken(struct tvec_state */*tv*/);
1743 /* --- @tvec_readword@, @tvec_readword_v@ --- *
1745 * Arguments: @struct tvec_state *tv@ = test-vector state
1746 * @dstr *d@ = string to append the word to
1747 * @const char **p_inout@ = pointer into string, updated
1748 * @const char *delims@ = additional delimiters to stop at
1749 * @const char *expect@, @va_list ap@ = what was expected
1751 * Returns: Zero on success, %$-1$% on failure.
1753 * Use: A `word' consists of characters other than whitespace, null
1754 * characters, and other than those listed in @delims@;
1755 * furthermore, a word does not begin with a `;'. (If you want
1756 * reading to stop at comments not preceded by whitespace, then
1757 * include `;' in @delims@. This is a common behaviour.)
1759 * If there is no word beginning at the current file position,
1760 * then return %$-1$%; furthermore, if @expect@ is not null,
1761 * then report an appropriate error via @tvec_syntax@.
1763 * Otherwise, the word is accumulated in @d@ and zero is
1764 * returned; if @d@ was not empty at the start of the call, the
1765 * newly read word is separated from the existing material by a
1766 * single space character. Since null bytes are never valid
1767 * word constituents, a null terminator is written to @d@, and
1768 * it is safe to treat the string in @d@ as being null-
1771 * If @p_inout@ is not null, then @*p_inout@ must be a pointer
1772 * into @d->buf@, which will be adjusted so that it will
1773 * continue to point at the same position even if the buffer is
1774 * reallocated. As a subtle tweak, if @*p_inout@ initially
1775 * points at the end of the buffer, then it will be adjusted to
1776 * point at the beginning of the next word, rather than at the
1777 * additional intervening space.
1780 extern PRINTF_LIKE(5, 6)
1781 int tvec_readword(struct tvec_state */*tv*/, dstr */*d*/,
1782 const char **/*p_inout*/, const char */*delims*/,
1783 const char */*expect*/, ...);
1784 extern int tvec_readword_v(struct tvec_state */*tv*/, dstr */*d*/,
1785 const char **/*p_inout*/, const char */*delims*/,
1786 const char */*expect*/, va_list */*ap*/);
1788 /*----- Integer types: signed and unsigned --------------------------------*/
1790 /* Integers may be input in decimal, hex, binary, or octal, following
1791 * approximately usual conventions.
1793 * * Signed integers may be preceded with a `+' or `-' sign.
1795 * * Decimal integers are just a sequence of decimal digits `0' ... `9'.
1797 * * Octal integers are a sequence of digits `0' ... `7', preceded by `0o'
1800 * * Hexadecimal integers are a sequence of digits `0' ... `9', `a'
1801 * ... `f', or `A' ... `F', preceded by `0x' or `0X'.
1803 * * Radix-B integers are a sequence of digits `0' ... `9', `a' ... `f', or
1804 * `A' ... `F', each with value less than B, preceded by `Br' or `BR',
1805 * where 0 < B < 36 is expressed in decimal without any leading `0' or
1806 * internal underscores `_'.
1808 * * A digit sequence may contain internal underscore `_' separators, but
1809 * not before or after all of the digits; and two consecutive `_'
1810 * characters are not permitted.
1813 extern const struct tvec_regty tvty_int, tvty_uint;
1815 /* The @arg.p@ slot may be null or a pointer to @struct tvec_irange@ or
1816 * @struct tvec_urange@ as appropriate. The bounds are inclusive; use, e.g.,
1817 * @LONG_MAX@ explicitly if one or the other bound is logically inapplicable.
1819 struct tvec_irange { long min, max; };
1820 struct tvec_urange { unsigned long min, max; };
1822 /* Bounds corresponding to common integer types. */
1823 extern const struct tvec_irange
1824 tvrange_schar, tvrange_short, tvrange_int, tvrange_long,
1825 tvrange_sbyte, tvrange_i16, tvrange_i32;
1826 extern const struct tvec_urange
1827 tvrange_uchar, tvrange_ushort, tvrange_uint, tvrange_ulong, tvrange_size,
1828 tvrange_byte, tvrange_u16, tvrange_u32;
1830 /* --- @tvec_claimeq_int@, @TVEC_CLAIMEQ_INT@ --- *
1832 * Arguments: @struct tvec_state *tv@ = test-vector state
1833 * @long i0, i1@ = two signed integers
1834 * @const char *file@, @unsigned @lno@ = calling file and line
1835 * @const char *expr@ = the expression to quote on failure
1837 * Returns: Nonzero if @i0@ and @i1@ are equal, otherwise zero.
1839 * Use: Check that values of @i0@ and @i1@ are equal. As for
1840 * @tvec_claim@ above, a test case is automatically begun and
1841 * ended if none is already underway. If the values are
1842 * unequal, then @tvec_fail@ is called, quoting @expr@, and the
1843 * mismatched values are dumped: @i0@ is printed as the output
1844 * value and @i1@ is printed as the input reference.
1846 * The @TVEC_CLAIM_INT@ macro is similar, only it (a) identifies
1847 * the file and line number of the call site automatically, and
1848 * (b) implicitly quotes the source text of the @i0@ and @i1@
1849 * arguments in the failure message.
1852 extern int tvec_claimeq_int(struct tvec_state */*tv*/,
1853 long /*i0*/, long /*i1*/,
1854 const char */*file*/, unsigned /*lno*/,
1855 const char */*expr*/);
1856 #define TVEC_CLAIMEQ_INT(tv, i0, i1) \
1857 (tvec_claimeq_int(tv, i0, i1, __FILE__, __LINE__, #i0 " /= " #i1))
1859 /* --- @tvec_claimeq_uint@, @TVEC_CLAIMEQ_UINT@ --- *
1861 * Arguments: @struct tvec_state *tv@ = test-vector state
1862 * @unsigned long u0, u1@ = two unsigned integers
1863 * @const char *file@, @unsigned @lno@ = calling file and line
1864 * @const char *expr@ = the expression to quote on failure
1866 * Returns: Nonzero if @u0@ and @u1@ are equal, otherwise zero.
1868 * Use: Check that values of @u0@ and @u1@ are equal. As for
1869 * @tvec_claim@ above, a test case is automatically begun and
1870 * ended if none is already underway. If the values are
1871 * unequal, then @tvec_fail@ is called, quoting @expr@, and the
1872 * mismatched values are dumped: @u0@ is printed as the output
1873 * value and @u1@ is printed as the input reference.
1875 * The @TVEC_CLAIM_UINT@ macro is similar, only it (a)
1876 * identifies the file and line number of the call site
1877 * automatically, and (b) implicitly quotes the source text of
1878 * the @u0@ and @u1@ arguments in the failure message.
1881 extern int tvec_claimeq_uint(struct tvec_state */*tv*/,
1882 unsigned long /*u0*/, unsigned long /*u1*/,
1883 const char */*file*/, unsigned /*lno*/,
1884 const char */*expr*/);
1885 #define TVEC_CLAIMEQ_UINT(tv, u0, u1) \
1886 (tvec_claimeq_uint(tv, u0, u1, __FILE__, __LINE__, #u0 " /= " #u1))
1888 /*----- Size type ---------------------------------------------------------*/
1890 /* A size is an unsigned integer followed by an optional unit specifier
1891 * consisting of an SI unit prefix and (optionally) the letter `B'.
1894 extern const struct tvec_regty tvty_size;
1896 /* --- @tvec_claimeq_size@ --- *
1898 * Arguments: @struct tvec_state *tv@ = test-vector state
1899 * @unsigned long sz0, sz1@ = two sizes
1900 * @const char *file@, @unsigned @lno@ = calling file and line
1901 * @const char *expr@ = the expression to quote on failure
1903 * Returns: Nonzero if @sz0@ and @sz1@ are equal, otherwise zero.
1905 * Use: Check that values of @u0@ and @u1@ are equal. As for
1906 * @tvec_claim@ above, a test case is automatically begun and
1907 * ended if none is already underway. If the values are
1908 * unequal, then @tvec_fail@ is called, quoting @expr@, and the
1909 * mismatched values are dumped: @u0@ is printed as the output
1910 * value and @u1@ is printed as the input reference.
1912 * The @TVEC_CLAIM_SIZE@ macro is similar, only it (a)
1913 * identifies the file and line number of the call site
1914 * automatically, and (b) implicitly quotes the source text of
1915 * the @u0@ and @u1@ arguments in the failure message.
1918 int tvec_claimeq_size(struct tvec_state *tv,
1919 unsigned long sz0, unsigned long sz1,
1920 const char *file, unsigned lno, const char *expr);
1921 #define TVEC_CLAIMEQ_UINT(tv, u0, u1) \
1922 (tvec_claimeq_uint(tv, u0, u1, __FILE__, __LINE__, #u0 " /= " #u1))
1924 /*----- Floating-point type -----------------------------------------------*/
1926 /* Floating-point values are either NaN (%|#nan|%, if supported by the
1927 * platform); positive or negative infinity (%|#inf|%, %|+#inf|%, or
1928 * %|#+inf|% (preferring the last), and %|-#inf|% or %|#-inf|% (preferring
1929 * the latter), if supported by the platform); or a number in strtod(3)
1932 * The comparison rules for floating-point numbers are complex: see
1933 * @tvec_claimeqish_float@ for details.
1936 extern const struct tvec_regty tvty_float;
1938 struct tvec_floatinfo {
1939 /* Details about acceptable floating-point values. */
1941 unsigned f; /* flags (@TVFF_...@ bits) */
1942 #define TVFF_NOMIN 1u /* ignore @min@ (allow -inf) */
1943 #define TVFF_NOMAX 2u /* ignore @max@ (allow +inf) */
1944 #define TVFF_NANOK 4u /* permit NaN */
1945 #define TVFF_EQMASK 0xf0 /* how to compare */
1946 #define TVFF_EXACT 0x00 /* must equal exactly */
1947 #define TVFF_ABSDELTA 0x10 /* must be within @delta@ */
1948 #define TVFF_RELDELTA 0x20 /* diff < @delta@ fraction */
1949 double min, max; /* smallest/largest value allowed */
1950 double delta; /* maximum tolerable difference */
1953 extern const struct tvec_floatinfo tvflt_finite, tvflt_nonneg;
1955 /* --- @tvec_claimeqish_float@, @TVEC_CLAIMEQISH_FLOAT@ --- *
1957 * Arguments: @struct tvec_state *tv@ = test-vector state
1958 * @double f0, f1@ = two floating-point numbers
1959 * @unsigned f@ = flags (@TVFF_...@)
1960 * @double delta@ = maximum tolerable difference
1961 * @const char *file@, @unsigned @lno@ = calling file and line
1962 * @const char *expr@ = the expression to quote on failure
1964 * Returns: Nonzero if @f0@ and @f1@ are sufficiently close, otherwise
1967 * Use: Check that values of @f0@ and @f1@ are sufficiently close.
1968 * As for @tvec_claim@ above, a test case is automatically begun
1969 * and ended if none is already underway. If the values are
1970 * too far apart, then @tvec_fail@ is called, quoting @expr@,
1971 * and the mismatched values are dumped: @f0@ is printed as the
1972 * output value and @f1@ is printed as the input reference.
1974 * The details for the comparison are as follows.
1976 * * A NaN value matches any other NaN, and nothing else.
1978 * * An infinity matches another infinity of the same sign,
1981 * * If @f&TVFF_EQMASK@ is @TVFF_EXACT@, then any
1982 * representable number matches only itself: in particular,
1983 * positive and negative zero are considered distinct.
1984 * (This allows tests to check that they land on the correct
1985 * side of branch cuts, for example.)
1987 * * If @f&TVFF_EQMASK@ is @TVFF_ABSDELTA@, then %$x$% matches
1988 * %$y$% when %$|x - y| < \delta$%.
1990 * * If @f&TVFF_EQMASK@ is @TVFF_RELDELTA@, then %$x$% matches
1991 * %$y$% when %$|1 - x/y| < \delta$%. (Note that this
1992 * criterion is asymmetric. Write %$x \approx_\delta y$%
1993 * if and only if %$|1 - x/y < \delta$%. Then, for example,
1994 * if %$y/(1 + \delta) < x < y (1 - \delta)$%, then
1995 * %$x \approx_\delta y$%, but %$y \not\approx_\delta x$%.)
1997 * The @TVEC_CLAIM_FLOAT@ macro is similar, only it (a)
1998 * identifies the file and line number of the call site
1999 * automatically, and (b) implicitly quotes the source text of
2000 * the @f0@ and @f1@ arguments (and @delta@) in the failure
2004 extern int tvec_claimeqish_float(struct tvec_state */*tv*/,
2005 double /*f0*/, double /*f1*/,
2006 unsigned /*f*/, double /*delta*/,
2007 const char */*file*/, unsigned /*lno*/,
2008 const char */*expr*/);
2009 #define TVEC_CLAIMEQISH_FLOAT(tv, f0, f1, f, delta) \
2010 (tvec_claimeqish_float(tv, f0, f1, f, delta, __FILE__, __LINE__, \
2011 #f0 " /= " #f1 " (+/- " #delta ")"))
2013 /* --- @tvec_claimeq_float@, @TVEC_CLAIMEQ_FLOAT@ --- *
2015 * Arguments: @struct tvec_state *tv@ = test-vector state
2016 * @double f0, f1@ = two floating-point numbers
2017 * @const char *file@, @unsigned @lno@ = calling file and line
2018 * @const char *expr@ = the expression to quote on failure
2020 * Returns: Nonzero if @f0@ and @u1@ are identical, otherwise zero.
2022 * Use: Check that values of @f0@ and @f1@ are identical. The
2023 * function is exactly equivalent to @tvec_claimeqish_float@
2024 * with @f == TVFF_EXACT@; the macro is similarly like
2025 * @TVEC_CLAIMEQISH_FLOAT@ with @f == TVFF_EXACT@, except that
2026 * it doesn't bother to quote a delta.
2029 extern int tvec_claimeq_float(struct tvec_state */*tv*/,
2030 double /*f0*/, double /*f1*/,
2031 const char */*file*/, unsigned /*lno*/,
2032 const char */*expr*/);
2033 #define TVEC_CLAIMEQ_FLOAT(tv, f0, f1) \
2034 (tvec_claimeq_float(tv, f0, f1, __FILE__, __LINE__, #f0 " /= " #f1))
2036 /*----- Durations ---------------------------------------------------------*/
2038 /* A duration measures a time interval in seconds. The input format consists
2039 * of a nonnegative decimal floating-point number in @strtod@ format followed
2040 * by an optional unit specification.
2043 extern const struct tvec_regty tvty_duration;
2045 /* --- @tvec_parsedurunit@ --- *
2047 * Arguments: @double *scale_out@ = where to leave the scale
2048 * @const char **p_inout@ = input unit string, updated
2050 * Returns: Zero on success, %$-1$% on error.
2052 * Use: If @*p_inout@ begins with a unit string followed by the end
2053 * of the string or some non-alphanumeric character, then store
2054 * the corresponding scale factor in @*scale_out@, advance
2055 * @*p_inout@ past the unit string, and return zero. Otherwise,
2059 extern int tvec_parsedurunit(double */*scale_out*/,
2060 const char **/*p_inout*/);
2062 /* --- @tvec_claimeqish_duration@, @TVEC_CLAIMEQISH_DURATION@ --- *
2064 * Arguments: @struct tvec_state *tv@ = test-vector state
2065 * @double to, t1@ = two durations
2066 * @unsigned f@ = flags (@TVFF_...@)
2067 * @double delta@ = maximum tolerable difference
2068 * @const char *file@, @unsigned @lno@ = calling file and line
2069 * @const char *expr@ = the expression to quote on failure
2071 * Returns: Nonzero if @t0@ and @t1@ are sufficiently close, otherwise
2074 * Use: Check that values of @t0@ and @t1@ are sufficiently close.
2075 * This is essentially the same as @tvec_claimeqish_float@, only
2076 * it dumps the values as durations on a mismatch.
2078 * The @TVEC_CLAIM_FLOAT@ macro is similar, only it (a)
2079 * identifies the file and line number of the call site
2080 * automatically, and (b) implicitly quotes the source text of
2081 * the @t0@ and @t1@ arguments (and @delta@) in the failure
2085 extern int tvec_claimeqish_duration(struct tvec_state */*tv*/,
2086 double /*t0*/, double /*t1*/,
2087 unsigned /*f*/, double /*delta*/,
2088 const char */*file*/, unsigned /*lno*/,
2089 const char */*expr*/);
2090 #define TVEC_CLAIMEQISH_DURATION(tv, t0, t1, f, delta) \
2091 (tvec_claimeqish_duration(tv, t0, t1, f, delta, __FILE__, __LINE__, \
2092 #t0 " /= " #t1 " (+/- " #delta ")"))
2094 /* --- @tvec_claimeq_duration@, @TVEC_CLAIMEQ_DURATION@ --- *
2096 * Arguments: @struct tvec_state *tv@ = test-vector state
2097 * @double t0, t1@ = two durations
2098 * @const char *file@, @unsigned @lno@ = calling file and line
2099 * @const char *expr@ = the expression to quote on failure
2101 * Returns: Nonzero if @t0@ and @t1@ are identical, otherwise zero.
2103 * Use: Check that values of @t0@ and @t1@ are identical. The
2104 * function is exactly equivalent to @tvec_claimeqish_duration@
2105 * with @f == TVFF_EXACT@; the macro is similarly like
2106 * @TVEC_CLAIMEQISH_DURATION@ with @f == TVFF_EXACT@, except
2107 * that it doesn't bother to quote a delta.
2110 int tvec_claimeq_duration(struct tvec_state */*tv*/,
2111 double /*t0*/, double /*t1*/,
2112 const char */*file*/, unsigned /*lno*/,
2113 const char */*expr*/);
2114 #define TVEC_CLAIMEQ_DURATION(tv, t0, t1) \
2115 (tvec_claimeq_float(tv, t0, t1, __FILE__, __LINE__, #t0 " /= " #t1))
2117 /*----- Enumerated types --------------------------------------------------*/
2119 /* An enumeration describes a set of values of some underlying type, each of
2120 * which has a symbolic name. Values outside of the defined set can occur --
2121 * on output, because of bugs in the tested code, or on input to test
2122 * handling of unexpected values.
2124 * There is a distinct enumerated type for each of the branches of
2125 * @tvec_misc@. In the following, we write @t@ for the type code, which is
2126 * @i@ for signed integer, @u@ for unsigned integer, @f@ for floating-point,
2127 * and @p@ for pointer.
2129 * On input, an enumerated value may be given by name or as a literal value.
2130 * For enumerations based on numeric types, the literal values can be written
2131 * in the same syntax as the underlying values. For enumerations based on
2132 * pointers, the only permitted literal is %|#nil|%, which denotes a null
2133 * pointer. On output, names are preferred (with the underlying value given
2137 #define DEFENUMTY(tag, ty, slot) \
2138 extern const struct tvec_regty tvty_##slot##enum;
2139 TVEC_MISCSLOTS(DEFENUMTY)
2142 /* A @struct tvec_tassoc@ associates a string tag with a value. */
2143 #define DEFASSOC(tag_, ty, slot) \
2144 struct tvec_##slot##assoc { const char *tag; ty slot; };
2145 TVEC_MISCSLOTS(DEFASSOC)
2148 #define TVEC_ENDENUM { 0, 0 }
2150 /* Information about an enumerated type. */
2151 #define DEFINFO(tag, ty, slot) \
2152 struct tvec_##slot##enuminfo { \
2153 const char *name; /* type name for diagnostics */ \
2154 const struct tvec_##slot##assoc *av; /* name/value mappings */ \
2155 EXTRA_##tag##_INFOSLOTS /* type-specific extra info */ \
2158 #define EXTRA_INT_INFOSLOTS \
2159 const struct tvec_irange *ir; /* allowed range of raw values */
2161 #define EXTRA_UINT_INFOSLOTS \
2162 const struct tvec_urange *ur; /* allowed range of raw values */
2164 #define EXTRA_FLT_INFOSLOTS \
2165 const struct tvec_floatinfo *fi; /* range and matching policy */
2167 #define EXTRA_PTR_INFOSLOTS /* (nothing) */
2169 TVEC_MISCSLOTS(DEFINFO)
2171 #undef EXTRA_INT_INFOSLOTS
2172 #undef EXTRA_UINT_INFOSLOTS
2173 #undef EXTRA_FLT_INFOSLOTS
2174 #undef EXTRA_PTR_INFOSLOTS
2178 /* Standard enumerations. */
2179 extern const struct tvec_ienuminfo tvenum_bool;
2180 extern const struct tvec_ienuminfo tvenum_cmp;
2182 /* --- @tvec_claimeq_tenum@, @TVEC_CLAIMEQ_TENUM@ --- *
2184 * Arguments: @struct tvec_state *tv@ = test-vector state
2185 * @const struct tvec_typeenuminfo *ei@ = enumeration type info
2186 * @ty t0, t1@ = two values
2187 * @const char *file@, @unsigned @lno@ = calling file and line
2188 * @const char *expr@ = the expression to quote on failure
2190 * Returns: Nonzero if @t0@ and @t1@ are equal, otherwise zero.
2192 * Use: Check that values of @t0@ and @t1@ are equal. As for
2193 * @tvec_claim@ above, a test case is automatically begun and
2194 * ended if none is already underway. If the values are
2195 * unequal, then @tvec_fail@ is called, quoting @expr@, and the
2196 * mismatched values are dumped: @t0@ is printed as the output
2197 * value and @t1@ is printed as the input reference.
2199 * The @TVEC_CLAIM_TENUM@ macro is similar, only it (a)
2200 * identifies the file and line number of the call site
2201 * automatically, and (b) implicitly quotes the source text of
2202 * the @t0@ and @t1@ arguments in the failure message.
2205 #define DECLCLAIM(tag, ty, slot) \
2206 extern int tvec_claimeq_##slot##enum \
2207 (struct tvec_state */*tv*/, \
2208 const struct tvec_##slot##enuminfo */*ei*/, \
2209 ty /*t0*/, ty /*t1*/, \
2210 const char */*file*/, unsigned /*lno*/, const char */*expr*/);
2211 TVEC_MISCSLOTS(DECLCLAIM)
2213 #define TVEC_CLAIMEQ_IENUM(tv, ei, i0, i1) \
2214 (tvec_claimeq_ienum(tv, ei, i0, i1, \
2215 __FILE__, __LINE__, #i0 " /= " #i1))
2216 #define TVEC_CLAIMEQ_UENUM(tv, ei, u0, u1) \
2217 (tvec_claimeq_uenum(tv, ei, u0, u1, \
2218 __FILE__, __LINE__, #u0 " /= " #u1))
2219 #define TVEC_CLAIMEQ_FENUM(tv, ei, f0, f1) \
2220 (tvec_claimeq_fenum(tv, ei, f0, f1, \
2221 __FILE__, __LINE__, #f0 " /= " #f1))
2222 #define TVEC_CLAIMEQ_PENUM(tv, ei, p0, p1) \
2223 (tvec_claimeq_penum(tv, ei, p0, p1, \
2224 __FILE__, __LINE__, #p0 " /= " #p1))
2226 /*----- Flags type --------------------------------------------------------*/
2228 /* A flags value packs a number of fields into a single nonnegative integer.
2229 * Symbolic names are associated with the possible values of the various
2230 * fields; more precisely, each name is associated with a value and a
2233 * The input syntax is a sequence of items separated by `%|||%' signs. Each
2234 * item may be the symbolic name of a field value, or a literal unsigned
2235 * integer. The masks associated with the given symbolic names must be
2236 * disjoint. The resulting numerical value is simply the bitwise OR of the
2239 * On output, the table of symbolic names and their associated values and
2240 * masks is repeatedly scanned, in order, to find disjoint matches -- i.e.,
2241 * entries whose value matches the target value in the bit positions
2242 * indicated by the mask, and whose mask doesn't overlap with any previously
2243 * found matches; the names are then output, separated by `%|||%'. Any
2244 * remaining nonzero bits not covered by any of the matching masks are output
2245 * as a single literal integer, in hex.
2248 extern const struct tvec_regty tvty_flags;
2251 /* Definition of a single flag or bitfield value.
2253 * Each named setting comes with a value @v@ and a mask @m@; the mask
2254 * should cover all of the value bits, i.e., @(v&~m) == 0@.
2257 const char *tag; /* name */
2258 unsigned long m, v; /* mask and value */
2261 #define TVEC_ENDFLAGS { 0, 0, 0 }
2263 struct tvec_flaginfo {
2264 /* Information about a flags type. */
2266 const char *name; /* type name for diagnostics */
2267 const struct tvec_flag *fv; /* name/mask/value mappings */
2268 const struct tvec_urange *range; /* permitted range for literals */
2271 /* --- @tvec_claimeq_flags@, @TVEC_CLAIMEQ_FLAGS@ --- *
2273 * Arguments: @struct tvec_state *tv@ = test-vector state
2274 * @const struct tvec_flaginfo *fi@ = flags type info
2275 * @unsigned long f0, f1@ = two values
2276 * @const char *file@, @unsigned @lno@ = calling file and line
2277 * @const char *expr@ = the expression to quote on failure
2279 * Returns: Nonzero if @f0@ and @f1@ are equal, otherwise zero.
2281 * Use: Check that values of @f0@ and @f1@ are equal. As for
2282 * @tvec_claim@ above, a test case is automatically begun and
2283 * ended if none is already underway. If the values are
2284 * unequal, then @tvec_fail@ is called, quoting @expr@, and the
2285 * mismatched values are dumped: @f0@ is printed as the output
2286 * value and @f1@ is printed as the input reference.
2288 * The @TVEC_CLAIM_FLAGS@ macro is similar, only it (a)
2289 * identifies the file and line number of the call site
2290 * automatically, and (b) implicitly quotes the source text of
2291 * the @f0@ and @f1@ arguments in the failure message.
2294 extern int tvec_claimeq_flags(struct tvec_state */*tv*/,
2295 const struct tvec_flaginfo */*fi*/,
2296 unsigned long /*f0*/, unsigned long /*f1*/,
2297 const char */*file*/, unsigned /*lno*/,
2298 const char */*expr*/);
2299 #define TVEC_CLAIMEQ_FLAGS(tv, fi, f0, f1) \
2300 (tvec_claimeq_flags(tv, fi, f0, f1, \
2301 __FILE__, __LINE__, #f0 " /= " #f1))
2303 /*----- Character type ----------------------------------------------------*/
2305 /* A character value holds a character, as read by @fgetc@. The special
2306 * @EOF@ value can also be represented.
2308 * On input, a character value can be given by symbolic name, with a leading
2309 * `%|#|%'; or a character or `%|\|%'-escape sequence, optionally in single
2312 * The following escape sequences and character names are recognized.
2314 * * `%|#eof|%' is the special end-of-file marker.
2316 * * `%|#nul|%' is the NUL character, sometimes used to terminate strings.
2318 * * `%|bell|%', `%|bel|%', `%|ding|%', or `%|\a|%' is the BEL character
2319 * used to ring the terminal bell (or do some other thing to attract the
2320 * user's attention).
2322 * * %|#backspace|%, %|#bs|%, or %|\b|% is the backspace character, used to
2323 * move the cursor backwords by one cell.
2325 * * %|#escape|% %|#esc|%, or%|\e|% is the escape character, used to
2326 * introduce special terminal commands.
2328 * * %|#formfeed|%, %|#ff|%, or %|\f|% is the formfeed character, used to
2329 * separate pages of text.
2331 * * %|#newline|%, %|#linefeed|%, %|#lf|%, %|#nl|%, or %|\n|% is the
2332 * newline character, used to terminate lines of text or advance the
2333 * cursor to the next line (perhaps without returning it to the start of
2336 * * %|#return|%, %|#carriage-return|%, %|#cr|%, or %|\r|% is the
2337 * carriage-return character, used to return the cursor to the start of
2340 * * %|#tab|%, %|#horizontal-tab|%, %|#ht|%, or %|\t|% is the tab
2341 * character, used to advance the cursor to the next tab stop on the
2344 * * %|#vertical-tab|%, %|#vt|%, %|\v|% is the vertical tab character.
2346 * * %|#space|%, %|#spc|% is the space character.
2348 * * %|#delete|%, %|#del|% is the delete character, used to erase the most
2351 * * %|\'|% is the single-quote character.
2353 * * %|\\|% is the backslash character.
2355 * * %|\"|% is the double-quote character.
2357 * * %|\NNN|% or %|\{NNN}|% is the character with code NNN in octal. The
2358 * NNN may be up to three digits long.
2360 * * %|\xNN|% or %|\x{NN}|% is the character with code NNN in hexadecimal.
2363 extern const struct tvec_regty tvty_char;
2365 /* --- @tvec_claimeq_char@, @TVEC_CLAIMEQ_CHAR@ --- *
2367 * Arguments: @struct tvec_state *tv@ = test-vector state
2368 * @int ch0, ch1@ = two character codes
2369 * @const char *file@, @unsigned @lno@ = calling file and line
2370 * @const char *expr@ = the expression to quote on failure
2372 * Returns: Nonzero if @ch0@ and @ch1@ are equal, otherwise zero.
2374 * Use: Check that values of @ch0@ and @ch1@ are equal. As for
2375 * @tvec_claim@ above, a test case is automatically begun and
2376 * ended if none is already underway. If the values are
2377 * unequal, then @tvec_fail@ is called, quoting @expr@, and the
2378 * mismatched values are dumped: @ch0@ is printed as the output
2379 * value and @ch1@ is printed as the input reference.
2381 * The @TVEC_CLAIM_CHAR@ macro is similar, only it (a)
2382 * identifies the file and line number of the call site
2383 * automatically, and (b) implicitly quotes the source text of
2384 * the @ch0@ and @ch1@ arguments in the failure message.
2387 extern int tvec_claimeq_char(struct tvec_state */*tv*/,
2388 int /*ch0*/, int /*ch1*/,
2389 const char */*file*/, unsigned /*lno*/,
2390 const char */*expr*/);
2391 #define TVEC_CLAIMEQ_CHAR(tv, c0, c1) \
2392 (tvec_claimeq_char(tv, c0, c1, __FILE__, __LINE__, #c0 " /= " #c1))
2394 /*----- Text and binary string types --------------------------------------*/
2396 /* A string is a sequence of octets. Text and binary strings differ
2397 * primarily in presentation: text strings are shown as raw characters where
2398 * possible; binary strings are shown as hex dumps with an auxiliary text
2401 * The input format for both kinds of strings is basically the same: a
2402 * `compound string', consisting of
2404 * * single-quoted strings, which are interpreted entirely literally, but
2405 * can't contain single quotes or newlines;
2407 * * double-quoted strings, in which `%|\|%'-escapes are interpreted as for
2410 * * character names, marked by an initial `%|#|%' sign;
2412 * * special tokens marked by an initial `%|!|%' sign; or
2414 * * barewords interpreted according to the current coding scheme.
2416 * The special tokens are
2418 * * `%|!bare|%', which causes subsequent sequences of barewords to be
2419 * treated as plain text;
2421 * * `%|!hex|%', `%|!base32|%', `%|!base64|%', which cause subsequent
2422 * barewords to be decoded in the requested manner.
2424 * * `%|!repeat|% %$n$% %|{|% %%\textit{string}%% %|}|%', which includes
2425 * %$n$% copies of the (compound) string.
2427 * The only difference between text and binary strings is that the initial
2428 * coding scheme is %|bare|% for text strings and %|hex|% for binary strings.
2430 * Either kind of string can contain internal nul characters. A trailing nul
2431 * is appended -- beyond the stated input length -- to input strings as a
2432 * convenience to test functions. Test functions may include such a nul
2433 * character on output but this is not checked by the equality test.
2435 * A @struct tvec_urange@ may be supplied as an argument: the length of the
2436 * string (in bytes) will be checked against the permitted range.
2439 extern const struct tvec_regty tvty_text, tvty_bytes;
2441 /* --- @tvec_alloctext@, @tvec_allocbytes@ --- *
2443 * Arguments: @union tvec_regval *rv@ = register value
2444 * @size_t sz@ = required size
2448 * Use: Allocated space in a text or binary string register. If the
2449 * current register size is sufficient, its buffer is left
2450 * alone; otherwise, the old buffer, if any, is freed and a
2451 * fresh buffer allocated. These functions are not intended to
2452 * be used to adjust a buffer repeatedly, e.g., while building
2453 * output incrementally: (a) they will perform badly, and (b)
2454 * the old buffer contents are simply discarded if reallocation
2455 * is necessary. Instead, use a @dbuf@ or @dstr@.
2457 * The @tvec_alloctext@ function sneakily allocates an extra
2458 * byte for a terminating zero. The @tvec_allocbytes@ function
2462 extern void tvec_alloctext(union tvec_regval */*rv*/, size_t /*sz*/);
2463 extern void tvec_allocbytes(union tvec_regval */*rv*/, size_t /*sz*/);
2465 /* --- @tvec_claimeq_text@, @TVEC_CLAIMEQ_TEXT@ --- *
2467 * Arguments: @struct tvec_state *tv@ = test-vector state
2468 * @const char *p0@, @size_t sz0@ = first string with length
2469 * @const char *p1@, @size_t sz1@ = second string with length
2470 * @const char *file@, @unsigned @lno@ = calling file and line
2471 * @const char *expr@ = the expression to quote on failure
2473 * Returns: Nonzero if the strings at @p0@ and @p1@ are equal, otherwise
2476 * Use: Check that strings at @p0@ and @p1@ are equal. As for
2477 * @tvec_claim@ above, a test case is automatically begun and
2478 * ended if none is already underway. If the values are
2479 * unequal, then @tvec_fail@ is called, quoting @expr@, and the
2480 * mismatched values are dumped: @p0@ is printed as the output
2481 * value and @p1@ is printed as the input reference.
2483 * The @TVEC_CLAIM_TEXT@ macro is similar, only it (a)
2484 * identifies the file and line number of the call site
2485 * automatically, and (b) implicitly quotes the source text of
2486 * the @ch0@ and @ch1@ arguments in the failure message.
2489 extern int tvec_claimeq_text(struct tvec_state */*tv*/,
2490 const char */*p0*/, size_t /*sz0*/,
2491 const char */*p1*/, size_t /*sz1*/,
2492 const char */*file*/, unsigned /*lno*/,
2493 const char */*expr*/);
2494 #define TVEC_CLAIMEQ_TEXT(tv, p0, sz0, p1, sz1) \
2495 (tvec_claimeq_text(tv, p0, sz0, p1, sz1, __FILE__, __LINE__, \
2496 #p0 "[" #sz0 "] /= " #p1 "[" #sz1 "]"))
2498 /* --- @tvec_claimeq_textz@, @TVEC_CLAIMEQ_TEXTZ@ --- *
2500 * Arguments: @struct tvec_state *tv@ = test-vector state
2501 * @const char *p0, *p1@ = two strings to compare
2502 * @const char *file@, @unsigned @lno@ = calling file and line
2503 * @const char *expr@ = the expression to quote on failure
2505 * Returns: Nonzero if the strings at @p0@ and @p1@ are equal, otherwise
2508 * Use: Check that strings at @p0@ and @p1@ are equal, as for
2509 * @tvec_claimeq_string@, except that the strings are assumed
2510 * null-terminated, so their lengths don't need to be supplied
2511 * explicitly. The macro is similarly like @TVEC_CLAIMEQ_TEXT@.
2514 extern int tvec_claimeq_textz(struct tvec_state */*tv*/,
2515 const char */*p0*/, const char */*p1*/,
2516 const char */*file*/, unsigned /*lno*/,
2517 const char */*expr*/);
2518 #define TVEC_CLAIMEQ_TEXTZ(tv, p0, p1) \
2519 (tvec_claimeq_textz(tv, p0, p1, __FILE__, __LINE__, #p0 " /= " #p1))
2521 /* --- @tvec_claimeq_bytes@, @TVEC_CLAIMEQ_BYTES@ --- *
2523 * Arguments: @struct tvec_state *tv@ = test-vector state
2524 * @const void *p0@, @size_t sz0@ = first string with length
2525 * @const void *p1@, @size_t sz1@ = second string with length
2526 * @const char *file@, @unsigned @lno@ = calling file and line
2527 * @const char *expr@ = the expression to quote on failure
2529 * Returns: Nonzero if the strings at @p0@ and @p1@ are equal, otherwise
2532 * Use: Check that binary strings at @p0@ and @p1@ are equal. As for
2533 * @tvec_claim@ above, a test case is automatically begun and
2534 * ended if none is already underway. If the values are
2535 * unequal, then @tvec_fail@ is called, quoting @expr@, and the
2536 * mismatched values are dumped: @p0@ is printed as the output
2537 * value and @p1@ is printed as the input reference.
2539 * The @TVEC_CLAIM_STRING@ macro is similar, only it (a)
2540 * identifies the file and line number of the call site
2541 * automatically, and (b) implicitly quotes the source text of
2542 * the @ch0@ and @ch1@ arguments in the failure message.
2545 extern int tvec_claimeq_bytes(struct tvec_state */*tv*/,
2546 const void */*p0*/, size_t /*sz0*/,
2547 const void */*p1*/, size_t /*sz1*/,
2548 const char */*file*/, unsigned /*lno*/,
2549 const char */*expr*/);
2550 #define TVEC_CLAIMEQ_BYTES(tv, p0, sz0, p1, sz1) \
2551 (tvec_claimeq(tv, p0, sz0, p1, sz1, __FILE__, __LINE__, \
2552 #p0 "[" #sz0 "] /= " #p1 "[" #sz1 "]"))
2554 /*----- Buffer type -------------------------------------------------------*/
2556 /* Buffer registers are primarily used for benchmarking. Only a buffer's
2557 * allocation parameters are significant: its contents are ignored on
2558 * comparison and output, and unspecified on input.
2560 * The input format gives the buffer's size, and an optional alignment
2561 * specification, in the form %|SZ [`@' M [`+' A]]|%. Each of %|SZ|%, %|M|%
2562 * and %|A|% are sizes, as an integer, optionally suffixed with a unit `kB',
2563 * `MB', `GB', `TB', `PB', `EB', `ZB', `YB' (with or without the `B')
2564 * denoting a power of 1024. The %|SZ|% gives the (effective) buffer size.
2565 * %|M|% is the `alignment quantum' and %|A|% is the `alignment offset'; both
2566 * default to zero, but if %|M|% is nonzero then the start of the buffer is
2567 * aligned such that it is %|A|% more than a multiple of %|M|% bytes. Note
2568 * that %|M|% need not be a power of two, though this is common.
2570 * Units other than `B' are used on output only when the size would be
2571 * expressed exactly.
2573 * Buffers are %%\emph{not}%% allocated by default. In benchmarks, this is
2574 * best done in a @before@ function.
2576 * No @claimeq@ functions or macros are provided for buffers because they
2577 * don't seem very useful.
2580 extern const struct tvec_regty tvty_buffer;
2582 /* --- @tvec_initbuffer@ --- *
2584 * Arguments: @union tvec_regval *rv@ = register value
2585 * @const union tvec_regval *ref@ = reference buffer
2586 * @size_t sz@ = size to allocate
2590 * Use: Initialize the alignment parameters in @rv@ to match @ref@,
2591 * and the size to @sz@.
2594 extern void tvec_initbuffer(union tvec_regval */*rv*/,
2595 const union tvec_regval */*ref*/, size_t /*sz*/);
2597 /* --- @tvec_allocbuffer@ --- *
2599 * Arguments: @union tvec_regval *rv@ = register value
2603 * Use: Allocate @sz@ bytes to the buffer and fill the space with a
2604 * distinctive pattern.
2607 extern void tvec_allocbuffer(union tvec_regval */*rv*/);
2609 /*----- That's all, folks -------------------------------------------------*/