diff --git a/.coveragerc b/.coveragerc index 5f78864..3f40d7b 100644 --- a/.coveragerc +++ b/.coveragerc @@ -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 diff --git a/.travis.yml b/.travis.yml index 01db5da..6e0223b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/requirements.txt b/requirements.txt index b869bad..ff3b625 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/scripts/diff_trace.py b/scripts/diff_trace.py index 33df530..1b559cc 100755 --- a/scripts/diff_trace.py +++ b/scripts/diff_trace.py @@ -13,6 +13,7 @@ from __future__ import print_function +import sys _py_flags = ['AN', 'AZ', 'AC', 'AV', 'AVS', 'BN', 'BIS', 'BUS', 'BVS', 'BZ'] @@ -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: @@ -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() @@ -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']))) @@ -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. ' + @@ -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])) @@ -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) diff --git a/scripts/get_instructions_used.py b/scripts/get_instructions_used.py index b6aef08..4336b2f 100755 --- a/scripts/get_instructions_used.py +++ b/scripts/get_instructions_used.py @@ -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'} @@ -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() @@ -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) diff --git a/scripts/test/__init__.py b/scripts/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/scripts/test/test_diff_trace.py b/scripts/test/test_diff_trace.py new file mode 100644 index 0000000..2fd218a --- /dev/null +++ b/scripts/test/test_diff_trace.py @@ -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) diff --git a/scripts/test/test_get_instructions_used.py b/scripts/test/test_get_instructions_used.py new file mode 100644 index 0000000..ee37f04 --- /dev/null +++ b/scripts/test/test_get_instructions_used.py @@ -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