Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/sh
0002 # SPDX-License-Identifier: GPL-2.0
0003 
0004 # Kselftest framework requirement - SKIP code is 4.
0005 ksft_skip=4
0006 
0007 msg="skip all tests:"
0008 if [ "$(id -u)" != "0" ]; then
0009         echo $msg please run this as root >&2
0010         exit $ksft_skip
0011 fi
0012 
0013 if [ "$building_out_of_srctree" ]; then
0014         # We are in linux-build/kselftest/bpf
0015         OUTPUT=../../
0016 else
0017         # We are in linux/tools/testing/selftests/bpf
0018         OUTPUT=../../../../
0019 fi
0020 
0021 test_run()
0022 {
0023         sysctl -w net.core.bpf_jit_enable=$1 2>&1 > /dev/null
0024         sysctl -w net.core.bpf_jit_harden=$2 2>&1 > /dev/null
0025 
0026         echo "[ JIT enabled:$1 hardened:$2 ]"
0027         dmesg -C
0028         if [ -f ${OUTPUT}/lib/test_bpf.ko ]; then
0029                 insmod ${OUTPUT}/lib/test_bpf.ko 2> /dev/null
0030                 if [ $? -ne 0 ]; then
0031                         rc=1
0032                 fi
0033         else
0034                 # Use modprobe dry run to check for missing test_bpf module
0035                 if ! /sbin/modprobe -q -n test_bpf; then
0036                         echo "test_bpf: [SKIP]"
0037                 elif /sbin/modprobe -q test_bpf; then
0038                         echo "test_bpf: ok"
0039                 else
0040                         echo "test_bpf: [FAIL]"
0041                         rc=1
0042                 fi
0043         fi
0044         rmmod  test_bpf 2> /dev/null
0045         dmesg | grep FAIL
0046 }
0047 
0048 test_save()
0049 {
0050         JE=`sysctl -n net.core.bpf_jit_enable`
0051         JH=`sysctl -n net.core.bpf_jit_harden`
0052 }
0053 
0054 test_restore()
0055 {
0056         sysctl -w net.core.bpf_jit_enable=$JE 2>&1 > /dev/null
0057         sysctl -w net.core.bpf_jit_harden=$JH 2>&1 > /dev/null
0058 }
0059 
0060 rc=0
0061 test_save
0062 test_run 0 0
0063 test_run 1 0
0064 test_run 1 1
0065 test_run 1 2
0066 test_restore
0067 exit $rc