Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/sh
0002 # SPDX-License-Identifier: GPL-2.0+
0003 
0004 #
0005 # Runs an individual test module.
0006 #
0007 # kselftest expects a separate executable for each test, this can be
0008 # created by adding a script like this:
0009 #
0010 #   #!/bin/sh
0011 #   SPDX-License-Identifier: GPL-2.0+
0012 #   $(dirname $0)/../kselftest/module.sh "description" module_name
0013 #
0014 # Example: tools/testing/selftests/lib/printf.sh
0015 
0016 desc=""                         # Output prefix.
0017 module=""                       # Filename (without the .ko).
0018 args=""                         # modprobe arguments.
0019 
0020 modprobe="/sbin/modprobe"
0021 
0022 main() {
0023     parse_args "$@"
0024     assert_root
0025     assert_have_module
0026     run_module
0027 }
0028 
0029 parse_args() {
0030     script=${0##*/}
0031 
0032     if [ $# -lt 2 ]; then
0033         echo "Usage: $script <description> <module_name> [FAIL]"
0034         exit 1
0035     fi
0036 
0037     desc="$1"
0038     shift || true
0039     module="$1"
0040     shift || true
0041     args="$@"
0042 }
0043 
0044 assert_root() {
0045     if [ ! -w /dev ]; then
0046         skip "please run as root"
0047     fi
0048 }
0049 
0050 assert_have_module() {
0051     if ! $modprobe -q -n $module; then
0052         skip "module $module is not found"
0053     fi
0054 }
0055 
0056 run_module() {
0057     if $modprobe -q $module $args; then
0058         $modprobe -q -r $module
0059         say "ok"
0060     else
0061         fail ""
0062     fi
0063 }
0064 
0065 say() {
0066     echo "$desc: $1"
0067 }
0068 
0069 
0070 fail() {
0071     say "$1 [FAIL]" >&2
0072     exit 1
0073 }
0074 
0075 skip() {
0076     say "$1 [SKIP]" >&2
0077     # Kselftest framework requirement - SKIP code is 4.
0078     exit 4
0079 }
0080 
0081 #
0082 # Main script
0083 #
0084 main "$@"