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