xref: /titanic_41/usr/src/test/util-tests/cmd/utiltest.ksh (revision c037192b037119c9fd354732fc29b38ce097d356)
1*c037192bSGarrett D'Amore#!/usr/bin/ksh
2*c037192bSGarrett D'Amore
3*c037192bSGarrett D'Amore#
4*c037192bSGarrett D'Amore# This file and its contents are supplied under the terms of the
5*c037192bSGarrett D'Amore# Common Development and Distribution License ("CDDL"), version 1.0.
6*c037192bSGarrett D'Amore# You may only use this file in accordance with the terms of version
7*c037192bSGarrett D'Amore# 1.0 of the CDDL.
8*c037192bSGarrett D'Amore#
9*c037192bSGarrett D'Amore# A full copy of the text of the CDDL should have accompanied this
10*c037192bSGarrett D'Amore# source.  A copy of the CDDL is also available via the Internet at
11*c037192bSGarrett D'Amore# http://www.illumos.org/license/CDDL.
12*c037192bSGarrett D'Amore#
13*c037192bSGarrett D'Amore
14*c037192bSGarrett D'Amore#
15*c037192bSGarrett D'Amore# Copyright (c) 2012 by Delphix. All rights reserved.
16*c037192bSGarrett D'Amore# Copyright 2014, OmniTI Computer Consulting, Inc. All rights reserved.
17*c037192bSGarrett D'Amore# Copyright 2014 Garrett D'Amore <garrett@damore.org>
18*c037192bSGarrett D'Amore#
19*c037192bSGarrett D'Amore
20*c037192bSGarrett D'Amoreexport MY_TESTS="/opt/util-tests"
21*c037192bSGarrett D'Amorerunner="/opt/test-runner/bin/run"
22*c037192bSGarrett D'Amore
23*c037192bSGarrett D'Amorefunction fail
24*c037192bSGarrett D'Amore{
25*c037192bSGarrett D'Amore	echo $1
26*c037192bSGarrett D'Amore	exit ${2:-1}
27*c037192bSGarrett D'Amore}
28*c037192bSGarrett D'Amore
29*c037192bSGarrett D'Amorefunction find_runfile
30*c037192bSGarrett D'Amore{
31*c037192bSGarrett D'Amore	typeset distro=
32*c037192bSGarrett D'Amore	if [[ -d /opt/delphix && -h /etc/delphix/version ]]; then
33*c037192bSGarrett D'Amore		distro=delphix
34*c037192bSGarrett D'Amore	elif [[ 0 -ne $(grep -c OpenIndiana /etc/release 2>/dev/null) ]]; then
35*c037192bSGarrett D'Amore		distro=openindiana
36*c037192bSGarrett D'Amore	elif [[ 0 -ne $(grep -c OmniOS /etc/release 2>/dev/null) ]]; then
37*c037192bSGarrett D'Amore		distro=omnios
38*c037192bSGarrett D'Amore	elif [[ -f $MY_TESTS/runfiles/default.run ]]; then
39*c037192bSGarrett D'Amore		# optional catch-all
40*c037192bSGarrett D'Amore		distro=default
41*c037192bSGarrett D'Amore	fi
42*c037192bSGarrett D'Amore
43*c037192bSGarrett D'Amore	[[ -n $distro ]] && echo $MY_TESTS/runfiles/$distro.run
44*c037192bSGarrett D'Amore}
45*c037192bSGarrett D'Amore
46*c037192bSGarrett D'Amorewhile getopts c: c; do
47*c037192bSGarrett D'Amore	case $c in
48*c037192bSGarrett D'Amore	'c')
49*c037192bSGarrett D'Amore		runfile=$OPTARG
50*c037192bSGarrett D'Amore		[[ -f $runfile ]] || fail "Cannot read file: $runfile"
51*c037192bSGarrett D'Amore		;;
52*c037192bSGarrett D'Amore	esac
53*c037192bSGarrett D'Amoredone
54*c037192bSGarrett D'Amoreshift $((OPTIND - 1))
55*c037192bSGarrett D'Amore
56*c037192bSGarrett D'Amore[[ -z $runfile ]] && runfile=$(find_runfile)
57*c037192bSGarrett D'Amore[[ -z $runfile ]] && fail "Couldn't determine distro"
58*c037192bSGarrett D'Amore
59*c037192bSGarrett D'Amore$runner -c $runfile
60*c037192bSGarrett D'Amore
61*c037192bSGarrett D'Amoreexit $?
62