#!/bin/sh
#回显执行的命令和参数
set -x
cd ../../utils
. ./sys_info.sh
cd -
#检查是否是root用户
if [ `whoami` != 'root' ] ; then
echo "You must be the superuser to run this script" >&2
exit 1
fi
#distro=`cat /etc/redhat-release | cut -b 1-6`
#看起来centos 会通过源码编译httpperf
case $distro in
"centos")
yum install make -y
wget ftp://ftp.hpl.hp.com/pub/httperf/httperf-0.9.0.tar.gz
tar -zxvf httperf-0.9.0.tar.gz
cd httperf-0.9.0
./configure --build=arm-linux
make
make install
print_info $? install-package
;;
"ubuntu")
apt-get install httperf -y
print_info $? install-package
;;
esac
#Test ' httperf server'
#执行httperf测试,并加log输出到文件中
httperf --server sina.com.cn --num-conn 300 --rate 30 2>&1 | tee httperf.log
print_info $? httper-test
$TCID="httperf-test"
#在文件中查找关键字符串,后面会根据这个字符串是否为null,来判断是否执行成功
str=`grep -Po "total 0" httperf.log`
if [ "$str" != "" ] ; then
lava-test-case $TCID --result pass
else
lava-test-case $TCID --result faile
fi
#根据进程名杀掉进程
pkill httperf
删除log
rm httperf.log
#删除包
case $distro in
"centos")
yum remove make -y
rm -f httperf-0.9.0.tar.gz
rm -rf httperf-0.9.0
print_info $? remove-httperf
;;
"ubuntu")
apt-get remove httperf -y
print_info $? remove-httperf
;;
esac