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