xref: /illumos-gate/usr/src/test/header-tests/cmd/headertest.ksh (revision a7cee4e9766ebda975dd156d1f10a70f51c242f0)
1#!/usr/bin/ksh
2
3#
4# This file and its contents are supplied under the terms of the
5# Common Development and Distribution License ("CDDL"), version 1.0.
6# You may only use this file in accordance with the terms of version
7# 1.0 of the CDDL.
8#
9# A full copy of the text of the CDDL should have accompanied this
10# source.  A copy of the CDDL is also available via the Internet at
11# http://www.illumos.org/license/CDDL.
12#
13
14#
15# Copyright (c) 2012 by Delphix. All rights reserved.
16# Copyright 2014, OmniTI Computer Consulting, Inc. All rights reserved.
17# Copyright 2016, Joyent, Inc.
18#
19
20case $0 in
21/opt/header-tests/bin/headertest)
22	root=""
23	;;
24/*/opt/header-tests/bin/headertest)
25	root="${0%/opt/header-tests/bin/headertest}"
26	;;
27*/opt/header-tests/bin/headertest)
28	root="$PWD/${0%/opt/header-tests/bin/headertest}"
29	;;
30esac
31
32# See ../tests/common/symbol_test.py
33[[ -n "$root" ]] && export HEADER_TEST_ROOT="$root"
34
35export MY_TESTS="$root/opt/header-tests"
36runner="$root/opt/test-runner/bin/run"
37outdir="$root/var/tmp/test_results"
38
39function fail
40{
41	echo $1
42	exit ${2:-1}
43}
44
45function find_runfile
46{
47	typeset distro=
48	if [[ -f "$MY_TESTS/runfiles/default.run" ]]; then
49		distro=default
50	fi
51
52	[[ -n "$distro" ]] && echo "$MY_TESTS/runfiles/$distro.run"
53}
54
55while getopts c:T: c; do
56	case $c in
57	'c')
58		runfile="$OPTARG"
59		[[ -f $runfile ]] || fail "Cannot read file: $runfile"
60		;;
61	'T')
62		xargs+=( -T "$OPTARG" )
63		;;
64	esac
65done
66shift $((OPTIND - 1))
67
68[[ -z "$runfile" ]] && runfile=$(find_runfile)
69[[ -z "$runfile" ]] && fail "Couldn't determine distro"
70
71"$runner" -c "$runfile" -i "$MY_TESTS" -o "$outdir" "${xargs[@]}"
72