All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3.1] selftests: Clean up module testing shell script
@ 2019-04-02 22:26 ` keescook
  0 siblings, 0 replies; 12+ messages in thread
From: Kees Cook @ 2019-04-02 22:26 UTC (permalink / raw)
  To: Tobin C. Harding; +Cc: Shuah Khan, linux-kselftest, linux-kernel

This adjusts kselftest_module.sh to take an option "args" argument for
modprobe arguments, removes bash-isms (since some system's /bin/sh may
not be bash), and refactors the lib/ scripts into a shorter calling
convention.

Signed-off-by: Kees Cook <keescook@chromium.org>
---
This is my suggested clean-up for the module testing script for the
strscpy_pad() series...
---
 tools/testing/selftests/kselftest_module.sh  | 24 ++++++++++++--------
 tools/testing/selftests/lib/bitmap.sh        | 17 +-------------
 tools/testing/selftests/lib/prime_numbers.sh | 17 ++------------
 tools/testing/selftests/lib/printf.sh        | 16 +------------
 tools/testing/selftests/lib/strscpy.sh       | 17 ++------------
 5 files changed, 20 insertions(+), 71 deletions(-)

diff --git a/tools/testing/selftests/kselftest_module.sh b/tools/testing/selftests/kselftest_module.sh
index b5d446738614..20a897d21fde 100755
--- a/tools/testing/selftests/kselftest_module.sh
+++ b/tools/testing/selftests/kselftest_module.sh
@@ -2,19 +2,20 @@
 # SPDX-License-Identifier: GPL-2.0+
 
 #
-# Runs an individual test module.  kselftest expects a separate
-# executable for each test.  So test should each have an individial
+# Runs an individual test module. kselftest expects a separate
+# executable for each test. So test should each have an individial
 # script that can call this script.
 #
 
 # Individual test scrits should define these:
 module=""			# filename (without the .ko).
 desc=""				# Output prefix.
+args=""				# modprobe arguments
 
 modprobe="/sbin/modprobe"
 
 main() {
-    parse_args $@
+    parse_args "$@"
     assert_root
     assert_have_module
     run_module
@@ -23,17 +24,20 @@ main() {
 parse_args() {
     script=${0##*/}
 
-    if [[ ! $# -eq 2 ]]; then
-	echo "Usage: $script <module_name> <description> [FAIL]"
+    if [ $# -lt 2 ]; then
+	echo "Usage: $script <description> <module_name> [FAIL]"
 	exit 1
     fi
 
-    module=$1
-    desc=$2
+    desc="$1"
+    shift || true
+    module="$1"
+    shift || true
+    args="$@"
 }
 
 assert_root() {
-    if [[ $EUID -ne 0 ]]; then
+    if [ ! -w /dev ]; then
 	skip "please run as root"
     fi
 }
@@ -45,7 +49,7 @@ assert_have_module() {
 }
 
 run_module() {
-    if $modprobe -q $module; then
+    if $modprobe -q $module $args; then
 	$modprobe -q -r $module
 	say "ok"
     else
@@ -72,4 +76,4 @@ skip() {
 #
 # Main script
 #
-main $@
+main "$@"
diff --git a/tools/testing/selftests/lib/bitmap.sh b/tools/testing/selftests/lib/bitmap.sh
index ed4180ea0021..5511dddc5c2d 100755
--- a/tools/testing/selftests/lib/bitmap.sh
+++ b/tools/testing/selftests/lib/bitmap.sh
@@ -1,18 +1,3 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0
-
-module=test_bitmap
-description="bitmap"
-
-#
-# Shouldn't need to edit anything below here.
-#
-
-file="kselftest_module.sh"
-path="../$file"
-if [[ ! $KBUILD_SRC == "" ]]; then
-    path="${KBUILD_SRC}/tools/testing/selftests/$file"
-fi
-
-$path $module $description
-
+$(dirname $0)/../kselftest_module.sh "bitmap" test_bitmap
diff --git a/tools/testing/selftests/lib/prime_numbers.sh b/tools/testing/selftests/lib/prime_numbers.sh
index 6f782386d897..2b6be0308a6d 100755
--- a/tools/testing/selftests/lib/prime_numbers.sh
+++ b/tools/testing/selftests/lib/prime_numbers.sh
@@ -1,18 +1,5 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0
 # Checks fast/slow prime_number generation for inconsistencies
-
-module=prime_numbers
-description="prime_numbers"
-
-#
-# Shouldn't need to edit anything below here.
-#
-
-file="kselftest_module.sh"
-path="../$file"
-if [[ ! $KBUILD_SRC == "" ]]; then
-    path="${KBUILD_SRC}/tools/testing/selftests/$file"
-fi
-
-$path $module $description
+$(dirname $0)/../kselftest_module.sh "prime numbers" prime_numbers \
+					selftest=65536
diff --git a/tools/testing/selftests/lib/printf.sh b/tools/testing/selftests/lib/printf.sh
index 89717915d028..2ffa61da0296 100755
--- a/tools/testing/selftests/lib/printf.sh
+++ b/tools/testing/selftests/lib/printf.sh
@@ -1,18 +1,4 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0
 # Tests the printf infrastructure using test_printf kernel module.
-
-module=test_printf
-description="printf"
-
-#
-# Shouldn't need to edit anything below here.
-#
-
-file="kselftest_module.sh"
-path="../$file"
-if [[ ! $KBUILD_SRC == "" ]]; then
-    path="${KBUILD_SRC}/tools/testing/selftests/$file"
-fi
-
-$path $module $description
+$(dirname $0)/../kselftest_module.sh "printf" test_printf
diff --git a/tools/testing/selftests/lib/strscpy.sh b/tools/testing/selftests/lib/strscpy.sh
index f3ba4b90e602..1f26dac74896 100755
--- a/tools/testing/selftests/lib/strscpy.sh
+++ b/tools/testing/selftests/lib/strscpy.sh
@@ -1,17 +1,4 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0+
-
-module=test_strscpy
-description="strscpy"
-
-#
-# Shouldn't need to edit anything below here.
-#
-
-file="kselftest_module.sh"
-path="../$file"
-if [[ ! $KBUILD_SRC == "" ]]; then
-    path="${KBUILD_SRC}/tools/testing/selftests/$file"
-fi
-
-$path $module $description
+# Test corner cases of the strscpy()-family of functions.
+$(dirname $0)/../kselftest_module.sh "strscpy" test_strscpy
-- 
2.17.1


-- 
Kees Cook

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3.1] selftests: Clean up module testing shell script
@ 2019-04-02 22:26 ` keescook
  0 siblings, 0 replies; 12+ messages in thread
