1# 2# run-transhuge-test.sh: 3# Script for hwpoison test of THP(Transparent Huge Page). 4# 5#!/bin/sh 6# 7 8THP_POISON_PRO_FILE_NAME="ttranshuge" 9THP_POISON_PRO="./$THP_POISON_PRO_FILE_NAME" 10 11THP_SYS_PATH="/sys/kernel/mm/transparent_hugepage" 12THP_SYS_ENABLED_FILE="$THP_SYS_PATH/enabled" 13 14executed_testcase=0 15failed_testcase=0 16 17error() 18{ 19 echo "$1" && exit 1 20} 21 22env_check() 23{ 24 if [ ! -f $THP_POISON_PRO_FILE_NAME ] ; then 25 error "Please make sure there is file $THP_POISON_PRO_FILE_NAME." 26 fi 27 28 if [ ! -d $THP_SYS_PATH ] ; then 29 error "THP(Transparent Huge Page) may be not supported by kernel." 30 fi 31 32 thp_enabled="$(cat $THP_SYS_ENABLED_FILE | awk '{print $3}')" 33 if [ "$thp_enabled" == "[never]" ] ; then 34 error "THP(Transparent Huge Page) is disabled now." 35 fi 36} 37 38result_check() 39{ 40 if [ "$1" != "0" ] ; then 41 failed_testcase=`expr $failed_testcase + 1` 42 fi 43} 44 45exec_testcase() 46{ 47 if [ "$1" = "head" ] ; then 48 page_position_in_thp=0 49 elif [ "$1" = "tail" ] ; then 50 page_position_in_thp=1 51 else 52 error "Which page do you want to poison?" 53 fi 54 55 if [ "$2" = "early" ] ; then 56 process_type="--early-kill" 57 elif [ "$2" = "late_touch" ] ; then 58 process_type="" 59 elif [ "$2" = "late_avoid" ] ; then 60 process_type="--avoid-touch" 61 else 62 error "No such process type." 63 fi 64 65 executed_testcase=`expr $executed_testcase + 1` 66 67 echo "------------------ Case $executed_testcase --------------------" 68 69 command="$THP_POISON_PRO $process_type --offset $page_position_in_thp" 70 echo $command 71 eval $command 72 result_check $? 73 74 echo -e "\n" 75} 76 77# Environment Check for Test. 78env_check 79 80# Execute Test Cases from Here. 81echo "============= HWPoison Test of Transparent Huge Page =================" 82 83exec_testcase "head" "early" 84 85exec_testcase "head" "late_touch" 86 87exec_testcase "head" "late_avoid" 88 89exec_testcase "tail" "early" 90 91exec_testcase "tail" "late_touch" 92 93exec_testcase "tail" "late_avoid" 94 95echo "=======================================================================" 96echo -n " Num of Executed Test Case: $executed_testcase" 97echo -e " Num of Failed Case: $failed_testcase\n" 98