linux-stable/tools/testing/selftests/memfd/run_hugetlbfs_test.sh
Shuah Khan (Samsung OSG) 8eecdd4d04 selftests: memfd: split regular and hugetlbfs tests
Split normal memfd and hugetlbfs tests to improve the test reporting.
Remove run_fuse_test.sh and memfd_test from run_tests.sh and add them
to the Makefile.

Add memfd_test to TEST_GEN_PROGS to be run separately.
Rename run_tests.sh to run_hugetlbfs_test.sh
Add run_fuse_test.sh and run_hugetlbfs_test.sh to TEST_PROGS

The report for non-root run wth this change is:

TAP version 13
selftests: memfd: memfd_test
========================================
memfd: CREATE
memfd: BASIC
memfd: SEAL-WRITE
memfd: SEAL-SHRINK
memfd: SEAL-GROW
memfd: SEAL-RESIZE
memfd: SHARE-DUP
memfd: SHARE-MMAP
memfd: SHARE-OPEN
memfd: SHARE-FORK
memfd: SHARE-DUP (shared file-table)
memfd: SHARE-MMAP (shared file-table)
memfd: SHARE-OPEN (shared file-table)
memfd: SHARE-FORK (shared file-table)
memfd: DONE
ok 1..1 selftests: memfd: memfd_test [PASS]
selftests: memfd: run_fuse_test.sh
========================================
opening: ./mnt/memfd
fuse: DONE
ok 1..2 selftests: memfd: run_fuse_test.sh [PASS]
selftests: memfd: run_hugetlbfs_test.sh
========================================
Please run memfd with hugetlbfs test as root
not ok 1..3 selftests: memfd: run_hugetlbfs_test.sh [SKIP]

Signed-off-by: Shuah Khan (Samsung OSG) <shuah@kernel.org>
Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com>
Signed-off-by: Shuah Khan (Samsung OSG) <shuah@kernel.org>
2018-05-30 15:29:06 -06:00

68 lines
1.6 KiB
Bash
Executable file

#!/bin/bash
# please run as root
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
#
# To test memfd_create with hugetlbfs, there needs to be hpages_test
# huge pages free. Attempt to allocate enough pages to test.
#
hpages_test=8
#
# Get count of free huge pages from /proc/meminfo
#
while read name size unit; do
if [ "$name" = "HugePages_Free:" ]; then
freepgs=$size
fi
done < /proc/meminfo
#
# If not enough free huge pages for test, attempt to increase
#
if [ -n "$freepgs" ] && [ $freepgs -lt $hpages_test ]; then
nr_hugepgs=`cat /proc/sys/vm/nr_hugepages`
hpages_needed=`expr $hpages_test - $freepgs`
if [ $UID != 0 ]; then
echo "Please run memfd with hugetlbfs test as root"
exit $ksft_skip
fi
echo 3 > /proc/sys/vm/drop_caches
echo $(( $hpages_needed + $nr_hugepgs )) > /proc/sys/vm/nr_hugepages
while read name size unit; do
if [ "$name" = "HugePages_Free:" ]; then
freepgs=$size
fi
done < /proc/meminfo
fi
#
# If still not enough huge pages available, exit. But, give back any huge
# pages potentially allocated above.
#
if [ $freepgs -lt $hpages_test ]; then
# nr_hugepgs non-zero only if we attempted to increase
if [ -n "$nr_hugepgs" ]; then
echo $nr_hugepgs > /proc/sys/vm/nr_hugepages
fi
printf "Not enough huge pages available (%d < %d)\n" \
$freepgs $needpgs
exit $ksft_skip
fi
#
# Run the hugetlbfs test
#
./memfd_test hugetlbfs
./run_fuse_test.sh hugetlbfs
#
# Give back any huge pages allocated for the test
#
if [ -n "$nr_hugepgs" ]; then
echo $nr_hugepgs > /proc/sys/vm/nr_hugepages
fi