android 6.0 monkey以及文件系统测试脚本

        近日,在搭建android6.0的测试框架,相对比较简单,下面总结一下如题两项的测试脚本,内存和cpu测试相关在之前的文章有过涉及。

monkey_test.sh

#!/system/bin/sh

ANR_LOG=/data/anr
DROPBOX_LOG=/data/system/dropbox

clean_logs() {
	rm -rf $ANR_LOG/*
	rm -rf $DROPBOX_LOG/*
}

helper()
{
    echo "#######################################"
	echo "###### $(basename ${0}) pkglist count ######"
    echo "#######################################"
    exit 1
}

if [ $# -eq 1 ]; then
	count=500
elif [ $# -eq 2 ]; then
	count=$2
else
	helper
fi

if [ ! -f $1 ]; then
	echo "packagelist file not exist"
	exit 1
fi

i=0
while read line
do 
#echo $line
    package[i]=$line
#    echo ${package[$i]}
    i=$(($i + 1))
done < $1

array_size=${#package[@]}
#echo $array_size

if [ $array_size -eq 0 ]; then
    echo "package list null."
    exit 1
else
    echo "monkey test start..."
fi
#for (( j = 0; j < array_size; j++ ))
for j in `seq $array_size`
do
	i=$(($j - 1))
#    monkey -p ${package[$j]} --throttle 500 --ignore-crashes --ignore-timeouts --ignore-security-exceptions \
#        --ignore-native-crashes --monitor-native-crashes -v -v -v 100 > /sdcard/mtklog/monkey.txt
#    monkey -p ${package[$i]} --throttle 500 --ignore-crashes --ignore-timeouts --ignore-security-exceptions \
#        --ignore-native-crashes --monitor-native-crashes --pct-syskeys 0 -v -v -v $count
#    echo ${package[$j]}
done

# send system logs to nas
loghandler send

echo "monkey test done..."

例如:我将pkg文件推送到/data/local目录,每个package发送50个随机事件,则使用如下命令即可:
 monkey_test /data/local/pkg 50

pkg文件为要测试的pkg包名列表,该脚本会去解析pkg,然后去按包名跑monkey。

上传日志脚本:

#!/system/bin/sh

# send logs to NAS

LOG_LOCAL=/data/local
ANR_LOG=/data/anr
DROPBOX_LOG=/data/system/dropbox

help_list() {
	echo "============================="
	echo "====$(basename ${0}) send/clean===="
	echo "============================="

	exit 0
}

if [ $# -ne "1" ]; then
	help_list
fi

if [ $1 == "clean" ]; then
	rm -rf $ANR_LOG/*
	rm -rf $DROPBOX_LOG/*
	exit 0
fi

VM_ID=`cat /sys/class/android_usb/android0/iSerial`
TIME=`date +%Y%m%d%H%M%S`

ANR_TAR=$VM_ID-anr-$TIME.tar
DROPBOX_TAR=$VM_ID-dropbox-$TIME.tar

ANR_COUNT=`ls $ANR_LOG | wc -w`
DROPBOX_COUNT=`ls $DROPBOX_LOG | wc -w`

zip_log_send()
{
	if [ $ANR_COUNT -gt "0" ]; then
		busybox tar zcvf $LOG_LOCAL/$ANR_TAR $ANR_LOG/*
		busybox tftp -p -l $LOG_LOCAL/$ANR_TAR -r $ANR_TAR 192.168.1.1 &
	fi
	
	if [ $DROPBOX_COUNT -gt "0" ]; then
		busybox tar zcvf $LOG_LOCAL/$DROPBOX_TAR $DROPBOX_LOG/*
		busybox tftp -p -l $LOG_LOCAL/$DROPBOX_TAR -r $DROPBOX_TAR 192.168.1.1 &
	fi
	exit 0
}

if [ $1 == "send" ]; then
	zip_log_send
fi

monkey跑完会调用上述脚本,将系统的日志目录通过tftp推送至服务器备案。

文件系统测试的脚本:

#!/system/bin/sh

# by kongbo
# fs test

CLEAN_TMP_FILE()
{
	if [ -e "/data/tes.dd" ]; then
		echo "rm tes file"
		rm -rf "/data/tes.dd"
	fi
}

CLEAN_TMP_FILE

SPACE_SRC=`df | grep "/storage/emulated"`
FREE_SRC=`echo $SPACE_SRC | busybox awk -F ' ' '{print $4}'`
FREE_SPACE=`echo $FREE_SRC | busybox awk -F '.' '{print $1}'`

G_TAG=`echo $FREE_SRC | grep "G"`
M_TAG=`echo $FREE_SRC | grep "M"`
K_TAG=`echo $FREE_SRC | grep "K"`

if [ -n "$K_TAG" ]; then
	echo "free space too low exit."
	exit 1
fi

echo "G_TAG:$G_TAG  M_TAG:$M_TAG"

((MAX_FILE_SIZE=$FREE_SPACE*4/5))
((MIN_FILE_SIZE=$FREE_SPACE/5))

if [ -n "$G_TAG" ]; then
	((max_count_num=$MAX_FILE_SIZE*1000))
	((min_count_num=$MIN_FILE_SIZE*1000))
elif [ -n "$M_TAG" ]; then
	((max_count_num=$MAX_FILE_SIZE))
	((min_count_num=$MIN_FILE_SIZE))
else
	echo "space err and will exit"
	exit 1
fi

cd /data

echo "====== max_count_num: $max_count_num  min_count_num: $min_count_num ======"

# write $MAX_FILE_SIZE G
sync;/system/bin/time -p sh -c "(dd if=/dev/zero of=tes.dd  bs=1024k count=$max_count_num)"

# read $MAX_FILE_SIZE G
echo 3 > /proc/sys/vm/drop_caches; /system/bin/time -p dd if=tes.dd of=/dev/null  bs=1024k

CLEAN_TMP_FILE

# write $MIN_FILE_SIZE G
sync;/system/bin/time -p sh -c "(dd if=/dev/zero of=tes.dd  bs=1024k count=$min_count_num)"

# read $MIN_FILE_SIZE G
echo 3 > /proc/sys/vm/drop_caches; /system/bin/time -p dd if=tes.dd of=/dev/null  bs=1024k

CLEAN_TMP_FILE

# test success and exit
exit 0
fsgo用法:
 将其推送至VM的/system/bin目录,命令行执行:fsgo
 测试项目:对剩余的user分区空间进行大文件读写填充,MAX为写入剩余空间80%大小的文件,后面跟着读取该文件;
MIN为写入剩余空间20%大小的文件,然后读取该文件。





















评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值