xref: /illumos-gate/usr/src/test/util-tests/cmd/utiltest.ksh (revision e5c541a6c70df2548bbaa19fa43a7dbebe4b637a)
1598f4ceeSGarrett D'Amore#!/usr/bin/ksh
2598f4ceeSGarrett D'Amore
3598f4ceeSGarrett D'Amore#
4598f4ceeSGarrett D'Amore# This file and its contents are supplied under the terms of the
5598f4ceeSGarrett D'Amore# Common Development and Distribution License ("CDDL"), version 1.0.
6598f4ceeSGarrett D'Amore# You may only use this file in accordance with the terms of version
7598f4ceeSGarrett D'Amore# 1.0 of the CDDL.
8598f4ceeSGarrett D'Amore#
9598f4ceeSGarrett D'Amore# A full copy of the text of the CDDL should have accompanied this
10598f4ceeSGarrett D'Amore# source.  A copy of the CDDL is also available via the Internet at
11598f4ceeSGarrett D'Amore# http://www.illumos.org/license/CDDL.
12598f4ceeSGarrett D'Amore#
13598f4ceeSGarrett D'Amore
14598f4ceeSGarrett D'Amore#
15598f4ceeSGarrett D'Amore# Copyright (c) 2012 by Delphix. All rights reserved.
16598f4ceeSGarrett D'Amore# Copyright 2014, OmniTI Computer Consulting, Inc. All rights reserved.
17598f4ceeSGarrett D'Amore# Copyright 2014 Garrett D'Amore <garrett@damore.org>
18598f4ceeSGarrett D'Amore#
19598f4ceeSGarrett D'Amore
20a1cdd5a6SToomas Soomeexport PATH="${PATH}:/opt/onbld/bin/$(uname -p)"
21a1cdd5a6SToomas Soomeexport LC_ALL="C"
22598f4ceeSGarrett D'Amoreexport MY_TESTS="/opt/util-tests"
23598f4ceeSGarrett D'Amorerunner="/opt/test-runner/bin/run"
24598f4ceeSGarrett D'Amore
25598f4ceeSGarrett D'Amorefunction fail
26598f4ceeSGarrett D'Amore{
27598f4ceeSGarrett D'Amore	echo $1
28598f4ceeSGarrett D'Amore	exit ${2:-1}
29598f4ceeSGarrett D'Amore}
30598f4ceeSGarrett D'Amore
31598f4ceeSGarrett D'Amorefunction find_runfile
32598f4ceeSGarrett D'Amore{
33598f4ceeSGarrett D'Amore	typeset distro=
34598f4ceeSGarrett D'Amore	if [[ -d /opt/delphix && -h /etc/delphix/version ]]; then
35598f4ceeSGarrett D'Amore		distro=delphix
36598f4ceeSGarrett D'Amore	elif [[ 0 -ne $(grep -c OpenIndiana /etc/release 2>/dev/null) ]]; then
37598f4ceeSGarrett D'Amore		distro=openindiana
38598f4ceeSGarrett D'Amore	elif [[ 0 -ne $(grep -c OmniOS /etc/release 2>/dev/null) ]]; then
39598f4ceeSGarrett D'Amore		distro=omnios
40*e5c541a6SRobert Mustacchi	fi
41*e5c541a6SRobert Mustacchi
42*e5c541a6SRobert Mustacchi	if [[ ! -f $MY_TESTS/runfiles/$distro.run ]] && \
43*e5c541a6SRobert Mustacchi	   [[ -f $MY_TESTS/runfiles/default.run ]]; then
44598f4ceeSGarrett D'Amore		distro=default
45598f4ceeSGarrett D'Amore	fi
46598f4ceeSGarrett D'Amore
47598f4ceeSGarrett D'Amore	[[ -n $distro ]] && echo $MY_TESTS/runfiles/$distro.run
48598f4ceeSGarrett D'Amore}
49598f4ceeSGarrett D'Amore
50598f4ceeSGarrett D'Amorewhile getopts c: c; do
51598f4ceeSGarrett D'Amore	case $c in
52598f4ceeSGarrett D'Amore	'c')
53598f4ceeSGarrett D'Amore		runfile=$OPTARG
54598f4ceeSGarrett D'Amore		[[ -f $runfile ]] || fail "Cannot read file: $runfile"
55598f4ceeSGarrett D'Amore		;;
56598f4ceeSGarrett D'Amore	esac
57598f4ceeSGarrett D'Amoredone
58598f4ceeSGarrett D'Amoreshift $((OPTIND - 1))
59598f4ceeSGarrett D'Amore
60598f4ceeSGarrett D'Amore[[ -z $runfile ]] && runfile=$(find_runfile)
61598f4ceeSGarrett D'Amore[[ -z $runfile ]] && fail "Couldn't determine distro"
62598f4ceeSGarrett D'Amore
63598f4ceeSGarrett D'Amore$runner -c $runfile
64598f4ceeSGarrett D'Amore
65598f4ceeSGarrett D'Amoreexit $?
66