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 2016 Joyent, Inc.
14  */
15 
16 /*
17  * Register functions with quick_exit() and verify that we honor the expected
18  * function call value. We facilitate this by having a global integer and
19  * modifying it to various values in subsequent functions. If we're not called
20  * in reverse order, we should spot the differences.
21  */
22 
23 #include <stdlib.h>
24 #include <sys/debug.h>
25 
26 static int qeo_val = 5;
27 
28 static void
qeo_fifth(void)29 qeo_fifth(void)
30 {
31 	VERIFY3S(qeo_val, ==, 5);
32 	qeo_val--;
33 }
34 
35 static void
qeo_fourth(void)36 qeo_fourth(void)
37 {
38 	VERIFY3S(qeo_val, ==, 4);
39 	qeo_val--;
40 }
41 
42 static void
qeo_third(void)43 qeo_third(void)
44 {
45 	VERIFY3S(qeo_val, ==, 3);
46 	qeo_val--;
47 }
48 
49 static void
qeo_second(void)50 qeo_second(void)
51 {
52 	VERIFY3S(qeo_val, ==, 2);
53 	qeo_val--;
54 }
55 
56 static void
qeo_first(void)57 qeo_first(void)
58 {
59 	VERIFY3S(qeo_val, ==, 1);
60 	qeo_val--;
61 }
62 
63 static void
qeo_zero(void)64 qeo_zero(void)
65 {
66 	VERIFY3S(qeo_val, ==, 0);
67 }
68 
69 int
main(void)70 main(void)
71 {
72 	VERIFY0(at_quick_exit(qeo_zero));
73 	VERIFY0(at_quick_exit(qeo_first));
74 	VERIFY0(at_quick_exit(qeo_second));
75 	VERIFY0(at_quick_exit(qeo_third));
76 	VERIFY0(at_quick_exit(qeo_fourth));
77 	VERIFY0(at_quick_exit(qeo_fifth));
78 	quick_exit(0);
79 	abort();
80 }
81