From: keescook @ 2019-04-02 22:26 UTC (permalink / raw)


This adjusts kselftest_module.sh to take an option "args" argument for
modprobe arguments, removes bash-isms (since some system's /bin/sh may
not be bash), and refactors the lib/ scripts into a shorter calling
convention.

Signed-off-by: Kees Cook <keescook at chromium.org>
---
This is my suggested clean-up for the module testing script for the
strscpy_pad() series...
---
 tools/testing/selftests/kselftest_module.sh  | 24 ++++++++++++--------
 tools/testing/selftests/lib/bitmap.sh        | 17 +-------------
 tools/testing/selftests/lib/prime_numbers.sh | 17 ++------------
 tools/testing/selftests/lib/printf.sh        | 16 +------------
 tools/testing/selftests/lib/strscpy.sh       | 17 ++------------
 5 files changed, 20 insertions(+), 71 deletions(-)

diff --git a/tools/testing/selftests/kselftest_module.sh b/tools/testing/selftests/kselftest_module.sh
index b5d446738614..20a897d21fde 100755
--- a/tools/testing/selftests/kselftest_module.sh
+++ b/tools/testing/selftests/kselftest_module.sh
@@ -2,19 +2,20 @@
 # SPDX-License-Identifier: GPL-2.0+
 
 #
-# Runs an individual test module.  kselftest expects a separate
-# executable for each test.  So test should each have an individial
+# Runs an individual test module. kselftest expects a separate
+# executable for each test. So test should each have an individial
 # script that can call this script.
 #
 
 # Individual test scrits should define these:
 module=""			# filename (without the .ko).
 desc=""				# Output prefix.
