#!/bin/bash

max=100

echo "************ test start ************" | tee /tmp/test.log

sleep 60

mc alias set ucas http://127.0.0.1 ucasadmin ucasadmin 1>/dev/null 2>&1

sleep 30

i=1
while [ ${i} -le ${max} ]
do
	echo ">>>>>>> count:${i} start <<<<<<<<" | tee -a /tmp/test.log
	date | tee -a /tmp/test.log
	mc support perf --json ucas >/tmp/now.log
	if [ $? -eq 0 ];then
		put=`cat /tmp/now.log|awk -F "throughputPerSec" '{print $2}'|awk -F: '{print $2}'|awk -F, '{print $1}'|awk 'BEGIN {max = 0} {if ($1>max) max=$1 fi} END {print  max}'`
		get=`cat /tmp/now.log|awk -F "throughputPerSec" '{print $4}'|awk -F: '{print $2}'|awk -F, '{print $1}'|awk 'BEGIN {max = 0} {if ($1>max) max=$1 fi} END {print  max}'`
		
		let put=put/1024/1024
		let get=get/1024/1024

		echo "put:${put} get:${get}" |tee -a /tmp/test.log
		if [ ${put} -ge 150 -a ${get} -ge 150 ];then
			echo "count:${i} pass" | tee -a /tmp/test.log
		else
			echo "count:${i} fail" | tee -a /tmp/test.log
			systemctl stop hb.service
			/opt/tool/saturn-gpio-set.sh --sys 0
			exit 1
		fi
	else 
		cat  /tmp/now.log | tee -a /tmp/test.log
		echo "count:${i} fail" | tee -a /tmp/test.log
		systemctl stop hb.service
		/opt/tool/saturn-gpio-set.sh --sys 0
		exit 1
	fi

	let i=i+1
	sleep 600
done
systemctl stop hb.service
/opt/tool/saturn-gpio-set.sh --sys 2

echo "********* ALL test PASS !!! ************" | tee -a /tmp/test.log
cp /tmp/test.log /opt/collect/

exit 0
