2 * Basic utility routines for the TAP protocol.
4 * Copyright 2009, 2010 Russ Allbery <rra@stanford.edu>
5 * Copyright 2006, 2007, 2008
6 * Board of Trustees, Leland Stanford Jr. University
7 * Copyright (c) 2004, 2005, 2006
8 * by Internet Systems Consortium, Inc. ("ISC")
9 * Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
10 * 2002, 2003 by The Internet Software Consortium and Rich Salz
12 * See LICENSE for licensing terms.
18 #include <sys/types.h> /* pid_t */
21 * __attribute__ is available in gcc 2.5 and later, but only with gcc 2.7
22 * could you use the __format__ form of the attributes, which is what we use
23 * (to avoid confusion with other macros).
26 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
27 # define __attribute__(spec) /* empty */
32 * BEGIN_DECLS is used at the beginning of declarations so that C++
33 * compilers don't mangle their names. END_DECLS is used at the end.
38 # define BEGIN_DECLS extern "C" {
41 # define BEGIN_DECLS /* empty */
42 # define END_DECLS /* empty */
46 * Used for iterating through arrays. ARRAY_SIZE returns the number of
47 * elements in the array (useful for a < upper bound in a for loop) and
48 * ARRAY_END returns a pointer to the element past the end (ISO C99 makes it
49 * legal to refer to such a pointer as long as it's never dereferenced).
51 #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
52 #define ARRAY_END(array) (&(array)[ARRAY_SIZE(array)])
57 * The test count. Always contains the number that will be used for the next
60 extern unsigned long testnum;
62 /* Print out the number of tests and set standard output to line buffered. */
63 void plan(unsigned long count);
66 * Prepare for lazy planning, in which the plan will be printed automatically
67 * at the end of the test program.
71 /* Skip the entire test suite. Call instead of plan. */
72 void skip_all(const char *format, ...)
73 __attribute__((__noreturn__, __format__(printf, 1, 2)));
75 /* Basic reporting functions. */
76 void ok(int success, const char *format, ...)
77 __attribute__((__format__(printf, 2, 3)));
78 void skip(const char *reason, ...)
79 __attribute__((__format__(printf, 1, 2)));
81 /* Report the same status on, or skip, the next count tests. */
82 void ok_block(unsigned long count, int success, const char *format, ...)
83 __attribute__((__format__(printf, 3, 4)));
84 void skip_block(unsigned long count, const char *reason, ...)
85 __attribute__((__format__(printf, 2, 3)));
87 /* Check an expected value against a seen value. */
88 void is_int(long wanted, long seen, const char *format, ...)
89 __attribute__((__format__(printf, 3, 4)));
90 void is_double(double wanted, double seen, const char *format, ...)
91 __attribute__((__format__(printf, 3, 4)));
92 void is_string(const char *wanted, const char *seen, const char *format, ...)
93 __attribute__((__format__(printf, 3, 4)));
94 void is_hex(unsigned long wanted, unsigned long seen, const char *format, ...)
95 __attribute__((__format__(printf, 3, 4)));
97 /* Bail out with an error. sysbail appends strerror(errno). */
98 void bail(const char *format, ...)
99 __attribute__((__noreturn__, __nonnull__, __format__(printf, 1, 2)));
100 void sysbail(const char *format, ...)
101 __attribute__((__noreturn__, __nonnull__, __format__(printf, 1, 2)));
103 /* Report a diagnostic to stderr prefixed with #. */
104 void diag(const char *format, ...)
105 __attribute__((__nonnull__, __format__(printf, 1, 2)));
106 void sysdiag(const char *format, ...)
107 __attribute__((__nonnull__, __format__(printf, 1, 2)));
111 #endif /* LIBTEST_H */