• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3#please run as root
4
5# Kselftest framework requirement - SKIP code is 4.
6ksft_skip=4
7
8mnt=./huge
9exitcode=0
10
11#get huge pagesize and freepages from /proc/meminfo
12while read name size unit; do
13	if [ "$name" = "HugePages_Free:" ]; then
14		freepgs=$size
15	fi
16	if [ "$name" = "Hugepagesize:" ]; then
17		hpgsize_KB=$size
18	fi
19done < /proc/meminfo
20
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.
26nr_cpus=$(nproc)
27hpgsize_MB=$((hpgsize_KB / 1024))
28half_ufd_size_MB=$((((nr_cpus * hpgsize_MB + 127) / 128) * 128))
29needmem_KB=$((half_ufd_size_MB * 2 * 1024))
30
31#set proper nr_hugepages
32if [ -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
43		fi
44		while read name size unit; do
45			if [ "$name" = "HugePages_Free:" ]; then
46				freepgs=$size
47			fi
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
55	fi
56else
57	echo "no hugetlbfs support in kernel?"
58	exit 1
59fi
60
61#filter 64bit architectures
62ARCH64STR="arm64 ia64 mips64 parisc64 ppc64 ppc64le riscv64 s390x sh64 sparc64 x86_64"
63if [ -z $ARCH ]; then
64  ARCH=`uname -m 2>/dev/null | sed -e 's/aarch64.*/arm64/'`
65fi
66VADDR64=0
67echo "$ARCH64STR" | grep $ARCH && VADDR64=1
68
69mkdir $mnt
70mount -t hugetlbfs none $mnt
71
72echo "---------------------"
73echo "running hugepage-mmap"
74echo "---------------------"
75./hugepage-mmap
76if [ $? -ne 0 ]; then
77	echo "[FAIL]"
78	exitcode=1
79else
80	echo "[PASS]"
81fi
82
83shmmax=`cat /proc/sys/kernel/shmmax`
84shmall=`cat /proc/sys/kernel/shmall`
85echo 268435456 > /proc/sys/kernel/shmmax
86echo 4194304 > /proc/sys/kernel/shmall
87echo "--------------------"
88echo "running hugepage-shm"
89echo "--------------------"
90./hugepage-shm
91if [ $? -ne 0 ]; then
92	echo "[FAIL]"
93	exitcode=1
94else
95	echo "[PASS]"
96fi
97echo $shmmax > /proc/sys/kernel/shmmax
98echo $shmall > /proc/sys/kernel/shmall
99
100echo "-------------------"
101echo "running map_hugetlb"
102echo "-------------------"
103./map_hugetlb
104if [ $? -ne 0 ]; then
105	echo "[FAIL]"
106	exitcode=1
107else
108	echo "[PASS]"
109fi
110
111echo "NOTE: The above hugetlb tests provide minimal coverage.  Use"
112echo "      https://github.com/libhugetlbfs/libhugetlbfs.git for"
113echo "      hugetlb regression testing."
114
115echo "---------------------------"
116echo "running map_fixed_noreplace"
117echo "---------------------------"
118./map_fixed_noreplace
119if [ $? -ne 0 ]; then
120	echo "[FAIL]"
121	exitcode=1
122else
123	echo "[PASS]"
124fi
125
126echo "------------------------------------------------------"
127echo "running: gup_test -u # get_user_pages_fast() benchmark"
128echo "------------------------------------------------------"
129./gup_test -u
130if [ $? -ne 0 ]; then
131	echo "[FAIL]"
132	exitcode=1
133else
134	echo "[PASS]"
135fi
136
137echo "------------------------------------------------------"
138echo "running: gup_test -a # pin_user_pages_fast() benchmark"
139echo "------------------------------------------------------"
140./gup_test -a
141if [ $? -ne 0 ]; then
142	echo "[FAIL]"
143	exitcode=1
144else
145	echo "[PASS]"
146fi
147
148echo "------------------------------------------------------------"
149echo "# Dump pages 0, 19, and 4096, using pin_user_pages:"
150echo "running: gup_test -ct -F 0x1 0 19 0x1000 # dump_page() test"
151echo "------------------------------------------------------------"
152./gup_test -ct -F 0x1 0 19 0x1000
153if [ $? -ne 0 ]; then
154	echo "[FAIL]"
155	exitcode=1
156else
157	echo "[PASS]"
158fi
159
160echo "-------------------"
161echo "running userfaultfd"
162echo "-------------------"
163./userfaultfd anon 20 16
164if [ $? -ne 0 ]; then
165	echo "[FAIL]"
166	exitcode=1
167else
168	echo "[PASS]"
169fi
170
171echo "---------------------------"
172echo "running userfaultfd_hugetlb"
173echo "---------------------------"
174# Test requires source and destination huge pages.  Size of source
175# (half_ufd_size_MB) is passed as argument to test.
176./userfaultfd hugetlb $half_ufd_size_MB 32 $mnt/ufd_test_file
177if [ $? -ne 0 ]; then
178	echo "[FAIL]"
179	exitcode=1
180else
181	echo "[PASS]"
182fi
183rm -f $mnt/ufd_test_file
184
185echo "-------------------------"
186echo "running userfaultfd_shmem"
187echo "-------------------------"
188./userfaultfd shmem 20 16
189if [ $? -ne 0 ]; then
190	echo "[FAIL]"
191	exitcode=1
192else
193	echo "[PASS]"
194fi
195
196#cleanup
197umount $mnt
198rm -rf $mnt
199echo $nr_hugepgs > /proc/sys/vm/nr_hugepages
200
201echo "-----------------------"
202echo "running compaction_test"
203echo "-----------------------"
204./compaction_test
205if [ $? -ne 0 ]; then
206	echo "[FAIL]"
207	exitcode=1
208else
209	echo "[PASS]"
210fi
211
212echo "----------------------"
213echo "running on-fault-limit"
214echo "----------------------"
215sudo -u nobody ./on-fault-limit
216if [ $? -ne 0 ]; then
217	echo "[FAIL]"
218	exitcode=1
219else
220	echo "[PASS]"
221fi
222
223echo "--------------------"
224echo "running map_populate"
225echo "--------------------"
226./map_populate
227if [ $? -ne 0 ]; then
228	echo "[FAIL]"
229	exitcode=1
230else
231	echo "[PASS]"
232fi
233
234echo "-------------------------"
235echo "running mlock-random-test"
236echo "-------------------------"
237./mlock-random-test
238if [ $? -ne 0 ]; then
239	echo "[FAIL]"
240	exitcode=1
241else
242	echo "[PASS]"
243fi
244
245echo "--------------------"
246echo "running mlock2-tests"
247echo "--------------------"
248./mlock2-tests
249if [ $? -ne 0 ]; then
250	echo "[FAIL]"
251	exitcode=1
252else
253	echo "[PASS]"
254fi
255
256echo "-------------------"
257echo "running mremap_test"
258echo "-------------------"
259./mremap_test
260if [ $? -ne 0 ]; then
261	echo "[FAIL]"
262	exitcode=1
263else
264	echo "[PASS]"
265fi
266
267echo "-----------------"
268echo "running thuge-gen"
269echo "-----------------"
270./thuge-gen
271if [ $? -ne 0 ]; then
272	echo "[FAIL]"
273	exitcode=1
274else
275	echo "[PASS]"
276fi
277
278if [ $VADDR64 -ne 0 ]; then
279echo "-----------------------------"
280echo "running virtual_address_range"
281echo "-----------------------------"
282./virtual_address_range
283if [ $? -ne 0 ]; then
284	echo "[FAIL]"
285	exitcode=1
286else
287	echo "[PASS]"
288fi
289
290echo "-----------------------------"
291echo "running virtual address 128TB switch test"
292echo "-----------------------------"
293./va_128TBswitch
294if [ $? -ne 0 ]; then
295    echo "[FAIL]"
296    exitcode=1
297else
298    echo "[PASS]"
299fi
300fi # VADDR64
301
302echo "------------------------------------"
303echo "running vmalloc stability smoke test"
304echo "------------------------------------"
305./test_vmalloc.sh smoke
306ret_val=$?
307
308if [ $ret_val -eq 0 ]; then
309	echo "[PASS]"
310elif [ $ret_val -eq $ksft_skip ]; then
311	 echo "[SKIP]"
312	 exitcode=$ksft_skip
313else
314	echo "[FAIL]"
315	exitcode=1
316fi
317
318echo "------------------------------------"
319echo "running MREMAP_DONTUNMAP smoke test"
320echo "------------------------------------"
321./mremap_dontunmap
322ret_val=$?
323
324if [ $ret_val -eq 0 ]; then
325	echo "[PASS]"
326elif [ $ret_val -eq $ksft_skip ]; then
327	 echo "[SKIP]"
328	 exitcode=$ksft_skip
329else
330	echo "[FAIL]"
331	exitcode=1
332fi
333
334echo "running HMM smoke test"
335echo "------------------------------------"
336./test_hmm.sh smoke
337ret_val=$?
338
339if [ $ret_val -eq 0 ]; then
340	echo "[PASS]"
341elif [ $ret_val -eq $ksft_skip ]; then
342	echo "[SKIP]"
343	exitcode=$ksft_skip
344else
345	echo "[FAIL]"
346	exitcode=1
347fi
348
349echo "--------------------------------------------------------"
350echo "running MADV_POPULATE_READ and MADV_POPULATE_WRITE tests"
351echo "--------------------------------------------------------"
352./madv_populate
353ret_val=$?
354
355if [ $ret_val -eq 0 ]; then
356	echo "[PASS]"
357elif [ $ret_val -eq $ksft_skip ]; then
358	echo "[SKIP]"
359	exitcode=$ksft_skip
360else
361	echo "[FAIL]"
362	exitcode=1
363fi
364
365echo "running memfd_secret test"
366echo "------------------------------------"
367./memfd_secret
368ret_val=$?
369
370if [ $ret_val -eq 0 ]; then
371	echo "[PASS]"
372elif [ $ret_val -eq $ksft_skip ]; then
373	echo "[SKIP]"
374	exitcode=$ksft_skip
375else
376	echo "[FAIL]"
377	exitcode=1
378fi
379
380echo "-------------------------------------------------------"
381echo "running KSM MADV_MERGEABLE test with 10 identical pages"
382echo "-------------------------------------------------------"
383./ksm_tests -M -p 10
384ret_val=$?
385
386if [ $ret_val -eq 0 ]; then
387	echo "[PASS]"
388elif [ $ret_val -eq $ksft_skip ]; then
389	 echo "[SKIP]"
390	 exitcode=$ksft_skip
391else
392	echo "[FAIL]"
393	exitcode=1
394fi
395
396echo "------------------------"
397echo "running KSM unmerge test"
398echo "------------------------"
399./ksm_tests -U
400ret_val=$?
401
402if [ $ret_val -eq 0 ]; then
403	echo "[PASS]"
404elif [ $ret_val -eq $ksft_skip ]; then
405	 echo "[SKIP]"
406	 exitcode=$ksft_skip
407else
408	echo "[FAIL]"
409	exitcode=1
410fi
411
412echo "----------------------------------------------------------"
413echo "running KSM test with 10 zero pages and use_zero_pages = 0"
414echo "----------------------------------------------------------"
415./ksm_tests -Z -p 10 -z 0
416ret_val=$?
417
418if [ $ret_val -eq 0 ]; then
419	echo "[PASS]"
420elif [ $ret_val -eq $ksft_skip ]; then
421	 echo "[SKIP]"
422	 exitcode=$ksft_skip
423else
424	echo "[FAIL]"
425	exitcode=1
426fi
427
428echo "----------------------------------------------------------"
429echo "running KSM test with 10 zero pages and use_zero_pages = 1"
430echo "----------------------------------------------------------"
431./ksm_tests -Z -p 10 -z 1
432ret_val=$?
433
434if [ $ret_val -eq 0 ]; then
435	echo "[PASS]"
436elif [ $ret_val -eq $ksft_skip ]; then
437	 echo "[SKIP]"
438	 exitcode=$ksft_skip
439else
440	echo "[FAIL]"
441	exitcode=1
442fi
443
444echo "-------------------------------------------------------------"
445echo "running KSM test with 2 NUMA nodes and merge_across_nodes = 1"
446echo "-------------------------------------------------------------"
447./ksm_tests -N -m 1
448ret_val=$?
449
450if [ $ret_val -eq 0 ]; then
451	echo "[PASS]"
452elif [ $ret_val -eq $ksft_skip ]; then
453	 echo "[SKIP]"
454	 exitcode=$ksft_skip
455else
456	echo "[FAIL]"
457	exitcode=1
458fi
459
460echo "-------------------------------------------------------------"
461echo "running KSM test with 2 NUMA nodes and merge_across_nodes = 0"
462echo "-------------------------------------------------------------"
463./ksm_tests -N -m 0
464ret_val=$?
465
466if [ $ret_val -eq 0 ]; then
467	echo "[PASS]"
468elif [ $ret_val -eq $ksft_skip ]; then
469	 echo "[SKIP]"
470	 exitcode=$ksft_skip
471else
472	echo "[FAIL]"
473	exitcode=1
474fi
475
476exit $exitcode
477
478exit $exitcode
479