xref: /freebsd/tests/sys/audit/utils.h (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
1f7f4e0f7SAlan Somers /*-
2f7f4e0f7SAlan Somers  * Copyright 2018 Aniket Pandey
3f7f4e0f7SAlan Somers  *
4f7f4e0f7SAlan Somers  * Redistribution and use in source and binary forms, with or without
5f7f4e0f7SAlan Somers  * modification, are permitted provided that the following conditions
6f7f4e0f7SAlan Somers  * are met:
7f7f4e0f7SAlan Somers  * 1. Redistributions of source code must retain the above copyright
8f7f4e0f7SAlan Somers  *    notice, this list of conditions and the following disclaimer.
9f7f4e0f7SAlan Somers  * 2. Redistributions in binary form must reproduce the above copyright
10f7f4e0f7SAlan Somers  *    notice, this list of conditions and the following disclaimer in the
11f7f4e0f7SAlan Somers  *    documentation and/or other materials provided with the distribution.
12f7f4e0f7SAlan Somers  *
13f7f4e0f7SAlan Somers  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14f7f4e0f7SAlan Somers  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15f7f4e0f7SAlan Somers  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16f7f4e0f7SAlan Somers  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17f7f4e0f7SAlan Somers  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18f7f4e0f7SAlan Somers  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19f7f4e0f7SAlan Somers  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
20f7f4e0f7SAlan Somers  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21f7f4e0f7SAlan Somers  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22f7f4e0f7SAlan Somers  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23f7f4e0f7SAlan Somers  * SUCH DAMAGE.
24f7f4e0f7SAlan Somers  */
25f7f4e0f7SAlan Somers 
26f7f4e0f7SAlan Somers 
27f7f4e0f7SAlan Somers #ifndef _UTILS_H_
28f7f4e0f7SAlan Somers #define _UTILS_H_
29f7f4e0f7SAlan Somers 
30f7f4e0f7SAlan Somers #include <poll.h>
31f7f4e0f7SAlan Somers #include <stdio.h>
32f7f4e0f7SAlan Somers #include <stdbool.h>
33f7f4e0f7SAlan Somers #include <bsm/audit.h>
34f7f4e0f7SAlan Somers 
35f7f4e0f7SAlan Somers void check_audit(struct pollfd [], const char *, FILE *);
36f7f4e0f7SAlan Somers FILE *setup(struct pollfd [], const char *);
37f7f4e0f7SAlan Somers void cleanup(void);
38*40407d39SAlex Richardson void skip_if_extattr_not_supported(const char *);
39*40407d39SAlex Richardson 
40*40407d39SAlex Richardson #define REQUIRE_EXTATTR_SUCCESS(call)						\
41*40407d39SAlex Richardson 	({									\
42*40407d39SAlex Richardson 		errno = 0; /* Reset errno before call */			\
43*40407d39SAlex Richardson 		ssize_t result = (call);					\
44*40407d39SAlex Richardson 		if (result == -1) {						\
45*40407d39SAlex Richardson 			atf_tc_fail_requirement(__FILE__, __LINE__,		\
46*40407d39SAlex Richardson 			    "%s failed with errno %d (%s)", #call, errno,	\
47*40407d39SAlex Richardson 			    strerror(errno));					\
48*40407d39SAlex Richardson 		}								\
49*40407d39SAlex Richardson 		result;								\
50*40407d39SAlex Richardson 	})
51*40407d39SAlex Richardson 
52*40407d39SAlex Richardson #define REQUIRE_EXTATTR_RESULT(_expected, expr)					\
53*40407d39SAlex Richardson 	do {									\
54*40407d39SAlex Richardson 		ssize_t expected = (_expected);					\
55*40407d39SAlex Richardson 		ssize_t _result = REQUIRE_EXTATTR_SUCCESS(expr);		\
56*40407d39SAlex Richardson 		ATF_REQUIRE_EQ_MSG(expected, _result, "%s: %zd != %zd", #expr,	\
57*40407d39SAlex Richardson 		    expected, _result);						\
58*40407d39SAlex Richardson 	} while (0)
59f7f4e0f7SAlan Somers 
60f7f4e0f7SAlan Somers #endif  /* _SETUP_H_ */
61