2014-03-17 11:49:18 +08:00
|
|
|
#!/usr/bin/python
|
2014-03-03 17:47:55 +08:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
import socket
|
|
|
|
import time
|
|
|
|
|
2014-03-06 16:52:34 +08:00
|
|
|
HOST_MAC = 'localhost'
|
2014-04-01 22:05:47 +08:00
|
|
|
HOST_ANDROID = ''
|
2014-03-06 16:52:34 +08:00
|
|
|
HOST_IOS = '10.10.30.61'
|
2014-03-03 17:47:55 +08:00
|
|
|
PORT = 5678
|
|
|
|
|
2014-03-06 16:52:34 +08:00
|
|
|
suc_build_mac = 0
|
|
|
|
suc_build_android = 0
|
|
|
|
|
|
|
|
TYPE_MAC = 0
|
|
|
|
TYPE_ANDROID = 1
|
|
|
|
TYPE_IOS = 2
|
|
|
|
|
|
|
|
sleep_time = 1.5
|
2014-04-01 22:05:47 +08:00
|
|
|
|
|
|
|
#
|
|
|
|
def getADBDeviceIP():
|
|
|
|
output = os.popen("adb shell netcfg")
|
|
|
|
configs = output.read().split('\r\n')
|
|
|
|
for l in configs:
|
|
|
|
items = l.split()
|
|
|
|
if(items[1] == 'UP'):
|
|
|
|
if(items[2] != '127.0.0.1'):
|
|
|
|
return items[2]
|
|
|
|
|
2014-03-06 16:52:34 +08:00
|
|
|
def autotest(type):
|
2014-03-03 17:47:55 +08:00
|
|
|
soc = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
|
2014-03-06 16:52:34 +08:00
|
|
|
if type == TYPE_MAC:
|
|
|
|
soc.connect((HOST_MAC, PORT))
|
|
|
|
if type == TYPE_ANDROID:
|
2014-04-01 22:05:47 +08:00
|
|
|
HOST_ANDROID = getADBDeviceIP()
|
2014-04-01 22:08:32 +08:00
|
|
|
soc.connect((HOST_ANDROID, PORT))
|
2014-03-06 16:52:34 +08:00
|
|
|
if type == TYPE_IOS:
|
|
|
|
soc.connect((HOST_IOS, PORT))
|
2014-03-17 11:49:18 +08:00
|
|
|
time.sleep(1)
|
2014-03-03 17:47:55 +08:00
|
|
|
print 'autotest run:'
|
|
|
|
soc.send('autotest run\r\n')
|
|
|
|
|
|
|
|
while True:
|
2014-04-01 16:05:28 +08:00
|
|
|
data = soc.recv(1024)
|
|
|
|
print data
|
|
|
|
if not data: break
|
2014-03-18 14:30:01 +08:00
|
|
|
|
2014-03-03 17:47:55 +08:00
|
|
|
print 'test end and close socket.'
|
|
|
|
soc.close()
|
|
|
|
|
|
|
|
#----------------autotest build and run----------------#
|
2014-03-06 16:52:34 +08:00
|
|
|
def MAC_BUILD():
|
|
|
|
def cleanProj():
|
2014-03-11 20:47:02 +08:00
|
|
|
infoClean = os.system('xcodebuild -project ./build/cocos2d_tests.xcodeproj -target cpp-tests\ Mac clean')
|
2014-03-06 16:52:34 +08:00
|
|
|
print 'infoClean: ', infoClean
|
|
|
|
if infoClean != 0:
|
|
|
|
return False
|
|
|
|
time.sleep(sleep_time)
|
|
|
|
return True
|
|
|
|
def buildProj():
|
2014-03-11 20:47:02 +08:00
|
|
|
infoBuild = os.system('xcodebuild -project ./build/cocos2d_tests.xcodeproj -target cpp-tests\ Mac')
|
2014-03-06 16:52:34 +08:00
|
|
|
print 'infoBuild: ', infoBuild
|
|
|
|
if infoBuild != 0:
|
|
|
|
return False
|
|
|
|
time.sleep(sleep_time)
|
|
|
|
return True
|
|
|
|
def openProj():
|
2014-03-11 20:47:02 +08:00
|
|
|
cmd = 'open ./build/build/Debug/cpp-tests\ Mac.app'
|
2014-03-06 16:52:34 +08:00
|
|
|
print 'cmd: ', cmd
|
|
|
|
infoOpen = os.system(cmd)
|
|
|
|
print 'infoOpen: ', infoOpen
|
|
|
|
if infoOpen != 0:
|
|
|
|
return False
|
|
|
|
time.sleep(sleep_time)
|
|
|
|
return True
|
|
|
|
def buildAndRun():
|
|
|
|
if not cleanProj():
|
|
|
|
print '**CLEAN FAILED**'
|
|
|
|
if not buildProj():
|
2014-03-17 11:49:18 +08:00
|
|
|
print '**BUILD FAILED**'
|
|
|
|
return False
|
2014-03-06 16:52:34 +08:00
|
|
|
if not openProj():
|
|
|
|
return False
|
|
|
|
time.sleep(sleep_time)
|
|
|
|
return True
|
|
|
|
return buildAndRun()
|
2014-03-03 17:47:55 +08:00
|
|
|
#----------------autotest build and run end----------------#
|
|
|
|
|
2014-03-18 14:30:01 +08:00
|
|
|
PATH_ANDROID_SRC = 'tests/cpp-tests/proj.android/'
|
|
|
|
FILE_ANDROID_DELETE = ['libs','gen','assets','bin','obj']
|
2014-03-06 16:52:34 +08:00
|
|
|
#----------------autotest-android build and run----------------#
|
|
|
|
def ANDROID_BUILD():
|
2014-03-18 14:06:33 +08:00
|
|
|
def checkDevice():
|
|
|
|
cmd = 'adb devices'
|
|
|
|
infoDev = os.popen(cmd).readlines()
|
|
|
|
firstDev = infoDev[1]
|
|
|
|
if len(firstDev) < 5 or firstDev.find('device') < 0:
|
|
|
|
print 'no android device.'
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
print 'device info:', firstDev
|
|
|
|
return True
|
2014-03-06 16:52:34 +08:00
|
|
|
def cleanProj():
|
2014-03-18 14:30:01 +08:00
|
|
|
for strFile in FILE_ANDROID_DELETE:
|
|
|
|
infoClean = os.system('rm -rf '+PATH_ANDROID_SRC+strFile)
|
|
|
|
infoClean = os.system('adb uninstall org.cocos2dx.cpp_tests');
|
2014-03-06 16:52:34 +08:00
|
|
|
print 'infoClean: ', infoClean
|
|
|
|
if infoClean != 0:
|
|
|
|
print 'clean **CLEAN FAILED**'
|
|
|
|
time.sleep(sleep_time)
|
|
|
|
def updateProperty():
|
|
|
|
infoUpdate = os.system('android update project -p ./cocos/2d/platform/android/java/ -t 12')
|
|
|
|
print 'cocos update:', infoUpdate
|
2014-03-18 14:30:01 +08:00
|
|
|
infoUpdate = os.system('android update project -p '+PATH_ANDROID_SRC+' -t 12')
|
2014-03-06 16:52:34 +08:00
|
|
|
print 'test update:', infoUpdate
|
|
|
|
def buildProj():
|
2014-03-18 14:30:01 +08:00
|
|
|
infoBuild = os.system('./build/android-build.py -p 13 cpp-tests')
|
|
|
|
print 'infoBuild cpp_tests: ', infoBuild
|
2014-03-18 16:21:41 +08:00
|
|
|
infoBuild = os.system('ant -buildfile '+PATH_ANDROID_SRC+' debug')
|
2014-03-06 16:52:34 +08:00
|
|
|
print 'infoBuild: ', infoBuild
|
|
|
|
if infoBuild != 0:
|
|
|
|
print 'build **BUILD FAILED**'
|
|
|
|
time.sleep(sleep_time)
|
|
|
|
return infoBuild
|
2014-03-18 16:21:41 +08:00
|
|
|
def installProj():
|
|
|
|
cmd = 'adb install '+PATH_ANDROID_SRC+'bin/CppTests-debug.apk'
|
|
|
|
infoInstall = os.system(cmd)
|
|
|
|
print 'infoInstall:', infoInstall
|
|
|
|
if infoInstall != 0:
|
|
|
|
print 'install **INSTALL FAILED**'
|
|
|
|
return infoInstall
|
2014-03-06 16:52:34 +08:00
|
|
|
def openProj():
|
2014-03-18 14:30:01 +08:00
|
|
|
cmd = 'adb shell am start -n org.cocos2dx.cpp_tests/org.cocos2dx.cpp_tests.Cocos2dxActivity'
|
2014-03-06 16:52:34 +08:00
|
|
|
print 'cmd: ', cmd
|
|
|
|
infoOpen = os.system(cmd)
|
|
|
|
print 'infoOpen: ', infoOpen
|
|
|
|
if infoOpen != 0:
|
|
|
|
return False
|
|
|
|
time.sleep(sleep_time)
|
|
|
|
return True
|
|
|
|
def buildAndRun():
|
2014-03-18 14:06:33 +08:00
|
|
|
if not checkDevice():
|
2014-03-18 14:30:01 +08:00
|
|
|
return False
|
2014-03-06 16:52:34 +08:00
|
|
|
cleanProj()
|
|
|
|
updateProperty()
|
2014-03-18 14:06:33 +08:00
|
|
|
buildProj()
|
2014-03-18 16:21:41 +08:00
|
|
|
installProj()
|
2014-03-06 16:52:34 +08:00
|
|
|
return openProj()
|
|
|
|
return buildAndRun()
|
|
|
|
#----------------autotest-android build and run end----------------#
|
|
|
|
|
2014-03-03 17:47:55 +08:00
|
|
|
def main():
|
2014-03-18 14:30:01 +08:00
|
|
|
print 'will build mac project.'
|
|
|
|
suc_build_mac = MAC_BUILD()
|
2014-04-09 16:30:08 +08:00
|
|
|
# print 'will build android project.'
|
|
|
|
# suc_build_android = ANDROID_BUILD()
|
2014-03-06 16:52:34 +08:00
|
|
|
if suc_build_mac:
|
|
|
|
autotest(TYPE_MAC)
|
|
|
|
if suc_build_android:
|
2014-03-18 14:30:01 +08:00
|
|
|
print 'will run android autotest.'
|
2014-03-06 16:52:34 +08:00
|
|
|
autotest(TYPE_ANDROID)
|
2014-03-03 17:47:55 +08:00
|
|
|
|
|
|
|
|
|
|
|
# -------------- main --------------
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys_ret = 0
|
2014-03-18 14:30:01 +08:00
|
|
|
try:
|
2014-03-03 17:47:55 +08:00
|
|
|
sys_ret = main()
|
|
|
|
except:
|
|
|
|
traceback.print_exc()
|
|
|
|
sys_ret = 1
|
|
|
|
finally:
|
|
|
|
sys.exit(sys_ret)
|
|
|
|
|