All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anders Roxell <anders.roxell@linaro.org>
To: Lei.Yang@windriver.com
Cc: mcgrof@kernel.org,
	"open list:KERNEL SELFTEST FRAMEWORK" 
	<linux-kselftest@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] sysctl: kselftests: fix test_modprobe issue
Date: Tue, 9 Oct 2018 09:29:10 +0200	[thread overview]
Message-ID: <CADYN=9+0RxfJRHhTM5GLMOi-EsOfe3tv+jvSfyQLLcSQB5FzHw@mail.gmail.com> (raw)
In-Reply-To: <1536229374-25699-1-git-send-email-Lei.Yang@windriver.com>

On Thu, 6 Sep 2018 at 12:20, Lei Yang <Lei.Yang@windriver.com> wrote:
>
> when CONFIG_TEST_SYSCTL=y, there is no "/sys/module/test_sysctl/"
> when CONFIG_TEST_SYSCTL=m, checking /sys/module/test_sysctl/ is
> before kernel module loading
>
> you'll get below error message
> root@intel-x86-64:/tmp/sysctl# ./sysctl.sh
> Checking production write strict setting ... ok
> ./sysctl.sh: /sys/module/test_sysctl/ not present
> You must have the following enabled in your kernel:
>
> This patch will fix this issue.
> when CONFIG_TEST_SYSCTL=y, it has no chance to check "/sys/module/test_sysctl/"
> when CONFIG_TEST_SYSCTL=m, it will load kernel module first before checking sys
> interface.
>
> Signed-off-by: Lei Yang <Lei.Yang@windriver.com>
> ---
>  tools/testing/selftests/sysctl/sysctl.sh | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/sysctl/sysctl.sh b/tools/testing/selftests/sysctl/sysctl.sh
> index 584eb8e..08dc995 100755
> --- a/tools/testing/selftests/sysctl/sysctl.sh
> +++ b/tools/testing/selftests/sysctl/sysctl.sh
> @@ -120,6 +120,7 @@ test_reqs()
>
>  function load_req_mod()
>  {
> +        trap "test_modprobe" EXIT
>         if [ ! -d $DIR ]; then
>                 if ! modprobe -q -n $TEST_DRIVER; then
>                         echo "$0: module $TEST_DRIVER not found [SKIP]"
> @@ -770,7 +771,6 @@ function parse_args()
>  test_reqs
>  allow_user_defaults
>  check_production_sysctl_writes_strict
> -test_modprobe
>  load_req_mod
>
>  trap "test_finish" EXIT
> --
> 1.9.1
>

do we really nead the test_modprobe function?
I think we can just remove that completely.
Also remove a lot in load_req_mod and only do: modprobe $TEST_DRIVER
if it fails its a non fatal error and we can go on and have a new
function in all
the tests sysctl_test_000(1|2|3|4|5) that checks for the files.
Maybe do something like this:

diff --git a/tools/testing/selftests/sysctl/sysctl.sh
b/tools/testing/selftests/sysctl/sysctl.sh
index 584eb8ea780a..a925d040dfe0 100755
--- a/tools/testing/selftests/sysctl/sysctl.sh
+++ b/tools/testing/selftests/sysctl/sysctl.sh
@@ -19,7 +19,6 @@ ksft_skip=4

 TEST_NAME="sysctl"
 TEST_DRIVER="test_${TEST_NAME}"
-TEST_DIR=$(dirname $0)
 TEST_FILE=$(mktemp)

 # This represents
@@ -38,21 +37,8 @@ ALL_TESTS="$ALL_TESTS 0003:1:1"
 ALL_TESTS="$ALL_TESTS 0004:1:1"
 ALL_TESTS="$ALL_TESTS 0005:3:1"

-test_modprobe()
-{
-       if [ ! -d $DIR ]; then
-               echo "$0: $DIR not present" >&2
-               echo "You must have the following enabled in your kernel:" >&2
-               cat $TEST_DIR/config >&2
-               exit $ksft_skip
-       fi
-}
-
 function allow_user_defaults()
 {
-       if [ -z $DIR ]; then
-               DIR="/sys/module/test_sysctl/"
-       fi
        if [ -z $DEFAULT_NUM_TESTS ]; then
                DEFAULT_NUM_TESTS=50
        fi
@@ -120,16 +106,7 @@ test_reqs()

 function load_req_mod()
 {
-       if [ ! -d $DIR ]; then
-               if ! modprobe -q -n $TEST_DRIVER; then
-                       echo "$0: module $TEST_DRIVER not found [SKIP]"
-                       exit $ksft_skip
-               fi
-               modprobe $TEST_DRIVER
-               if [ $? -ne 0 ]; then
-                       exit
-               fi
-       fi
+       modprobe $TEST_DRIVER
 }

 reset_vals()
@@ -548,9 +525,18 @@ run_stringtests()
        test_rc
 }

+check_sysctl_file()
+{
+       if [ ! -f ${1} ]; then
+               echo "$0: ${1} not present" >&2
+               exit $ksft_skip
+       fi
+}
+
 sysctl_test_0001()
 {
        TARGET="${SYSCTL}/int_0001"
+       check_sysctl_file ${TARGET}
        reset_vals
        ORIG=$(cat "${TARGET}")
        TEST_STR=$(( $ORIG + 1 ))
@@ -562,6 +548,7 @@ sysctl_test_0001()
 sysctl_test_0002()
 {
        TARGET="${SYSCTL}/string_0001"
+       check_sysctl_file ${TARGET}
        reset_vals
        ORIG=$(cat "${TARGET}")
        TEST_STR="Testing sysctl"
@@ -575,6 +562,7 @@ sysctl_test_0002()
 sysctl_test_0003()
 {
        TARGET="${SYSCTL}/int_0002"
+       check_sysctl_file ${TARGET}
        reset_vals
        ORIG=$(cat "${TARGET}")
        TEST_STR=$(( $ORIG + 1 ))
@@ -587,6 +575,7 @@ sysctl_test_0003()
 sysctl_test_0004()
 {
        TARGET="${SYSCTL}/uint_0001"
+       check_sysctl_file ${TARGET}
        reset_vals
        ORIG=$(cat "${TARGET}")
        TEST_STR=$(( $ORIG + 1 ))
@@ -599,6 +588,7 @@ sysctl_test_0004()
 sysctl_test_0005()
 {
        TARGET="${SYSCTL}/int_0003"
+       check_sysctl_file ${TARGET}
        reset_vals
        ORIG=$(cat "${TARGET}")

@@ -620,8 +610,6 @@ list_tests()
        echo "0005 x $(get_test_count 0005) - tests proc_douintvec() array"
 }

-test_reqs
-
 usage()
 {
        NUM_TESTS=$(grep -o ' ' <<<"$ALL_TESTS" | grep -c .)
@@ -770,7 +758,6 @@ function parse_args()
 test_reqs
 allow_user_defaults
 check_production_sysctl_writes_strict
-test_modprobe
 load_req_mod

 trap "test_finish" EXIT


Cheers,
Anders

WARNING: multiple messages have this Message-ID (diff)
From: anders.roxell at linaro.org (Anders Roxell)
Subject: [PATCH v2] sysctl: kselftests: fix test_modprobe issue
Date: Tue, 9 Oct 2018 09:29:10 +0200	[thread overview]
Message-ID: <CADYN=9+0RxfJRHhTM5GLMOi-EsOfe3tv+jvSfyQLLcSQB5FzHw@mail.gmail.com> (raw)
In-Reply-To: <1536229374-25699-1-git-send-email-Lei.Yang@windriver.com>

On Thu, 6 Sep 2018 at 12:20, Lei Yang <Lei.Yang at windriver.com> wrote:
>
> when CONFIG_TEST_SYSCTL=y, there is no "/sys/module/test_sysctl/"
> when CONFIG_TEST_SYSCTL=m, checking /sys/module/test_sysctl/ is
> before kernel module loading
>
> you'll get below error message
> root at intel-x86-64:/tmp/sysctl# ./sysctl.sh
> Checking production write strict setting ... ok
> ./sysctl.sh: /sys/module/test_sysctl/ not present
> You must have the following enabled in your kernel:
>
> This patch will fix this issue.
> when CONFIG_TEST_SYSCTL=y, it has no chance to check "/sys/module/test_sysctl/"
> when CONFIG_TEST_SYSCTL=m, it will load kernel module first before checking sys
> interface.
>
> Signed-off-by: Lei Yang <Lei.Yang at windriver.com>
> ---
>  tools/testing/selftests/sysctl/sysctl.sh | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/sysctl/sysctl.sh b/tools/testing/selftests/sysctl/sysctl.sh
> index 584eb8e..08dc995 100755
> --- a/tools/testing/selftests/sysctl/sysctl.sh
> +++ b/tools/testing/selftests/sysctl/sysctl.sh
> @@ -120,6 +120,7 @@ test_reqs()
>
>  function load_req_mod()
>  {
> +        trap "test_modprobe" EXIT
>         if [ ! -d $DIR ]; then
>                 if ! modprobe -q -n $TEST_DRIVER; then
>                         echo "$0: module $TEST_DRIVER not found [SKIP]"
> @@ -770,7 +771,6 @@ function parse_args()
>  test_reqs
>  allow_user_defaults
>  check_production_sysctl_writes_strict
> -test_modprobe
>  load_req_mod
>
>  trap "test_finish" EXIT
> --
> 1.9.1
>

do we really nead the test_modprobe function?
I think we can just remove that completely.
Also remove a lot in load_req_mod and only do: modprobe $TEST_DRIVER
if it fails its a non fatal error and we can go on and have a new
function in all
the tests sysctl_test_000(1|2|3|4|5) that checks for the files.
Maybe do something like this:

diff --git a/tools/testing/selftests/sysctl/sysctl.sh
b/tools/testing/selftests/sysctl/sysctl.sh
index 584eb8ea780a..a925d040dfe0 100755
--- a/tools/testing/selftests/sysctl/sysctl.sh
+++ b/tools/testing/selftests/sysctl/sysctl.sh
@@ -19,7 +19,6 @@ ksft_skip=4

 TEST_NAME="sysctl"
 TEST_DRIVER="test_${TEST_NAME}"
-TEST_DIR=$(dirname $0)
 TEST_FILE=$(mktemp)

 # This represents
@@ -38,21 +37,8 @@ ALL_TESTS="$ALL_TESTS 0003:1:1"
 ALL_TESTS="$ALL_TESTS 0004:1:1"
 ALL_TESTS="$ALL_TESTS 0005:3:1"

-test_modprobe()
-{
-       if [ ! -d $DIR ]; then
-               echo "$0: $DIR not present" >&2
-               echo "You must have the following enabled in your kernel:" >&2
-               cat $TEST_DIR/config >&2
-               exit $ksft_skip
-       fi
-}
-
 function allow_user_defaults()
 {
-       if [ -z $DIR ]; then
-               DIR="/sys/module/test_sysctl/"
-       fi
        if [ -z $DEFAULT_NUM_TESTS ]; then
                DEFAULT_NUM_TESTS=50
        fi
@@ -120,16 +106,7 @@ test_reqs()

 function load_req_mod()
 {
-       if [ ! -d $DIR ]; then
-               if ! modprobe -q -n $TEST_DRIVER; then
-                       echo "$0: module $TEST_DRIVER not found [SKIP]"
-                       exit $ksft_skip
-               fi
-               modprobe $TEST_DRIVER
-               if [ $? -ne 0 ]; then
-                       exit
-               fi
-       fi
+       modprobe $TEST_DRIVER
 }

 reset_vals()
@@ -548,9 +525,18 @@ run_stringtests()
        test_rc
 }

+check_sysctl_file()
+{
+       if [ ! -f ${1} ]; then
+               echo "$0: ${1} not present" >&2
+               exit $ksft_skip
+       fi
+}
+
 sysctl_test_0001()
 {
        TARGET="${SYSCTL}/int_0001"
+       check_sysctl_file ${TARGET}
        reset_vals
        ORIG=$(cat "${TARGET}")
        TEST_STR=$(( $ORIG + 1 ))
@@ -562,6 +548,7 @@ sysctl_test_0001()
 sysctl_test_0002()
 {
        TARGET="${SYSCTL}/string_0001"
+       check_sysctl_file ${TARGET}
        reset_vals
        ORIG=$(cat "${TARGET}")
        TEST_STR="Testing sysctl"
@@ -575,6 +562,7 @@ sysctl_test_0002()
 sysctl_test_0003()
 {
        TARGET="${SYSCTL}/int_0002"
+       check_sysctl_file ${TARGET}
        reset_vals
        ORIG=$(cat "${TARGET}")
        TEST_STR=$(( $ORIG + 1 ))
@@ -587,6 +575,7 @@ sysctl_test_0003()
 sysctl_test_0004()
 {
        TARGET="${SYSCTL}/uint_0001"
+       check_sysctl_file ${TARGET}
        reset_vals
        ORIG=$(cat "${TARGET}")
        TEST_STR=$(( $ORIG + 1 ))
@@ -599,6 +588,7 @@ sysctl_test_0004()
 sysctl_test_0005()
 {
        TARGET="${SYSCTL}/int_0003"
+       check_sysctl_file ${TARGET}
        reset_vals
        ORIG=$(cat "${TARGET}")

@@ -620,8 +610,6 @@ list_tests()
        echo "0005 x $(get_test_count 0005) - tests proc_douintvec() array"
 }

-test_reqs
-
 usage()
 {
        NUM_TESTS=$(grep -o ' ' <<<"$ALL_TESTS" | grep -c .)
@@ -770,7 +758,6 @@ function parse_args()
 test_reqs
 allow_user_defaults
 check_production_sysctl_writes_strict
-test_modprobe
 load_req_mod

 trap "test_finish" EXIT


Cheers,
Anders

WARNING: multiple messages have this Message-ID (diff)
From: anders.roxell@linaro.org (Anders Roxell)
Subject: [PATCH v2] sysctl: kselftests: fix test_modprobe issue
Date: Tue, 9 Oct 2018 09:29:10 +0200	[thread overview]
Message-ID: <CADYN=9+0RxfJRHhTM5GLMOi-EsOfe3tv+jvSfyQLLcSQB5FzHw@mail.gmail.com> (raw)
Message-ID: <20181009072910.hC9OHpVtWQAWzW-P2R_SZn307qrSrdNtpfOoCtuz-KE@z> (raw)
In-Reply-To: <1536229374-25699-1-git-send-email-Lei.Yang@windriver.com>

On Thu, 6 Sep 2018@12:20, Lei Yang <Lei.Yang@windriver.com> wrote:
>
> when CONFIG_TEST_SYSCTL=y, there is no "/sys/module/test_sysctl/"
> when CONFIG_TEST_SYSCTL=m, checking /sys/module/test_sysctl/ is
> before kernel module loading
>
> you'll get below error message
> root at intel-x86-64:/tmp/sysctl# ./sysctl.sh
> Checking production write strict setting ... ok
> ./sysctl.sh: /sys/module/test_sysctl/ not present
> You must have the following enabled in your kernel:
>
> This patch will fix this issue.
> when CONFIG_TEST_SYSCTL=y, it has no chance to check "/sys/module/test_sysctl/"
> when CONFIG_TEST_SYSCTL=m, it will load kernel module first before checking sys
> interface.
>
> Signed-off-by: Lei Yang <Lei.Yang at windriver.com>
> ---
>  tools/testing/selftests/sysctl/sysctl.sh | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/sysctl/sysctl.sh b/tools/testing/selftests/sysctl/sysctl.sh
> index 584eb8e..08dc995 100755
> --- a/tools/testing/selftests/sysctl/sysctl.sh
> +++ b/tools/testing/selftests/sysctl/sysctl.sh
> @@ -120,6 +120,7 @@ test_reqs()
>
>  function load_req_mod()
>  {
> +        trap "test_modprobe" EXIT
>         if [ ! -d $DIR ]; then
>                 if ! modprobe -q -n $TEST_DRIVER; then
>                         echo "$0: module $TEST_DRIVER not found [SKIP]"
> @@ -770,7 +771,6 @@ function parse_args()
>  test_reqs
>  allow_user_defaults
>  check_production_sysctl_writes_strict
> -test_modprobe
>  load_req_mod
>
>  trap "test_finish" EXIT
> --
> 1.9.1
>

do we really nead the test_modprobe function?
I think we can just remove that completely.
Also remove a lot in load_req_mod and only do: modprobe $TEST_DRIVER
if it fails its a non fatal error and we can go on and have a new
function in all
the tests sysctl_test_000(1|2|3|4|5) that checks for the files.
Maybe do something like this:

diff --git a/tools/testing/selftests/sysctl/sysctl.sh
b/tools/testing/selftests/sysctl/sysctl.sh
index 584eb8ea780a..a925d040dfe0 100755
--- a/tools/testing/selftests/sysctl/sysctl.sh
+++ b/tools/testing/selftests/sysctl/sysctl.sh
@@ -19,7 +19,6 @@ ksft_skip=4

 TEST_NAME="sysctl"
 TEST_DRIVER="test_${TEST_NAME}"
-TEST_DIR=$(dirname $0)
 TEST_FILE=$(mktemp)

 # This represents
@@ -38,21 +37,8 @@ ALL_TESTS="$ALL_TESTS 0003:1:1"
 ALL_TESTS="$ALL_TESTS 0004:1:1"
 ALL_TESTS="$ALL_TESTS 0005:3:1"

-test_modprobe()
-{
-       if [ ! -d $DIR ]; then
-               echo "$0: $DIR not present" >&2
-               echo "You must have the following enabled in your kernel:" >&2
-               cat $TEST_DIR/config >&2
-               exit $ksft_skip
-       fi
-}
-
 function allow_user_defaults()
 {
-       if [ -z $DIR ]; then
-               DIR="/sys/module/test_sysctl/"
-       fi
        if [ -z $DEFAULT_NUM_TESTS ]; then
                DEFAULT_NUM_TESTS=50
        fi
@@ -120,16 +106,7 @@ test_reqs()

 function load_req_mod()
 {
-       if [ ! -d $DIR ]; then
-               if ! modprobe -q -n $TEST_DRIVER; then
-                       echo "$0: module $TEST_DRIVER not found [SKIP]"
-                       exit $ksft_skip
-               fi
-               modprobe $TEST_DRIVER
-               if [ $? -ne 0 ]; then
-                       exit
-               fi
-       fi
+       modprobe $TEST_DRIVER
 }

 reset_vals()
@@ -548,9 +525,18 @@ run_stringtests()
        test_rc
 }

+check_sysctl_file()
+{
+       if [ ! -f ${1} ]; then
+               echo "$0: ${1} not present" >&2
+               exit $ksft_skip
+       fi
+}
+
 sysctl_test_0001()
 {
        TARGET="${SYSCTL}/int_0001"
+       check_sysctl_file ${TARGET}
        reset_vals
        ORIG=$(cat "${TARGET}")
        TEST_STR=$(( $ORIG + 1 ))
@@ -562,6 +548,7 @@ sysctl_test_0001()
 sysctl_test_0002()
 {
        TARGET="${SYSCTL}/string_0001"
+       check_sysctl_file ${TARGET}
        reset_vals
        ORIG=$(cat "${TARGET}")
        TEST_STR="Testing sysctl"
@@ -575,6 +562,7 @@ sysctl_test_0002()
 sysctl_test_0003()
 {
        TARGET="${SYSCTL}/int_0002"
+       check_sysctl_file ${TARGET}
        reset_vals
        ORIG=$(cat "${TARGET}")
        TEST_STR=$(( $ORIG + 1 ))
@@ -587,6 +575,7 @@ sysctl_test_0003()
 sysctl_test_0004()
 {
        TARGET="${SYSCTL}/uint_0001"
+       check_sysctl_file ${TARGET}
        reset_vals
        ORIG=$(cat "${TARGET}")
        TEST_STR=$(( $ORIG + 1 ))
@@ -599,6 +588,7 @@ sysctl_test_0004()
 sysctl_test_0005()
 {
        TARGET="${SYSCTL}/int_0003"
+       check_sysctl_file ${TARGET}
        reset_vals
        ORIG=$(cat "${TARGET}")

@@ -620,8 +610,6 @@ list_tests()
        echo "0005 x $(get_test_count 0005) - tests proc_douintvec() array"
 }

-test_reqs
-
 usage()
 {
        NUM_TESTS=$(grep -o ' ' <<<"$ALL_TESTS" | grep -c .)
@@ -770,7 +758,6 @@ function parse_args()
 test_reqs
 allow_user_defaults
 check_production_sysctl_writes_strict
-test_modprobe
 load_req_mod

 trap "test_finish" EXIT


Cheers,
Anders

  reply	other threads:[~2018-10-09  7:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-06 10:22 [PATCH v2] sysctl: kselftests: fix test_modprobe issue Lei Yang
2018-09-06 10:22 ` Lei Yang
2018-09-06 10:22 ` Lei.Yang
2018-10-09  7:29 ` Anders Roxell [this message]
2018-10-09  7:29   ` Anders Roxell
2018-10-09  7:29   ` anders.roxell
2018-11-21 22:27 ` Luis Chamberlain
2018-11-21 22:27   ` Luis Chamberlain
2018-11-21 22:27   ` mcgrof

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CADYN=9+0RxfJRHhTM5GLMOi-EsOfe3tv+jvSfyQLLcSQB5FzHw@mail.gmail.com' \
    --to=anders.roxell@linaro.org \
    --cc=Lei.Yang@windriver.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.