Add a general mechanism in Fuego to check that a module is available and insertable.
PATCH 1/1 Add a general mechanism in Fuego to check that a module is available and insertable.
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.
--- scripts/functions.sh | 19 +++++++++++++++++++ scripts/need_check.sh | 28 ++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+)
scripts/functions.sh +19 -0
@@ -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
scripts/need_check.sh +28 -0
@@ -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 }
Signature · 1 line
2.17.1
In general, this is a nice feature, but there are a few implementation issues.
Please see comments inline below.
Quoted 21 lines
-----Original Message-----
From: Wang MingyuUsage:
SetNEED_MODULEat the beginning offuego_test.sh:NEED_MODULE="name of module"
The name of the module is separated by a space.
Signed-off-by Wang Mingyu <[email protected]>--- scripts/functions.sh | 19 +++++++++++++++++++ scripts/need_check.sh | 28 ++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+)scripts/functions.sh +0
-0
scripts/functions.sh function is_abs_path { · line 1065
Quoted 10 lines
scripts/functions.sh +7
-0@@ -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)
This style of creating a file on the target and moving it back to the host for processing is deprecated. I'm experimenting now with doing a direct variable assignment based on the output from 'cmd'.
scripts/functions.sh function is_abs_path { · line 1067
Quoted 2 lines
scripts/functions.sh +2
-0+ cmd "touch $tmpfile" + if [ ! -z "$TARGET_PATH" ] ; then
[ ! -z is the same as [ -n
test -n is fewer operations, and is preferred.
However, this test occurs on the host, not on the target. I think a separate step is needed if we really want to pre-check that /lib/modules exists on the board, or maybe the 'grep' will fail, and we can determine that way that /lib/modules is missing.
Quoted 3 lines
scripts/functions.sh +2
-0+ # 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"
It would not have occurred to me to check modules.builtin as well.
However, if the module is in modules.order, it would be nice to also check 1) that the module file is actually present, and 2) that the module can be loaded. It is too difficult to do (2), but checking (1) should not be hard. I'm going to play around with this and see what I can come up with.
scripts/functions.sh function is_abs_path { · line 1075
Quoted 6 lines
scripts/functions.sh +6
-0+ fi + get $tmpfile $tmpfile + LOCATION=$(cat $tmpfile) + export $2=$LOCATION + cmd "rm $tmpfile" + rm -f $tmpfile # -f for tests running on the host
A lot of these lines can disappear if we don't use a temp file to hold data.
Quoted 10 lines
scripts/functions.sh +2
-0+} + function allocate_next_batch_id { local filename=$FUEGO_RW/logs/next_batch_id if [ -f $filename ] ; thenscripts/need_check.sh +0
-0
scripts/need_check.sh function check_program { · line 338
Quoted 6 lines
scripts/need_check.sh +3
-0@@ -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 {
if we support multiple arguments, a better function name would be "check_modules"
I hesitate to support multiple modules, as I don't know of any use cases yet.
Quoted 30 lines
scripts/need_check.sh +9
-0+ # 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, butit's not there!"
scripts/need_check.sh +13
-0+ 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
Quoted 1 line
the target"
You'll end up showing multiple ABORTED messages here - one in check_module and one here. I'm not sure you need this second one.
Quoted 7 lines
scripts/need_check.sh +3
-1+ return $rcode + fi + fi } --2.17.1
I wrote some test code, and am playing around with some possible improvements. You patch will likely be applied, but possibly with some changes.
I'll let you know what I end up changing.
Thanks for the patch.
-- Tim
Quoted 3 lines
-----Original Message-----
From: Tim Bird
...
Quoted 5 lines
I wrote some test code, and am playing around with some possible improvements.
You patch will likely be applied, but possibly with some changes.I'll let you know what I end up changing.
Below is the code for this I ended up with. This is pushed to the fuegotest 'next' branch on bitbucket. Please test on your side an let me know if it works for you.
-- Tim
From 48b10b68f8a1211b152bb05c98ddfbfbd710d778 Mon Sep 17 00:00:00 2001
From: Tim Bird <[email protected]>
Date: Wed, 31 Jul 2019 18:06:39 -0600
Subject: [PATCH] core: adjust is_on_target_module to avoid temp files
Change is_on_target_module to use output of 'cmd' to set LOCATION variable, instead of redirecting it through a file. Also, handle builtin modules and external modules differently (checking the presence of the .ko file for external modules).
Remove some redundant ABORTING messages from check_needs.
--- scripts/functions.sh | 46 +++++++++++++++++++++++++++++++++++++--------- scripts/need_check.sh | 9 +++++---- 2 files changed, 42 insertions(+), 13 deletions(-)
scripts/functions.sh +37 -9
@@ -1045,6 +1045,17 @@ function assert_has_program { assert_define ${progVar} "Missing '$1' program on target board" } +# check for a module on the target, and abort if it is missing +# $1 has the module that is required on the target board +# this has the side effect of defining MODULE_$1 (uppercased) +# with the value as the directory where $1 is found on the board. +function assert_has_module { + upName=${1^^} + modVar=MODULE_${upName//[-,.]/_} + is_on_target_module $1 ${modVar} + assert_define ${modVar} "Missing '$1' module on target board" +} + # check if the path is an absolute path or a relative path # $1 - the path to check function is_abs_path {
@@ -1061,18 +1072,35 @@ function is_abs_path { # $1 - file, module on target # $2 - variable to set during the build function is_on_target_module { + # clear variables, in case this is called multiple times + LOCATION="" + export $2=$LOCATION + + # this is really unlikely to be missing, but check just in case 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" + if [ $(cmd "test -d $TARGET_PATH ; echo \$?") != "0" ] ; then + return 1 fi - get $tmpfile $tmpfile - LOCATION=$(cat $tmpfile) + + # check for module builtin to kernel + LOCATION=$(cmd "grep \"/$1.ko\" $TARGET_PATH/\$(uname -r)/modules.builtin") + if [ -z "$LOCATION" ] ; then + # check for module outside of kernel + LOCATION2=$(cmd "grep \"/$1.ko\" $TARGET_PATH/\$(uname -r)/modules.order") + if [ -n "$LOCATION2" ] ; then + # check that module file is there + if cmd "test -f $TARGET_PATH/\$(uname -r)/$LOCATION2" ; then + LOCATION=$LOCATION2 + else + return 1 + fi + else + return 1 + fi + fi + export $2=$LOCATION - cmd "rm $tmpfile" - rm -f $tmpfile # -f for tests running on the host + return 0 } function allocate_next_batch_id {
scripts/need_check.sh +5 -4
@@ -27,6 +27,9 @@ ONE_M=1048576 ONE_G=1073741824 ONE_T=1099511627776 +# check for module presence +#NEED_MODULE=msdos + # $1 has a string to convert to bytes function to_bytes { str=$1
@@ -324,7 +327,7 @@ function check_program { for prg in "${arg_array[@]}" ; do is_on_target_path $prg prg_path if [ -z "$prg_path" ] ; then - echo -e "\n\nABORTED: Expected command \"$prg\" is on the target, but it's not there!" + echo -e "\n\nABORTED: Expected command \"$prg\" on the target, but it's not there!" return 1 fi done
@@ -344,7 +347,7 @@ function check_module { 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!" + echo -e "\n\nABORTED: Expected module \"$mod\" on the target, but it's not there!" return 1 fi done
@@ -392,7 +395,6 @@ function check_needs { check_program "${NEED_PROGRAM}" rcode=$? if [ $rcode -ne 0 ] ; then - echo "ABORTED: \"${NEED_PROGRAM}\" are required, but not all exist on the target" return $rcode fi fi
@@ -400,7 +402,6 @@ function check_needs { 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
Signature · 1 line
2.1.4
Hi Tim
The NEED_MODULE and assert_has_module have been confirmed. It seems to be no problem.
best regards
-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Thursday, August 01, 2019 8:17 AM
To: Wang, Mingyu/王 鸣瑜 <[email protected]>; [email protected]
Subject: RE: [Fuego] [PATCH] Add a general mechanism in Fuego to check that a module is available and insertable.
Quoted 3 lines
-----Original Message-----
From: Tim Bird
...
Quoted 5 lines
I wrote some test code, and am playing around with some possible improvements.
You patch will likely be applied, but possibly with some changes.I'll let you know what I end up changing.
Below is the code for this I ended up with. This is pushed to the fuegotest 'next' branch on bitbucket. Please test on your side an let me know if it works for you.
-- Tim
From 48b10b68f8a1211b152bb05c98ddfbfbd710d778 Mon Sep 17 00:00:00 2001
From: Tim Bird <[email protected]>
Date: Wed, 31 Jul 2019 18:06:39 -0600
Subject: [PATCH] core: adjust is_on_target_module to avoid temp files
Change is_on_target_module to use output of 'cmd' to set LOCATION variable, instead of redirecting it through a file. Also, handle builtin modules and external modules differently (checking the presence of the .ko file for external modules).
Remove some redundant ABORTING messages from check_needs.
--- scripts/functions.sh | 46 +++++++++++++++++++++++++++++++++++++--------- scripts/need_check.sh | 9 +++++---- 2 files changed, 42 insertions(+), 13 deletions(-)
scripts/functions.sh +13 -0
@@ -1045,6 +1045,17 @@ function assert_has_program { assert_define ${progVar} "Missing '$1' program on target board" } +# check for a module on the target, and abort if it is missing # $1 has +the module that is required on the target board # this has the side +effect of defining MODULE_$1 (uppercased) # with the value as the +directory where $1 is found on the board. +function assert_has_module { + upName=${1^^} + modVar=MODULE_${upName//[-,.]/_} + is_on_target_module $1 ${modVar} + assert_define ${modVar} "Missing '$1' module on target board" +} + # check if the path is an absolute path or a relative path # $1 - the path to check function is_abs_path { @@ -1061,18 +1072,35 @@ function is_abs_path { # $1 - file, module on target # $2 - variable to set during the build function is_on_target_module { + # clear variables, in case this is called multiple times + LOCATION=""
+ export $2=$LOCATION
+
+ # this is really unlikely to be missing, but check just in case
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"
+ if [ $(cmd "test -d $TARGET_PATH ; echo \$?") != "0" ] ; then
+ return 1
fi
- get $tmpfile $tmpfile
- LOCATION=$(cat $tmpfile)
+
+ # check for module builtin to kernel + LOCATION=$(cmd "grep \"/$1.ko\" $TARGET_PATH/\$(uname -r)/modules.builtin") + if [ -z "$LOCATION" ] ; then + # check for module outside of kernel + LOCATION2=$(cmd "grep \"/$1.ko\" $TARGET_PATH/\$(uname -r)/modules.order") + if [ -n "$LOCATION2" ] ; then
+ # check that module file is there
+ if cmd "test -f $TARGET_PATH/\$(uname -r)/$LOCATION2" ; then
+ LOCATION=$LOCATION2
+ else
+ return 1
+ fi
+ else
+ return 1
+ fi
+ fi
+
export $2=$LOCATION
- cmd "rm $tmpfile" - rm -f $tmpfile # -f for tests running on the host + return 0
}
function allocate_next_batch_id {
scripts/need_check.sh +5 -4
@@ -27,6 +27,9 @@ ONE_M=1048576 ONE_G=1073741824 ONE_T=1099511627776 +# check for module presence +#NEED_MODULE=msdos + # $1 has a string to convert to bytes function to_bytes { str=$1
@@ -324,7 +327,7 @@ function check_program { for prg in "${arg_array[@]}" ; do is_on_target_path $prg prg_path if [ -z "$prg_path" ] ; then - echo -e "\n\nABORTED: Expected command \"$prg\" is on the target, but it's not there!" + echo -e "\n\nABORTED: Expected command \"$prg\" on the target, but it's not there!" return 1 fi done
@@ -344,7 +347,7 @@ function check_module { 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!" + echo -e "\n\nABORTED: Expected module \"$mod\" on the target, but it's not there!" return 1 fi done
@@ -392,7 +395,6 @@ function check_needs { check_program "${NEED_PROGRAM}" rcode=$? if [ $rcode -ne 0 ] ; then - echo "ABORTED: \"${NEED_PROGRAM}\" are required, but not all exist on the target" return $rcode fi fi
@@ -400,7 +402,6 @@ function check_needs { 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.1.4