treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / tools / testing / selftests / vm / run_vmtests
bloba692ea8283177dc8716ae6af24c2b7684471e4c4
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 #please run as root
5 # Kselftest framework requirement - SKIP code is 4.
6 ksft_skip=4
8 mnt=./huge
9 exitcode=0
11 #get huge pagesize and freepages from /proc/meminfo
12 while read name size unit; do
13 if [ "$name" = "HugePages_Free:" ]; then
14 freepgs=$size
16 if [ "$name" = "Hugepagesize:" ]; then
17 hpgsize_KB=$size
19 done < /proc/meminfo
21 # Simple hugetlbfs tests have a hardcoded minimum requirement of
22 # huge pages totaling 256MB (262144KB) in size. The userfaultfd
23 # hugetlb test requires a minimum of 2 * nr_cpus huge pages. Take
24 # both of these requirements into account and attempt to increase
25 # number of huge pages available.
26 nr_cpus=$(nproc)
27 hpgsize_MB=$((hpgsize_KB / 1024))
28 half_ufd_size_MB=$((((nr_cpus * hpgsize_MB + 127) / 128) * 128))
29 needmem_KB=$((half_ufd_size_MB * 2 * 1024))
31 #set proper nr_hugepages
32 if [ -n "$freepgs" ] && [ -n "$hpgsize_KB" ]; then
33 nr_hugepgs=`cat /proc/sys/vm/nr_hugepages`
34 needpgs=$((needmem_KB / hpgsize_KB))
35 tries=2
36 while [ $tries -gt 0 ] && [ $freepgs -lt $needpgs ]; do
37 lackpgs=$(( $needpgs - $freepgs ))
38 echo 3 > /proc/sys/vm/drop_caches
39 echo $(( $lackpgs + $nr_hugepgs )) > /proc/sys/vm/nr_hugepages
40 if [ $? -ne 0 ]; then
41 echo "Please run this test as root"
42 exit $ksft_skip
44 while read name size unit; do
45 if [ "$name" = "HugePages_Free:" ]; then
46 freepgs=$size
48 done < /proc/meminfo
49 tries=$((tries - 1))
50 done
51 if [ $freepgs -lt $needpgs ]; then
52 printf "Not enough huge pages available (%d < %d)\n" \
53 $freepgs $needpgs
54 exit 1
56 else
57 echo "no hugetlbfs support in kernel?"
58 exit 1
61 #filter 64bit architectures
62 ARCH64STR="arm64 ia64 mips64 parisc64 ppc64 riscv64 s390x sh64 sparc64 x86_64"
63 if [ -z $ARCH ]; then
64 ARCH=`uname -m 2>/dev/null | sed -e 's/aarch64.*/arm64/'`
66 VADDR64=0
67 echo "$ARCH64STR" | grep $ARCH && VADDR64=1
69 mkdir $mnt
70 mount -t hugetlbfs none $mnt
72 echo "---------------------"
73 echo "running hugepage-mmap"
74 echo "---------------------"
75 ./hugepage-mmap
76 if [ $? -ne 0 ]; then
77 echo "[FAIL]"
78 exitcode=1
79 else
80 echo "[PASS]"
83 shmmax=`cat /proc/sys/kernel/shmmax`
84 shmall=`cat /proc/sys/kernel/shmall`
85 echo 268435456 > /proc/sys/kernel/shmmax
86 echo 4194304 > /proc/sys/kernel/shmall
87 echo "--------------------"
88 echo "running hugepage-shm"
89 echo "--------------------"
90 ./hugepage-shm
91 if [ $? -ne 0 ]; then
92 echo "[FAIL]"
93 exitcode=1
94 else
95 echo "[PASS]"
97 echo $shmmax > /proc/sys/kernel/shmmax
98 echo $shmall > /proc/sys/kernel/shmall
100 echo "-------------------"
101 echo "running map_hugetlb"
102 echo "-------------------"
103 ./map_hugetlb
104 if [ $? -ne 0 ]; then
105 echo "[FAIL]"
106 exitcode=1
107 else
108 echo "[PASS]"
111 echo "NOTE: The above hugetlb tests provide minimal coverage. Use"
112 echo " https://github.com/libhugetlbfs/libhugetlbfs.git for"
113 echo " hugetlb regression testing."
115 echo "-------------------"
116 echo "running userfaultfd"
117 echo "-------------------"
118 ./userfaultfd anon 128 32
119 if [ $? -ne 0 ]; then
120 echo "[FAIL]"
121 exitcode=1
122 else
123 echo "[PASS]"
126 echo "---------------------------"
127 echo "running userfaultfd_hugetlb"
128 echo "---------------------------"
129 # Test requires source and destination huge pages. Size of source
130 # (half_ufd_size_MB) is passed as argument to test.
131 ./userfaultfd hugetlb $half_ufd_size_MB 32 $mnt/ufd_test_file
132 if [ $? -ne 0 ]; then
133 echo "[FAIL]"
134 exitcode=1
135 else
136 echo "[PASS]"
138 rm -f $mnt/ufd_test_file
140 echo "-------------------------"
141 echo "running userfaultfd_shmem"
142 echo "-------------------------"
143 ./userfaultfd shmem 128 32
144 if [ $? -ne 0 ]; then
145 echo "[FAIL]"
146 exitcode=1
147 else
148 echo "[PASS]"
151 #cleanup
152 umount $mnt
153 rm -rf $mnt
154 echo $nr_hugepgs > /proc/sys/vm/nr_hugepages
156 echo "-----------------------"
157 echo "running compaction_test"
158 echo "-----------------------"
159 ./compaction_test
160 if [ $? -ne 0 ]; then
161 echo "[FAIL]"
162 exitcode=1
163 else
164 echo "[PASS]"
167 echo "----------------------"
168 echo "running on-fault-limit"
169 echo "----------------------"
170 sudo -u nobody ./on-fault-limit
171 if [ $? -ne 0 ]; then
172 echo "[FAIL]"
173 exitcode=1
174 else
175 echo "[PASS]"
178 echo "--------------------"
179 echo "running map_populate"
180 echo "--------------------"
181 ./map_populate
182 if [ $? -ne 0 ]; then
183 echo "[FAIL]"
184 exitcode=1
185 else
186 echo "[PASS]"
189 echo "--------------------"
190 echo "running mlock2-tests"
191 echo "--------------------"
192 ./mlock2-tests
193 if [ $? -ne 0 ]; then
194 echo "[FAIL]"
195 exitcode=1
196 else
197 echo "[PASS]"
200 if [ $VADDR64 -ne 0 ]; then
201 echo "-----------------------------"
202 echo "running virtual_address_range"
203 echo "-----------------------------"
204 ./virtual_address_range
205 if [ $? -ne 0 ]; then
206 echo "[FAIL]"
207 exitcode=1
208 else
209 echo "[PASS]"
212 echo "-----------------------------"
213 echo "running virtual address 128TB switch test"
214 echo "-----------------------------"
215 ./va_128TBswitch
216 if [ $? -ne 0 ]; then
217 echo "[FAIL]"
218 exitcode=1
219 else
220 echo "[PASS]"
222 fi # VADDR64
224 echo "------------------------------------"
225 echo "running vmalloc stability smoke test"
226 echo "------------------------------------"
227 ./test_vmalloc.sh smoke
228 ret_val=$?
230 if [ $ret_val -eq 0 ]; then
231 echo "[PASS]"
232 elif [ $ret_val -eq $ksft_skip ]; then
233 echo "[SKIP]"
234 exitcode=$ksft_skip
235 else
236 echo "[FAIL]"
237 exitcode=1
240 exit $exitcode