summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur She <arthur.she@linaro.org>2016-03-28 22:13:43 -0700
committerArthur She <arthur.she@linaro.org>2016-03-28 22:13:43 -0700
commit8c6e89d8b1e4036e5af71b6cfcaf8948344bb476 (patch)
treefc49bf141cd510a2cf2d5fc846aafddc773db271
parent13391ec5a17f50bc6062a17c88e3bb6b64d0ceee (diff)
oom-test.sh: Update oom-test.shHEADmaster
Due to which process will be killed by OOM killer is not easy to predict, the test scenario would be changed to run background workload and trigger OOM continuously. If the system doesn't crash for 6h, the test will be treated as pass.
-rwxr-xr-xoom-test.sh76
1 files changed, 23 insertions, 53 deletions
diff --git a/oom-test.sh b/oom-test.sh
index a74d62d..b84e757 100755
--- a/oom-test.sh
+++ b/oom-test.sh
@@ -2,7 +2,8 @@
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)
+MEM_TRUNK=$(awk '/MemTotal/{printf "%d\n", $2 * 0.2;}' < /proc/meminfo)
+BG_WORKER_NO=$(cat /proc/cpuinfo | grep processor | wc -l)
stress-ng --help > /dev/null 2>&1
if [ $? -ne 0 ];then
@@ -14,79 +15,48 @@ build_kernel()
{
local build_kernel_pid
+ # clone kernel source
+ echo "Cloning kernel source from: ${KERNEL_REPO}"
+ #git clone ${KERNEL_REPO}
+ echo "Start building kernel.."
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()
+stress_ng_workload()
{
- # allocate 60% of total memory
- stress-ng --vm-bytes ${BIG_MEM_TRUNK}k --vm-keep --vm 1 >/dev/null 2>&1 &
- echo $!
+ echo "Start ${BG_WORKER_NO} background stress-ng workers.."
+ stress-ng --random ${BG_WORKER_NO} > /dev/null 2>&1 &
}
-over_allocator()
+mem_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 $?
+ # allocate 20% of total memory
+ stress-ng --vm-bytes ${MEM_TRUNK}k --vm-keep --vm 1 >/dev/null 2>&1 &
}
-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.."
+echo "Start background workload.."
+#build_kernel
+stress_ng_workload
+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
+ mem_allocator
- sleep 10
+ sleep 5
done
-[ $(check_pid ${bapid}) -eq 0 ] && kill -9 ${bapid}
-[ $(check_pid ${bkpid}) -eq 0 ] && kill -9 ${bkpid}
+# kill all stress-ng process
+for p in `ps aux|grep stress-n[g]|awk '{print $2}'`
+do
+ kill -9 $p
+done
echo "Test successfully!"
exit 0