OLD | NEW |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 '''Generator script for PerformanceTests/Pywebsocket/. Run | 5 '''Generator script for PerformanceTests/Pywebsocket/. Run |
6 $ python resources/generate.py | 6 $ python resources/generate.py |
7 at PerformanceTests/Pywebsocket/, and commit the generated files.''' | 7 at PerformanceTests/Pywebsocket/, and commit the generated files.''' |
8 | 8 |
9 import sys | 9 import sys |
10 import os | 10 import os |
11 | 11 |
12 | 12 |
13 def generate(connection_type, | 13 def generate(connection_type, |
14 benchmark_name, | 14 benchmark_name, |
15 data_type, | 15 data_type, |
16 is_worker, | 16 is_worker, |
17 is_async, | 17 is_async, |
18 does_verify): | 18 does_verify): |
19 pywebsocket_server = 'http://localhost:8001' | |
20 | |
21 test_file_name = ('%s-%s%s-%s-%s-%s.html' % | 19 test_file_name = ('%s-%s%s-%s-%s-%s.html' % |
22 (connection_type, | 20 (connection_type, |
23 benchmark_name, | 21 benchmark_name, |
24 '' if data_type == '' else '-' + data_type, | 22 '' if data_type == '' else '-' + data_type, |
25 'worker' if is_worker else 'window', | 23 'worker' if is_worker else 'window', |
26 'async' if is_async else 'sync', | 24 'async' if is_async else 'sync', |
27 'verify' if does_verify else 'noverify')) | 25 'verify' if does_verify else 'noverify')) |
28 | 26 |
29 test_file_content_template = '''<!DOCTYPE html> | 27 test_file_content_template = '''<!DOCTYPE html> |
30 <head> | 28 <head> |
31 <script src="../resources/runner.js"></script> | 29 <script src="../resources/runner.js"></script> |
32 <script src="{pywebsocket_server_root}/util.js"></script> | |
33 <script src="resources/util_performance_test.js"></script> | 30 <script src="resources/util_performance_test.js"></script> |
34 <script src="{pywebsocket_server_root}/{script_name}"></script> | |
35 </head> | 31 </head> |
36 <body onload="startPerformanceTest( | 32 <body onload="startPerformanceTest( |
37 '{connection_type}', | 33 '{connection_type}', |
38 '{benchmark_name}Benchmark', | 34 '{benchmark_name}Benchmark', |
39 '{data_type}', | 35 '{data_type}', |
40 {is_worker}, | 36 {is_worker}, |
41 {is_async}, | 37 {is_async}, |
42 {does_verify})"> | 38 {does_verify})"> |
43 </body> | 39 </body> |
44 </html> | 40 </html> |
45 ''' | 41 ''' |
46 | 42 |
47 if connection_type == 'WebSocket': | 43 if connection_type == 'WebSocket': |
48 script_name = 'benchmark.js' | 44 script_name = 'benchmark.js' |
49 elif connection_type == 'XHR': | 45 elif connection_type == 'XHR': |
50 script_name = 'xhr_benchmark.js' | 46 script_name = 'xhr_benchmark.js' |
51 else: | 47 else: |
52 script_name = 'fetch_benchmark.js' | 48 script_name = 'fetch_benchmark.js' |
53 | 49 |
54 test_file_content = test_file_content_template.format( | 50 test_file_content = test_file_content_template.format( |
55 pywebsocket_server_root=pywebsocket_server, | |
56 script_name=script_name, | 51 script_name=script_name, |
57 connection_type=connection_type, | 52 connection_type=connection_type, |
58 benchmark_name=benchmark_name, | 53 benchmark_name=benchmark_name, |
59 data_type=data_type, | 54 data_type=data_type, |
60 is_worker='true' if is_worker else 'false', | 55 is_worker='true' if is_worker else 'false', |
61 is_async='true' if is_async else 'false', | 56 is_async='true' if is_async else 'false', |
62 does_verify='true' if does_verify else 'false') | 57 does_verify='true' if does_verify else 'false') |
63 | 58 |
64 with open(test_file_name, 'w') as f: | 59 with open(test_file_name, 'w') as f: |
65 f.write(test_file_content) | 60 f.write(test_file_content) |
(...skipping 17 matching lines...) Expand all Loading... |
83 if benchmark_name == 'receive' and not is_worker: | 78 if benchmark_name == 'receive' and not is_worker: |
84 # Disable XHR-receive-*-window-sync tests. | 79 # Disable XHR-receive-*-window-sync tests. |
85 continue | 80 continue |
86 | 81 |
87 for data_type in ['arraybuffer', 'blob', 'text']: | 82 for data_type in ['arraybuffer', 'blob', 'text']: |
88 generate('XHR', benchmark_name, data_type, | 83 generate('XHR', benchmark_name, data_type, |
89 is_worker, is_async=False, does_verify=True) | 84 is_worker, is_async=False, does_verify=True) |
90 | 85 |
91 if __name__ == "__main__": | 86 if __name__ == "__main__": |
92 sys.exit(main()) | 87 sys.exit(main()) |
OLD | NEW |