Return-Path: From: Wang Mingyu Date: Tue, 30 Jul 2019 08:43:57 -0700 Message-ID: <1564501437-23436-1-git-send-email-wangmy@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Fuego] [PATCH] Add a general mechanism in Fuego to check that a module is available and insertable. List-Id: Mailing list for the Fuego test framework List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: fuego@lists.linuxfoundation.org Usage: Set NEED_MODULE at the beginning of fuego_test.sh: NEED_MODULE="name of module" The name of the module is separated by a space. Signed-off-by: Wang Mingyu --- scripts/functions.sh | 19 +++++++++++++++++++ scripts/need_check.sh | 28 ++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/scripts/functions.sh b/scripts/functions.sh index 81b20dc..3abd6f3 100755 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -1056,6 +1056,25 @@ function is_abs_path { fi } +# check for a module on a directory listed on the /lib/modules in the target, +# and set a variable if it's present +# $1 - file, module on target +# $2 - variable to set during the build +function is_on_target_module { + TARGET_PATH="/lib/modules" + tmpfile=$(mktemp /tmp/found_loc.XXXXXX) + cmd "touch $tmpfile" + if [ ! -z "$TARGET_PATH" ] ; then + # execute a command on the target to detect $d/$1 + cmd "grep \"$1.ko\" $TARGET_PATH/\$(uname -r)/modules.builtin $TARGET_PATH/\$(uname -r)/modules.order | head -n 1 > $tmpfile" + fi + get $tmpfile $tmpfile + LOCATION=$(cat $tmpfile) + export $2=$LOCATION + cmd "rm $tmpfile" + rm -f $tmpfile # -f for tests running on the host +} + function allocate_next_batch_id { local filename=$FUEGO_RW/logs/next_batch_id if [ -f $filename ] ; then diff --git a/scripts/need_check.sh b/scripts/need_check.sh index 0ffa209..145d784 100755 --- a/scripts/need_check.sh +++ b/scripts/need_check.sh @@ -333,6 +333,26 @@ function check_program { return 0 } +# check if those specified module exist on board +# $1 has single string with a list of module entries to check for +function check_module { + # split $1 on whitespace, without file globbing + set -f + arg_array=($1) + set +f + + for mod in "${arg_array[@]}" ; do + is_on_target_module $mod mod_path + if [ -z "$mod_path" ] ; then + echo -e "\n\nABORTED: Expected module \"$mod\" is on the target, but it's not there!" + return 1 + fi + done + + # return OK if all necessary modules exist on the target + return 0 +} + function check_needs { # check for each possible need variable and process it if [ -n "${NEED_MEMORY}" ] ; then @@ -376,5 +396,13 @@ function check_needs { return $rcode fi fi + if [ -n "${NEED_MODULE}" ] ; then + check_module "${NEED_MODULE}" + rcode=$? + if [ $rcode -ne 0 ] ; then + echo "ABORTED: \"${NEED_MODULE}\" are required, but not all exist on the target" + return $rcode + fi + fi } -- 2.17.1