Skip to content

Commit

Permalink
Merge pull request #58 from futurecore/improve-asm-tests
Browse files Browse the repository at this point in the history
Remove max_insts from asm tests.
  • Loading branch information
snim2 committed Aug 11, 2016
2 parents 529b0a6 + d756502 commit c094bf5
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 20 deletions.
42 changes: 38 additions & 4 deletions revelation/test/asm/ilatst.S
Original file line number Diff line number Diff line change
@@ -1,7 +1,41 @@
#include "epiphany-macros.h"
.global main
interrupt_handler:
mov r0, #1
mov r1, %low(message)
movt r1, %high(message)
mov r2, #17
mov r3, #5
trap #7
TEAR_DOWN
main:
mov r0, #0x3ff
movts ilatst, r0 ; After this instruction ILAT will hold 0x3fe. One bit
; will be cleared and put into IPEND.
TEAR_DOWN
; ivt = (uint32_t *) 0x24;
mov r0, #0x24
; branch_addr = (uint32_t) &interrupt_handler;
mov r1, %low(interrupt_handler)
movt r1, %high(interrupt_handler)
; branch_addr -= (uint32_t) ivt;
sub r2, r1, r0
; branch_addr = (branch_addr >> 1);
lsr r2, r2, #1
; rel_branch_instruction32 = 0xe8;
mov r3, 0xe8
; rel_branch_instruction32 |= ((branch_addr & (0x00ffffff))) << 8;
mov r4, %low(0x00ffffff)
movt r4, %high(0x00ffffff)
and r5, r2, r4 ; branch_addr & (0x00ffffff)
mov r6, #8
lsl r7, r5, r6 ; (branch_addr & 0x00ffffff) << 8
orr r8, r3, r7
; *ivt = rel_branch_instruction32;
str r8, [r0, #0]
; Clear interrupt mask.
mov r45, 0
movts imask, r45
; Enable interrupts.
gie
; Set interrupt latch.
mov r45, 0x200
movts ilatst, r45
message:
.ascii "Interrupt fired.\n"
Binary file modified revelation/test/asm/ilatst.elf
Binary file not shown.
41 changes: 39 additions & 2 deletions revelation/test/asm/rti.S
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
#include "epiphany-macros.h"
.global main
main:
interrupt_handler:
mov r0, #1
mov r1, %low(message)
movt r1, %high(message)
mov r2, #17
mov r3, #5
trap #7
rti
TEAR_DOWN
main:
; ivt = (uint32_t *) 0x24;
mov r0, #0x24
; branch_addr = (uint32_t) &interrupt_handler;
mov r1, %low(interrupt_handler)
movt r1, %high(interrupt_handler)
; branch_addr -= (uint32_t) ivt;
sub r2, r1, r0
; branch_addr = (branch_addr >> 1);
lsr r2, r2, #1
; rel_branch_instruction32 = 0xe8;
mov r3, 0xe8
; rel_branch_instruction32 |= ((branch_addr & (0x00ffffff))) << 8;
mov r4, %low(0x00ffffff)
movt r4, %high(0x00ffffff)
and r5, r2, r4 ; branch_addr & (0x00ffffff)
mov r6, #8
lsl r7, r5, r6 ; (branch_addr & 0x00ffffff) << 8
orr r8, r3, r7
; *ivt = rel_branch_instruction32;
str r8, [r0, #0]
; Clear interrupt mask.
mov r45, 0
movts imask, r45
; Enable interrupts.
gie
; Set interrupt latch.
mov r45, 0x200
movts ilatst, r45
TEAR_DOWN
message:
.ascii "Interrupt fired.\n"
Binary file modified revelation/test/asm/rti.elf
Binary file not shown.
16 changes: 2 additions & 14 deletions revelation/test/test_asm.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
@pytest.mark.parametrize("elf,expected",
[('trap.elf', "Hello, world!"),
('trap_undocumented.elf', "Hello, world!"),
('ilatst.elf', "Interrupt fired."),
('rti.elf', "Interrupt fired."),
])
def test_elf_with_stdout(elf, expected, capfd):
"""Test ELF files by checking STDOUT.
Expand All @@ -20,7 +22,6 @@ def test_elf_with_stdout(elf, expected, capfd):
revelation = Revelation()
with open(elf_filename, 'rb') as elf:
revelation.init_state(elf, elf_filename, False, is_test=True)
revelation.max_insts = 10000
revelation.run()
assert not revelation.states[0].running
out, err = capfd.readouterr()
Expand Down Expand Up @@ -51,8 +52,6 @@ def test_elf_with_stdout(elf, expected, capfd):
rf4=0x640, rf5=0x640, rf6=0x640,
rf7=0x640, rf8=0x640)),
('ilatcl.elf', StateChecker(rf0=0x3ff, rfILATCL=0x3ff, rfILAT=0)),
('ilatst.elf', StateChecker(rfILATST=0x3ff, rfILAT=0x3fe,
rfIPEND=0x1)),
('jalr.elf', StateChecker(rfLR=0x356)),
('jr.elf', StateChecker(rf0=3, rf1=1, rf2=2)),
('low_high.elf', StateChecker(rf3=0xffffffff)),
Expand All @@ -65,7 +64,6 @@ def test_elf_with_stdout(elf, expected, capfd):
('movts.elf', StateChecker(rf0=7, rfIRET=7)),
('nop.elf', StateChecker(pc=0x354)),
('orr.elf', StateChecker(rf0=5, rf1=7, rf2=7)),
('rti.elf', StateChecker(GID=0)),
('rts.elf', StateChecker(rf1=100, rf2=200, rf3=300, rfLR=0x352)),
('special_regs.elf', StateChecker(rf0=1, rf1=2, rf2=3, rf3=4, rf4=5,
rf5=6, rf6=7, rf7=8, rf8=9, rf10=11,
Expand All @@ -85,7 +83,6 @@ def test_elf(elf, expected):
revelation = Revelation()
with open(elf_filename, 'rb') as elf:
revelation.init_state(elf, elf_filename, False, is_test=True)
revelation.max_insts = 10000
revelation.run()
expected.check(revelation.states[0])

Expand All @@ -100,12 +97,10 @@ def test_elf_writes_to_memory(elf, expected, memory):
revelation = Revelation()
with open(elf_filename, 'rb') as elf:
revelation.init_state(elf, elf_filename, False, is_test=True)
revelation.max_insts = 10000
revelation.run()
expected.check(revelation.states[0], memory)



@pytest.mark.parametrize("elf,expected",
[('fabs.elf', StateChecker(rf0=float2bits(5.0),
rf1=float2bits(0.0),
Expand Down Expand Up @@ -178,7 +173,6 @@ def test_fp_elf(elf, expected):
revelation = Revelation()
with open(elf_filename, 'rb') as elf:
revelation.init_state(elf, elf_filename, False, is_test=True)
revelation.max_insts = 10000
revelation.run()
expected.fp_check(revelation.states[0])

Expand All @@ -196,7 +190,6 @@ def test_load(elf, expected):
with open(elf_filename, 'rb') as elf:
revelation.init_state(elf, elf_filename, False, is_test=True)
revelation.states[0].mem.write(0x00100004, 4, 0xffffffff)
revelation.max_insts = 10000
revelation.run()
expected.check(revelation.states[0])

Expand All @@ -213,7 +206,6 @@ def test_store(elf, expected):
revelation = Revelation()
with open(elf_filename, 'rb') as elf:
revelation.init_state(elf, elf_filename, False, is_test=True)
revelation.max_insts = 10000
revelation.run()
expected.check(revelation.states[0], memory=[(0x00100004, 4, 0xffffffff)])

Expand All @@ -224,7 +216,6 @@ def test_elf_load_pm():
with open(elf_filename, 'rb') as elf:
revelation.init_state(elf, elf_filename, False, is_test=True)
revelation.states[0].mem.write(0x80002, 4, 0xffffffff)
revelation.max_insts = 10000
revelation.run()
expected = StateChecker(rf0=0xffffffff, rf1=0x100004, rf2=0x80002)
expected.check(revelation.states[0])
Expand All @@ -237,7 +228,6 @@ def test_elf_store_pm():
revelation = Revelation()
with open(elf_filename, 'rb') as elf:
revelation.init_state(elf, elf_filename, False, is_test=True)
revelation.max_insts = 10000
revelation.run()
expected = StateChecker(rf0=0xffffffff, rf1=0x00100004, rf2=4)
expected.check(revelation.states[0], memory=[(0x100000, 4, 0xffffffff)])
Expand All @@ -249,7 +239,6 @@ def test_testset32():
with open(elf_filename, 'rb') as elf:
revelation.init_state(elf, elf_filename, False, is_test=True)
revelation.states[0].mem.write(0x100004, 4, 0x0)
revelation.max_insts = 100000
revelation.run()
expected = StateChecker(AZ=1, rf0=0, rf1=0x100000, rf2=0x4)
expected.check(revelation.states[0], memory=[(0x100004, 4, 0xffff)])
Expand All @@ -268,7 +257,6 @@ def test_testset32_fail(capfd):
revelation = Revelation()
with open(elf_filename, 'rb') as elf:
revelation.init_state(elf, elf_filename, False, is_test=True)
revelation.max_insts = 100000
revelation.run()
out, err = capfd.readouterr()
assert err == ''
Expand Down

0 comments on commit c094bf5

Please sign in to comment.