+args=""				# modprobe arguments
 
 modprobe="/sbin/modprobe"
 
 main() {
-    parse_args $@
+    parse_args "$@"
     assert_root
     assert_have_module
     run_module
@@ -23,17 +24,20 @@ main() {
 parse_args() {
     script=${0##*/}
 
-    if [[ ! $# -eq 2 ]]; then
-	echo "Usage: $script <module_name> <description> [FAIL]"
+    if [ $# -lt 2 ]; then
+	echo "Usage: $script <description> <module_name> [FAIL]"
 	exit 1
     fi
 
-    module=$1
-    desc=$2
+    desc="$1"
+    shift || true
+    module="$1"
+    shift || true
+    args="$@"
 }
 
 assert_root() {
-    if [[ $EUID -ne 0 ]]; then
+    if [ ! -w /dev ]; then
 	skip "please run as root"
     fi
 }
@@ -45,7 +49,7 @@ assert_have_module() {
 }
 
 run_module() {
-    if $modprobe -q $module; then
+    if $modprobe -q $module $args; then
 	$modprobe -q -r $module
 	say "ok"
     else
@@ -72,4 +76,4 @@ skip() {
 #
 # Main script
 #
-main $@
+main "$@"
diff --git a/tools/testing/selftests/lib/bitmap.sh b/tools/testing/selftests/lib/bitmap.sh
index ed4180ea0021..5511dddc5c2d 100755
--- a/tools/testing/selftests/lib/bitmap.sh
+++ b/tools/testing/selftests/lib/bitmap.sh
@@ -1,18 +1,3 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0
-
-module=test_bitmap
-description="bitmap"
-
-#
-# Shouldn't need to edit anything below here.
-#
-
-file="kselftest_module.sh"
-path="../$file"
-if [[ ! $KBUILD_SRC == "" ]]; then
-    path="${KBUILD_SRC}/tools/testing/selftests/$file"
-fi
-
-$path $module $description
-
+$(dirname $0)/../kselftest_module.sh "bitmap" test_bitmap
diff --git a/tools/testing/selftests/lib/prime_numbers.sh b/tools/testing/selftests/lib/prime_numbers.sh
index 6f782386d897..2b6be0308a6d 100755
--- a/tools/testing/selftests/lib/prime_numbers.sh
+++ b/tools/testing/selftests/lib/prime_numbers.sh
@@ -1,18 +1,5 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0
 # Checks fast/slow prime_number generation for inconsistencies
-
-module=prime_numbers
-description="prime_numbers"
-
-#
-# Shouldn't need to edit anything below here.
-#
-
-file="kselftest_module.sh"
-path="../$file"
-if [[ ! $KBUILD_SRC == "" ]]; then
-    path="${KBUILD_SRC}/tools/testing/selftests/$file"
-fi
-
-$path $module $description
+$(dirname $0)/../kselftest_module.sh "prime numbers" prime_numbers \
+					selftest=65536
diff --git a/tools/testing/selftests/lib/printf.sh b/tools/testing/selftests/lib/printf.sh
index 89717915d028..2ffa61da0296 100755
--- a/tools/testing/selftests/lib/printf.sh
+++ b/tools/testing/selftests/lib/printf.sh
@@ -1,18 +1,4 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0
 # Tests the printf infrastructure using test_printf kernel module.
-
-module=test_printf
-description="printf"
-
-#
-# Shouldn't need to edit anything below here.
-#
-
-file="kselftest_module.sh"
-path="../$file"
-if [[ ! $KBUILD_SRC == "" ]]; then
-    path="${KBUILD_SRC}/tools/testing/selftests/$file"
-fi
-
-$path $module $description
+$(dirname $0)/../kselftest_module.sh "printf" test_printf
diff --git a/tools/testing/selftests/lib/strscpy.sh b/tools/testing/selftests/lib/strscpy.sh
index f3ba4b90e602..1f26dac74896 100755
--- a/tools/testing/selftests/lib/strscpy.sh
+++ b/tools/testing/selftests/lib/strscpy.sh
@@ -1,17 +1,4 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0+
-
-module=test_strscpy
-description="strscpy"
-
-#
-# Shouldn't need to edit anything below here.
-#
-
-file="kselftest_module.sh"
-path="../$file"
-if [[ ! $KBUILD_SRC == "" ]]; then
-    path="${KBUILD_SRC}/tools/testing/selftests/$file"
-fi
-
-$path $module $description
+# Test corner cases of the strscpy()-family of functions.
+$(dirname $0)/../kselftest_module.sh "strscpy" test_strscpy
-- 
2.17.1


-- 
Kees Cook

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v3.1] selftests: Clean up module testing shell script
@ 2019-04-02 22:26 ` keescook
  0 siblings, 0 replies; 12+ messages in thread
From: Kees Cook @ 2019-04-02 22:26 UTC (permalink / raw)


This adjusts kselftest_module.sh to take an option "args" argument for
modprobe arguments, removes bash-isms (since some system's /bin/sh may
not be bash), and refactors the lib/ scripts into a shorter calling
convention.

Signed-off-by: Kees Cook <keescook at chromium.org>
---
This is my suggested clean-up for the module testing script for the
strscpy_pad() series...
---
 tools/testing/selftests/kselftest_module.sh  | 24 ++++++++++++--------
 tools/testing/selftests/lib/bitmap.sh        | 17 +-------------
 tools/testing/selftests/lib/prime_numbers.sh | 17 ++------------
 tools/testing/selftests/lib/printf.sh        | 16 +------------
 tools/testing/selftests/lib/strscpy.sh       | 17 ++------------
 5 files changed, 20 insertions(+), 71 deletions(-)

diff --git a/tools/testing/selftests/kselftest_module.sh b/tools/testing/selftests/kselftest_module.sh
index b5d446738614..20a897d21fde 100755
--- a/tools/testing/selftests/kselftest_module.sh
+++ b/tools/testing/selftests/kselftest_module.sh
@@ -2,19 +2,20 @@
 # SPDX-License-Identifier: GPL-2.0+
 
 #
-# Runs an individual test module.  kselftest expects a separate
-# executable for each test.  So test should each have an individial
+# Runs an individual test module. kselftest expects a separate
+# executable for each test. So test should each have an individial
 # script that can call this script.
 #
 
 # Individual test scrits should define these:
 module=""			# filename (without the .ko).
 desc=""				# Output prefix.
+args=""				# modprobe arguments
 
 modprobe="/sbin/modprobe"
 
 main() {
-    parse_args $@
+    parse_args "$@"
     assert_root
     assert_have_module
     run_module
@@ -23,17 +24,20 @@ main() {
 parse_args() {
     script=${0##*/}
 
-    if [[ ! $# -eq 2 ]]; then
-	echo "Usage: $script <module_name> <description> [FAIL]"
+    if [ $# -lt 2 ]; then
+	echo "Usage: $script <description> <module_name> [FAIL]"
 	exit 1
     fi
 
-    module=$1
-    desc=$2
+    desc="$1"
+    shift || true
+    module="$1"
+    shift || true
+    args="$@"
 }
 
 assert_root() {
-    if [[ $EUID -ne 0 ]]; then
+    if [ ! -w /dev ]; then
 	skip "please run as root"
     fi
 }
@@ -45,7 +49,7 @@ assert_have_module() {
 }
 
 run_module() {
-    if $modprobe -q $module; then
+    if $modprobe -q $module $args; then
 	$modprobe -q -r $module
 	say "ok"
     else
@@ -72,4 +76,4 @@ skip() {
 #
 # Main script
 #
-main $@
+main "$@"
diff --git a/tools/testing/selftests/lib/bitmap.sh b/tools/testing/selftests/lib/bitmap.sh
index ed4180ea0021..5511dddc5c2d 100755
--- a/tools/testing/selftests/lib/bitmap.sh
+++ b/tools/testing/selftests/lib/bitmap.sh
@@ -1,18 +1,3 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0
-
-module=test_bitmap
-description="bitmap"
-
-#
-# Shouldn't need to edit anything below here.
-#
-
-file="kselftest_module.sh"
-path="../$file"
-if [[ ! $KBUILD_SRC == "" ]]; then
-    path="${KBUILD_SRC}/tools/testing/selftests/$file"
-fi
-
-$path $module $description
-
+$(dirname $0)/../kselftest_module.sh "bitmap" test_bitmap
diff --git a/tools/testing/selftests/lib/prime_numbers.sh b/tools/testing/selftests/lib/prime_numbers.sh
index 6f782386d897..2b6be0308a6d 100755
--- a/tools/testing/selftests/lib/prime_numbers.sh
+++ b/tools/testing/selftests/lib/prime_numbers.sh
@@ -1,18 +1,5 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0
 # Checks fast/slow prime_number generation for inconsistencies
-
-module=prime_numbers
-description="prime_numbers"
-
-#
-# Shouldn't need to edit anything below here.
-#
-
-file="kselftest_module.sh"
-path="../$file"
-if [[ ! $KBUILD_SRC == "" ]]; then
-    path="${KBUILD_SRC}/tools/testing/selftests/$file"
-fi
-
-$path $module $description
+$(dirname $0)/../kselftest_module.sh "prime numbers" prime_numbers \
+					selftest=65536
diff --git a/tools/testing/selftests/lib/printf.sh b/tools/testing/selftests/lib/printf.sh
index 89717915d028..2ffa61da0296 100755
--- a/tools/testing/selftests/lib/printf.sh
+++ b/tools/testing/selftests/lib/printf.sh
@@ -1,18 +1,4 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0
 # Tests the printf infrastructure using test_printf kernel module.
-
-module=test_printf
-description="printf"
-
-#
-# Shouldn't need to edit anything below here.
-#
-
-file="kselftest_module.sh"
-path="../$file"
-if [[ ! $KBUILD_SRC == "" ]]; then
-    path="${KBUILD_SRC}/tools/testing/selftests/$file"
-fi
-
-$path $module $description
+$(dirname $0)/../kselftest_module.sh "printf" test_printf
diff --git a/tools/testing/selftests/lib/strscpy.sh b/tools/testing/selftests/lib/strscpy.sh
index f3ba4b90e602..1f26dac74896 100755
--- a/tools/testing/selftests/lib/strscpy.sh
+++ b/tools/testing/selftests/lib/strscpy.sh
@@ -1,17 +1,4 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0+
-
-module=test_strscpy
-description="strscpy"
-
-#
-# Shouldn't need to edit anything below here.
-#
-
-file="kselftest_module.sh"
-path="../$file"
-if [[ ! $KBUILD_SRC == "" ]]; then
-    path="${KBUILD_SRC}/tools/testing/selftests/$file"
-fi
-
-$path $module $description
+# Test corner cases of the strscpy()-family of functions.
+$(dirname $0)/../kselftest_module.sh "strscpy" test_strscpy
-- 
2.17.1


-- 
Kees Cook

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH v3.1] selftests: Clean up module testing shell script
  2019-04-02 22:26 ` keescook
  (?)
@ 2019-04-02 22:31   ` rdunlap
  -1 siblings, 0 replies; 12+ messages in thread
From: Randy Dunlap @ 2019-04-02 22:31 UTC (permalink / raw)
  To: Kees Cook, Tobin C. Harding; +Cc: Shuah Khan, linux-kselftest, linux-kernel

Hi,

Minor corrections below:

On 4/2/19 3:26 PM, Kees Cook wrote:
> This adjusts kselftest_module.sh to take an option "args" argument for
> modprobe arguments, removes bash-isms (since some system's /bin/sh may
> not be bash), and refactors the lib/ scripts into a shorter calling
> convention.
> 
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
> This is my suggested clean-up for the module testing script for the
> strscpy_pad() series...
> ---
>  tools/testing/selftests/kselftest_module.sh  | 24 ++++++++++++--------
>  tools/testing/selftests/lib/bitmap.sh        | 17 +-------------
>  tools/testing/selftests/lib/prime_numbers.sh | 17 ++------------
>  tools/testing/selftests/lib/printf.sh        | 16 +------------
>  tools/testing/selftests/lib/strscpy.sh       | 17 ++------------
>  5 files changed, 20 insertions(+), 71 deletions(-)
> 
> diff --git a/tools/testing/selftests/kselftest_module.sh b/tools/testing/selftests/kselftest_module.sh
> index b5d446738614..20a897d21fde 100755
> --- a/tools/testing/selftests/kselftest_module.sh
> +++ b/tools/testing/selftests/kselftest_module.sh
> @@ -2,19 +2,20 @@
>  # SPDX-License-Identifier: GPL-2.0+
>  
>  #
> -# Runs an individual test module.  kselftest expects a separate
> -# executable for each test.  So test should each have an individial
> +# Runs an individual test module. kselftest expects a separate
> +# executable for each test. So test should each have an individial

                                  tests (?)                individual

>  # script that can call this script.
>  #
>  
>  # Individual test scrits should define these:

                     scripts

>  module=""			# filename (without the .ko).
>  desc=""				# Output prefix.
> +args=""				# modprobe arguments
>  
>  modprobe="/sbin/modprobe"
>  
>  main() {
> -    parse_args $@
> +    parse_args "$@"
>      assert_root
>      assert_have_module
>      run_module
> @@ -23,17 +24,20 @@ main() {
>  parse_args() {
>      script=${0##*/}
>  
> -    if [[ ! $# -eq 2 ]]; then
> -	echo "Usage: $script <module_name> <description> [FAIL]"
> +    if [ $# -lt 2 ]; then
> +	echo "Usage: $script <description> <module_name> [FAIL]"
>  	exit 1
>      fi
>  
> -    module=$1
> -    desc=$2
> +    desc="$1"
> +    shift || true
> +    module="$1"
> +    shift || true
> +    args="$@"
>  }
>  
>  assert_root() {
> -    if [[ $EUID -ne 0 ]]; then
> +    if [ ! -w /dev ]; then
>  	skip "please run as root"
>      fi
>  }
> @@ -45,7 +49,7 @@ assert_have_module() {
>  }
>  
>  run_module() {
> -    if $modprobe -q $module; then
> +    if $modprobe -q $module $args; then
>  	$modprobe -q -r $module
>  	say "ok"
>      else
> @@ -72,4 +76,4 @@ skip() {
>  #
>  # Main script
>  #
> -main $@
> +main "$@"


ciao.
-- 
~Randy

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3.1] selftests: Clean up module testing shell script
@ 2019-04-02 22:31   ` rdunlap
  0 siblings, 0 replies; 12+ messages in thread
From: rdunlap @ 2019-04-02 22:31 UTC (permalink / raw)


Hi,

Minor corrections below:

On 4/2/19 3:26 PM, Kees Cook wrote:
> This adjusts kselftest_module.sh to take an option "args" argument for
> modprobe arguments, removes bash-isms (since some system's /bin/sh may
> not be bash), and refactors the lib/ scripts into a shorter calling
> convention.
> 
> Signed-off-by: Kees Cook <keescook at chromium.org>
> ---
> This is my suggested clean-up for the module testing script for the
> strscpy_pad() series...
> ---
>  tools/testing/selftests/kselftest_module.sh  | 24 ++++++++++++--------
>  tools/testing/selftests/lib/bitmap.sh        | 17 +-------------
>  tools/testing/selftests/lib/prime_numbers.sh | 17 ++------------
>  tools/testing/selftests/lib/printf.sh        | 16 +------------
>  tools/testing/selftests/lib/strscpy.sh       | 17 ++------------
>  5 files changed, 20 insertions(+), 71 deletions(-)
> 
> diff --git a/tools/testing/selftests/kselftest_module.sh b/tools/testing/selftests/kselftest_module.sh
> index b5d446738614..20a897d21fde 100755
> --- a/tools/testing/selftests/kselftest_module.sh
> +++ b/tools/testing/selftests/kselftest_module.sh
> @@ -2,19 +2,20 @@
>  # SPDX-License-Identifier: GPL-2.0+
>  
>  #
> -# Runs an individual test module.  kselftest expects a separate
> -# executable for each test.  So test should each have an individial
> +# Runs an individual test module. kselftest expects a separate
> +# executable for each test. So test should each have an individial

                                  tests (?)                individual

>  # script that can call this script.
>  #
>  
>  # Individual test scrits should define these:

                     scripts

>  module=""			# filename (without the .ko).
>  desc=""				# Output prefix.
> +args=""				# modprobe arguments
>  
>  modprobe="/sbin/modprobe"
>  
>  main() {
> -    parse_args $@
> +    parse_args "$@"
>      assert_root
>      assert_have_module
>      run_module
> @@ -23,17 +24,20 @@ main() {
>  parse_args() {
>      script=${0##*/}
>  
> -    if [[ ! $# -eq 2 ]]; then
> -	echo "Usage: $script <module_name> <description> [FAIL]"
> +    if [ $# -lt 2 ]; then
> +	echo "Usage: $script <description> <module_name> [FAIL]"
>  	exit 1
>      fi
>  
> -    module=$1
> -    desc=$2
> +    desc="$1"
> +    shift || true
> +    module="$1"
> +    shift || true
> +    args="$@"
>  }
>  
>  assert_root() {
> -    if [[ $EUID -ne 0 ]]; then
> +    if [ ! -w /dev ]; then
>  	skip "please run as root"
>      fi
>  }
> @@ -45,7 +49,7 @@ assert_have_module() {
>  }
>  
>  run_module() {
> -    if $modprobe -q $module; then
> +    if $modprobe -q $module $args; then
>  	$modprobe -q -r $module
>  	say "ok"
>      else
> @@ -72,4 +76,4 @@ skip() {
>  #
>  # Main script
>  #
> -main $@
> +main "$@"


ciao.
-- 
~Randy

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3.1] selftests: Clean up module testing shell script
@ 2019-04-02 22:31   ` rdunlap
  0 siblings, 0 replies; 12+ messages in thread
From: Randy Dunlap @ 2019-04-02 22:31 UTC (permalink / raw)


Hi,

Minor corrections below:

On 4/2/19 3:26 PM, Kees Cook wrote:
> This adjusts kselftest_module.sh to take an option "args" argument for
> modprobe arguments, removes bash-isms (since some system's /bin/sh may
> not be bash), and refactors the lib/ scripts into a shorter calling
> convention.
> 
> Signed-off-by: Kees Cook <keescook at chromium.org>
> ---
> This is my suggested clean-up for the module testing script for the
> strscpy_pad() series...
> ---
>  tools/testing/selftests/kselftest_module.sh  | 24 ++++++++++++--------
>  tools/testing/selftests/lib/bitmap.sh        | 17 +-------------
>  tools/testing/selftests/lib/prime_numbers.sh | 17 ++------------
>  tools/testing/selftests/lib/printf.sh        | 16 +------------
>  tools/testing/selftests/lib/strscpy.sh       | 17 ++------------
>  5 files changed, 20 insertions(+), 71 deletions(-)
> 
> diff --git a/tools/testing/selftests/kselftest_module.sh b/tools/testing/selftests/kselftest_module.sh
> index b5d446738614..20a897d21fde 100755
> --- a/tools/testing/selftests/kselftest_module.sh
> +++ b/tools/testing/selftests/kselftest_module.sh
> @@ -2,19 +2,20 @@
>  # SPDX-License-Identifier: GPL-2.0+
>  
>  #
> -# Runs an individual test module.  kselftest expects a separate
> -# executable for each test.  So test should each have an individial
> +# Runs an individual test module. kselftest expects a separate
> +# executable for each test. So test should each have an individial

                                  tests (?)                individual

>  # script that can call this script.
>  #
>  
>  # Individual test scrits should define these:

                     scripts

>  module=""			# filename (without the .ko).
>  desc=""				# Output prefix.
> +args=""				# modprobe arguments
>  
>  modprobe="/sbin/modprobe"
>  
>  main() {
> -    parse_args $@
> +    parse_args "$@"
>      assert_root
>      assert_have_module
>      run_module
> @@ -23,17 +24,20 @@ main() {
>  parse_args() {
>      script=${0##*/}
>  
> -    if [[ ! $# -eq 2 ]]; then
> -	echo "Usage: $script <module_name> <description> [FAIL]"
> +    if [ $# -lt 2 ]; then
> +	echo "Usage: $script <description> <module_name> [FAIL]"
>  	exit 1
>      fi
>  
> -    module=$1
> -    desc=$2
> +    desc="$1"
> +    shift || true
> +    module="$1"
> +    shift || true
> +    args="$@"
>  }
>  
>  assert_root() {
> -    if [[ $EUID -ne 0 ]]; then
> +    if [ ! -w /dev ]; then
>  	skip "please run as root"
>      fi
>  }
> @@ -45,7 +49,7 @@ assert_have_module() {
>  }
>  
>  run_module() {
> -    if $modprobe -q $module; then
> +    if $modprobe -q $module $args; then
>  	$modprobe -q -r $module
>  	say "ok"
>      else
> @@ -72,4 +76,4 @@ skip() {
>  #
>  # Main script
>  #
> -main $@
> +main "$@"


ciao.
-- 
~Randy

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3.1] selftests: Clean up module testing shell script
  2019-04-02 22:26 ` keescook
  (?)
@ 2019-04-03  0:23   ` me
  -1 siblings, 0 replies; 12+ messages in thread
From: Tobin C. Harding @ 2019-04-03  0:23 UTC (permalink / raw)
  To: Kees Cook; +Cc: Tobin C. Harding, Shuah Khan, linux-kselftest, linux-kernel

On Tue, Apr 02, 2019 at 03:26:10PM -0700, Kees Cook wrote:
> This adjusts kselftest_module.sh to take an option "args" argument for
> modprobe arguments, removes bash-isms (since some system's /bin/sh may
> not be bash), and refactors the lib/ scripts into a shorter calling
> convention.
> 
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
> This is my suggested clean-up for the module testing script for the
> strscpy_pad() series...

You are seriously at risk of being the most awesome code reviewer on
LKML.  Beer is on me next time I see you.

I will roll this into a v4 for the strscpy_pad() set.  Would you like a
Co-developed-by tag or just a mention in the commit log?

thanks,
Tobin.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3.1] selftests: Clean up module testing shell script
@ 2019-04-03  0:23   ` me
  0 siblings, 0 replies; 12+ messages in thread
From: me @ 2019-04-03  0:23 UTC (permalink / raw)


On Tue, Apr 02, 2019 at 03:26:10PM -0700, Kees Cook wrote:
> This adjusts kselftest_module.sh to take an option "args" argument for
> modprobe arguments, removes bash-isms (since some system's /bin/sh may
> not be bash), and refactors the lib/ scripts into a shorter calling
> convention.
> 
> Signed-off-by: Kees Cook <keescook at chromium.org>
> ---
> This is my suggested clean-up for the module testing script for the
> strscpy_pad() series...

You are seriously at risk of being the most awesome code reviewer on
LKML.  Beer is on me next time I see you.

I will roll this into a v4 for the strscpy_pad() set.  Would you like a
Co-developed-by tag or just a mention in the commit log?

thanks,
Tobin.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3.1] selftests: Clean up module testing shell script
@ 2019-04-03  0:23   ` me
  0 siblings, 0 replies; 12+ messages in thread
From: Tobin C. Harding @ 2019-04-03  0:23 UTC (permalink / raw)


On Tue, Apr 02, 2019@03:26:10PM -0700, Kees Cook wrote:
> This adjusts kselftest_module.sh to take an option "args" argument for
> modprobe arguments, removes bash-isms (since some system's /bin/sh may
> not be bash), and refactors the lib/ scripts into a shorter calling
> convention.
> 
> Signed-off-by: Kees Cook <keescook at chromium.org>
> ---
> This is my suggested clean-up for the module testing script for the
> strscpy_pad() series...

You are seriously at risk of being the most awesome code reviewer on
LKML.  Beer is on me next time I see you.

I will roll this into a v4 for the strscpy_pad() set.  Would you like a
Co-developed-by tag or just a mention in the commit log?

thanks,
Tobin.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3.1] selftests: Clean up module testing shell script
  2019-04-03  0:23   ` me
  (?)
@ 2019-04-03 15:28     ` keescook
  -1 siblings, 0 replies; 12+ messages in thread
From: Kees Cook @ 2019-04-03 15:28 UTC (permalink / raw)
  To: Tobin C. Harding
  Cc: Tobin C. Harding, Shuah Khan, open list:KERNEL SELFTEST FRAMEWORK, LKML

On Tue, Apr 2, 2019 at 5:24 PM Tobin C. Harding <me@tobin.cc> wrote:
>
> On Tue, Apr 02, 2019 at 03:26:10PM -0700, Kees Cook wrote:
> > This adjusts kselftest_module.sh to take an option "args" argument for
> > modprobe arguments, removes bash-isms (since some system's /bin/sh may
> > not be bash), and refactors the lib/ scripts into a shorter calling
> > convention.
> >
> > Signed-off-by: Kees Cook <keescook@chromium.org>
> > ---
> > This is my suggested clean-up for the module testing script for the
> > strscpy_pad() series...
>
> You are seriously at risk of being the most awesome code reviewer on
> LKML.  Beer is on me next time I see you.

And slowest! ;)

> I will roll this into a v4 for the strscpy_pad() set.  Would you like a
> Co-developed-by tag or just a mention in the commit log?

I'm happy either way. I really just tweaked it; maybe commit log?

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3.1] selftests: Clean up module testing shell script
@ 2019-04-03 15:28     ` keescook
  0 siblings, 0 replies; 12+ messages in thread
From: keescook @ 2019-04-03 15:28 UTC (permalink / raw)


On Tue, Apr 2, 2019 at 5:24 PM Tobin C. Harding <me at tobin.cc> wrote:
>
> On Tue, Apr 02, 2019 at 03:26:10PM -0700, Kees Cook wrote:
> > This adjusts kselftest_module.sh to take an option "args" argument for
> > modprobe arguments, removes bash-isms (since some system's /bin/sh may
> > not be bash), and refactors the lib/ scripts into a shorter calling
> > convention.
> >
> > Signed-off-by: Kees Cook <keescook at chromium.org>
> > ---
> > This is my suggested clean-up for the module testing script for the
> > strscpy_pad() series...
>
> You are seriously at risk of being the most awesome code reviewer on
> LKML.  Beer is on me next time I see you.

And slowest! ;)

> I will roll this into a v4 for the strscpy_pad() set.  Would you like a
> Co-developed-by tag or just a mention in the commit log?

I'm happy either way. I really just tweaked it; maybe commit log?

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3.1] selftests: Clean up module testing shell script
@ 2019-04-03 15:28     ` keescook
  0 siblings, 0 replies; 12+ messages in thread
From: Kees Cook @ 2019-04-03 15:28 UTC (permalink / raw)


On Tue, Apr 2, 2019@5:24 PM Tobin C. Harding <me@tobin.cc> wrote:
>
> On Tue, Apr 02, 2019@03:26:10PM -0700, Kees Cook wrote:
> > This adjusts kselftest_module.sh to take an option "args" argument for
> > modprobe arguments, removes bash-isms (since some system's /bin/sh may
> > not be bash), and refactors the lib/ scripts into a shorter calling
> > convention.
> >
> > Signed-off-by: Kees Cook <keescook at chromium.org>
> > ---
> > This is my suggested clean-up for the module testing script for the
> > strscpy_pad() series...
>
> You are seriously at risk of being the most awesome code reviewer on
> LKML.  Beer is on me next time I see you.

And slowest! ;)

> I will roll this into a v4 for the strscpy_pad() set.  Would you like a
> Co-developed-by tag or just a mention in the commit log?

I'm happy either way. I really just tweaked it; maybe commit log?

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2019-04-03 15:28 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-02 22:26 [PATCH v3.1] selftests: Clean up module testing shell script Kees Cook
2019-04-02 22:26 ` Kees Cook
2019-04-02 22:26 ` keescook
2019-04-02 22:31 ` Randy Dunlap
2019-04-02 22:31   ` Randy Dunlap
2019-04-02 22:31   ` rdunlap
2019-04-03  0:23 ` Tobin C. Harding
2019-04-03  0:23   ` Tobin C. Harding
2019-04-03  0:23   ` me
2019-04-03 15:28   ` Kees Cook
2019-04-03 15:28     ` Kees Cook
2019-04-03 15:28     ` keescook

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.