Path: blob/master/tools/testing/selftests/kselftest/module.sh
26285 views
#!/bin/sh1# SPDX-License-Identifier: GPL-2.0+23#4# Runs an individual test module.5#6# kselftest expects a separate executable for each test, this can be7# created by adding a script like this:8#9# #!/bin/sh10# SPDX-License-Identifier: GPL-2.0+11# $(dirname $0)/../kselftest/module.sh "description" module_name12#13# Example: tools/testing/selftests/lib/bitmap.sh1415desc="" # Output prefix.16module="" # Filename (without the .ko).17args="" # modprobe arguments.1819modprobe="/sbin/modprobe"2021main() {22parse_args "$@"23assert_root24assert_have_module25run_module26}2728parse_args() {29script=${0##*/}3031if [ $# -lt 2 ]; then32echo "Usage: $script <description> <module_name> [FAIL]"33exit 134fi3536desc="$1"37shift || true38module="$1"39shift || true40args="$@"41}4243assert_root() {44if [ ! -w /dev ]; then45skip "please run as root"46fi47}4849assert_have_module() {50if ! $modprobe -q -n $module; then51skip "module $module is not found"52fi53}5455run_module() {56if $modprobe -q $module $args; then57$modprobe -q -r $module58say "ok"59else60fail ""61fi62}6364say() {65echo "$desc: $1"66}676869fail() {70say "$1 [FAIL]" >&271exit 172}7374skip() {75say "$1 [SKIP]" >&276# Kselftest framework requirement - SKIP code is 4.77exit 478}7980#81# Main script82#83main "$@"848586