Merge tag 'sound-5.8' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound
[linux-2.6-microblaze.git] / tools / testing / selftests / vm / test_hmm.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 #
4 # Copyright (C) 2018 Uladzislau Rezki (Sony) <urezki@gmail.com>
5 #
6 # This is a test script for the kernel test driver to analyse vmalloc
7 # allocator. Therefore it is just a kernel module loader. You can specify
8 # and pass different parameters in order to:
9 #     a) analyse performance of vmalloc allocations;
10 #     b) stressing and stability check of vmalloc subsystem.
11
12 TEST_NAME="test_hmm"
13 DRIVER="test_hmm"
14
15 # 1 if fails
16 exitcode=1
17
18 # Kselftest framework requirement - SKIP code is 4.
19 ksft_skip=4
20
21 check_test_requirements()
22 {
23         uid=$(id -u)
24         if [ $uid -ne 0 ]; then
25                 echo "$0: Must be run as root"
26                 exit $ksft_skip
27         fi
28
29         if ! which modprobe > /dev/null 2>&1; then
30                 echo "$0: You need modprobe installed"
31                 exit $ksft_skip
32         fi
33
34         if ! modinfo $DRIVER > /dev/null 2>&1; then
35                 echo "$0: You must have the following enabled in your kernel:"
36                 echo "CONFIG_TEST_HMM=m"
37                 exit $ksft_skip
38         fi
39 }
40
41 load_driver()
42 {
43         modprobe $DRIVER > /dev/null 2>&1
44         if [ $? == 0 ]; then
45                 major=$(awk "\$2==\"HMM_DMIRROR\" {print \$1}" /proc/devices)
46                 mknod /dev/hmm_dmirror0 c $major 0
47                 mknod /dev/hmm_dmirror1 c $major 1
48         fi
49 }
50
51 unload_driver()
52 {
53         modprobe -r $DRIVER > /dev/null 2>&1
54         rm -f /dev/hmm_dmirror?
55 }
56
57 run_smoke()
58 {
59         echo "Running smoke test. Note, this test provides basic coverage."
60
61         load_driver
62         $(dirname "${BASH_SOURCE[0]}")/hmm-tests
63         unload_driver
64 }
65
66 usage()
67 {
68         echo -n "Usage: $0"
69         echo
70         echo "Example usage:"
71         echo
72         echo "# Shows help message"
73         echo "./${TEST_NAME}.sh"
74         echo
75         echo "# Smoke testing"
76         echo "./${TEST_NAME}.sh smoke"
77         echo
78         exit 0
79 }
80
81 function run_test()
82 {
83         if [ $# -eq 0 ]; then
84                 usage
85         else
86                 if [ "$1" = "smoke" ]; then
87                         run_smoke
88                 else
89                         usage
90                 fi
91         fi
92 }
93
94 check_test_requirements
95 run_test $@
96
97 exit 0