Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(384)

Side by Side Diff: tools/perf/page_sets/update_webrtc_cases.py

Issue 2761163003: Use local pages for webrtc telemetry tests. (Closed)
Patch Set: Add script to download pages. (Benchmarks not tested yet) Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2017 The Chromium Authors. All rights reserved.
nednguyen 2017/03/24 20:12:37 Our convention is script has no .py tail. Also ple
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import os
6 import shutil
7 import subprocess
8 import sys
9 import tempfile
10 import urllib2
11
12
13 TEST_PAGES_LOCATION_BY_REPO = {
14 'test-pages': [
15 'src/canvas-capture',
16 'src/multiple-peerconnections',
17 ],
18 'samples': [
19 'src/content/datachannel/datatransfer',
20 'src/content/getusermedia/resolution',
21 'src/content/peerconnection/constraints',
22 'src/content/peerconnection/audio',
23 ],
24 }
25
26 ADDED_SCRIPT_TAGS = (
27 '<script src="%s.js"></script>\n'
28 '<script src="adapter.js"></script>\n'
29 '<script>function trace(arg) { console.log(arg); }</script>\n'
30 )
31
32 COPYRIGHT_NOTICE = [
33 'Copyright 2017 The Chromium Authors. All rights reserved.\n',
34 'Use of this source code is governed by a BSD-style license that can be\n',
35 'found in the LICENSE file.\n',
36 ]
37
38 JS_COPYRIGHT_NOTICE = ' * '.join(['/*\n'] + COPYRIGHT_NOTICE) + ' */\n'
39 HTML_COPYRIGHT_NOTICE = ' * '.join(['<!--\n'] + COPYRIGHT_NOTICE) + '-->\n'
40
41 STRIPPED_TAGS = ['<meta', '<link', '<script']
kjellander_chromium 2017/03/24 19:51:25 Do we really want to remove all <script> tags? It
ehmaldonado_chromium 2017/03/24 20:13:53 I tried to preserve the directory structure, but i
kjellander_chromium 2017/03/24 20:18:30 OK, if there's a limitation in how the files are s
42
43 WEBRTC_GITHUB_URL = 'https://github.com/webrtc/'
44 ADAPTER_LATEST_URL = 'https://webrtc.github.io/adapter/adapter-latest.js'
45
46
47 class TemporaryDirectory(object):
48 def __init__(self):
49 self._closed = False
50 self._name = None
51 self._name = tempfile.mkdtemp()
52 def __enter__(self):
53 return self._name
54 def __exit__(self, exc, value, tb):
55 if self._name and not self._closed:
56 shutil.rmtree(self._name)
57 self._closed = True
58
59
60 def CopyJSFile(origin, destination):
61 contents = []
62 with open(origin) as input_file:
63 contents = input_file.readlines()
64
65 contents = [JS_COPYRIGHT_NOTICE] + contents[8:]
kjellander_chromium 2017/03/24 19:51:25 I guess 8 comes from the WebRTC license header whi
ehmaldonado_chromium 2017/03/24 20:13:53 I could also try to delete the first (multiline) c
kjellander_chromium 2017/03/24 20:18:30 I think it should be, but no big deal since this i
66
67 with open(destination, 'w') as output_file:
68 output_file.writelines(contents)
69
70
71 def CopyHTMLFile(test_name, origin, destination):
72 contents = []
73 with open(origin) as input_file:
74 for line in input_file:
75 if any(tag in line for tag in STRIPPED_TAGS):
kjellander_chromium 2017/03/24 19:51:25 This seems to assume each of the stripped tags are
ehmaldonado_chromium 2017/03/24 20:13:53 Will do.
76 continue
77 if line.strip().startswith('</body>'):
78 contents.append(ADDED_SCRIPT_TAGS % test_name)
79 contents.append(line)
80
81 contents = contents[:1] + [HTML_COPYRIGHT_NOTICE] + contents[8:]
82
83 with open(destination, 'w') as output_file:
84 output_file.writelines(contents)
85
86
87 def main():
88 output_dir = sys.argv[1]
89
90 if not os.path.isdir(output_dir):
91 os.makedirs(output_dir)
92
93 with TemporaryDirectory() as temp_dir:
94 for repo_name, test_dirs in TEST_PAGES_LOCATION_BY_REPO.items():
95 p = subprocess.Popen(['git', 'clone', WEBRTC_GITHUB_URL + repo_name],
96 cwd=temp_dir)
97 p.wait()
kjellander_chromium 2017/03/24 19:51:25 How is the case when git clone fails handled? Does
ehmaldonado_chromium 2017/03/24 20:13:53 Yes. Git's output is printed to console.
kjellander_chromium 2017/03/24 20:18:30 That's fine then, since this will be run interacti
98
99 for test_dir in test_dirs:
100 test_dir = os.path.join(temp_dir, repo_name, test_dir)
101 test_name = os.path.basename(test_dir)
102
103 CopyJSFile(os.path.join(test_dir, 'js', 'main.js'),
104 os.path.join(output_dir, test_name + '.js'))
105 CopyHTMLFile(test_name, os.path.join(test_dir, 'index.html'),
106 os.path.join(output_dir, test_name + '.html'))
107
108 response = urllib2.urlopen(ADAPTER_LATEST_URL)
109 adapter_js_contents = JS_COPYRIGHT_NOTICE + response.read()
110
111 with open(os.path.join(output_dir, 'adapter.js'), 'w') as output_file:
112 output_file.write(adapter_js_contents)
113
kjellander_chromium 2017/03/24 19:51:25 +1 blank line
ehmaldonado_chromium 2017/03/24 20:13:53 Will do.
114 if __name__ == '__main__':
115 main()
OLDNEW
« no previous file with comments | « tools/perf/page_sets/data/webrtc_stresstest_cases_001.wpr.sha1 ('k') | tools/perf/page_sets/webrtc_cases.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698