mirror of https://github.com/axmolengine/axmol.git
[ci skip], add ssh upload file in emptytest.py.
This commit is contained in:
parent
55911e1e78
commit
e749ab8ddb
|
@ -1,9 +1,9 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# create new project by cocos-console
|
# check crash of cppemptytest
|
||||||
# compile, deploy project and run
|
# install/open/uninstall apk
|
||||||
# perpose: for emptytest.
|
# perpose: for emptytest.
|
||||||
# now support: mac- mac/ios/android
|
# now support: android
|
||||||
# will add: window-android,linux-android
|
# will add: autotest-win7
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
@ -11,6 +11,10 @@ import json
|
||||||
import time
|
import time
|
||||||
import socket
|
import socket
|
||||||
import platform
|
import platform
|
||||||
|
import threading
|
||||||
|
import codecs
|
||||||
|
import re
|
||||||
|
import paramiko
|
||||||
|
|
||||||
payload = {}
|
payload = {}
|
||||||
#get payload from os env
|
#get payload from os env
|
||||||
|
@ -26,7 +30,6 @@ if payload.has_key('number'):
|
||||||
print 'pr_num:' + str(pr_num)
|
print 'pr_num:' + str(pr_num)
|
||||||
run_app_time = 5
|
run_app_time = 5
|
||||||
if os.environ.has_key('RUN_APP_TIME'):
|
if os.environ.has_key('RUN_APP_TIME'):
|
||||||
global run_app_time
|
|
||||||
run_app_time = os.environ['RUN_APP_TIME']
|
run_app_time = os.environ['RUN_APP_TIME']
|
||||||
print 'run_app_time:', run_app_time
|
print 'run_app_time:', run_app_time
|
||||||
|
|
||||||
|
@ -49,8 +52,6 @@ if os.environ.has_key('TEST_INDEX'):
|
||||||
current_platform = platform.system()
|
current_platform = platform.system()
|
||||||
print 'current platform is:', current_platform
|
print 'current platform is:', current_platform
|
||||||
|
|
||||||
empty_test_result = True
|
|
||||||
empty_test_result_info = ''
|
|
||||||
arrDevices = []
|
arrDevices = []
|
||||||
def getDevices():
|
def getDevices():
|
||||||
cmd = 'adb devices'
|
cmd = 'adb devices'
|
||||||
|
@ -84,94 +85,95 @@ def mapIP():
|
||||||
ip_d = getADBDeviceIP(device['name'])
|
ip_d = getADBDeviceIP(device['name'])
|
||||||
device['ip'] = ip_d
|
device['ip'] = ip_d
|
||||||
|
|
||||||
device_info = {}
|
allThreadIsRunning = {}
|
||||||
|
def setThreadStatus():
|
||||||
|
for device in arrDevices:
|
||||||
|
allThreadIsRunning[device['name']] = 1
|
||||||
|
|
||||||
|
devices_info = {}
|
||||||
info_list = '{"product":["model","brand","name","cpu.abi","cpu.abi2","manufacturer","locale.language","locale.region"],"build":["id","version.sdk","version.release"]}'
|
info_list = '{"product":["model","brand","name","cpu.abi","cpu.abi2","manufacturer","locale.language","locale.region"],"build":["id","version.sdk","version.release"]}'
|
||||||
if os.environ.has_key('DEVICE_INFO_LIST'):
|
if os.environ.has_key('DEVICE_INFO_LIST'):
|
||||||
info_list = os.environ['DEVICE_INFO_LIST']
|
info_list = os.environ['DEVICE_INFO_LIST']
|
||||||
info_list = eval(info_list)
|
info_list = eval(info_list)
|
||||||
def getDeviceInfoByName(name):
|
def getDeviceInfoByName(name):
|
||||||
cmd = ''
|
cmd = ''
|
||||||
|
dev_name = name
|
||||||
if len(name) > 0:
|
if len(name) > 0:
|
||||||
cmd = 'adb -s '+name+' shell cat /system/build.prop'
|
cmd = 'adb -s '+name+' shell cat /system/build.prop'
|
||||||
else:
|
else:
|
||||||
cmd = 'adb shell cat /system/build.prop'
|
cmd = 'adb shell cat /system/build.prop'
|
||||||
|
dev_name = 'device one'
|
||||||
pip_cat = os.popen(cmd)
|
pip_cat = os.popen(cmd)
|
||||||
read_info = pip_cat.read()
|
read_info = pip_cat.read()
|
||||||
read_info_list = read_info.split('\r\n')
|
read_info_list = read_info.split('\r\n')
|
||||||
def checkProperty(item_str):
|
device_info_one = {}
|
||||||
|
def checkProperty(item_str, device_name):
|
||||||
for argv in info_list:
|
for argv in info_list:
|
||||||
for item in info_list[argv]:
|
for item in info_list[argv]:
|
||||||
prop = argv+'.'+item
|
prop = argv+'.'+item
|
||||||
if item_str.find(prop) > -1:
|
if item_str.find(prop) > -1:
|
||||||
arr_item = item_str.split('=')
|
arr_item = item_str.split('=')
|
||||||
device_info[prop] = arr_item[1]
|
device_info_one[prop] = arr_item[1]
|
||||||
break
|
break
|
||||||
for item in read_info_list:
|
for item in read_info_list:
|
||||||
checkProperty(item)
|
checkProperty(item, dev_name)
|
||||||
|
devices_info[dev_name] = device_info_one
|
||||||
|
|
||||||
#getDeviceInfoByName('')
|
#getDeviceInfoByName('')
|
||||||
#print 'device_info:',device_info
|
#print 'device_info:',device_info
|
||||||
def logDeviceInfomation():
|
def getDeviceInfomation():
|
||||||
getDeviceInfoByName('')
|
for device in arrDevices:
|
||||||
for key in device_info:
|
getDeviceInfoByName(device['name'])
|
||||||
print '\t'+key+':'+device_info[key]
|
|
||||||
|
|
||||||
info_empty_test = {}
|
info_empty_test = {}
|
||||||
|
info_empty_test_pro = ['install','open','socket','uninstall']
|
||||||
|
def init_info_empty_test():
|
||||||
|
for item in info_empty_test_pro:
|
||||||
|
info_empty_test[item] = {}
|
||||||
|
init_info_empty_test()
|
||||||
|
|
||||||
apk_name = 'apks/'+test_name[gIdx]+'/'+test_name[gIdx]+'_'+str(pr_num)+'.apk'
|
apk_name = 'apks/'+test_name[gIdx]+'/'+test_name[gIdx]+'_'+str(pr_num)+'.apk'
|
||||||
def install_apk():
|
def install_apk_on_device(device):
|
||||||
print 'will install apk:', apk_name
|
name = device['name']
|
||||||
global empty_test_result
|
cmd = 'adb -s '+name+' install '+apk_name
|
||||||
if len(arrDevices) == 0:
|
print 'install on '+name
|
||||||
empty_test_result = False
|
info_install = os.popen(cmd).read()
|
||||||
empty_test_result_info = 'no android device.'
|
print 'infomation of install apk:', info_install
|
||||||
print empty_test_result_info
|
info_install_arr = info_install.split('\r\n')
|
||||||
return False
|
info_install_result = False
|
||||||
info_of_install = []
|
for item in info_install_arr:
|
||||||
if not os.path.isfile(apk_name):
|
if item.find('Success') > -1:
|
||||||
print apk_name, 'is not exist!'
|
info_install_result = True
|
||||||
empty_test_result = False
|
info_empty_test['install'][name] = info_install_result
|
||||||
return False
|
|
||||||
for device in arrDevices:
|
|
||||||
name = device['name']
|
|
||||||
cmd = 'adb -s '+name+' install '+apk_name
|
|
||||||
print 'install on '+name
|
|
||||||
info_install = os.popen(cmd).read()
|
|
||||||
print 'infomation of install apk:', info_install
|
|
||||||
info_of_install.append(info_install.split('\r\n'))
|
|
||||||
info_empty_test['install'] = info_of_install
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def open_apk(type_of_apk):
|
def open_apk_on_device(device):
|
||||||
print 'will open activity:'
|
print 'will open activity:'
|
||||||
for device in arrDevices:
|
name = device['name']
|
||||||
cmd = 'adb -s '+device['name']+' shell am start -n '+package_name[gIdx]+'/'+activity_name[gIdx]
|
cmd = 'adb -s '+name+' shell am start -n '+package_name[gIdx]+'/'+activity_name[gIdx]
|
||||||
# print 'start activity:', cmd
|
# print 'start activity:', cmd
|
||||||
info_start = os.popen(cmd).read()
|
info_start = os.popen(cmd).read()
|
||||||
info_start = info_start.split('\n')
|
info_start = info_start.split('\r\n')
|
||||||
# print 'info_start:', info_start
|
# print 'info_start:', info_start
|
||||||
for info in info_start:
|
info_start_result = True
|
||||||
if info.find('Error:') > -1:
|
for info in info_start:
|
||||||
print 'infomation of open activity:',info
|
if info.find('Error:') > -1:
|
||||||
global empty_test_result
|
print 'infomation of open activity:',info
|
||||||
empty_test_result = False
|
info_start_result = False
|
||||||
empty_test_result_info = 'open :'+info
|
info_empty_test['open'][name] = info_start_result
|
||||||
return info
|
|
||||||
if len(arrDevices):
|
|
||||||
print 'activity is opened.'
|
|
||||||
else:
|
|
||||||
print 'no device.'
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
PORT = 5678
|
PORT = 5678
|
||||||
def socket_status(device_name):
|
def socket_status_on_device(device):
|
||||||
|
name = device['name']
|
||||||
|
ip = device['ip']
|
||||||
soc = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
|
soc = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
|
||||||
status_socket = False
|
status_socket = False
|
||||||
global empty_test_result
|
info_of_socket_result = ''
|
||||||
try:
|
try:
|
||||||
print 'telnet ', device_name['ip'], PORT
|
print 'telnet ', ip, PORT
|
||||||
soc.connect((device_name['ip'], PORT))
|
soc.connect((ip, PORT))
|
||||||
cmd = 'resolution\r\n'
|
cmd = 'resolution\r\n'
|
||||||
# print 'socket cmd :', cmd
|
|
||||||
print 'connected successfully.'
|
print 'connected successfully.'
|
||||||
print 'send console command: resolution'
|
print 'send console command: resolution'
|
||||||
soc.send(cmd)
|
soc.send(cmd)
|
||||||
|
@ -180,71 +182,158 @@ def socket_status(device_name):
|
||||||
if len(data):
|
if len(data):
|
||||||
print data
|
print data
|
||||||
if data.find('size:') > -1:
|
if data.find('size:') > -1:
|
||||||
print 'OK'
|
info_of_socket_result = 'OK'
|
||||||
print 'close', test_name[gIdx]
|
print 'close', test_name[gIdx]
|
||||||
soc.send('director end')
|
soc.send('director end')
|
||||||
print 'OK'
|
|
||||||
status_socket = True
|
status_socket = True
|
||||||
break
|
break
|
||||||
if not data:
|
if not data:
|
||||||
empty_test_result = False
|
info_of_socket_result = test_name[gIdx]+' is crashed!'
|
||||||
empty_test_result_info = test_name[gIdx]+' is crashed!'
|
|
||||||
print empty_test_result_info
|
|
||||||
break
|
break
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
empty_test_result = False
|
info_of_socket_result = test_name[gIdx]+' is crashed!'
|
||||||
empty_test_result_info = test_name[gIdx]+' is crashed!'
|
|
||||||
print empty_test_result_info
|
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
soc.close()
|
soc.close()
|
||||||
|
time.sleep(2)
|
||||||
|
info_empty_test['socket'][name] = info_of_socket_result
|
||||||
return status_socket
|
return status_socket
|
||||||
|
|
||||||
def uninstall_apk(idx):
|
def uninstall_apk_on_device(device):
|
||||||
# adb shell pm uninstall -n org.cocos2dx.hellolua
|
# adb shell pm uninstall -n org.cocos2dx.hellolua
|
||||||
print 'uninstall ', test_name[idx]
|
print 'uninstall ', test_name[gIdx]
|
||||||
for device in arrDevices:
|
name = device['name']
|
||||||
cmd = 'adb -s '+device['name']+' shell pm uninstall -n '+package_name[idx]
|
cmd = 'adb -s '+name+' shell pm uninstall -n '+package_name[gIdx]
|
||||||
info_uninstall = os.popen(cmd).read()
|
info_uninstall = os.popen(cmd).read()
|
||||||
if info_uninstall.find('Success') > -1:
|
info_uninstall_result = ''
|
||||||
print 'OK'
|
if info_uninstall.find('Success') > -1:
|
||||||
else:
|
info_uninstall_result = 'OK'
|
||||||
empty_test_result_info = 'uninstall Failed!'
|
else:
|
||||||
print empty_test_result_info
|
info_uninstall_result = 'uninstall Failed!'
|
||||||
|
info_empty_test['uninstall'][name] = info_uninstall_result
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def excute_test_on_device(device):
|
||||||
|
uninstall_apk_on_device(device)
|
||||||
|
print device
|
||||||
|
info_install = install_apk_on_device(device)
|
||||||
|
print 'install:', info_install
|
||||||
|
info_open = open_apk_on_device(device)
|
||||||
|
print 'open:', info_open
|
||||||
|
time.sleep(3)
|
||||||
|
info_socket = socket_status_on_device(device)
|
||||||
|
print 'socket:', info_socket
|
||||||
|
info_uninstall = uninstall_apk_on_device(device)
|
||||||
|
print 'uninstall:', info_uninstall
|
||||||
|
allThreadIsRunning[device['name']] = 0
|
||||||
|
|
||||||
|
def send_result_to_master():
|
||||||
|
if not os.environ.has_key('REMOTE_IP'):
|
||||||
|
return false
|
||||||
|
remote_ip = os.environ['REMOTE_IP']
|
||||||
|
remote_port = os.environ['REMOTE_PORT']
|
||||||
|
remote_user = os.environ['REMOTE_USER']
|
||||||
|
remote_pwd = os.environ['REMOTE_PWD']
|
||||||
|
remote_dir = os.environ['REMOTE_DIR']
|
||||||
|
print remote_dir
|
||||||
|
ssh = paramiko.SSHClient()
|
||||||
|
print 'ssh:',ssh
|
||||||
|
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||||
|
ssh.connect(remote_ip, int(remote_port), remote_user, remote_pwd)
|
||||||
|
# create dir
|
||||||
|
stdin, stdout, stderr = ssh.exec_command("mkdir "+remote_dir)
|
||||||
|
ssh.close()
|
||||||
|
trans = paramiko.Transport((remote_ip,int(remote_port)))
|
||||||
|
trans.connect(username = remote_user, password = remote_pwd)
|
||||||
|
sftp = paramiko.SFTPClient.from_transport(trans)
|
||||||
|
remotepath = remote_dir+test_name[gIdx]+'_'+str(pr_num)+'.html'
|
||||||
|
localpath = 'html/cpp_empty_test/cpp_empty_test_'+str(pr_num)+'.html'
|
||||||
|
sftp.put(localpath, remotepath)
|
||||||
|
sftp.close()
|
||||||
|
|
||||||
|
def check_thread_is_running():
|
||||||
|
while 1:
|
||||||
|
in_running = 0
|
||||||
|
for key in allThreadIsRunning:
|
||||||
|
in_running = in_running + allThreadIsRunning[key]
|
||||||
|
# print 'in_running:', in_running
|
||||||
|
time.sleep(3)
|
||||||
|
if not in_running:
|
||||||
|
break
|
||||||
|
print 'all cpp emptytest is finished.'
|
||||||
|
log_emptytest_result()
|
||||||
|
print 'will send result:'
|
||||||
|
send_result_to_master()
|
||||||
|
print 'end of check thread is running.'
|
||||||
|
|
||||||
|
def generate_html_with_result(result):
|
||||||
|
target_path = 'html/cpp_empty_test/cpp_empty_test_'+str(pr_num)+'.html'
|
||||||
|
data = codecs.open('hello.html', encoding='UTF-8').read()
|
||||||
|
data = re.sub("content", result, data)
|
||||||
|
codecs.open(target_path, 'wb', encoding='UTF-8').write(data)
|
||||||
|
|
||||||
|
empty_test_result = True
|
||||||
|
str_result = ''
|
||||||
|
def log_emptytest_result():
|
||||||
|
def appendToResult(one_str):
|
||||||
|
global str_result
|
||||||
|
str_result = str_result + one_str + '\r\n'
|
||||||
|
appendToResult('<pre>')
|
||||||
|
appendToResult('empty test start:')
|
||||||
|
for device in arrDevices:
|
||||||
|
name = device['name']
|
||||||
|
appendToResult('device infomation of : '+name)
|
||||||
|
for key in devices_info[name]:
|
||||||
|
appendToResult('\t'+key+':'+devices_info[name][key])
|
||||||
|
appendToResult('install: ' + str(info_empty_test['install'][name]))
|
||||||
|
appendToResult('open: ' + str(info_empty_test['open'][name]))
|
||||||
|
appendToResult('telnet ' + str(device['ip'])+' : ' + str(info_empty_test['socket'][name]))
|
||||||
|
appendToResult('close: ' + str(info_empty_test['socket'][name]))
|
||||||
|
appendToResult('uninstall: ' + str(info_empty_test['uninstall'][name]))
|
||||||
|
if not info_empty_test['install'][name] or not info_empty_test['open'][name] or not info_empty_test['socket'][name] or not info_empty_test['uninstall'][name]:
|
||||||
|
empty_test_result = False
|
||||||
|
appendToResult('empty test is failed!')
|
||||||
|
else: appendToResult('empty test is successfully!')
|
||||||
|
appendToResult('')
|
||||||
|
appendToResult('empty test end.</pre>')
|
||||||
|
generate_html_with_result(str_result)
|
||||||
|
print 'log empty test end'
|
||||||
|
|
||||||
|
class myThread(threading.Thread):
|
||||||
|
def __init__(self,threadname):
|
||||||
|
threading.Thread.__init__(self,name=threadname)
|
||||||
|
def run(self):
|
||||||
|
time.sleep(2)
|
||||||
|
device = self.getName()
|
||||||
|
print type(device)
|
||||||
|
device = eval(device)
|
||||||
|
print type(device), device
|
||||||
|
excute_test_on_device(device)
|
||||||
|
|
||||||
|
def run_emptytest():
|
||||||
|
for device in arrDevices:
|
||||||
|
th = myThread(device)
|
||||||
|
th.start()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print 'in main:'
|
print 'in main:'
|
||||||
getDevices()
|
getDevices()
|
||||||
if len(arrDevices):
|
if len(arrDevices):
|
||||||
mapIP()
|
mapIP()
|
||||||
|
setThreadStatus()
|
||||||
print 'arrDevices:',arrDevices
|
print 'arrDevices:',arrDevices
|
||||||
uninstall_apk(gIdx)
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
else:
|
else:
|
||||||
print 'there is no device for emptytest, please check devices!'
|
print 'there is no device for emptytest, please check devices!'
|
||||||
return 1
|
return 1
|
||||||
print 'empty test start:'
|
|
||||||
print 'device infomation:'
|
|
||||||
if len(arrDevices):
|
if len(arrDevices):
|
||||||
logDeviceInfomation()
|
getDeviceInfomation()
|
||||||
else:
|
run_emptytest()
|
||||||
print '\tno android device.'
|
check_thread_is_running()
|
||||||
install_info = install_apk()
|
|
||||||
open_info = open_apk(test_name[gIdx])
|
|
||||||
info_empty_test['open_info'] = open_info
|
|
||||||
if open_info:
|
|
||||||
time.sleep(5)
|
|
||||||
socket_info = socket_status(arrDevices[0])
|
|
||||||
info_empty_test['socket_info'] = socket_info
|
|
||||||
if install_info:
|
|
||||||
time.sleep(run_app_time)
|
|
||||||
info_uninstall = uninstall_apk(gIdx)
|
|
||||||
print 'info_empty_test:', info_empty_test
|
print 'info_empty_test:', info_empty_test
|
||||||
print 'empty test end', empty_test_result
|
print 'empty test end', empty_test_result
|
||||||
if empty_test_result:
|
if empty_test_result:
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
print 'empty_test_result_info:', empty_test_result_info
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
# -------------- main --------------
|
# -------------- main --------------
|
||||||
|
|
Loading…
Reference in New Issue