treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / tools / testing / selftests / bpf / test_kmod.sh
blob9df0d2ac45f8453b9529c4ea90fb19dba3f86480
1 #!/bin/sh
2 # SPDX-License-Identifier: GPL-2.0
4 # Kselftest framework requirement - SKIP code is 4.
5 ksft_skip=4
7 msg="skip all tests:"
8 if [ "$(id -u)" != "0" ]; then
9 echo $msg please run this as root >&2
10 exit $ksft_skip
13 SRC_TREE=../../../../
15 test_run()
17 sysctl -w net.core.bpf_jit_enable=$1 2>&1 > /dev/null
18 sysctl -w net.core.bpf_jit_harden=$2 2>&1 > /dev/null
20 echo "[ JIT enabled:$1 hardened:$2 ]"
21 dmesg -C
22 if [ -f ${SRC_TREE}/lib/test_bpf.ko ]; then
23 insmod ${SRC_TREE}/lib/test_bpf.ko 2> /dev/null
24 if [ $? -ne 0 ]; then
25 rc=1
27 else
28 # Use modprobe dry run to check for missing test_bpf module
29 if ! /sbin/modprobe -q -n test_bpf; then
30 echo "test_bpf: [SKIP]"
31 elif /sbin/modprobe -q test_bpf; then
32 echo "test_bpf: ok"
33 else
34 echo "test_bpf: [FAIL]"
35 rc=1
38 rmmod test_bpf 2> /dev/null
39 dmesg | grep FAIL
42 test_save()
44 JE=`sysctl -n net.core.bpf_jit_enable`
45 JH=`sysctl -n net.core.bpf_jit_harden`
48 test_restore()
50 sysctl -w net.core.bpf_jit_enable=$JE 2>&1 > /dev/null
51 sysctl -w net.core.bpf_jit_harden=$JH 2>&1 > /dev/null
54 rc=0
55 test_save
56 test_run 0 0
57 test_run 1 0
58 test_run 1 1
59 test_run 1 2
60 test_restore
61 exit $rc