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