Advertisement
Guest User

Untitled

a guest
May 26th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.45 KB | None | 0 0
  1. import argparse
  2. import os
  3. import subprocess
  4. import sys
  5.  
  6. PYTHON_CMD = 'python'
  7.  
  8. BROWSER_TEST_CMD = os.path.join('testing', 'scripts',
  9. 'run_gpu_integration_test_as_googletest.py')
  10. GPU_TEST_CMD = os.path.join('content', 'test', 'gpu',
  11. 'run_gpu_integration_test.py')
  12. ANGLE_TEST_CMD = 'angle_end2end_tests'
  13.  
  14. WEBGL_TEST_OPT = 'webgl_conformance'
  15. TRACE_TEST_OPT = 'trace_test'
  16. INFO_TEST_OPT = 'info_collection'
  17.  
  18. WEBGL2_CONFORMANCE_VERSION = '2.0.1'
  19. WEBGL2_ABBREVIATED_RESULT = os.path.join('content', 'test', 'data', 'gpu',
  20. 'webgl2_conformance_tests_output.json')
  21.  
  22. TRYBOT_SHARDS = {
  23. 'webgl' : 2,
  24. 'webgl2' : 20,
  25. 'angle' : 4,
  26. 'info' : 1,
  27. 'trace' : 1
  28. }
  29.  
  30. RESERVED_OPTIONS = [
  31. '-v', '--verbose',
  32. '--show-stdout', '--passthrough',
  33. '--browser', '--browser-executable=',
  34. '--chrome-root', '--chromium-output-directory', '--top-level-dirs',
  35. '--extra-browser-args', '--enable-logging', '--js-flags',
  36. '--use-angle', '--use-gl', '--use-cmd-decoder',
  37. '--write-full-results-to', '--isolated-script-test-output',
  38. '--webgl-conformance-version', '--read-abbreviated-json-results-from',
  39. '--expected-vendor-id', '--expected-device-id',
  40. '--total-shards', '--shard-index',
  41. '--test-launcher-total-shards', '--test-launcher-shard-index',
  42. '--test-filter', '--gtest_filter',
  43. '--test-launcher-retry-limit',
  44. '--use-gpu-in-tests'
  45. ]
  46.  
  47. def execute_cmd(cmd, log=None):
  48. proc = subprocess.Popen(cmd,
  49. stdout=subprocess.PIPE if log else None, stderr=subprocess.STDOUT,
  50. shell=sys.platform.startswith('win'))
  51.  
  52. if log:
  53. with open(log, 'w') as log_file:
  54. for line in iter(proc.stdout.readline, b''):
  55. line = line.strip()
  56. print(line)
  57. log_file.write(line + '\n')
  58.  
  59. return proc.wait()
  60.  
  61. def execute_shard(cmd, args):
  62. shard_postfix = ''
  63. if args.shard > 1:
  64. shard_postfix = '.shard' + format(args.index, '02d')
  65.  
  66. result_name, result_ext = os.path.splitext(args.result)
  67. log_name, log_ext = os.path.splitext(args.log)
  68.  
  69. for n in range(1, args.repeat+1):
  70. postfix = shard_postfix
  71. if args.repeat > 1:
  72. postfix += '.' + format(n, '03d')
  73.  
  74. new_cmd = cmd[:]
  75. if not args.type == 'angle':
  76. new_cmd.append('--isolated-script-test-output='
  77. + result_name + postfix + result_ext)
  78.  
  79. print('\n' + ' '.join(new_cmd) + '\n')
  80. if args.print_only:
  81. return
  82.  
  83. log = log_name + postfix + log_ext
  84. execute_cmd(new_cmd, log)
  85.  
  86. def update_global_arguments(args):
  87. global BROWSER_TEST_CMD
  88. global GPU_TEST_CMD
  89. global ANGLE_TEST_CMD
  90. global WEBGL2_ABBREVIATED_RESULT
  91.  
  92. if args.build == 'default':
  93. ANGLE_TEST_CMD = os.path.join('out', 'Default', ANGLE_TEST_CMD)
  94. elif args.build == 'release':
  95. ANGLE_TEST_CMD = os.path.join('out', 'Release', ANGLE_TEST_CMD)
  96. elif args.build == 'debug':
  97. ANGLE_TEST_CMD = os.path.join('out', 'Debug', ANGLE_TEST_CMD)
  98.  
  99. if args.dir:
  100. BROWSER_TEST_CMD = os.path.join(args.dir, BROWSER_TEST_CMD)
  101. GPU_TEST_CMD = os.path.join(args.dir, GPU_TEST_CMD)
  102. ANGLE_TEST_CMD = os.path.join(args.dir, ANGLE_TEST_CMD)
  103. WEBGL2_ABBREVIATED_RESULT = os.path.join(args.dir, WEBGL2_ABBREVIATED_RESULT)
  104.  
  105. def generate_webgl_arguments(args):
  106. # Common arguments
  107. common_args = ['--show-stdout', '--browser=' + args.build,
  108. '--passthrough', '-v']
  109. if args.dir :
  110. common_args.append('--chrome-root=' + args.dir)
  111.  
  112. # Browser arguments
  113. # TODO: check --enable-logging=stderr
  114. browser_args = ['--js-flags=--expose-gc', '--enable-logging=stderr']
  115. if args.backend == 'd3d9v':
  116. browser_args.extend(['--use-angle=d3d9', '--use-gl=angle',
  117. '--use-cmd-decoder=validating'])
  118. elif args.backend == 'd3d11v':
  119. browser_args.extend(['--use-angle=d3d11',
  120. '--use-cmd-decoder=validating'])
  121. elif args.backend == 'd3d9':
  122. browser_args.extend(['--use-angle=d3d9',
  123. '--use-cmd-decoder=passthrough'])
  124. elif args.backend == 'd3d11':
  125. browser_args.extend(['--use-angle=d3d11',
  126. '--use-cmd-decoder=passthrough'])
  127. elif args.backend == 'gl':
  128. browser_args.extend(['--use-angle=gl', '--use-gl=angle',
  129. '--use-cmd-decoder=passthrough'])
  130. elif args.backend == 'vulkan':
  131. browser_args.extend(['--use-angle=vulkan',
  132. '--use-cmd-decoder=passthrough'])
  133.  
  134. # WebGL arguments
  135. webgl_args = []
  136. if args.type == 'webgl2':
  137. webgl_args.append('--webgl-conformance-version='
  138. + WEBGL2_CONFORMANCE_VERSION)
  139. webgl_args.append('--read-abbreviated-json-results-from='
  140. + WEBGL2_ABBREVIATED_RESULT)
  141. elif args.type == 'info':
  142. webgl_args.extend(['--expected-vendor-id', '8086'])
  143. webgl_args.extend(['--expected-device-id', '5912'])
  144.  
  145. total_args = []
  146. total_args.extend(common_args)
  147. total_args.append('--extra-browser-args=' + ' '.join(browser_args))
  148. total_args.extend(webgl_args)
  149.  
  150. if args.filter:
  151. filter = args.filter
  152. if (not filter.startswith('*') and not filter.startswith('deqp')
  153. and not filter.startswith('conformance')):
  154. filter = '*' + filter
  155. if not filter.endswith('*') and not filter.endswith('html'):
  156. filter = filter + '*'
  157. total_args.append('--test-filter=' + filter)
  158.  
  159. return total_args
  160.  
  161. def generate_angle_arguments(args):
  162. total_args = ['--use-gpu-in-tests', '--test-launcher-retry-limit=0']
  163. if args.filter:
  164. total_args.append('--gtest_filter=' + args.filter)
  165. return total_args
  166.  
  167. def main():
  168. parser = argparse.ArgumentParser(
  169. description='Run WebGL and ANGLE tests',
  170. formatter_class=argparse.RawTextHelpFormatter)
  171. parser.add_argument('type',
  172. choices=['webgl', 'webgl2', 'angle', 'trace', 'info'],
  173. help='Specify the test you want to run.\n\n'\
  174. 'webgl webgl conformance tests\n'\
  175. 'webgl2 webgl2 conformance tests\n'\
  176. 'angle angle end2end tests\n'\
  177. 'trace trace tests\n'\
  178. 'info info collection tests')
  179. parser.add_argument('--backend', '-e',
  180. choices=['d3d9v', 'd3d11v', 'd3d9', 'd3d11', 'gl', 'vulkan'], default='',
  181. help='Specify the backend. Only available for webgl/webgl2.\n'\
  182. 'Default is empty, will run default conformance tests.\n\n'\
  183. 'd3d9v d3d9 validating\n'\
  184. 'd3d11v d3d11 validating\n'\
  185. 'd3d9 d3d9 passthrough\n'\
  186. 'd3d11 d3d11 passthrough\n'\
  187. 'gl gl passthrough\n'\
  188. 'vulkan vulkan passthrough\n\n')
  189. parser.add_argument('--dir', '-d', default='',
  190. help='Chromium source directory.\n'\
  191. 'Default is current directory.\n\n')
  192. parser.add_argument('--build', '-b',
  193. choices=['release', 'debug', 'default'], default='release',
  194. help='Browser type to run. Default is release.\n'\
  195. 'release/debug/default assume that chrome executables are\n'\
  196. 'generated into out/Release or out/Debug or out/Default.\n\n')
  197. parser.add_argument('--repeat', '-r', default='1', type=int,
  198. help='The number of times to repeat running this test.\n'\
  199. 'If the number of shards is more than 1, the running sequence will\n'\
  200. 'be shard0 * N times, shard1 * N times ...\n\n')
  201. parser.add_argument('--shard', '-s', default='1', type=int,
  202. help='Total number of shards being used for this test.\n'\
  203. 'Default is 1.\n\n')
  204. parser.add_argument('--index', '-i', default='-1', type=int,
  205. help='Shard index of this test.\n'\
  206. 'If the number of shards is more than 1 and this argument is not\n'\
  207. 'specified, all shards will be ran in sequence.\n\n')
  208. parser.add_argument('--trybot', '-t', action='store_true',
  209. help='Use the same number of shards as official try bot.\n\n')
  210. parser.add_argument('--log', '-g', default='',
  211. help='Saves the test log to that path.\n'\
  212. 'Default is [webgl2|d3d9|...]_test.log.\n\n')
  213. parser.add_argument('--result', '-w', default='',
  214. help='Writes the trybot style test results to a JSON file.\n'\
  215. 'Default is [webgl2|d3d9|...]_test_result.json.\n\n')
  216. parser.add_argument('--filter', '-f', default='',
  217. help='Keyword to match the test cases.\n'\
  218. 'Devide with |.\n\n')
  219. parser.add_argument('--print-only', '-p', action='store_true',
  220. help='Print the command only without executing it.\n\n')
  221. # parser.add_argument('--actual-result', '-a', default='',
  222. # help='Writes the actual results and expected results to a JSON file.\n'\
  223. # 'Default is [webgl2|d3d9|...]_test__result_actual.json.\n\n')
  224. args, extra_args = parser.parse_known_args()
  225.  
  226. # Check arguments
  227. if args.trybot:
  228. if args.shard > 1 or args.index > -1:
  229. sys.exit('Cannot specify shard and index when trybot is enabled')
  230. args.shard = TRYBOT_SHARDS[args.type]
  231.  
  232. if args.shard < 1:
  233. sys.exit('Invalid shard number')
  234. elif args.index >= args.shard:
  235. sys.exit('Invalid index number')
  236.  
  237. if args.repeat < 1:
  238. sys.exit('Invalid repeat number')
  239.  
  240. if args.backend:
  241. if not args.type == 'webgl' and not args.type == 'webgl2':
  242. sys.exit('Backend is only available for webgl/webgl2')
  243.  
  244. for arg in extra_args:
  245. for option in RESERVED_OPTIONS:
  246. if arg.startswith(option):
  247. sys.exit('This option has been reserved for internal usage: ' + arg)
  248.  
  249. # Update arguments
  250. update_global_arguments(args)
  251.  
  252. if not args.log:
  253. prefix = args.type
  254. if args.backend:
  255. prefix = prefix + '_' + args.backend
  256. args.log = prefix + '_test.log'
  257.  
  258. if not args.result:
  259. prefix = args.type
  260. if args.backend:
  261. prefix = prefix + '_' + args.backend
  262. args.result = prefix + '_test_result.json'
  263.  
  264. # Generate command
  265. cmd = []
  266. shard_arg = ''
  267. index_arg = ''
  268.  
  269. if args.type == 'angle':
  270. cmd.append(ANGLE_TEST_CMD)
  271. cmd.extend(generate_angle_arguments(args))
  272.  
  273. shard_arg = '--test-launcher-total-shards='
  274. index_arg = '--test-launcher-shard-index='
  275. else:
  276. cmd.append(PYTHON_CMD)
  277. cmd.append(BROWSER_TEST_CMD)
  278. cmd.append(GPU_TEST_CMD)
  279. if args.type == 'trace':
  280. cmd.append(TRACE_TEST_OPT)
  281. elif args.type == 'info':
  282. cmd.append(INFO_TEST_OPT)
  283. else:
  284. cmd.append(WEBGL_TEST_OPT)
  285. cmd.extend(generate_webgl_arguments(args))
  286.  
  287. shard_arg = '--total-shards='
  288. index_arg = '--shard-index='
  289.  
  290. cmd.extend(extra_args)
  291.  
  292. # Execute command
  293. if args.shard == 1:
  294. execute_shard(cmd, args)
  295. else:
  296. cmd.append(shard_arg + str(args.shard))
  297.  
  298. if args.index >= 0:
  299. cmd.append(index_arg + str(args.index))
  300. execute_shard(cmd, args)
  301. else:
  302. for i in range(0, args.shard):
  303. shard_cmd = cmd[:]
  304. shard_cmd.append(index_arg + str(i))
  305. args.index = i
  306. execute_shard(shard_cmd, args)
  307.  
  308. return 0
  309.  
  310. if __name__ == '__main__':
  311. sys.exit(main())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement