1 #!/bin/sh 1 #!/bin/sh 2 # SPDX-License-Identifier: GPL-2.0 2 # SPDX-License-Identifier: GPL-2.0 3 3 4 # Usage: !! 4 SRC_TREE=../../../../ 5 # ./test_kmod.sh [module_param]... << 6 # Ex.: ./test_kmod.sh test_range=1,3 << 7 # All the parameters are passed to the kernel << 8 << 9 # Kselftest framework requirement - SKIP code << 10 ksft_skip=4 << 11 << 12 msg="skip all tests:" << 13 if [ "$(id -u)" != "0" ]; then << 14 echo $msg please run this as root >&2 << 15 exit $ksft_skip << 16 fi << 17 << 18 if [ "$building_out_of_srctree" ]; then << 19 # We are in linux-build/kselftest/bpf << 20 OUTPUT=../../ << 21 else << 22 # We are in linux/tools/testing/selfte << 23 OUTPUT=../../../../ << 24 fi << 25 5 26 test_run() 6 test_run() 27 { 7 { 28 sysctl -w net.core.bpf_jit_enable=$1 2 8 sysctl -w net.core.bpf_jit_enable=$1 2>&1 > /dev/null 29 sysctl -w net.core.bpf_jit_harden=$2 2 9 sysctl -w net.core.bpf_jit_harden=$2 2>&1 > /dev/null 30 10 31 echo "[ JIT enabled:$1 hardened:$2 ]" 11 echo "[ JIT enabled:$1 hardened:$2 ]" 32 shift 2 << 33 dmesg -C 12 dmesg -C 34 if [ -f ${OUTPUT}/lib/test_bpf.ko ]; t !! 13 insmod $SRC_TREE/lib/test_bpf.ko 2> /dev/null 35 insmod ${OUTPUT}/lib/test_bpf. !! 14 if [ $? -ne 0 ]; then 36 if [ $? -ne 0 ]; then !! 15 rc=1 37 rc=1 << 38 fi << 39 else << 40 # Use modprobe dry run to chec << 41 if ! /sbin/modprobe -q -n test << 42 echo "test_bpf: [SKIP] << 43 elif /sbin/modprobe -q test_bp << 44 echo "test_bpf: ok" << 45 else << 46 echo "test_bpf: [FAIL] << 47 rc=1 << 48 fi << 49 fi 16 fi 50 rmmod test_bpf 2> /dev/null 17 rmmod test_bpf 2> /dev/null 51 dmesg | grep FAIL 18 dmesg | grep FAIL 52 } 19 } 53 20 54 test_save() 21 test_save() 55 { 22 { 56 JE=`sysctl -n net.core.bpf_jit_enable` 23 JE=`sysctl -n net.core.bpf_jit_enable` 57 JH=`sysctl -n net.core.bpf_jit_harden` 24 JH=`sysctl -n net.core.bpf_jit_harden` 58 } 25 } 59 26 60 test_restore() 27 test_restore() 61 { 28 { 62 sysctl -w net.core.bpf_jit_enable=$JE 29 sysctl -w net.core.bpf_jit_enable=$JE 2>&1 > /dev/null 63 sysctl -w net.core.bpf_jit_harden=$JH 30 sysctl -w net.core.bpf_jit_harden=$JH 2>&1 > /dev/null 64 } 31 } 65 32 66 rc=0 33 rc=0 67 test_save 34 test_save 68 test_run 0 0 "$@" !! 35 test_run 0 0 69 test_run 1 0 "$@" !! 36 test_run 1 0 70 test_run 1 1 "$@" !! 37 test_run 1 1 71 test_run 1 2 "$@" !! 38 test_run 1 2 72 test_restore 39 test_restore 73 exit $rc 40 exit $rc
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.