Alex Thiessen | 15aad88 | 2018-01-02 17:40:55 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | ## |
| 4 | ## This file is part of the coreboot project. |
| 5 | ## |
| 6 | ## Copyright (C) 2003-2018 Alex Thiessen <alex.thiessen.de+coreboot@gmail.com> |
| 7 | ## |
| 8 | ## This program is free software; you can redistribute it and/or modify |
| 9 | ## it under the terms of the GNU General Public License as published by |
| 10 | ## the Free Software Foundation; version 3 or later of the License. |
| 11 | ## |
| 12 | ## This program is distributed in the hope that it will be useful, |
| 13 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | ## GNU General Public License for more details. |
| 16 | ## |
| 17 | ## SPDX-License-Identifier: GPL-3.0-or-later |
| 18 | ## <https://spdx.org/licenses/GPL-3.0-or-later.html> |
| 19 | ## |
| 20 | |
| 21 | set -o errexit |
| 22 | set -o nounset |
| 23 | |
| 24 | # dependency check |
| 25 | dependencies=(cut git readlink) |
| 26 | for dependency in "${dependencies[@]}"; do |
| 27 | if ! command -v "${dependency}" 1>/dev/null; then |
| 28 | echo "missing ${dependency}, test skipped" >&2 |
| 29 | exit 0 |
| 30 | fi |
| 31 | done |
| 32 | |
| 33 | # helper functions |
| 34 | function clone_submodules() { |
| 35 | clone_dir="${1}" |
| 36 | log_dir="${2}" |
| 37 | |
| 38 | modules_dir="$(readlink --canonicalize-missing \ |
| 39 | "$(git rev-parse --git-dir)/modules")" |
| 40 | cd "${clone_dir}" |
| 41 | git submodule init 1>>"${log_dir}/clone.log" 2>&1 |
| 42 | for submodule in $(git config --get-regexp "submodule\..*\.url" \ |
| 43 | | cut --delimiter=. --fields=2); do |
| 44 | git config "submodule.${submodule}.url" \ |
| 45 | "${modules_dir}/${submodule}" |
| 46 | done |
| 47 | git submodule update 1>>"${log_dir}/clone.log" 2>&1 |
| 48 | } |
| 49 | |
| 50 | function check_exit_code() { |
| 51 | declare -i err=${?} |
| 52 | |
| 53 | # either "positive" or "negative" |
| 54 | polarity="${1}" |
| 55 | log_file="${2}" |
| 56 | |
| 57 | # exit code 124 is special as per `timeout` manpage |
| 58 | if [ "${polarity}" == "positive" ] && [ ${err} -eq 124 ]; then |
| 59 | echo >&2 "timed out" |
| 60 | fi |
| 61 | |
| 62 | if [ "${polarity}" == "positive" ] && [ ${err} -ne 0 ]; then |
| 63 | echo "bad exit code: expected 0, actually ${err}" |
| 64 | echo "for details, refer to log file \"${log_file}\"" |
| 65 | exit ${err} |
| 66 | elif [ "${polarity}" == "negative" ] && [ ${err} -eq 0 ]; then |
| 67 | echo "bad exit code: expected non-zero, actually 0" |
| 68 | echo "for details, refer to log file \"${log_file}\"" |
| 69 | exit 1 |
| 70 | fi |
| 71 | } |