Update .gitignore files
[openafs.git] / tests / tap / basic.h
1 /*
2  * Basic utility routines for the TAP protocol.
3  *
4  * This file is part of C TAP Harness.  The current version plus supporting
5  * documentation is at <http://www.eyrie.org/~eagle/software/c-tap-harness/>.
6  *
7  * Copyright 2009, 2010 Russ Allbery <rra@stanford.edu>
8  * Copyright 2001, 2002, 2004, 2005, 2006, 2007, 2008
9  *     The Board of Trustees of the Leland Stanford Junior University
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included in
19  * all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  */
29
30 #ifndef TAP_BASIC_H
31 #define TAP_BASIC_H 1
32
33 #include <stdarg.h>             /* va_list */
34 #include <sys/types.h>          /* pid_t */
35
36 /*
37  * __attribute__ is available in gcc 2.5 and later, but only with gcc 2.7
38  * could you use the __format__ form of the attributes, which is what we use
39  * (to avoid confusion with other macros).
40  */
41 #ifndef __attribute__
42 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
43 #  define __attribute__(spec)   /* empty */
44 # endif
45 #endif
46
47 /*
48  * BEGIN_DECLS is used at the beginning of declarations so that C++
49  * compilers don't mangle their names.  END_DECLS is used at the end.
50  */
51 #undef BEGIN_DECLS
52 #undef END_DECLS
53 #ifdef __cplusplus
54 # define BEGIN_DECLS    extern "C" {
55 # define END_DECLS      }
56 #else
57 # define BEGIN_DECLS    /* empty */
58 # define END_DECLS      /* empty */
59 #endif
60
61 /*
62  * Used for iterating through arrays.  ARRAY_SIZE returns the number of
63  * elements in the array (useful for a < upper bound in a for loop) and
64  * ARRAY_END returns a pointer to the element past the end (ISO C99 makes it
65  * legal to refer to such a pointer as long as it's never dereferenced).
66  */
67 #define ARRAY_SIZE(array)       (sizeof(array) / sizeof((array)[0]))
68 #define ARRAY_END(array)        (&(array)[ARRAY_SIZE(array)])
69
70 BEGIN_DECLS
71
72 /*
73  * The test count.  Always contains the number that will be used for the next
74  * test status.
75  */
76 extern unsigned long testnum;
77
78 /* Print out the number of tests and set standard output to line buffered. */
79 void plan(unsigned long count);
80
81 /*
82  * Prepare for lazy planning, in which the plan will be  printed automatically
83  * at the end of the test program.
84  */
85 void plan_lazy(void);
86
87 /* Skip the entire test suite.  Call instead of plan. */
88 void skip_all(const char *format, ...)
89     __attribute__((__noreturn__, __format__(printf, 1, 2)));
90
91 /*
92  * Basic reporting functions.  The okv() function is the same as ok() but
93  * takes the test description as a va_list to make it easier to reuse the
94  * reporting infrastructure when writing new tests.
95  */
96 void ok(int success, const char *format, ...)
97     __attribute__((__format__(printf, 2, 3)));
98 void okv(int success, const char *format, va_list args);
99 void skip(const char *reason, ...)
100     __attribute__((__format__(printf, 1, 2)));
101
102 /* Report the same status on, or skip, the next count tests. */
103 void ok_block(unsigned long count, int success, const char *format, ...)
104     __attribute__((__format__(printf, 3, 4)));
105 void skip_block(unsigned long count, const char *reason, ...)
106     __attribute__((__format__(printf, 2, 3)));
107
108 /* Check an expected value against a seen value. */
109 void is_int(long wanted, long seen, const char *format, ...)
110     __attribute__((__format__(printf, 3, 4)));
111 void is_double(double wanted, double seen, double epsilon,
112                const char *format, ...)
113     __attribute__((__format__(printf, 4, 5)));
114 void is_string(const char *wanted, const char *seen, const char *format, ...)
115     __attribute__((__format__(printf, 3, 4)));
116 void is_hex(unsigned long wanted, unsigned long seen, const char *format, ...)
117     __attribute__((__format__(printf, 3, 4)));
118
119 /* Bail out with an error.  sysbail appends strerror(errno). */
120 void bail(const char *format, ...)
121     __attribute__((__noreturn__, __nonnull__, __format__(printf, 1, 2)));
122 void sysbail(const char *format, ...)
123     __attribute__((__noreturn__, __nonnull__, __format__(printf, 1, 2)));
124
125 /* Report a diagnostic to stderr prefixed with #. */
126 void diag(const char *format, ...)
127     __attribute__((__nonnull__, __format__(printf, 1, 2)));
128 void sysdiag(const char *format, ...)
129     __attribute__((__nonnull__, __format__(printf, 1, 2)));
130
131 /*
132  * Find a test file under BUILD or SOURCE, returning the full path.  The
133  * returned path should be freed with test_file_path_free().
134  */
135 char *test_file_path(const char *file)
136     __attribute__((__malloc__, __nonnull__));
137 void test_file_path_free(char *path);
138
139 END_DECLS
140
141 #endif /* TAP_BASIC_H */