106 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03#4# Copyright (C) 2018 Uladzislau Rezki (Sony) <urezki@gmail.com>5#6# This is a test script for the kernel test driver to analyse vmalloc7# allocator. Therefore it is just a kernel module loader. You can specify8# and pass different parameters in order to:9# a) analyse performance of vmalloc allocations;10# b) stressing and stability check of vmalloc subsystem.11 12TEST_NAME="test_hmm"13DRIVER="test_hmm"14 15# 1 if fails16exitcode=117 18# Kselftest framework requirement - SKIP code is 4.19ksft_skip=420 21check_test_requirements()22{23 uid=$(id -u)24 if [ $uid -ne 0 ]; then25 echo "$0: Must be run as root"26 exit $ksft_skip27 fi28 29 if ! which modprobe > /dev/null 2>&1; then30 echo "$0: You need modprobe installed"31 exit $ksft_skip32 fi33 34 if ! modinfo $DRIVER > /dev/null 2>&1; then35 echo "$0: You must have the following enabled in your kernel:"36 echo "CONFIG_TEST_HMM=m"37 exit $ksft_skip38 fi39}40 41load_driver()42{43 if [ $# -eq 0 ]; then44 modprobe $DRIVER > /dev/null 2>&145 else46 if [ $# -eq 2 ]; then47 modprobe $DRIVER spm_addr_dev0=$1 spm_addr_dev1=$248 > /dev/null 2>&149 else50 echo "Missing module parameters. Make sure pass"\51 "spm_addr_dev0 and spm_addr_dev1"52 usage53 fi54 fi55}56 57unload_driver()58{59 modprobe -r $DRIVER > /dev/null 2>&160}61 62run_smoke()63{64 echo "Running smoke test. Note, this test provides basic coverage."65 66 load_driver $1 $267 $(dirname "${BASH_SOURCE[0]}")/hmm-tests68 unload_driver69}70 71usage()72{73 echo -n "Usage: $0"74 echo75 echo "Example usage:"76 echo77 echo "# Shows help message"78 echo "./${TEST_NAME}.sh"79 echo80 echo "# Smoke testing"81 echo "./${TEST_NAME}.sh smoke"82 echo83 echo "# Smoke testing with SPM enabled"84 echo "./${TEST_NAME}.sh smoke <spm_addr_dev0> <spm_addr_dev1>"85 echo86 exit 087}88 89function run_test()90{91 if [ $# -eq 0 ]; then92 usage93 else94 if [ "$1" = "smoke" ]; then95 run_smoke $2 $396 else97 usage98 fi99 fi100}101 102check_test_requirements103run_test $@104 105exit 0106