#!/usr/bin/env bash # # Copyright (c) 2018-2019 Intel Corporation # # SPDX-License-Identifier: Apache-2.0 # This file contains common functions that # are being used by our metrics and integration tests die() { local msg="$*" echo -e "[$(basename $0):${BASH_LINENO[0]}] ERROR: $msg" >&2 exit 1 } warn() { local msg="$*" echo -e "[$(basename $0):${BASH_LINENO[0]}] WARNING: $msg" } info() { local msg="$*" echo -e "[$(basename $0):${BASH_LINENO[0]}] INFO: $msg" } handle_error() { local exit_code="${?}" local line_number="${1:-}" echo -e "[$(basename $0):$line_number] ERROR: $(eval echo "$BASH_COMMAND")" exit "${exit_code}" } trap 'handle_error $LINENO' ERR waitForProcess() { wait_time="$1" sleep_time="$2" cmd="$3" while [ "$wait_time" -gt 0 ]; do if eval "$cmd"; then return 0 else sleep "$sleep_time" wait_time=$((wait_time-sleep_time)) fi done return 1 }