A method for OTA upgrade of automated test application at TV end

1. Demand

Application A and B need to be upgraded

A:com.konka.kksmarthome

B:com.konka.iotserver

The upgrade of B depends on a specified version of A (only when the system detects the version number of A, B will be upgraded)

After the user is powered on, the application can be successfully pushed and upgraded (background silent upgrade)

Pressure test the OTA upgrade 200 times to check the upgrade success rate.

2. Hanging bag:

Upgrade the background, hang the two packages of A and B separately, and add dependencies. (B depends on A)

3. Strategy

Ⅰ. Two scripts need to be designed, one is xshell and the other is python script

Script name:

1.test_kksmarthome.sh

2.reboot_appupgrade_PC.py

Ⅱ. Copy script 1 to TV

adb push C:\Users\Administrator\Desktop\test_kksmarthome.sh /data

Ⅲ. Open xshell 6, click to run the script, and then select reboot_appupgrade_PC.py to run.

①.test_kksmarthome.sh code is as follows:

test_dir="/data/testDir"
log_dir="$test_dir/log"
sum_dir="$test_dir/summary"
out_file="$test_dir/result.txt"
out_file1="/dev/console"
sum_vid_file="$sum_dir/summary_vid.txt"
sum_mul_file="$sum_dir/summary_mul.txt"
sum_rec_file="$sum_dir/summary_rec.txt"
sum_req_file="$sum_dir/summary_req.txt"
vid_install_file="$sum_dir/vid_install.txt"
vid_find_file="$sum_dir/vid_find.txt"
vid_download_file="$sum_dir/vid_download.txt"
mul_install_file="$sum_dir/mul_install.txt"
mul_find_file="$sum_dir/mul_find.txt"
mul_download_file="$sum_dir/mul_download.txt"
rec_install_file="$sum_dir/rec_install.txt"
rec_find_file="$sum_dir/rec_find.txt"
rec_download_file="$sum_dir/rec_download.txt"
req_file="$sum_dir/req.txt"
test_down_file="$sum_dir/test_down.sh"
count_file="$test_dir/count.txt"

#定义测试路径和文件
if [ ! -d $test_dir ];then 
	mkdir $test_dir
	mkdir $log_dir
	mkdir $sum_dir
	echo "" > $sum_vid_file
	echo "" > $sum_mul_file
	echo "" > $sum_rec_file
	echo "" > $sum_req_file
	echo "0" > $vid_install_file
	echo "0" > $vid_find_file
	echo "0" > $vid_download_file
	echo "0" > $mul_install_file
	echo "0" > $mul_find_file
	echo "0" > $mul_download_file
	echo "0" > $rec_install_file
	echo "0" > $rec_find_file
	echo "0" > $rec_download_file
	echo "0" > $req_file
	echo "echo AAA  AAA  AAA  AAA  AAA  AAA" > $test_down_file
	echo "0" > $count_file
	clear
	
fi

#定义循环次数参数
count=`cat $count_file`
let count++

echo "--------------------- 第${count}次 ----------------------" >>$out_file
echo "--------------------- 第${count}次 ----------------------" >>$out_file1

#打印log
start logd
sleep 1
logcat -G 50M
sleep 1
logcat -v time > $log_dir/第${count}次.log&
sleep 10

#设置超时。十分钟内如果检测到两个应用均安装成功则输出pass,结束循环;否则循环超过十分钟自动结束
timeout=300.0
start_time=`cat /proc/uptime | busybox awk '{print $1}'`
while true;do
	a1=`dumpsys package com.konka.kksmarthome|grep versionName=2.7.1167`
	a2=`dumpsys package com.konka.iotserver|grep versionName=2.7.214`
	if [ "${a1}" -a "${a2}"  ];then	
		echo "pass" >>$out_file
		echo "pass" >>$out_file1
		break
	fi
	sleep 5
	cur_time=`cat /proc/uptime | busybox awk '{print $1}'`
	f=`busybox awk -v s=$start_time -v c=$cur_time -v to=$timeout 'BEGIN{d=c-s;if(d>300){print "timeout"}}'`
	if [ "${f}" ];then
		echo "timeout !!!" >> $out_file
		echo "timeout !!!" >> $out_file1
		break
	fi
