#!/bin/sh KERNEL_REPO="https://github.com/rsalveti/linux.git" TEST_TIME=$((6*60*60)) # 6 hours = 6 * 60 * 60 seconds 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 sudo apt-get update sudo apt-get -y install stress-ng fi 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 & } stress_ng_workload() { echo "Start ${BG_WORKER_NO} background stress-ng workers.." stress-ng --random ${BG_WORKER_NO} > /dev/null 2>&1 & } mem_allocator() { # allocate 20% of total memory stress-ng --vm-bytes ${MEM_TRUNK}k --vm-keep --vm 1 >/dev/null 2>&1 & } START_TIME=$(date +%s) echo "Start background workload.." #build_kernel stress_ng_workload echo "Start OOM test.." while [ $(($(date +%s)-${START_TIME})) -lt ${TEST_TIME} ] do echo -n "." mem_allocator sleep 5 done # 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