xref: /openbsd-src/regress/sys/kern/flock/util.h (revision cdea53de8c31eb4f1cc163c500ea6568511cbde6)
1*cdea53deSanton /*	$OpenBSD: util.h,v 1.1 2018/11/06 18:11:11 anton Exp $	*/
2*cdea53deSanton 
3*cdea53deSanton /*
4*cdea53deSanton  * Copyright (c) 2018 Anton Lindqvist <anton@openbsd.org>
5*cdea53deSanton  *
6*cdea53deSanton  * Permission to use, copy, modify, and distribute this software for any
7*cdea53deSanton  * purpose with or without fee is hereby granted, provided that the above
8*cdea53deSanton  * copyright notice and this permission notice appear in all copies.
9*cdea53deSanton  *
10*cdea53deSanton  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11*cdea53deSanton  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12*cdea53deSanton  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13*cdea53deSanton  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14*cdea53deSanton  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15*cdea53deSanton  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16*cdea53deSanton  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*cdea53deSanton  */
18*cdea53deSanton 
19*cdea53deSanton #define FAIL(test) do {							\
20*cdea53deSanton 	if (test) {							\
21*cdea53deSanton 		if (verbose)						\
22*cdea53deSanton 			printf("%s: %d: FAIL (%s)\n",			\
23*cdea53deSanton 			    __func__, __LINE__, #test);			\
24*cdea53deSanton 		return -1;						\
25*cdea53deSanton 	}								\
26*cdea53deSanton } while (0)
27*cdea53deSanton 
28*cdea53deSanton #define SUCCEED do {							\
29*cdea53deSanton 	if (verbose)							\
30*cdea53deSanton 		printf("SUCCEED\n");					\
31*cdea53deSanton 	return 0;							\
32*cdea53deSanton } while (0)
33*cdea53deSanton 
34*cdea53deSanton struct test {
35*cdea53deSanton 	int (*testfn)(int);	/* function to perform the test */
36*cdea53deSanton 	int intr;		/* non-zero if the test interrupts a lock */
37*cdea53deSanton };
38*cdea53deSanton 
39*cdea53deSanton int		make_file(off_t size);
40*cdea53deSanton int		safe_waitpid(pid_t pid);
41*cdea53deSanton __dead void	usage(void);
42*cdea53deSanton 
43*cdea53deSanton extern int verbose;
44