diff options
author | Arthur She <arthur.she@linaro.org> | 2016-02-18 14:07:46 -0800 |
---|---|---|
committer | Arthur She <arthur.she@linaro.org> | 2016-02-18 22:26:59 -0800 |
commit | 13391ec5a17f50bc6062a17c88e3bb6b64d0ceee (patch) | |
tree | 5590a394a754ec6066af53fa05bd1add34767527 | |
parent | 8fddf8e4c27659f3184a672257c492f4100b6fed (diff) |
Add oom-test.sh for 6h OOM stress test
-rwxr-xr-x | oom-test.sh | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/oom-test.sh b/oom-test.sh new file mode 100755 index 0000000..a74d62d --- /dev/null +++ b/oom-test.sh @@ -0,0 +1,92 @@ +#!/bin/sh + +KERNEL_REPO="https://github.com/rsalveti/linux.git" +TEST_TIME=$((6*60*60)) # 6 hours = 6 * 60 * 60 seconds +BIG_MEM_TRUNK=$(awk '/MemTotal/{printf "%d\n", $2 * 0.7;}' < /proc/meminfo) + +stress-ng --help > /dev/null 2>&1 +if [ $? -ne 0 ];then + sudo apt-get update + sudo apt-get -y install stress-ng +fi + +build_kernel() +{ + local build_kernel_pid + + cd linux + make clean > /dev/null 2>&1 + make defconfig > /dev/null 2>&1 + make Image modules > ../build_kernel.log 2>&1 & + build_kernel_pid=$! + cd .. + echo ${build_kernel_pid} +} + +big_allocator() +{ + # allocate 60% of total memory + stress-ng --vm-bytes ${BIG_MEM_TRUNK}k --vm-keep --vm 1 >/dev/null 2>&1 & + echo $! +} + +over_allocator() +{ + # allocate 30% of total memory, it suould be over allocated + stress-ng --vm-bytes $(awk '/MemTotal/{printf "%d\n", $2 * 0.3;}' < /proc/meminfo)k --vm-keep --vm 1 >/dev/null 2>&1 +# echo $? +} + +check_pid() +{ + local rcode + pid_to_check=$1 + + rcode=0 + if ! ps -p ${pid_to_check} > /dev/null ; then + wait ${pid_to_check} + pid_exit_code=$? + rcode = 1 + fi + echo ${rcode} +} + +# clone kernel source +echo "Cloning kernel source from: ${KERNEL_REPO}" +#git clone ${KERNEL_REPO} + +START_TIME=$(date +%s) + +echo "Allocating ${BIG_MEM_TRUNK}k memory.." +bapid=$(big_allocator) +echo "Big trunk memory allocator pid: ${bapid}" +echo "Start to build kernel" +bkpid=$(build_kernel) +echo "Build kernel PID: ${bkpid}" +echo "Start OOM test.." + +while [ $(($(date +%s)-${START_TIME})) -lt ${TEST_TIME} ] +do + echo -n "." + [ $(check_pid ${bapid}) -ne 0 ] && bapid=$(big_allocator) + if [ $(check_pid ${bkpid}) -ne 0 ]; then + if [ ${pid_exit_code} -ne 0 ]; then + echo "\nKernel build failed, test failed!!" + exit 1 + else + echo "Kernel built successfully, start another round.." + bkpid=$(build_kernel) + echo "Build kernel PID: ${bkpid}" + fi + fi + # Over allocate memory to trigger OOM + over_allocator + + sleep 10 +done + +[ $(check_pid ${bapid}) -eq 0 ] && kill -9 ${bapid} +[ $(check_pid ${bkpid}) -eq 0 ] && kill -9 ${bkpid} + +echo "Test successfully!" +exit 0 |