2011-08-25 10:05:28 +02:00
|
|
|
import platform;
|
|
|
|
import shutil;
|
|
|
|
import os;
|
|
|
|
import glob;
|
2011-08-31 16:05:15 +02:00
|
|
|
import atexit;
|
2011-09-01 14:09:25 +02:00
|
|
|
import codecs;
|
2011-09-21 17:29:18 +02:00
|
|
|
import subprocess;
|
2012-09-26 09:45:21 +02:00
|
|
|
import sys
|
2011-09-21 17:29:18 +02:00
|
|
|
import errno;
|
|
|
|
from datetime import datetime,timedelta;
|
2011-08-25 10:05:28 +02:00
|
|
|
|
2011-09-23 20:40:57 +02:00
|
|
|
srcPath = ''
|
2011-08-25 10:05:28 +02:00
|
|
|
SettingsPath = ''
|
2011-08-31 16:05:15 +02:00
|
|
|
tmpSettingsDir = ''
|
2011-08-25 10:05:28 +02:00
|
|
|
testSettings.logScreenshotOnFail = True
|
2012-01-10 12:24:06 +01:00
|
|
|
testSettings.logScreenshotOnError = True
|
2012-12-12 13:12:28 +01:00
|
|
|
__origStartApplication__ = None
|
2011-08-25 10:05:28 +02:00
|
|
|
|
2011-11-29 16:00:18 +01:00
|
|
|
source("../../shared/classes.py")
|
2011-08-26 12:39:04 +02:00
|
|
|
source("../../shared/utils.py")
|
2012-10-19 17:36:14 +02:00
|
|
|
source("../../shared/fs_utils.py")
|
2011-08-31 16:05:15 +02:00
|
|
|
source("../../shared/build_utils.py")
|
2011-10-07 15:05:55 +02:00
|
|
|
source("../../shared/project.py")
|
2011-09-21 17:29:18 +02:00
|
|
|
source("../../shared/editor_utils.py")
|
2011-11-09 16:40:35 +01:00
|
|
|
source("../../shared/project_explorer.py")
|
|
|
|
source("../../shared/hook_utils.py")
|
2012-01-31 15:49:59 +01:00
|
|
|
source("../../shared/debugger.py")
|
2012-02-10 16:25:08 +01:00
|
|
|
source("../../shared/workarounds.py")
|
2011-08-25 10:05:28 +02:00
|
|
|
|
2012-12-12 13:12:28 +01:00
|
|
|
# ATTENTION: if a test case calls startApplication("qtcreator...") for several times this
|
|
|
|
# function must be called BEFORE any call except the first (which is done always automatically)
|
|
|
|
def overrideStartApplication():
|
|
|
|
global startApplication, __origStartApplication__
|
|
|
|
if (platform.system() != "Darwin"):
|
|
|
|
return
|
|
|
|
if (__origStartApplication__ == None):
|
|
|
|
__origStartApplication__ = startApplication
|
2012-02-24 15:21:42 +01:00
|
|
|
def startApplication(*args):
|
|
|
|
args = list(args)
|
|
|
|
if str(args[0]).startswith('qtcreator'):
|
|
|
|
args[0] = args[0].replace('qtcreator', '"Qt Creator"', 1)
|
2012-12-12 13:12:28 +01:00
|
|
|
test.log("Using workaround for MacOS (different AUT name)")
|
|
|
|
return __origStartApplication__(*args)
|
2012-02-24 15:21:42 +01:00
|
|
|
|
2013-02-22 14:31:39 +01:00
|
|
|
def startedWithoutPluginError():
|
|
|
|
try:
|
|
|
|
loaderErrorWidgetName = ("{name='ExtensionSystem__Internal__PluginErrorOverview' "
|
|
|
|
"type='ExtensionSystem::PluginErrorOverview' visible='1' "
|
|
|
|
"windowTitle='Qt Creator - Plugin loader messages'}")
|
|
|
|
loaderError = waitForObject(loaderErrorWidgetName, 1000)
|
|
|
|
test.fatal("Could not perform clean start of Qt Creator - Plugin error occurred.",
|
|
|
|
waitForObject("{name='pluginError' type='QTextEdit' visible='1' window=%s}"
|
|
|
|
% loaderErrorWidgetName, 1000).plainText)
|
|
|
|
clickButton("{text~='(Next.*|Continue)' type='QPushButton' visible='1'}")
|
|
|
|
invokeMenuItem("File", "Exit")
|
|
|
|
return False
|
|
|
|
except:
|
|
|
|
return True
|
|
|
|
|
2011-09-21 17:29:18 +02:00
|
|
|
def waitForCleanShutdown(timeOut=10):
|
2011-09-06 09:12:15 +02:00
|
|
|
appCtxt = currentApplicationContext()
|
2011-10-07 15:43:45 +02:00
|
|
|
shutdownDone = (str(appCtxt)=="")
|
2011-09-21 17:29:18 +02:00
|
|
|
if platform.system() in ('Windows','Microsoft'):
|
|
|
|
endtime = datetime.utcnow() + timedelta(seconds=timeOut)
|
|
|
|
while not shutdownDone:
|
|
|
|
# following work-around because os.kill() works for win not until python 2.7
|
2011-10-07 15:43:45 +02:00
|
|
|
if appCtxt.pid==-1:
|
|
|
|
break
|
2011-09-21 17:29:18 +02:00
|
|
|
tasks = subprocess.Popen("tasklist /FI \"PID eq %d\"" % appCtxt.pid, shell=True,stdout=subprocess.PIPE)
|
|
|
|
output = tasks.communicate()[0]
|
|
|
|
tasks.stdout.close()
|
|
|
|
if (output=="INFO: No tasks are running which match the specified criteria."
|
|
|
|
or output=="" or output.find("ERROR")==0):
|
|
|
|
shutdownDone=True
|
|
|
|
if not shutdownDone and datetime.utcnow() > endtime:
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
endtime = datetime.utcnow() + timedelta(seconds=timeOut)
|
|
|
|
while not shutdownDone:
|
|
|
|
try:
|
|
|
|
os.kill(appCtxt.pid,0)
|
|
|
|
except OSError, err:
|
|
|
|
if err.errno == errno.EPERM or err.errno == errno.ESRCH:
|
|
|
|
shutdownDone=True
|
|
|
|
if not shutdownDone and datetime.utcnow() > endtime:
|
|
|
|
break
|
|
|
|
|
2012-11-15 13:33:48 +01:00
|
|
|
def __removeTestingDir__():
|
|
|
|
def __removeIt__(directory):
|
|
|
|
deleteDirIfExists(directory)
|
|
|
|
return not os.path.exists(directory)
|
|
|
|
|
|
|
|
devicesXML = os.path.join(tmpSettingsDir, "QtProject", "qtcreator", "devices.xml")
|
|
|
|
lastMTime = os.path.getmtime(devicesXML)
|
|
|
|
testingDir = os.path.dirname(os.path.dirname(tmpSettingsDir))
|
2011-09-21 17:29:18 +02:00
|
|
|
waitForCleanShutdown()
|
2012-11-15 13:33:48 +01:00
|
|
|
waitFor('os.path.getmtime(devicesXML) > lastMTime', 5000)
|
|
|
|
waitFor('__removeIt__(testingDir)', 2000)
|
2011-08-31 16:05:15 +02:00
|
|
|
|
2012-09-03 15:02:46 +02:00
|
|
|
def substituteTildeWithinToolchains(settingsDir):
|
2012-10-09 12:21:04 +02:00
|
|
|
toolchains = os.path.join(settingsDir, "QtProject", 'qtcreator', 'toolchains.xml')
|
2012-09-03 15:02:46 +02:00
|
|
|
origToolchains = toolchains + "_orig"
|
|
|
|
home = os.path.expanduser("~")
|
|
|
|
os.rename(toolchains, origToolchains)
|
|
|
|
origFile = open(origToolchains, "r")
|
|
|
|
modifiedFile = open(toolchains, "w")
|
|
|
|
for line in origFile:
|
|
|
|
if "~" in line:
|
|
|
|
line = line.replace("~", home)
|
|
|
|
modifiedFile.write(line)
|
|
|
|
origFile.close()
|
|
|
|
modifiedFile.close()
|
|
|
|
os.remove(origToolchains)
|
|
|
|
test.log("Substituted all tildes with '%s' inside toolchains.xml..." % home)
|
|
|
|
|
2012-09-26 09:45:21 +02:00
|
|
|
def __guessABI__(supportedABIs, use64Bit):
|
|
|
|
if use64Bit:
|
|
|
|
searchFor = "64bit"
|
|
|
|
else:
|
|
|
|
searchFor = "32bit"
|
|
|
|
for abi in supportedABIs:
|
|
|
|
if searchFor in abi:
|
|
|
|
return abi
|
|
|
|
if use64Bit:
|
|
|
|
test.log("Supported ABIs do not include an ABI supporting 64bit - trying 32bit now")
|
|
|
|
return __guessABI__(supportedABIs, False)
|
|
|
|
test.fatal('Could not guess ABI!',
|
|
|
|
'Given ABIs: %s' % str(supportedABIs))
|
|
|
|
return ''
|
|
|
|
|
|
|
|
def __is64BitOS__():
|
|
|
|
if platform.system() == 'Darwin':
|
|
|
|
return sys.maxsize > (2 ** 32)
|
|
|
|
if platform.system() in ('Microsoft', 'Windows'):
|
|
|
|
machine = os.getenv("PROCESSOR_ARCHITEW6432", os.getenv("PROCESSOR_ARCHITECTURE"))
|
|
|
|
else:
|
|
|
|
machine = platform.machine()
|
|
|
|
if machine:
|
|
|
|
return '64' in machine
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def substituteUnchosenTargetABIs(settingsDir):
|
|
|
|
class ReadState:
|
|
|
|
NONE = 0
|
|
|
|
READING = 1
|
|
|
|
CLOSED = 2
|
|
|
|
|
|
|
|
on64Bit = __is64BitOS__()
|
2012-10-09 12:21:04 +02:00
|
|
|
toolchains = os.path.join(settingsDir, "QtProject", 'qtcreator', 'toolchains.xml')
|
2012-09-26 09:45:21 +02:00
|
|
|
origToolchains = toolchains + "_orig"
|
|
|
|
os.rename(toolchains, origToolchains)
|
|
|
|
origFile = open(origToolchains, "r")
|
|
|
|
modifiedFile = open(toolchains, "w")
|
|
|
|
supported = []
|
|
|
|
readState = ReadState.NONE
|
|
|
|
for line in origFile:
|
|
|
|
if readState == ReadState.NONE:
|
|
|
|
if "SupportedAbis" in line:
|
|
|
|
supported = []
|
|
|
|
readState = ReadState.READING
|
|
|
|
elif readState == ReadState.READING:
|
|
|
|
if "</valuelist>" in line:
|
|
|
|
readState = ReadState.CLOSED
|
|
|
|
else:
|
|
|
|
supported.append(line.split(">", 1)[1].rsplit("<", 1)[0])
|
|
|
|
elif readState == ReadState.CLOSED:
|
|
|
|
if "SupportedAbis" in line:
|
|
|
|
supported = []
|
|
|
|
readState = ReadState.READING
|
|
|
|
elif "SET_BY_SQUISH" in line:
|
|
|
|
line = line.replace("SET_BY_SQUISH", __guessABI__(supported, on64Bit))
|
|
|
|
modifiedFile.write(line)
|
|
|
|
origFile.close()
|
|
|
|
modifiedFile.close()
|
|
|
|
os.remove(origToolchains)
|
|
|
|
test.log("Substituted unchosen ABIs inside toolchains.xml...")
|
|
|
|
|
2012-12-12 16:06:48 +01:00
|
|
|
def copySettingsToTmpDir():
|
|
|
|
global tmpSettingsDir
|
|
|
|
global SettingsPath
|
|
|
|
tmpSettingsDir = tempDir()
|
|
|
|
tmpSettingsDir = os.path.abspath(tmpSettingsDir + "/settings")
|
|
|
|
shutil.copytree(cwd, tmpSettingsDir)
|
|
|
|
if platform.system() in ('Linux', 'Darwin'):
|
|
|
|
substituteTildeWithinToolchains(tmpSettingsDir)
|
|
|
|
substituteUnchosenTargetABIs(tmpSettingsDir)
|
|
|
|
SettingsPath = ' -settingspath "%s"' % tmpSettingsDir
|
|
|
|
|
2011-08-25 10:05:28 +02:00
|
|
|
if platform.system() in ('Windows', 'Microsoft'):
|
2011-09-26 16:58:39 +02:00
|
|
|
sdkPath = "C:\\QtSDK"
|
2011-08-25 10:05:28 +02:00
|
|
|
cwd = os.getcwd() # current dir is directory holding qtcreator.py
|
2011-09-26 16:58:39 +02:00
|
|
|
cwd+="\\..\\..\\settings\\windows"
|
2011-09-28 13:06:52 +02:00
|
|
|
defaultQtVersion = "Qt 4.7.4 for Desktop - MinGW 4.4 (Qt SDK)"
|
2011-08-25 10:05:28 +02:00
|
|
|
else:
|
2011-09-23 20:40:57 +02:00
|
|
|
sdkPath = os.path.expanduser("~/QtSDK")
|
2011-08-25 10:05:28 +02:00
|
|
|
cwd = os.getcwd() # current dir is directory holding qtcreator.py
|
|
|
|
cwd+="/../../settings/unix"
|
2011-09-28 13:06:52 +02:00
|
|
|
defaultQtVersion = "Desktop Qt 4.7.4 for GCC (Qt SDK)"
|
2011-12-15 13:41:25 +01:00
|
|
|
srcPath = os.getenv("SYSTEST_SRCPATH", sdkPath + "/src")
|
2011-08-31 16:05:15 +02:00
|
|
|
|
2012-12-12 13:12:28 +01:00
|
|
|
overrideStartApplication()
|
|
|
|
|
2011-08-31 16:05:15 +02:00
|
|
|
# the following only doesn't work if the test ends in an exception
|
2012-01-09 15:33:14 +01:00
|
|
|
if os.getenv("SYSTEST_NOSETTINGSPATH") != "1":
|
|
|
|
cwd = os.path.abspath(cwd)
|
2012-12-12 16:06:48 +01:00
|
|
|
copySettingsToTmpDir()
|
2012-11-15 13:33:48 +01:00
|
|
|
atexit.register(__removeTestingDir__)
|