178 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="vmalloc"13DRIVER="test_${TEST_NAME}"14NUM_CPUS=`grep -c ^processor /proc/cpuinfo`15 16# 1 if fails17exitcode=118 19# Kselftest framework requirement - SKIP code is 4.20ksft_skip=421 22#23# Static templates for performance, stressing and smoke tests.24# Also it is possible to pass any supported parameters manualy.25#26PERF_PARAM="sequential_test_order=1 test_repeat_count=3"27SMOKE_PARAM="test_loop_count=10000 test_repeat_count=10"28STRESS_PARAM="nr_threads=$NUM_CPUS test_repeat_count=20"29 30check_test_requirements()31{32 uid=$(id -u)33 if [ $uid -ne 0 ]; then34 echo "$0: Must be run as root"35 exit $ksft_skip36 fi37 38 if ! which modprobe > /dev/null 2>&1; then39 echo "$0: You need modprobe installed"40 exit $ksft_skip41 fi42 43 if ! modinfo $DRIVER > /dev/null 2>&1; then44 echo "$0: You must have the following enabled in your kernel:"45 echo "CONFIG_TEST_VMALLOC=m"46 exit $ksft_skip47 fi48}49 50run_perfformance_check()51{52 echo "Run performance tests to evaluate how fast vmalloc allocation is."53 echo "It runs all test cases on one single CPU with sequential order."54 55 modprobe $DRIVER $PERF_PARAM > /dev/null 2>&156 echo "Done."57 echo "Ccheck the kernel message buffer to see the summary."58}59 60run_stability_check()61{62 echo "Run stability tests. In order to stress vmalloc subsystem all"63 echo "available test cases are run by NUM_CPUS workers simultaneously."64 echo "It will take time, so be patient."65 66 modprobe $DRIVER $STRESS_PARAM > /dev/null 2>&167 echo "Done."68 echo "Check the kernel ring buffer to see the summary."69}70 71run_smoke_check()72{73 echo "Run smoke test. Note, this test provides basic coverage."74 echo "Please check $0 output how it can be used"75 echo "for deep performance analysis as well as stress testing."76 77 modprobe $DRIVER $SMOKE_PARAM > /dev/null 2>&178 echo "Done."79 echo "Check the kernel ring buffer to see the summary."80}81 82usage()83{84 echo -n "Usage: $0 [ performance ] | [ stress ] | | [ smoke ] | "85 echo "manual parameters"86 echo87 echo "Valid tests and parameters:"88 echo89 modinfo $DRIVER90 echo91 echo "Example usage:"92 echo93 echo "# Shows help message"94 echo "./${DRIVER}.sh"95 echo96 echo "# Runs 1 test(id_1), repeats it 5 times by NUM_CPUS workers"97 echo "./${DRIVER}.sh nr_threads=$NUM_CPUS run_test_mask=1 test_repeat_count=5"98 echo99 echo -n "# Runs 4 tests(id_1|id_2|id_4|id_16) on one CPU with "100 echo "sequential order"101 echo -n "./${DRIVER}.sh sequential_test_order=1 "102 echo "run_test_mask=23"103 echo104 echo -n "# Runs all tests by NUM_CPUS workers, shuffled order, repeats "105 echo "20 times"106 echo "./${DRIVER}.sh nr_threads=$NUM_CPUS test_repeat_count=20"107 echo108 echo "# Performance analysis"109 echo "./${DRIVER}.sh performance"110 echo111 echo "# Stress testing"112 echo "./${DRIVER}.sh stress"113 echo114 exit 0115}116 117function validate_passed_args()118{119 VALID_ARGS=`modinfo $DRIVER | awk '/parm:/ {print $2}' | sed 's/:.*//'`120 121 #122 # Something has been passed, check it.123 #124 for passed_arg in $@; do125 key=${passed_arg//=*/}126 val="${passed_arg:$((${#key}+1))}"127 valid=0128 129 for valid_arg in $VALID_ARGS; do130 if [[ $key = $valid_arg ]] && [[ $val -gt 0 ]]; then131 valid=1132 break133 fi134 done135 136 if [[ $valid -ne 1 ]]; then137 echo "Error: key or value is not correct: ${key} $val"138 exit $exitcode139 fi140 done141}142 143function run_manual_check()144{145 #146 # Validate passed parameters. If there is wrong one,147 # the script exists and does not execute further.148 #149 validate_passed_args $@150 151 echo "Run the test with following parameters: $@"152 modprobe $DRIVER $@ > /dev/null 2>&1153 echo "Done."154 echo "Check the kernel ring buffer to see the summary."155}156 157function run_test()158{159 if [ $# -eq 0 ]; then160 usage161 else162 if [[ "$1" = "performance" ]]; then163 run_perfformance_check164 elif [[ "$1" = "stress" ]]; then165 run_stability_check166 elif [[ "$1" = "smoke" ]]; then167 run_smoke_check168 else169 run_manual_check $@170 fi171 fi172}173 174check_test_requirements175run_test $@176 177exit 0178