| 1 | #!/bin/bash |
| 2 | # |
| 3 | # SPDX-License-Identifier: GPL-2.0-only |
| 4 | # |
| 5 | # Copyright (c) 2019 Michael Jeanson <mjeanson@efficios.com> |
| 6 | # Copyright (C) 2019 Philippe Proulx <pproulx@efficios.com> |
| 7 | # |
| 8 | |
| 9 | # This file is meant to be sourced at the start of shell script-based tests. |
| 10 | |
| 11 | |
| 12 | # Error out when encountering an undefined variable |
| 13 | set -u |
| 14 | |
| 15 | # If "readlink -f" is available, get a resolved absolute path to the |
| 16 | # tests source dir, otherwise make do with a relative path. |
| 17 | scriptdir="$(dirname "${BASH_SOURCE[0]}")" |
| 18 | if readlink -f "." >/dev/null 2>&1; then |
| 19 | testsdir=$(readlink -f "$scriptdir/..") |
| 20 | else |
| 21 | testsdir="$scriptdir/.." |
| 22 | fi |
| 23 | |
| 24 | # Allow overriding the source and build directories |
| 25 | if [ "x${UST_TESTS_SRCDIR:-}" = "x" ]; then |
| 26 | UST_TESTS_SRCDIR="$testsdir" |
| 27 | fi |
| 28 | export UST_TESTS_SRCDIR |
| 29 | |
| 30 | if [ "x${UST_TESTS_BUILDDIR:-}" = "x" ]; then |
| 31 | UST_TESTS_BUILDDIR="$testsdir" |
| 32 | fi |
| 33 | export UST_TESTS_BUILDDIR |
| 34 | |
| 35 | # The OS on which we are running. See [1] for possible values of 'uname -s'. |
| 36 | # We do a bit of translation to ease our life down the road for comparison. |
| 37 | # Export it so that called executables can use it. |
| 38 | # [1] https://en.wikipedia.org/wiki/Uname#Examples |
| 39 | if [ "x${UST_OS_TYPE:-}" = "x" ]; then |
| 40 | UST_OS_TYPE="$(uname -s)" |
| 41 | case "$UST_OS_TYPE" in |
| 42 | MINGW*) |
| 43 | UST_OS_TYPE="mingw" |
| 44 | ;; |
| 45 | Darwin) |
| 46 | UST_OS_TYPE="darwin" |
| 47 | ;; |
| 48 | Linux) |
| 49 | UST_OS_TYPE="linux" |
| 50 | ;; |
| 51 | CYGWIN*) |
| 52 | UST_OS_TYPE="cygwin" |
| 53 | ;; |
| 54 | FreeBSD) |
| 55 | UST_OS_TYPE="freebsd" |
| 56 | ;; |
| 57 | *) |
| 58 | UST_OS_TYPE="unsupported" |
| 59 | ;; |
| 60 | esac |
| 61 | fi |
| 62 | export UST_OS_TYPE |
| 63 | |