1#!/usr/bin/ksh
2#
3# This file and its contents are supplied under the terms of the
4# Common Development and Distribution License ("CDDL"), version 1.0.
5# You may only use this file in accordance with the terms of version
6# 1.0 of the CDDL.
7#
8# A full copy of the text of the CDDL should have accompanied this
9# source.  A copy of the CDDL is also available via the Internet at
10# http://www.illumos.org/license/CDDL.
11#
12
13#
14# Copyright 2016 Joyent, Inc.
15#
16
17#
18# Test quick_exit(3C). We specifically test the following things:
19#    o That we get a requested exit status
20#    o That at_quick_exit() functions fire in a registered, reverse order.
21#
22# These are all done by helper programs
23#
24
25set -o errexit
26set -o pipefail
27
28qe_root=$(dirname $0)
29qe_status32=$qe_root/quick_exit_status.32
30qe_status64=$qe_root/quick_exit_status.64
31qe_order32=$qe_root/quick_exit_order.32
32qe_order64=$qe_root/quick_exit_order.64
33
34function fatal
35{
36	typeset msg="$*"
37	echo "Test Failed: $msg" >&2
38	exit 1
39}
40
41function check_status
42{
43	typeset stat=$1
44	$qe_status32 $stat
45	if [[ $? -ne $stat ]]; then
46		fatal "Test failed: Expected $qestatus32 to exit $stat " \
47		    "got $?"
48	fi
49
50	$qe_status64 $stat
51	if [[ $? -ne $stat ]]; then
52		fatal "Test failed: Expected $qestatus64 to exit $stat " \
53		    "got $?" >&2
54	fi
55}
56
57function check_order
58{
59	$qe_order32 || fatal "$qe_order32 returned $?"
60	$qe_order64 || fatal "$qe_order32 returned $?"
61}
62
63check_status 0
64check_status 23
65check_status 42
66check_order
67exit 0
68