Verify book downloads with a SHA256 checksum

This commit is contained in:
AndyGrant committed 2018-06-23 16:14:40 -04:00
1 parent 605ab18b8a
commit e93b65fd25
5 files changed
+72 -28

No files matched your search

+25 -14
View File
@@ -1,4 +1,4 @@
import ast, argparse, time, sys, platform, multiprocessing import ast, argparse, time, sys, platform, multiprocessing, hashlib
import shutil, subprocess, requests, zipfile, os, math, json import shutil, subprocess, requests, zipfile, os, math, json
# Run from any location ... # Run from any location ...
@@ -49,6 +49,7 @@ def getNameAsExe(program):
def getFile(source, outname): def getFile(source, outname):
# Read a file from the given source and save it locally # Read a file from the given source and save it locally
print('Downloading : {0}'.format(source))
request = requests.get(url=source, stream=True) request = requests.get(url=source, stream=True)
with open(outname, 'wb') as fout: with open(outname, 'wb') as fout:
for chunk in request.iter_content(chunk_size=1024): for chunk in request.iter_content(chunk_size=1024):
@@ -83,10 +84,11 @@ def getEngine(data):
if os.path.isfile('Engines/' + exe): if os.path.isfile('Engines/' + exe):
return return
# Log the fact that we are downloading a new engine # Log the fact that we are setting up a new engine
print('\nEngine :', data['name']) print('\nSETTING UP ENGINE')
print( 'Commit :', data['sha']) print('Engine :', data['name'])
print( 'Source :', source) print('Commit :', data['sha'])
print('Source :', source)
# Extract and delete the zip file # Extract and delete the zip file
getFile(source, name + '.zip') getFile(source, name + '.zip')
@@ -208,7 +210,7 @@ def getCutechessCommand(data, scalefactor):
bookflags = ( bookflags = (
'-openings' '-openings'
' file=' + data['test']['bookname'] + ' file=' + data['test']['book']['name'] +
' format=pgn' ' format=pgn'
' order=random' ' order=random'
' plies=16' ' plies=16'
@@ -259,7 +261,7 @@ def getBenchSignature(engine):
# Log and return computed bench and speed # Log and return computed bench and speed
print ('Bench for {0} is {1}'.format(engine['name'], bench[0])) print ('Bench for {0} is {1}'.format(engine['name'], bench[0]))
print ('NPS for {0} is {1}\n'.format(engine['name'], int(avg))) print ('NPS for {0} is {1}'.format(engine['name'], int(avg)))
return (bench[0], avg) return (bench[0], avg)
def reportWrongBench(data, engine): def reportWrongBench(data, engine):
@@ -304,12 +306,8 @@ def reportResults(data, wins, losses, draws, crashes, timeloss):
def completeWorkload(data): def completeWorkload(data):
# Download engines and opening book # Download and verify bench of dev engine
getEngine(data['test']['dev']) getEngine(data['test']['dev'])
getEngine(data['test']['base'])
getFile(data['test']['booksource'], data['test']['bookname'])
# Verify the bench of the dev engine
devbench, devnps = getBenchSignature(data['test']['dev']) devbench, devnps = getBenchSignature(data['test']['dev'])
if devbench != int(data['test']['dev']['bench']): if devbench != int(data['test']['dev']['bench']):
print ('<ERROR> Invalid Bench. Got {0} Expected {1}'.format( print ('<ERROR> Invalid Bench. Got {0} Expected {1}'.format(
@@ -317,7 +315,8 @@ def completeWorkload(data):
reportWrongBench(data, data['test']['dev']) reportWrongBench(data, data['test']['dev'])
return return
# Verify the bench of the base engine # Download and verify bench of base engine
getEngine(data['test']['base'])
basebench, basenps = getBenchSignature(data['test']['base']) basebench, basenps = getBenchSignature(data['test']['base'])
if basebench != int(data['test']['base']['bench']): if basebench != int(data['test']['base']['bench']):
print ('<ERROR> Invalid Bench. Got {0} Expected {1}'.format( print ('<ERROR> Invalid Bench. Got {0} Expected {1}'.format(
@@ -325,11 +324,23 @@ def completeWorkload(data):
reportWrongBench(data, data['test']['base']) reportWrongBench(data, data['test']['base'])
return return
# Download and verify sha of the opening book
print('\nVERIFYING OPENING BOOK')
if not os.path.isfile(data['test']['book']['name']):
getFile(data['test']['book']['source'], data['test']['book']['name'])
with open(data['test']['book']['name']) as fin:
digest = hashlib.sha256(fin.read().encode('utf-8')).hexdigest()
print ('Correct SHA : {0}'.format(digest.upper()))
print ('MY Book SHA : {0}'.format(data['test']['book']['sha'].upper()))
if (digest != data['test']['book']['sha']):
print ('<ERROR> Invalid SHA for {0}'.format(data['test']['book']['name']))
sys.exit()
# Compute and report CPU scaling factor # Compute and report CPU scaling factor
avgnps = (devnps + basenps) / 2.0 avgnps = (devnps + basenps) / 2.0
reportNPS(data, avgnps) reportNPS(data, avgnps)
scalefactor = 2650000 / avgnps scalefactor = 2650000 / avgnps
print ('FACTOR : {0}'.format(round(1 / scalefactor, 2))) print ('\nFACTOR : {0}'.format(round(1 / scalefactor, 2)))
# Compute and report cutechess-cli string # Compute and report cutechess-cli string
command = getCutechessCommand(data, scalefactor) command = getCutechessCommand(data, scalefactor)
+40 -9
View File
@@ -1,24 +1,55 @@
FRAMEWORK_REPO_URL = 'http://github.com/AndyGrant/OpenBench/' FRAMEWORK_REPO_URL = 'http://github.com/AndyGrant/OpenBench/'
FRAMEWORK_DEFAULTS = { FRAMEWORK_DEFAULTS = {
'config' : { 'config' : {
# Framework source, must be changed for your instance
'framework' : 'http://github.com/AndyGrant/OpenBench/',
# Links for side bar
'source' : 'http://github.com/AndyGrant/EtherealDev/', 'source' : 'http://github.com/AndyGrant/EtherealDev/',
'homepage' : 'http://github.com/AndyGrant/Ethereal', 'homepage' : 'http://github.com/AndyGrant/Ethereal',
'framework' : 'http://github.com/AndyGrant/OpenBench/',
'engine' : 'Ethereal', # Configured engines for the framework. To scale NPS for your engine,
'timecontrol' : '5.0+0.05', # in order to match the time controls used here, do the following.
# Average a few bench runs for the latest version of Ethereal. Now
# take a few bench runs for the latest version of the new engine.
# Scale your NPS to match Ethereal's NPS of 2,500,000
'engines' : {
'Ethereal' : {'nps' : 2500000},
},
# Default engine test options
'protocol' : 'uci',
'threads' : 1,
'hash' : 8, 'hash' : 8,
'threads' : 1, 'threads' : 1,
'protocol' : 'uci', 'timecontrol' : '5.0+0.05',
# SPRT bounds and confidence values
'elolower' : 0.0, 'elolower' : 0.0,
'eloupper' : 5.0, 'eloupper' : 5.0,
'alpha' : 0.10, 'alpha' : 0.10,
'beta' : 0.10, 'beta' : 0.10,
'threads' : 1,
'books' : [ # Book confgiruation. When addding a book, follow the provided template.
'2moves_v1.pgn', # The SHA is defined by hashlib.sha256(book).hexdigest(). OpenBench.py
'8moves_v3.pgn', # (Client File) has an example to show you how to find a hash digest
], 'books' : {
'2moves_v1.pgn' : {
'name' : '2moves_v1.pgn',
'sha' : '46aed7f2696618b2b914942032957b7a97a8f343bf54ba83e20a47818f0d42e0',
'source' : FRAMEWORK_REPO_URL + 'raw/master/Books/2moves_v1.pgn',
'default' : True,
},
'8moves_v3.pgn' : {
'name' : '8moves_v3.pgn',
'sha' : '04fcce1488a94f3b7795cef6f74d89016eb278328897c1018e6162c5967273f5',
'source' : FRAMEWORK_REPO_URL + 'raw/master/Books/8moves_v3.pgn',
'default' : False,
}
},
} }
} }
+1 -2
View File
@@ -204,8 +204,7 @@ def workloadDictionary(machine, result, test):
'result' : { 'id' : result.id, }, 'result' : { 'id' : result.id, },
'test' : { 'test' : {
'id' : test.id, 'id' : test.id,
'bookname' : test.bookname, 'book' : FRAMEWORK_DEFAULTS['config']['books'][test.bookname],
'booksource' : FRAMEWORK_REPO_URL + 'raw/master/Books/' + test.bookname,
'timecontrol' : test.timecontrol, 'timecontrol' : test.timecontrol,
'dev' : { 'dev' : {
'id' : test.dev.id, 'id' : test.dev.id,
-1
View File
@@ -35,7 +35,6 @@
</ul> </ul>
<ul> <ul>
<li class="header">LINKS</li> <li class="header">LINKS</li>
<li><a href="{{config.homepage}}">{{config.engine}}</a></li>
<li><a href="{{config.framework}}">OpenBench </a></li> <li><a href="{{config.framework}}">OpenBench </a></li>
</ul> </ul>
{% endblock %} {% endblock %}
+6 -2
View File
@@ -33,8 +33,12 @@
</br> </br>
<label> Opening Book </label> <label> Opening Book </label>
<select name="bookname"> <select name="bookname">
{% for book in config.books %} {% for name, data in config.books.items %}
<option value="{{book}}">{{book}}</option> {% if data.default %}
<option selected value="{{name}}">{{data.name}}</option>
{% else %}
<option value="{{name}}">{{data.name}}</option>
{% endif %}
{% endfor %} {% endfor %}
</select> </select>
</br> </br>