Skip to content

Instantly share code, notes, and snippets.

@Hexcles
Last active November 14, 2017 21:18
Show Gist options
  • Save Hexcles/e258a7275b9283d971c4bd1661780c57 to your computer and use it in GitHub Desktop.
Save Hexcles/e258a7275b9283d971c4bd1661780c57 to your computer and use it in GitHub Desktop.
Simple LayoutTests global baseline optimization
from __future__ import print_function
from collections import defaultdict
import hashlib
import re
def main():
baselines = defaultdict(dict)
f = open('baselines', 'r')
regexp_head = re.compile(r'^\./(platform/[^/]+/)')
regexp_tail = re.compile(r'-expected\.(png|txt|wav)$')
for line in f.readlines():
filename = line.strip()
testname = regexp_head.sub('', filename)
testname = regexp_tail.sub('.html', testname)
sha1sum = hashlib.sha1(open(filename, 'rb').read()).digest()
if sha1sum not in baselines[testname]:
baselines[testname][sha1sum] = [filename]
else:
baselines[testname][sha1sum].append(filename)
for testname in baselines:
found_dupe = False
for sha1sum in baselines[testname]:
if len(baselines[testname][sha1sum]) == 1:
continue
found_dupe = True
break
if found_dupe:
print(testname)
if __name__ == '__main__':
main()
#!/bin/bash
# Must run from third_party/WebKit/LayoutTests
find . -name "*-expected.txt" -or -name "*-expected.png" -or -name "*-expected.wav" > baselines
python2 find_dupes.py > dupes
cat dupes | xargs ../Tools/Scripts/webkit-patch optimize-baselines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment