1 | /* |
---|
2 | * Basic utility routines for the TAP protocol. |
---|
3 | * |
---|
4 | * Copyright 2006, 2007, 2008 |
---|
5 | * Board of Trustees, Leland Stanford Jr. University |
---|
6 | * Copyright (c) 2004, 2005, 2006 |
---|
7 | * by Internet Systems Consortium, Inc. ("ISC") |
---|
8 | * Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, |
---|
9 | * 2002, 2003 by The Internet Software Consortium and Rich Salz |
---|
10 | * |
---|
11 | * See LICENSE for licensing terms. |
---|
12 | */ |
---|
13 | |
---|
14 | #ifndef TAP_BASIC_H |
---|
15 | #define TAP_BASIC_H 1 |
---|
16 | |
---|
17 | #include <sys/types.h> /* pid_t */ |
---|
18 | |
---|
19 | /* |
---|
20 | * __attribute__ is available in gcc 2.5 and later, but only with gcc 2.7 |
---|
21 | * could you use the __format__ form of the attributes, which is what we use |
---|
22 | * (to avoid confusion with other macros). |
---|
23 | */ |
---|
24 | #ifndef __attribute__ |
---|
25 | # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) |
---|
26 | # define __attribute__(spec) /* empty */ |
---|
27 | # endif |
---|
28 | #endif |
---|
29 | |
---|
30 | /* |
---|
31 | * BEGIN_DECLS is used at the beginning of declarations so that C++ |
---|
32 | * compilers don't mangle their names. END_DECLS is used at the end. |
---|
33 | */ |
---|
34 | #undef BEGIN_DECLS |
---|
35 | #undef END_DECLS |
---|
36 | #ifdef __cplusplus |
---|
37 | # define BEGIN_DECLS extern "C" { |
---|
38 | # define END_DECLS } |
---|
39 | #else |
---|
40 | # define BEGIN_DECLS /* empty */ |
---|
41 | # define END_DECLS /* empty */ |
---|
42 | #endif |
---|
43 | |
---|
44 | /* |
---|
45 | * Used for iterating through arrays. ARRAY_SIZE returns the number of |
---|
46 | * elements in the array (useful for a < upper bound in a for loop) and |
---|
47 | * ARRAY_END returns a pointer to the element past the end (ISO C99 makes it |
---|
48 | * legal to refer to such a pointer as long as it's never dereferenced). |
---|
49 | */ |
---|
50 | #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0])) |
---|
51 | #define ARRAY_END(array) (&(array)[ARRAY_SIZE(array)]) |
---|
52 | |
---|
53 | BEGIN_DECLS |
---|
54 | |
---|
55 | /* |
---|
56 | * The test count. Always contains the number that will be used for the next |
---|
57 | * test status. |
---|
58 | */ |
---|
59 | extern int testnum; |
---|
60 | |
---|
61 | /* Print out the number of tests and set standard output to line buffered. */ |
---|
62 | void plan(int count); |
---|
63 | |
---|
64 | /* Skip the entire test suite. Call instead of plan. */ |
---|
65 | void skip_all(const char *format, ...) |
---|
66 | __attribute__((__noreturn__, __format__(printf, 1, 2))); |
---|
67 | |
---|
68 | /* Basic reporting functions. */ |
---|
69 | void ok(int success, const char *format, ...) |
---|
70 | __attribute__((__format__(printf, 2, 3))); |
---|
71 | void skip(const char *reason, ...) |
---|
72 | __attribute__((__format__(printf, 1, 2))); |
---|
73 | |
---|
74 | /* Report the same status on, or skip, the next count tests. */ |
---|
75 | void ok_block(int count, int success, const char *format, ...) |
---|
76 | __attribute__((__format__(printf, 3, 4))); |
---|
77 | void skip_block(int count, const char *reason, ...) |
---|
78 | __attribute__((__format__(printf, 2, 3))); |
---|
79 | |
---|
80 | /* Check an expected value against a seen value. */ |
---|
81 | void is_int(int wanted, int seen, const char *format, ...) |
---|
82 | __attribute__((__format__(printf, 3, 4))); |
---|
83 | void is_double(double wanted, double seen, const char *format, ...) |
---|
84 | __attribute__((__format__(printf, 3, 4))); |
---|
85 | void is_string(const char *wanted, const char *seen, const char *format, ...) |
---|
86 | __attribute__((__format__(printf, 3, 4))); |
---|
87 | void is_hex(unsigned long wanted, unsigned long seen, const char *format, ...) |
---|
88 | __attribute__((__format__(printf, 3, 4))); |
---|
89 | |
---|
90 | /* Bail out with an error. sysbail appends strerror(errno). */ |
---|
91 | void bail(const char *format, ...) |
---|
92 | __attribute__((__noreturn__, __format__(printf, 1, 2))); |
---|
93 | void sysbail(const char *format, ...) |
---|
94 | __attribute__((__noreturn__, __format__(printf, 1, 2))); |
---|
95 | |
---|
96 | END_DECLS |
---|
97 | |
---|
98 | #endif /* LIBTEST_H */ |
---|