done

#检测安装包结果,输出应用安装结果到结果文件
if [ "${a1}" ];then
	echo "${count}.kksmarthome:安装成功" >> $out_file
fi
if [ "${a2}" ];then
	echo "${count}.iotserver:安装成功" >> $out_file
fi

#检测全局log,将升级信息相关log归类到升级log
cat /$log_dir/第${count}次.log | grep "AppUpgrade" > $log_dir/${count}.txt

#检测升级log中是否存在“请求升级信息成功”,并记录到结果文件
a=`grep "AppUpgrade.*请求升级信息成功" $log_dir/${count}.txt`
if [ "${a}" ];then
	echo "${count}.请求升级信息成功" >> $out_file
fi 

#检测升级log中是否存在两个应用的相关“发现可升级版本”信息,并记录到结果文件
b1=`grep "发现可升级版本: com.konka.kksmarthome" $log_dir/${count}.txt`
b2=`grep "发现可升级版本: com.konka.iotserver" $log_dir/${count}.txt`
if [ "${b1}" ];then
	echo "${count}.kksmarthome:发现可升级版本成功" >> $out_file
fi
if [ "${b2}" ];then
	echo "${count}.iotserver:发现可升级版本成功" >> $out_file
fi

#检测升级log中是否存在两个应用的相关“下载完成”信息,并记录到结果文件
c1=`grep "下载完成 ID:2331 ,\[阿斐亚智家\]" $log_dir/${count}.txt`
c2=`grep "下载完成 ID:2338 ,\[IotServer\]" $log_dir/${count}.txt`
if [ "${c1}" ];then
	echo "${count}.kksmarthome:下载成功" >> $out_file
fi
if [ "${c2}" ];then
	echo "${count}.iotserver:下载成功" >> $out_file
fi

#记录统计成功次数

#记录统计kksmarthome的结果成功次数
d1=`grep "${count}.kksmarthome:安装成功" $out_file`
d2=`grep "${count}.kksmarthome:发现可升级版本成功" $out_file`
d3=`grep "${count}.kksmarthome:下载成功" $out_file`
if [ "${d1}" ];then 
	vid_install=`cat $vid_install_file`
	let vid_install++
	echo "${vid_install}" >$vid_install_file
fi
if [ "${d2}" ];then 
	vid_find=`cat $vid_find_file`
	let vid_find++
	echo "${vid_find}" >$vid_find_file
fi
if [ "${d3}" ];then 
	vid_download=`cat $vid_download_file`
	let vid_download++
	echo "${vid_download}" >$vid_download_file
fi

#记录统计iotserver的结果成功次数
e1=`grep "${count}.iotserver:安装成功" $out_file`
e2=`grep "${count}.iotserver:发现可升级版本成功" $out_file`
e3=`grep "${count}.iotserver:下载成功" $out_file`
if [ "${e1}" ];then 
	mul_install=`cat $mul_install_file`
	let mul_install++
	echo "${mul_install}" >$mul_install_file
fi
if [ "${e2}" ];then 
	mul_find=`cat $mul_find_file`
	let mul_find++
	echo "${mul_find}" >$mul_find_file
fi
if [ "${e3}" ];then 
	mul_download=`cat $mul_download_file`
	let mul_download++
	echo "${mul_download}" >$mul_download_file
fi



#记录统计请求信息的结果成功次数
g=`grep "${count}.请求升级信息成功" $out_file`
if [ "${g}" ];then 
	req=`cat $req_file`
	let req++
	echo "${req}" >$req_file
fi

