soc/intel/xeon_sp/util: Enhance lock_pam0123
[coreboot2.git] / util / gitconfig / test / helpers.sh
blobfbb844264b7ade972ce34e1931e039e023359aac
1 #!/usr/bin/env bash
2 ##
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; version 3 or later of the License.
6 ##
7 ## This program is distributed in the hope that it will be useful,
8 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
9 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 ## GNU General Public License for more details.
12 ## SPDX-License-Identifier: GPL-3.0-or-later
13 ## <https://spdx.org/licenses/GPL-3.0-or-later.html>
16 set -o errexit
17 set -o nounset
19 # dependency check
20 dependencies=(cut git readlink)
21 for dependency in "${dependencies[@]}"; do
22 if ! command -v "${dependency}" 1>/dev/null; then
23 echo "missing ${dependency}, test skipped" >&2
24 exit 0
26 done
28 # helper functions
29 function clone_submodules() {
30 clone_dir="${1}"
31 log_dir="${2}"
33 modules_dir="$(readlink --canonicalize-missing \
34 "$(git rev-parse --git-dir)/modules")"
35 cd "${clone_dir}"
36 git submodule init 1>>"${log_dir}/clone.log" 2>&1
37 for submodule in $(git config --get-regexp "submodule\..*\.url" \
38 | cut --delimiter=. --fields=2); do
39 git config "submodule.${submodule}.url" \
40 "${modules_dir}/${submodule}"
41 done
42 git submodule update 1>>"${log_dir}/clone.log" 2>&1
45 function check_exit_code() {
46 declare -i err=${?}
48 # either "positive" or "negative"
49 polarity="${1}"
50 log_file="${2}"
52 # exit code 124 is special as per `timeout` manpage
53 if [ "${polarity}" == "positive" ] && [ ${err} -eq 124 ]; then
54 echo >&2 "timed out"
57 if [ "${polarity}" == "positive" ] && [ ${err} -ne 0 ]; then
58 echo "bad exit code: expected 0, actually ${err}"
59 echo "for details, refer to log file \"${log_file}\""
60 exit ${err}
61 elif [ "${polarity}" == "negative" ] && [ ${err} -eq 0 ]; then
62 echo "bad exit code: expected non-zero, actually 0"
63 echo "for details, refer to log file \"${log_file}\""
64 exit 1