1# -*- coding: utf-8 -*- 2 3import os 4import sys 5import shutil 6import random 7import subprocess 8 9def die (msg): 10 print msg 11 exit(-1) 12 13def shellquote(s): 14 return '"%s"' % s.replace('\\', '\\\\').replace('"', '\"').replace('$', '\$').replace('`', '\`') 15 16def execute (args, workDir = None): 17 curPath = os.getcwd() 18 if workDir != None: 19 os.chdir(workDir) 20 retcode = subprocess.call(args) 21 os.chdir(curPath) 22 if retcode != 0: 23 raise Exception("Failed to execute %s, got %d" % (str(args), retcode)) 24 25class Config: 26 def __init__ (self, name, srcPath, buildPath, genParams, buildParams, testBinaryName, executor = 'executor', execserver = 'execserver', junitTool = 'testlog-to-junit'): 27 self.name = name 28 self.srcPath = srcPath 29 self.buildPath = buildPath 30 self.genParams = genParams 31 self.buildParams = buildParams 32 self.testBinaryName = testBinaryName 33 self.executor = executor 34 self.execserver = execserver 35 self.junitTool = junitTool 36 37def initBuildDir (config): 38 if os.path.exists(config.buildPath): 39 shutil.rmtree(config.buildPath) 40 41 os.makedirs(config.buildPath) 42 execute(["cmake", os.path.realpath(config.srcPath)] + config.genParams, workDir = config.buildPath) 43 44def prepareBuildDir (config): 45 # If build dir exists, try to refresh 46 if os.path.exists(config.buildPath): 47 try: 48 execute(["cmake", "."], workDir = config.buildPath) 49 except: 50 print "WARNING: Failed to refresh build dir, recreating" 51 initBuildDir(config) 52 else: 53 initBuildDir(config) 54 55def build (config): 56 prepareBuildDir(config) 57 execute(["cmake", "--build", "."] + config.buildParams, workDir = config.buildPath) 58 59def runInternalTests (config): 60 batchResultFile = config.name + ".qpa" 61 infoLogFile = config.name + ".txt" 62 junitFile = config.name + ".xml" 63 64 testWorkDir = os.path.join(config.buildPath, "modules", "internal") 65 junitToolPath = os.path.join(config.buildPath, 'executor', config.junitTool) 66 67 # Remove old files 68 for file in [batchResultFile, junitFile]: 69 if os.path.exists(file): 70 os.remove(file) 71 72 build(config) 73 74 # Dump case list 75 execute([config.testBinaryName, "--deqp-runmode=xml-caselist"], workDir = testWorkDir) 76 77 # Run test binary using executor 78 args = [ 79 os.path.join(config.buildPath, 'executor', config.executor), 80 '--port=%d' % random.randint(50000, 60000), 81 '--start-server=%s' % os.path.join(config.buildPath, 'execserver', config.execserver), 82 '--binaryname=%s' % config.testBinaryName, 83 '--cmdline=--deqp-crashhandler=enable --deqp-watchdog=enable', 84 '--workdir=%s' % testWorkDir, 85 '--caselistdir=%s' % os.path.join(testWorkDir), 86 '--testset=dE-IT.*', 87 '--out=%s' % batchResultFile, 88 '--info=%s' % infoLogFile 89 ] 90 execute(args) 91 92 # Convert log to junit format 93 execute([junitToolPath, batchResultFile, junitFile]) 94 95SRC_PATH = os.path.normpath(os.path.join(os.path.dirname(__file__), "..")) 96BASE_BUILD_PATH = os.path.normpath(os.path.join(SRC_PATH, "..", "de-internal-tests")) 97 98CONFIGS = [ 99 Config( 100 "win32-vs10-debug", 101 SRC_PATH, 102 os.path.join(BASE_BUILD_PATH, "win32-vs10-debug"), 103 ['-GVisual Studio 10', '-DDEQP_TARGET=no_modules'], 104 ['--config', 'Debug', '--', '/m'], 105 'Debug\\de-internal-tests.exe', 106 'Debug\\executor.exe', 107 'Debug\\execserver.exe', 108 'Debug\\testlog-to-junit.exe' 109 ), 110 Config( 111 "win32-vs10-release", 112 SRC_PATH, 113 os.path.join(BASE_BUILD_PATH, "win32-vs10-release"), 114 ['-GVisual Studio 10', '-DDEQP_TARGET=no_modules'], 115 ['--config', 'Release', '--', '/m'], 116 'Release\\de-internal-tests.exe', 117 'Release\\executor.exe', 118 'Release\\execserver.exe', 119 'Release\\testlog-to-junit.exe' 120 ), 121 Config( 122 "win64-vs10-debug", 123 SRC_PATH, 124 os.path.join(BASE_BUILD_PATH, "win64-vs10-debug"), 125 ['-GVisual Studio 10 Win64', '-DDEQP_TARGET=no_modules'], 126 ['--config', 'Debug', '--', '/m'], 127 'Debug\\de-internal-tests.exe', 128 'Debug\\executor.exe', 129 'Debug\\execserver.exe', 130 'Debug\\testlog-to-junit.exe' 131 ), 132 Config( 133 "win64-vs10-release", 134 SRC_PATH, 135 os.path.join(BASE_BUILD_PATH, "win64-vs10-release"), 136 ['-GVisual Studio 10 Win64', '-DDEQP_TARGET=no_modules'], 137 ['--config', 'Release', '--', '/m'], 138 'Release\\de-internal-tests.exe', 139 'Release\\executor.exe', 140 'Release\\execserver.exe', 141 'Release\\testlog-to-junit.exe' 142 ), 143 144 # GCC configs 145 Config( 146 "linux32-gcc-debug", 147 SRC_PATH, 148 os.path.join(BASE_BUILD_PATH, "linux32-gcc-debug"), 149 ['-DDEQP_TARGET=no_modules', '-DCMAKE_BUILD_TYPE=Debug', '-DCMAKE_C_FLAGS=-m32', '-DCMAKE_CXX_FLAGS=-m32', '-DCMAKE_LIBRARY_PATH=/usr/lib32;usr/lib/i386-linux-gnu'], 150 ['--', '-j', '2'], 151 './de-internal-tests' 152 ), 153 Config( 154 "linux32-gcc-release", 155 SRC_PATH, 156 os.path.join(BASE_BUILD_PATH, "linux32-gcc-release"), 157 ['-DDEQP_TARGET=no_modules', '-DCMAKE_BUILD_TYPE=Release', '-DCMAKE_C_FLAGS=-m32', '-DCMAKE_CXX_FLAGS=-m32', '-DCMAKE_LIBRARY_PATH=/usr/lib32;usr/lib/i386-linux-gnu'], 158 ['--', '-j', '2'], 159 './de-internal-tests' 160 ), 161 Config( 162 "linux64-gcc-debug", 163 SRC_PATH, 164 os.path.join(BASE_BUILD_PATH, "linux64-gcc-debug"), 165 ['-DDEQP_TARGET=no_modules', '-DCMAKE_BUILD_TYPE=Debug', '-DCMAKE_C_FLAGS=-m64', '-DCMAKE_CXX_FLAGS=-m64'], 166 ['--', '-j', '2'], 167 './de-internal-tests' 168 ), 169 Config( 170 "linux64-gcc-release", 171 SRC_PATH, 172 os.path.join(BASE_BUILD_PATH, "linux64-gcc-release"), 173 ['-DDEQP_TARGET=no_modules', '-DCMAKE_BUILD_TYPE=Release', '-DCMAKE_C_FLAGS=-m64', '-DCMAKE_CXX_FLAGS=-m64'], 174 ['--', '-j', '2'], 175 './de-internal-tests' 176 ), 177 178 # Clang configs 179 Config( 180 "linux32-clang-debug", 181 SRC_PATH, 182 os.path.join(BASE_BUILD_PATH, "linux32-clang-debug"), 183 ['-DDEQP_TARGET=no_modules', '-DCMAKE_BUILD_TYPE=Debug', '-DCMAKE_C_FLAGS=-m32', '-DCMAKE_CXX_FLAGS=-m32', '-DCMAKE_LIBRARY_PATH=/usr/lib32;usr/lib/i386-linux-gnu', '-DCMAKE_C_COMPILER=clang', '-DCMAKE_CXX_COMPILER=clang++', '-DDE_COMPILER=DE_COMPILER_CLANG'], 184 ['--', '-j', '2'], 185 './de-internal-tests' 186 ), 187 Config( 188 "linux32-clang-release", 189 SRC_PATH, 190 os.path.join(BASE_BUILD_PATH, "linux32-clang-release"), 191 ['-DDEQP_TARGET=no_modules', '-DCMAKE_BUILD_TYPE=Release', '-DCMAKE_C_FLAGS=-m32', '-DCMAKE_CXX_FLAGS=-m32', '-DCMAKE_LIBRARY_PATH=/usr/lib32;usr/lib/i386-linux-gnu', '-DCMAKE_C_COMPILER=clang', '-DCMAKE_CXX_COMPILER=clang++', '-DDE_COMPILER=DE_COMPILER_CLANG'], 192 ['--', '-j', '2'], 193 './de-internal-tests' 194 ), 195 Config( 196 "linux64-clang-debug", 197 SRC_PATH, 198 os.path.join(BASE_BUILD_PATH, "linux64-clang-debug"), 199 ['-DDEQP_TARGET=no_modules', '-DCMAKE_BUILD_TYPE=Debug', '-DCMAKE_C_FLAGS=-m64', '-DCMAKE_CXX_FLAGS=-m64', '-DCMAKE_C_COMPILER=clang', '-DCMAKE_CXX_COMPILER=clang++', '-DDE_COMPILER=DE_COMPILER_CLANG'], 200 ['--', '-j', '2'], 201 './de-internal-tests' 202 ), 203 Config( 204 "linux64-clang-release", 205 SRC_PATH, 206 os.path.join(BASE_BUILD_PATH, "linux64-clang-release"), 207 ['-DDEQP_TARGET=no_modules', '-DCMAKE_BUILD_TYPE=Release', '-DCMAKE_C_FLAGS=-m64', '-DCMAKE_CXX_FLAGS=-m64', '-DCMAKE_C_COMPILER=clang', '-DCMAKE_CXX_COMPILER=clang++', '-DDE_COMPILER=DE_COMPILER_CLANG'], 208 ['--', '-j', '2'], 209 './de-internal-tests' 210 ) 211] 212 213def findConfig (name): 214 for config in CONFIGS: 215 if config.name == name: 216 return config 217 return None 218 219if __name__ == "__main__": 220 if len(sys.argv) != 2: 221 die("%s: [config]" % sys.argv[0]) 222 223 config = findConfig(sys.argv[1]) 224 if config == None: 225 die("Config '%s' not found" % sys.argv[1]) 226 227 random.seed() 228 runInternalTests(config) 229