1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2023 Oxide Computer Company
14  */
15 
16 #include <err.h>
17 #include <string.h>
18 #include <stdlib.h>
19 
20 #include "common.h"
21 
22 void
test_fail(const char * fmt,...)23 test_fail(const char *fmt, ...)
24 {
25 	va_list args;
26 	char *fmt_hdr = NULL;
27 
28 	va_start(args, fmt);
29 	(void) asprintf(&fmt_hdr, "TEST FAILED - %s", fmt);
30 	verrx(EXIT_FAILURE, fmt_hdr, args);
31 	/* NOTREATCHED */
32 	va_end(args);
33 }
34 
35 void
test_pass(void)36 test_pass(void)
37 {
38 	errx(EXIT_SUCCESS, "TEST PASSED");
39 	/* NOTREATCHED */
40 }
41 
42 int
test_basic_prep(int sigfd_flags)43 test_basic_prep(int sigfd_flags)
44 {
45 	sigset_t mask;
46 
47 	assert(sigemptyset(&mask) == 0);
48 	assert(sigaddset(&mask, SIGUSR1) == 0);
49 	assert(sigaddset(&mask, SIGUSR2) == 0);
50 	assert(sigaddset(&mask, SIGALRM) == 0);
51 
52 	int fd = signalfd(-1, &mask, sigfd_flags);
53 	assert(fd >= 0);
54 
55 	assert(sigprocmask(SIG_BLOCK, &mask, NULL) == 0);
56 
57 	return (fd);
58 }
59