74 lines · bash
1#!/bin/sh2# SPDX-License-Identifier: GPL-2.03 4# Usage:5# ./test_kmod.sh [module_param]...6# Ex.: ./test_kmod.sh test_range=1,37# All the parameters are passed to the kernel module.8 9# Kselftest framework requirement - SKIP code is 4.10ksft_skip=411 12msg="skip all tests:"13if [ "$(id -u)" != "0" ]; then14 echo $msg please run this as root >&215 exit $ksft_skip16fi17 18if [ "$building_out_of_srctree" ]; then19 # We are in linux-build/kselftest/bpf20 OUTPUT=../../21else22 # We are in linux/tools/testing/selftests/bpf23 OUTPUT=../../../../24fi25 26test_run()27{28 sysctl -w net.core.bpf_jit_enable=$1 2>&1 > /dev/null29 sysctl -w net.core.bpf_jit_harden=$2 2>&1 > /dev/null30 31 echo "[ JIT enabled:$1 hardened:$2 ]"32 shift 233 dmesg -C34 if [ -f ${OUTPUT}/lib/test_bpf.ko ]; then35 insmod ${OUTPUT}/lib/test_bpf.ko "$@" 2> /dev/null36 if [ $? -ne 0 ]; then37 rc=138 fi39 else40 # Use modprobe dry run to check for missing test_bpf module41 if ! /sbin/modprobe -q -n test_bpf "$@"; then42 echo "test_bpf: [SKIP]"43 elif /sbin/modprobe -q test_bpf "$@"; then44 echo "test_bpf: ok"45 else46 echo "test_bpf: [FAIL]"47 rc=148 fi49 fi50 rmmod test_bpf 2> /dev/null51 dmesg | grep FAIL52}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/null63 sysctl -w net.core.bpf_jit_harden=$JH 2>&1 > /dev/null64}65 66rc=067test_save68test_run 0 0 "$@"69test_run 1 0 "$@"70test_run 1 1 "$@"71test_run 1 2 "$@"72test_restore73exit $rc74