#将两个应用和请求信息结果成功数汇总到各自的总文件
echo "--------------------- 第${count}次 ----------------------" >>$sum_vid_file
echo "安装成功次数:`cat $vid_install_file`" >>$sum_vid_file
echo "发现版本成功次数:`cat $vid_find_file`" >>$sum_vid_file
echo "下载成功次数:`cat $vid_download_file`" >>$sum_vid_file
echo "--------------------- 第${count}次 ----------------------" >>$sum_mul_file
echo "安装成功次数:`cat $mul_install_file`" >>$sum_mul_file
echo "发现版本成功次数:`cat $mul_find_file`" >>$sum_mul_file
echo "下载成功次数:`cat $mul_download_file`" >>$sum_mul_file
echo "--------------------- 第${count}次 ----------------------" >>$sum_rec_file
echo "安装成功次数:`cat $rec_install_file`" >>$sum_rec_file
echo "发现版本成功次数:`cat $rec_find_file`" >>$sum_rec_file
echo "下载成功次数:`cat $rec_download_file`" >>$sum_rec_file
echo "--------------------- 第${count}次 ----------------------" >>$sum_req_file
echo "请求成功次数:`cat $req_file`" >>$sum_req_file

#循环次数+1
echo "${count}" >$count_file

echo "finish"  >>$out_file1


#if [[ $count -lt 100 ]];then
if [[ $count -lt 100 ]];then
	#前100次删除一个应用,并安装低版本iotserver 
    pm uninstall com.konka.kksmarthome	
	sleep 5
	pm uninstall com.konka.iotserver
	sleep 5
	pm install /data/210927094924u34u.apk
	sleep 20
else
	#删除kksmarthome和iotserver
    pm uninstall com.konka.kksmarthome
	sleep 3
	pm uninstall com.konka.iotserver
	sleep 3
fi


sh $test_down_file
cat $test_down_file
 

②.reboot_appupgrade_PC.py code is as follows: test

# $language = "Python"
# $interface = "1.0"


def main(): 
    xsh.Screen.Synchronous = False  # 屏幕实时刷新True部分机器串口、Xshell客户端卡死,False是否失败抓漏未验证
    xsh.Screen.Send("pm uninstall com.konka.kksmarthome \n\r")  #卸载kksmarthome
    xsh.Session.Sleep(3000)
    xsh.Screen.Send("pm uninstall com.konka.iotserver \n\r")  #卸载iotserver
    xsh.Session.Sleep(3000)
    xsh.Screen.Send("rm -r /data/testDir \n\r ")  #执行前需删掉旧的testDir文件夹
    xsh.Session.Sleep(2000)
    xsh.Screen.Send("su \n\r ")  # 执行reboot命令前先su,获得root权限
    xsh.Session.Sleep(2000)

    for x in range(0, 200):  # arg2为循环次数,即重启200次
        xsh.Screen.Send("reboot  \n\r ")
        xsh.Session.Sleep(2000)
        xsh.Screen.Clear()
        #xsh.Session.Sleep(35000)  # 重启后等待1min,时长由机器性能决定,时间不宜过长,但要确保TV已正常开机
        xsh.Screen.WaitForStrings("Start", 60000)
        xsh.Session.Sleep(20000)
        xsh.Screen.Send("\n\r ") 
        xsh.Session.Sleep(1000)
        xsh.Screen.Send("su \n\r ") 
        xsh.Session.Sleep(1000)
        xsh.Screen.Send("\n\r ") 
        xsh.Session.Sleep(1000)
        xsh.Screen.Send("sh -x /data/test_kksmarthome.sh < /dev/null & \n\r")  # 执行TV端升级检测脚本
        xsh.Session.Sleep(5000)  # 避免首次echo生成sh脚本AAA时,保留着当前screen,执行clear后再监听画面AAA
        xsh.Screen.Clear()
        #xsh.Session.Sleep(660000)  # 预留shell脚本执行时间11mins,单位为毫秒
        #xsh.Session.Sleep(60000)  # 调试环境,验证捕获AAA有效性
        xsh.Screen.WaitForStrings("AAA", 660000)  # 在test_kksmarthome.sh脚本运行完成后,100s时间内监测到屏幕有AAA信息后执行reboot命令
        xsh.Screen.Clear()  # xsh.Screen.Send("clear  \r ")  # 清屏 确认\n\r或\r或\n需要换多少行
        continue


main()

 Ⅳ. After the test is completed, enter the serial port to check the result.txt to know the success and failure times of the upgrade.

Guess you like

Origin blog.csdn.net/weixin_41982551/article/details/127119356