1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3
4SRC_TREE=../../../../
5
6test_run()
7{
8	sysctl -w net.core.bpf_jit_enable=$1 2>&1 > /dev/null
9	sysctl -w net.core.bpf_jit_harden=$2 2>&1 > /dev/null
10
11	echo "[ JIT enabled:$1 hardened:$2 ]"
12	dmesg -C
13	if [ -f ${SRC_TREE}/lib/test_bpf.ko ]; then
14		insmod ${SRC_TREE}/lib/test_bpf.ko 2> /dev/null
15		if [ $? -ne 0 ]; then
16			rc=1
17		fi
18	else
19		# Use modprobe dry run to check for missing test_bpf module
20		if ! /sbin/modprobe -q -n test_bpf; then
21			echo "test_bpf: [SKIP]"
22		elif /sbin/modprobe -q test_bpf; then
23			echo "test_bpf: ok"
24		else
25			echo "test_bpf: [FAIL]"
26			rc=1
27		fi
28	fi
29	rmmod  test_bpf 2> /dev/null
30	dmesg | grep FAIL
31}
32
33test_save()
34{
35	JE=`sysctl -n net.core.bpf_jit_enable`
36	JH=`sysctl -n net.core.bpf_jit_harden`
37}
38
39test_restore()
40{
41	sysctl -w net.core.bpf_jit_enable=$JE 2>&1 > /dev/null
42	sysctl -w net.core.bpf_jit_harden=$JH 2>&1 > /dev/null
43}
44
45rc=0
46test_save
47test_run 0 0
48test_run 1 0
49test_run 1 1
50test_run 1 2
51test_restore
52exit $rc
53