summaryrefslogtreecommitdiff
path: root/automated/lib/sh-test-lib
diff options
context:
space:
mode:
Diffstat (limited to 'automated/lib/sh-test-lib')
-rwxr-xr-xautomated/lib/sh-test-lib49
1 files changed, 45 insertions, 4 deletions
diff --git a/automated/lib/sh-test-lib b/automated/lib/sh-test-lib
index ed0d96e..1e02795 100755
--- a/automated/lib/sh-test-lib
+++ b/automated/lib/sh-test-lib
@@ -3,6 +3,17 @@
LANG=C
export LANG
+error_fatal() {
+ msg="$1"
+ [ -z "${msg}" ] && msg="Unknown error"
+ if which lava-test-raise;then
+ lava-test-raise "${msg}"
+ else
+ printf "FATAL ERROR: %s\n" "${msg}" >&2
+ fi
+ exit 1
+}
+
error_msg() {
msg="$1"
[ -z "${msg}" ] && msg="Unknown error"
@@ -146,7 +157,7 @@ detect_abi() {
case "${abi}" in
armv7|armv7l|armv7el|armv7lh) abi="armeabi" ;;
arm64|armv8|arm64-v8a|aarch64) abi="arm64" ;;
- x86_64) abi="x86" ;;
+ x86_64) abi="x86_64" ;;
*) error_msg "Unsupported architecture: ${abi}" ;;
esac
}
@@ -193,8 +204,13 @@ install_deps() {
dist_name
case "${dist}" in
debian|ubuntu)
- # Use the default answers for all questions.
- DEBIAN_FRONTEND=noninteractive apt-get update -q -y
+ last_apt_time=/tmp/apt-get-updated.last
+ apt_cache_time=21600 # 6 hours
+ # Only run apt-get update if it hasn't been run in $apt_cache_time seconds
+ if [ ! -e ${last_apt_time} ] || \
+ [ "$(stat --format=%Y ${last_apt_time})" -lt $(( $(date +%s) - apt_cache_time )) ]; then
+ DEBIAN_FRONTEND=noninteractive apt-get update -q -y && touch ${last_apt_time}
+ fi
# shellcheck disable=SC2086
DEBIAN_FRONTEND=noninteractive apt-get install -q -y ${pkgs}
;;
@@ -252,7 +268,7 @@ validate_check_sum() {
convert_to_mb() {
[ "$#" -ne 2 ] && error_msg "Usage: convert_to_mb value units"
- if ! echo "$1" | egrep -q "^[0-9.]+$"; then
+ if ! echo "$1" | grep -E -q "^[0-9.]+$"; then
error_msg "The first argument isn't a number"
fi
value="$1"
@@ -340,3 +356,28 @@ create_out_dir() {
mkdir -p "${OUTPUT}"
[ -d "${OUTPUT}" ] || error_msg "Could not create output directory ${OUTPUT}"
}
+
+generate_skipfile() {
+ # Generate a skipfile and set the SKIPFILE variable based on SKIPFILE_YAML,
+ # BOARD, BRANCH, and ENVIRONMENT.
+ #
+ # In:
+ # SKIPFILE_YAML: (required) skipgen/yaml formatted skipfile
+ # SKIPFILE_PATH: (required) destination file for generated skipfile
+ # BOARD: (optional) board name to pass to skipgen
+ # BRANCH: (optional) branch name to pass to skipgen
+ # ENVIRONMENT: (optional) environment name to pass to skipgen
+ #
+ info_msg "Generating a skipfile based on ${SKIPFILE_YAML}"
+ detect_abi
+ SKIPGEN_ARGS=""
+ test -n "${BOARD}" && SKIPGEN_ARGS="${SKIPGEN_ARGS} --board ${BOARD}"
+ test -n "${BRANCH}" && SKIPGEN_ARGS="${SKIPGEN_ARGS} --branch ${BRANCH}"
+ test -n "${ENVIRONMENT}" && SKIPGEN_ARGS="${SKIPGEN_ARGS} --environment ${ENVIRONMENT}"
+ # shellcheck disable=SC2086
+ ../../bin/${abi}/skipgen ${SKIPGEN_ARGS} "${SKIPFILE_YAML}" > "${SKIPFILE_PATH}"
+ test $? -eq 0 || error_msg "skipgen failed to generate a skipfile"
+ info_msg "Using the following generated skipfile contents (until EOF):"
+ cat "${SKIPFILE_PATH}"
+ info_msg "EOF"
+}