Skip to content

Commit 43b3b81

Browse files
author
Sarah Mount
committed
Factor out script tests.
1 parent 1a15752 commit 43b3b81

File tree

7 files changed

+94
-56
lines changed

7 files changed

+94
-56
lines changed

.coveragerc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
[run]
2-
omit = revelation/test/*
3-
data_file = ./.coverage
4-
source = ./revelation/
2+
source =
3+
revelation/*.py
4+
omit =
5+
revelation/test/*
6+
scripts/*
7+
scripts/test/*
8+
data_file =
9+
./.coverage
10+
511

612
[report]
13+
show_missing = 1
14+
715
# Regexes for lines to exclude from consideration
816
exclude_lines =
917
# Have to re-enable the standard pragma

.travis.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ install:
1717
- cd $TRAVIS_BUILD_DIR
1818
- export PYTHONPATH=${PYTHONPATH}:${HOME}/pydgin/
1919
script:
20-
- py.test -n 4 -rxs --color=yes --cov-config .coveragerc --cov-report term-missing
21-
--cov=revelation revelation/test/
22-
- python -m doctest scripts/diff_trace.py
23-
- python -m doctest scripts/get_instructions_used.py
20+
- py.test -n 4 -rxs --color=yes --cov-config .coveragerc --cov=revelation revelation/test/ scripts/test/
2421
- mkdir bin
2522
- test "$TRANSLATE" == "true" && PYTHONPATH=${HOME}/pydgin/:${HOME}/pypy:. ${HOME}/pypy/rpython/bin/rpython
2623
--no-pdb --opt=jit revelation/sim.py || true

scripts/diff_trace.py

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
from __future__ import print_function
1515

16+
import sys
1617

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

@@ -24,20 +25,10 @@
2425
def parse_pydgin_inst(line):
2526
"""Parse a single line of a Pydgin trace.
2627
Keep the original line for debugging purposes.
27-
28-
>>> i0 = parse_pydgin_inst(' 0 00002ce8 bcond32 0 AN=False')
29-
>>> ex0 = {'AN': False, 'line': ' 0 00002ce8 bcond32 0 AN=False', 'pc': 0}
30-
>>> i0 == ex0
31-
True
32-
33-
>>> i1 = parse_pydgin_inst(' b0 020040fc ldstrpmd32 13 :: RD.RF[0 ] = 000002f8 :: :: WR.MEM[000002f8] = 00000000 :: WR.RF[0 ] = 00000300')
34-
>>> 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]}
35-
>>> i1 == ex1
36-
True
3728
"""
3829
inst = dict()
3930
if (line.startswith('NOTE:') or line.startswith('sparse') or
40-
line.startswith('DONE!') or line.startswith('Instructions')):
31+
line.startswith('DONE!') or line.startswith('Instructions')):
4132
return None
4233
tokens = line.split()
4334
if not tokens:
@@ -85,16 +76,6 @@ def parse_pydgin_inst(line):
8576
def parse_esim_inst(line):
8677
"""Parse a single line of an e-sim trace.
8778
Keep the original line for debugging purposes.
88-
89-
>>> i0 = parse_esim_inst('0x000000 b.l 0x0000000000000058 - pc <- 0x58 - nbit <- 0x0')
90-
>>> ex0 = {'AN': False, 'line': '0x000000 b.l 0x0000000000000058 - pc <- 0x58 - nbit <- 0x0', 'pc': 0}
91-
>>> i0 == ex0
92-
True
93-
94-
>>> i1 = parse_esim_inst('0x0000b0 --- _epiphany_star strd r2,[r0],+0x1 - memaddr <- 0x2f8, memory <- 0x0, memaddr <- 0x2fc, memory <- 0x0, registers <- 0x300')
95-
>>> 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]}
96-
>>> i1 == ex1
97-
True
9879
"""
9980
inst = dict()
10081
tokens = line.split()
@@ -160,7 +141,7 @@ def diff_files(trace0, trace1):
160141
if len(py_trace) == 0:
161142
print('Revelation trace is empty')
162143
return
163-
for num, (py_inst, e_inst) in enumerate(zip(py_trace, e_trace)):
144+
for _, (py_inst, e_inst) in enumerate(zip(py_trace, e_trace)):
164145
diff = compare_instructions(py_inst, e_inst)
165146
if diff is not None:
166147
print('Semantics of instruction at {0} differ:'.format(hex(e_inst['pc'])))
@@ -179,19 +160,6 @@ def compare_instructions(py_inst, e_inst):
179160
at each block of 4 bytes. For example, where the Pydgin trace would say:
180161
"WR.MEM[000002f8] = 00000000", the e-sim would write out:
181162
"memaddr <- 0x2f8, memory <- 0x0, memaddr <- 0x2fc, memory <- 0x0,"
182-
183-
>>> e_inst0 = {'pc': 0, 'line': '0x000000 b.l 0x0000000000000058 - pc <- 0x58 - nbit <- 0x0', 'AN': False}
184-
>>> 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]}
185-
>>> py_inst0 = {'pc': 0, 'line': ' 0 00002ce8 bcond32 0 AN=False', 'AN': False}
186-
>>> 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]}
187-
>>> compare_instructions(py_inst0, e_inst0) is None
188-
True
189-
>>> compare_instructions(py_inst1, e_inst1) is None
190-
True
191-
>>> compare_instructions(py_inst0, e_inst1)
192-
'Program counters differ. Revelation: 0x0, e-sim: 0xb0'
193-
>>> compare_instructions(py_inst1, e_inst0)
194-
'Program counters differ. Revelation: 0xb0, e-sim: 0x0'
195163
"""
196164
if py_inst['pc'] != e_inst['pc']:
197165
return ('Program counters differ. ' +
@@ -225,8 +193,8 @@ def compare_instructions(py_inst, e_inst):
225193
for flag in _py_flags:
226194
# e-sim only prints flags if they have been updated.
227195
if (flag in py_inst and
228-
flag in e_inst and
229-
not (py_inst[flag] == e_inst[flag])):
196+
flag in e_inst and
197+
not (py_inst[flag] == e_inst[flag])):
230198
return ('Flags differ. Revelation: {0}<-{1} ' +
231199
'e-sim: {2}<-{3}').format(flag, str(py_inst[flag]),
232200
flag, str(e_inst[flag]))
@@ -241,7 +209,6 @@ def print_usage():
241209

242210

243211
if __name__ == '__main__':
244-
import sys
245212
if sys.argv[1] == '-h' or sys.argv[1] == '--help':
246213
print_usage()
247214
sys.exit(0)

scripts/get_instructions_used.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
Then call this script (order of the CLI arguments matters):
88
$ python get_instructions_used.py e_trace.out py_trace.out
99
"""
10+
1011
from __future__ import print_function
1112

13+
import sys
14+
1215
_e_flags = {'nbit':'AN', 'zbit':'AZ', 'cbit':'AC', 'vbit':'AV',
1316
'vsbit':'AVS', 'bnbit':'BN', 'bisbit':'BIS', 'busbit':'BUS',
1417
'bvsbit':'BVS', 'bzbit':'BZ'}
@@ -17,16 +20,6 @@
1720
def parse_esim_inst(line):
1821
"""Parse a single line of an e-sim trace.
1922
Keep the original line for debugging purposes.
20-
21-
>>> i0 = parse_esim_inst('0x000000 b.l 0x0000000000000058 - pc <- 0x58 - nbit <- 0x0')
22-
>>> ex0 = {'pc': 0, 'AN': False, 'instruction': 'b.l', 'line': '0x000000 b.l 0x0000000000000058 - pc <- 0x58 - nbit <- 0x0'}
23-
>>> i0 == ex0
24-
True
25-
26-
>>> i1 = parse_esim_inst('0x0000b0 --- _epiphany_star strd r2,[r0],+0x1 - memaddr <- 0x2f8, memory <- 0x0, memaddr <- 0x2fc, memory <- 0x0, registers <- 0x300')
27-
>>> 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]}
28-
>>> i1 == ex1
29-
True
3023
"""
3124
inst = dict()
3225
tokens = line.split()
@@ -96,7 +89,6 @@ def print_usage():
9689

9790

9891
if __name__ == '__main__':
99-
import sys
10092
if sys.argv[1] == '-h' or sys.argv[1] == '--help':
10193
print_usage()
10294
sys.exit(0)

scripts/test/__init__.py

Whitespace-only changes.

scripts/test/test_diff_trace.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from diff_trace import parse_pydgin_inst, parse_esim_inst, compare_instructions
2+
3+
4+
def test_parse_pydgin_inst():
5+
got0 = parse_pydgin_inst(' 0 00002ce8 bcond32 0 AN=False')
6+
expected0 = { 'AN':False, 'pc':0,
7+
'line':' 0 00002ce8 bcond32 0 AN=False' }
8+
assert expected0 == got0
9+
10+
got1 = parse_pydgin_inst(' b0 020040fc ldstrpmd32 13 ::'
11+
' RD.RF[0 ] = 000002f8 :: :: WR.MEM[000002f8] = '
12+
'00000000 :: WR.RF[0 ] = 00000300')
13+
expected1 = { 'mem':[(760, 0)], 'pc':176, 'reg':[768],
14+
'line':(' b0 020040fc ldstrpmd32 13 :: '
15+
'RD.RF[0 ] = 000002f8 :: :: WR.MEM[000002f8] = '
16+
'00000000 :: WR.RF[0 ] = 00000300') }
17+
assert expected1 == got1
18+
19+
20+
def test_parse_esim_inst():
21+
out0 = parse_esim_inst('0x000000 b.l '
22+
'0x0000000000000058 - pc <- 0x58 - nbit <- 0x0')
23+
expected0 = { 'pc':0, 'AN':False,
24+
'line':('0x000000 b.l '
25+
'0x0000000000000058 - pc <- 0x58 - nbit <- 0x0') }
26+
assert expected0 == out0
27+
out1 = parse_esim_inst('0x0000b0 --- _epiphany_star strd r2,[r0],+0x1 -'
28+
' memaddr <- 0x2f8, memory <- 0x0, memaddr <- 0x2fc,'
29+
' memory <- 0x0, registers <- 0x300')
30+
expected1 = { 'mem':[(760, 0), (764, 0)], 'pc':176, 'reg':[768],
31+
'line':'0x0000b0 --- _epiphany_star strd r2,[r0],+0x1 -'
32+
' memaddr <- 0x2f8, memory <- 0x0, memaddr <- 0x2fc,'
33+
' memory <- 0x0, registers <- 0x300' }
34+
assert expected1 == out1
35+
36+
37+
def test_compare_instructions():
38+
e_inst0 = { 'pc':0, 'AN':False,
39+
'line': '0x000000 b.l 0x0000000000000058'
40+
' - pc <- 0x58 - nbit <- 0x0' }
41+
e_inst1 = { 'mem':[(760, 0), (764, 0)], 'pc':176, 'reg': [768],
42+
'line': '0x0000b0 --- _epiphany_star strd r2,[r0],+0x1 -'
43+
' memaddr <- 0x2f8, memory <- 0x0, memaddr <- 0x2fc, '
44+
'memory <- 0x0, registers <- 0x300' }
45+
py_inst0 = { 'pc': 0, 'AN': False,
46+
'line': ' 0 00002ce8 bcond32 0 AN=False' }
47+
py_inst1 = { 'mem': [(760, 0), (764, 0)], 'pc': 176, 'reg': [768],
48+
'line': ' b0 020040fc ldstrpmd32 13 :: RD.RF[0 ]'
49+
' = 000002f8 :: :: WR.MEM[000002f8] = 00000000 :: WR.RF[0 ] ='
50+
' 00000300' }
51+
assert compare_instructions(py_inst0, e_inst0) is None
52+
assert compare_instructions(py_inst0, e_inst1)
53+
expected0 = 'Program counters differ. Revelation: 0x0, e-sim: 0xb0'
54+
expected1 = 'Program counters differ. Revelation: 0xb0, e-sim: 0x0'
55+
assert expected0 == compare_instructions(py_inst0, e_inst1)
56+
assert expected1 == compare_instructions(py_inst1, e_inst0)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from get_instructions_used import parse_esim_inst
2+
3+
def test_parse_esim_inst():
4+
got0 = parse_esim_inst('0x000000 b.l '
5+
'0x0000000000000058 - pc <- 0x58 - nbit <- 0x0')
6+
expected0 = { 'pc':0, 'AN':False, 'instruction':'b.l',
7+
'line': '0x000000 b.l '
8+
'0x0000000000000058 - pc <- 0x58 - nbit <- 0x0' }
9+
assert expected0 == got0
10+
got1 = parse_esim_inst('0x0000b0 --- _epiphany_star strd r2,[r0],+0x1'
11+
' - memaddr <- 0x2f8, memory <- 0x0, memaddr <- '
12+
'0x2fc, memory <- 0x0, registers <- 0x300')
13+
expected1 = { 'instruction':'strd', 'mem':[(760, 0), (764, 0)], 'pc':176,
14+
'reg':[768],
15+
'line':'0x0000b0 --- _epiphany_star strd r2,[r0],+0x1 - '
16+
'memaddr <- 0x2f8, memory <- 0x0, memaddr <- 0x2fc, memory '
17+
'<- 0x0, registers <- 0x300' }
18+
assert expected1 == got1

0 commit comments

Comments
 (0)