Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor refactorings #33

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
[run]
omit = revelation/test/*
data_file = ./.coverage
source = ./revelation/
source =
revelation/*.py
omit =
revelation/test/*
scripts/*
scripts/test/*
data_file =
./.coverage


[report]
show_missing = 1

# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma
Expand Down
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ install:
- cd $TRAVIS_BUILD_DIR
- export PYTHONPATH=${PYTHONPATH}:${HOME}/pydgin/
script:
- py.test -n 4 -rxs --color=yes --cov-config .coveragerc --cov-report term-missing
--cov=revelation revelation/test/
- python -m doctest scripts/diff_trace.py
- python -m doctest scripts/get_instructions_used.py
- py.test -n 4 -rxs --color=yes --cov-config .coveragerc --cov=revelation revelation/test/ scripts/test/
- cd docs
- make html
- make linkcheck
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
coverage==4.0.3
coverage==4.2
coveralls==1.1
py==1.4.31
pytest==2.9.2
pytest-capturelog==0.7
pytest-cov==2.2.1
pytest-cov==2.2.0
pytest-xdist==1.14
requests==2.9.1
Sphinx==1.4.5
Expand Down
43 changes: 5 additions & 38 deletions scripts/diff_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from __future__ import print_function

import sys

_py_flags = ['AN', 'AZ', 'AC', 'AV', 'AVS', 'BN', 'BIS', 'BUS', 'BVS', 'BZ']

Expand All @@ -24,20 +25,10 @@
def parse_pydgin_inst(line):
"""Parse a single line of a Pydgin trace.
Keep the original line for debugging purposes.

>>> i0 = parse_pydgin_inst(' 0 00002ce8 bcond32 0 AN=False')
>>> ex0 = {'AN': False, 'line': ' 0 00002ce8 bcond32 0 AN=False', 'pc': 0}
>>> i0 == ex0
True

>>> i1 = parse_pydgin_inst(' b0 020040fc ldstrpmd32 13 :: RD.RF[0 ] = 000002f8 :: :: WR.MEM[000002f8] = 00000000 :: WR.RF[0 ] = 00000300')
>>> ex1 = {'line': ' b0 020040fc ldstrpmd32 13 :: RD.RF[0 ] = 000002f8 :: :: WR.MEM[000002f8] = 00000000 :: WR.RF[0 ] = 00000300', 'mem': [(760, 0)], 'pc': 176, 'reg': [768]}
>>> i1 == ex1
True
"""
inst = dict()
if (line.startswith('NOTE:') or line.startswith('sparse') or
line.startswith('DONE!') or line.startswith('Instructions')):
line.startswith('DONE!') or line.startswith('Instructions')):
return None
tokens = line.split()
if not tokens:
Expand Down Expand Up @@ -85,16 +76,6 @@ def parse_pydgin_inst(line):
def parse_esim_inst(line):
"""Parse a single line of an e-sim trace.
Keep the original line for debugging purposes.

>>> i0 = parse_esim_inst('0x000000 b.l 0x0000000000000058 - pc <- 0x58 - nbit <- 0x0')
>>> ex0 = {'AN': False, 'line': '0x000000 b.l 0x0000000000000058 - pc <- 0x58 - nbit <- 0x0', 'pc': 0}
>>> i0 == ex0
True

>>> i1 = parse_esim_inst('0x0000b0 --- _epiphany_star strd r2,[r0],+0x1 - memaddr <- 0x2f8, memory <- 0x0, memaddr <- 0x2fc, memory <- 0x0, registers <- 0x300')
>>> ex1 = {'line': '0x0000b0 --- _epiphany_star strd r2,[r0],+0x1 - memaddr <- 0x2f8, memory <- 0x0, memaddr <- 0x2fc, memory <- 0x0, registers <- 0x300', 'mem': [(760, 0), (764, 0)], 'pc': 176, 'reg': [768]}
>>> i1 == ex1
True
"""
inst = dict()
tokens = line.split()
Expand Down Expand Up @@ -160,7 +141,7 @@ def diff_files(trace0, trace1):
if len(py_trace) == 0:
print('Revelation trace is empty')
return
for num, (py_inst, e_inst) in enumerate(zip(py_trace, e_trace)):
for _, (py_inst, e_inst) in enumerate(zip(py_trace, e_trace)):
diff = compare_instructions(py_inst, e_inst)
if diff is not None:
print('Semantics of instruction at {0} differ:'.format(hex(e_inst['pc'])))
Expand All @@ -179,19 +160,6 @@ def compare_instructions(py_inst, e_inst):
at each block of 4 bytes. For example, where the Pydgin trace would say:
"WR.MEM[000002f8] = 00000000", the e-sim would write out:
"memaddr <- 0x2f8, memory <- 0x0, memaddr <- 0x2fc, memory <- 0x0,"

>>> e_inst0 = {'pc': 0, 'line': '0x000000 b.l 0x0000000000000058 - pc <- 0x58 - nbit <- 0x0', 'AN': False}
>>> e_inst1 = {'mem': [(760, 0), (764, 0)], 'pc': 176, 'line': '0x0000b0 --- _epiphany_star strd r2,[r0],+0x1 - memaddr <- 0x2f8, memory <- 0x0, memaddr <- 0x2fc, memory <- 0x0, registers <- 0x300', 'reg': [768]}
>>> py_inst0 = {'pc': 0, 'line': ' 0 00002ce8 bcond32 0 AN=False', 'AN': False}
>>> py_inst1 = {'mem': [(760, 0), (764, 0)], 'pc': 176, 'line': ' b0 020040fc ldstrpmd32 13 :: RD.RF[0 ] = 000002f8 :: :: WR.MEM[000002f8] = 00000000 :: WR.RF[0 ] = 00000300', 'reg': [768]}
>>> compare_instructions(py_inst0, e_inst0) is None
True
>>> compare_instructions(py_inst1, e_inst1) is None
True
>>> compare_instructions(py_inst0, e_inst1)
'Program counters differ. Revelation: 0x0, e-sim: 0xb0'
>>> compare_instructions(py_inst1, e_inst0)
'Program counters differ. Revelation: 0xb0, e-sim: 0x0'
"""
if py_inst['pc'] != e_inst['pc']:
return ('Program counters differ. ' +
Expand Down Expand Up @@ -225,8 +193,8 @@ def compare_instructions(py_inst, e_inst):
for flag in _py_flags:
# e-sim only prints flags if they have been updated.
if (flag in py_inst and
flag in e_inst and
not (py_inst[flag] == e_inst[flag])):
flag in e_inst and
not (py_inst[flag] == e_inst[flag])):
return ('Flags differ. Revelation: {0}<-{1} ' +
'e-sim: {2}<-{3}').format(flag, str(py_inst[flag]),
flag, str(e_inst[flag]))
Expand All @@ -241,7 +209,6 @@ def print_usage():


if __name__ == '__main__':
import sys
if sys.argv[1] == '-h' or sys.argv[1] == '--help':
print_usage()
sys.exit(0)
Expand Down
14 changes: 3 additions & 11 deletions scripts/get_instructions_used.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
Then call this script (order of the CLI arguments matters):
$ python get_instructions_used.py e_trace.out py_trace.out
"""

from __future__ import print_function

import sys

_e_flags = {'nbit':'AN', 'zbit':'AZ', 'cbit':'AC', 'vbit':'AV',
'vsbit':'AVS', 'bnbit':'BN', 'bisbit':'BIS', 'busbit':'BUS',
'bvsbit':'BVS', 'bzbit':'BZ'}
Expand All @@ -17,16 +20,6 @@
def parse_esim_inst(line):
"""Parse a single line of an e-sim trace.
Keep the original line for debugging purposes.

>>> i0 = parse_esim_inst('0x000000 b.l 0x0000000000000058 - pc <- 0x58 - nbit <- 0x0')
>>> ex0 = {'pc': 0, 'AN': False, 'instruction': 'b.l', 'line': '0x000000 b.l 0x0000000000000058 - pc <- 0x58 - nbit <- 0x0'}
>>> i0 == ex0
True

>>> i1 = parse_esim_inst('0x0000b0 --- _epiphany_star strd r2,[r0],+0x1 - memaddr <- 0x2f8, memory <- 0x0, memaddr <- 0x2fc, memory <- 0x0, registers <- 0x300')
>>> ex1 = {'instruction': 'strd', 'line': '0x0000b0 --- _epiphany_star strd r2,[r0],+0x1 - memaddr <- 0x2f8, memory <- 0x0, memaddr <- 0x2fc, memory <- 0x0, registers <- 0x300', 'mem': [(760, 0), (764, 0)], 'pc': 176, 'reg': [768]}
>>> i1 == ex1
True
"""
inst = dict()
tokens = line.split()
Expand Down Expand Up @@ -96,7 +89,6 @@ def print_usage():


if __name__ == '__main__':
import sys
if sys.argv[1] == '-h' or sys.argv[1] == '--help':
print_usage()
sys.exit(0)
Expand Down
Empty file added scripts/test/__init__.py
Empty file.
56 changes: 56 additions & 0 deletions scripts/test/test_diff_trace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from diff_trace import parse_pydgin_inst, parse_esim_inst, compare_instructions


def test_parse_pydgin_inst():
got0 = parse_pydgin_inst(' 0 00002ce8 bcond32 0 AN=False')
expected0 = { 'AN':False, 'pc':0,
'line':' 0 00002ce8 bcond32 0 AN=False' }
assert expected0 == got0

got1 = parse_pydgin_inst(' b0 020040fc ldstrpmd32 13 ::'
' RD.RF[0 ] = 000002f8 :: :: WR.MEM[000002f8] = '
'00000000 :: WR.RF[0 ] = 00000300')
expected1 = { 'mem':[(760, 0)], 'pc':176, 'reg':[768],
'line':(' b0 020040fc ldstrpmd32 13 :: '
'RD.RF[0 ] = 000002f8 :: :: WR.MEM[000002f8] = '
'00000000 :: WR.RF[0 ] = 00000300') }
assert expected1 == got1


def test_parse_esim_inst():
out0 = parse_esim_inst('0x000000 b.l '
'0x0000000000000058 - pc <- 0x58 - nbit <- 0x0')
expected0 = { 'pc':0, 'AN':False,
'line':('0x000000 b.l '
'0x0000000000000058 - pc <- 0x58 - nbit <- 0x0') }
assert expected0 == out0
out1 = parse_esim_inst('0x0000b0 --- _epiphany_star strd r2,[r0],+0x1 -'
' memaddr <- 0x2f8, memory <- 0x0, memaddr <- 0x2fc,'
' memory <- 0x0, registers <- 0x300')
expected1 = { 'mem':[(760, 0), (764, 0)], 'pc':176, 'reg':[768],
'line':'0x0000b0 --- _epiphany_star strd r2,[r0],+0x1 -'
' memaddr <- 0x2f8, memory <- 0x0, memaddr <- 0x2fc,'
' memory <- 0x0, registers <- 0x300' }
assert expected1 == out1


def test_compare_instructions():
e_inst0 = { 'pc':0, 'AN':False,
'line': '0x000000 b.l 0x0000000000000058'
' - pc <- 0x58 - nbit <- 0x0' }
e_inst1 = { 'mem':[(760, 0), (764, 0)], 'pc':176, 'reg': [768],
'line': '0x0000b0 --- _epiphany_star strd r2,[r0],+0x1 -'
' memaddr <- 0x2f8, memory <- 0x0, memaddr <- 0x2fc, '
'memory <- 0x0, registers <- 0x300' }
py_inst0 = { 'pc': 0, 'AN': False,
'line': ' 0 00002ce8 bcond32 0 AN=False' }
py_inst1 = { 'mem': [(760, 0), (764, 0)], 'pc': 176, 'reg': [768],
'line': ' b0 020040fc ldstrpmd32 13 :: RD.RF[0 ]'
' = 000002f8 :: :: WR.MEM[000002f8] = 00000000 :: WR.RF[0 ] ='
' 00000300' }
assert compare_instructions(py_inst0, e_inst0) is None
assert compare_instructions(py_inst0, e_inst1)
expected0 = 'Program counters differ. Revelation: 0x0, e-sim: 0xb0'
expected1 = 'Program counters differ. Revelation: 0xb0, e-sim: 0x0'
assert expected0 == compare_instructions(py_inst0, e_inst1)
assert expected1 == compare_instructions(py_inst1, e_inst0)
18 changes: 18 additions & 0 deletions scripts/test/test_get_instructions_used.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from get_instructions_used import parse_esim_inst

def test_parse_esim_inst():
got0 = parse_esim_inst('0x000000 b.l '
'0x0000000000000058 - pc <- 0x58 - nbit <- 0x0')
expected0 = { 'pc':0, 'AN':False, 'instruction':'b.l',
'line': '0x000000 b.l '
'0x0000000000000058 - pc <- 0x58 - nbit <- 0x0' }
assert expected0 == got0
got1 = parse_esim_inst('0x0000b0 --- _epiphany_star strd r2,[r0],+0x1'
' - memaddr <- 0x2f8, memory <- 0x0, memaddr <- '
'0x2fc, memory <- 0x0, registers <- 0x300')
expected1 = { 'instruction':'strd', 'mem':[(760, 0), (764, 0)], 'pc':176,
'reg':[768],
'line':'0x0000b0 --- _epiphany_star strd r2,[r0],+0x1 - '
'memaddr <- 0x2f8, memory <- 0x0, memaddr <- 0x2fc, memory '
'<- 0x0, registers <- 0x300' }
assert expected1 == got1