Home | History | Annotate | Download | only in memfd
      1 #!/bin/bash
      2 # please run as root
      3 
      4 #
      5 # Normal tests requiring no special resources
      6 #
      7 ./run_fuse_test.sh
      8 ./memfd_test
      9 
     10 #
     11 # To test memfd_create with hugetlbfs, there needs to be hpages_test
     12 # huge pages free.  Attempt to allocate enough pages to test.
     13 #
     14 hpages_test=8
     15 
     16 #
     17 # Get count of free huge pages from /proc/meminfo
     18 #
     19 while read name size unit; do
     20         if [ "$name" = "HugePages_Free:" ]; then
     21                 freepgs=$size
     22         fi
     23 done < /proc/meminfo
     24 
     25 #
     26 # If not enough free huge pages for test, attempt to increase
     27 #
     28 if [ -n "$freepgs" ] && [ $freepgs -lt $hpages_test ]; then
     29 	nr_hugepgs=`cat /proc/sys/vm/nr_hugepages`
     30 	hpages_needed=`expr $hpages_test - $freepgs`
     31 
     32 	echo 3 > /proc/sys/vm/drop_caches
     33 	echo $(( $hpages_needed + $nr_hugepgs )) > /proc/sys/vm/nr_hugepages
     34 	if [ $? -ne 0 ]; then
     35 		echo "Please run this test as root"
     36 		exit 1
     37 	fi
     38 	while read name size unit; do
     39 		if [ "$name" = "HugePages_Free:" ]; then
     40 			freepgs=$size
     41 		fi
     42 	done < /proc/meminfo
     43 fi
     44 
     45 #
     46 # If still not enough huge pages available, exit.  But, give back any huge
     47 # pages potentially allocated above.
     48 #
     49 if [ $freepgs -lt $hpages_test ]; then
     50 	# nr_hugepgs non-zero only if we attempted to increase
     51 	if [ -n "$nr_hugepgs" ]; then
     52 		echo $nr_hugepgs > /proc/sys/vm/nr_hugepages
     53 	fi
     54 	printf "Not enough huge pages available (%d < %d)\n" \
     55 		$freepgs $needpgs
     56 	exit 1
     57 fi
     58 
     59 #
     60 # Run the hugetlbfs test
     61 #
     62 ./memfd_test hugetlbfs
     63 
     64 #
     65 # Give back any huge pages allocated for the test
     66 #
     67 if [ -n "$nr_hugepgs" ]; then
     68 	echo $nr_hugepgs > /proc/sys/vm/nr_hugepages
     69 fi
     70