Return-Path: From: Wang Mingyu Date: Tue, 16 Oct 2018 00:16:47 -0700 Message-ID: <1539674207-112500-2-git-send-email-wangmy@cn.fujitsu.com> In-Reply-To: <1539674207-112500-1-git-send-email-wangmy@cn.fujitsu.com> References: <1539674207-112500-1-git-send-email-wangmy@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Fuego] [PATCH] Add a core function: assert_has_program(). List-Id: Mailing list for the Fuego test framework List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: fuego@lists.linuxfoundation.org This function is used to combine the code that check whether a program or file exists, from 2 lines into a single function call. Called like so: assert_has_program expect Signed-off-by: Wang Mingyu --- engine/scripts/functions.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/engine/scripts/functions.sh b/engine/scripts/functions.sh index ff7b272..fe236c4 100644 --- a/engine/scripts/functions.sh +++ b/engine/scripts/functions.sh @@ -961,3 +961,28 @@ function is_on_sdk { export $2=$LOCATION rm -f $tmpfile } + +# check for a program or file on the target, and send message if the program or file is missing +# $1 - file, dir or program on target +function assert_has_program { + # FIXTHIS: race condition + tmpfile=$(mktemp /tmp/found_loc.XXXXXX) + cmd "touch $tmpfile" + if [ -z "$PATH" ] ; then + safe_cmd "find / -name \"$1\" | head -n 1 >$tmpfile" + else + # split search path on colon + for d in $(echo "$PATH" | tr ":" "\n") ; do + # execute a command on the target to detect $d/$1 + cmd "if [ -z \"\$(cat $tmpfile)\" -a -e \"$d/$1\" ] ; then echo \"$d/$1\" >$tmpfile ; fi" + done + fi + get $tmpfile $tmpfile + varname=$(cat $tmpfile) + cmd "rm $tmpfile" + rm -f $tmpfile # -f for tests running on the host + if [ -z "$varname" ] + then + abort_job "$1 is not defined. Missing '$1' program on target board" + fi +} -- 1.8.3.1