aboutsummaryrefslogtreecommitdiffstats
path: root/asm
diff options
context:
space:
mode:
authorGravatar Peter McGoron 2023-02-11 17:27:29 +0000
committerGravatar Peter McGoron 2023-02-11 17:27:29 +0000
commitb80cb225a4a8c3f826e1a0876b0ada40b87cd8a9 (patch)
tree4eb43a6b28ca44cecb8e8c85f63ca77d6c164a71 /asm
parentmore add tests (diff)
add stack overflow and underflow tests
Diffstat (limited to 'asm')
-rw-r--r--asm/creole.py18
-rw-r--r--asm/test.py49
2 files changed, 51 insertions, 16 deletions
diff --git a/asm/creole.py b/asm/creole.py
index e48d65f..2e323e4 100644
--- a/asm/creole.py
+++ b/asm/creole.py
@@ -165,18 +165,18 @@ class Line:
self.opcode = opcode
self.args = args
- def check_line(self, labnum, regnum):
+ def check_line(self, lablen, reglen):
for a in self.args:
if a[0] == ArgType.REG:
- if a[1] < 0 or a[1] >= regnum:
+ if a[1] < 0 or a[1] >= reglen:
raise RangeCheckException(a[0],
a[1],
- regnum)
+ reglen)
elif a[0] == ArgType.LAB:
- if a[1] < 0 or a[1] >= labnum:
+ if a[1] < 0 or a[1] >= lablen:
raise RangeCheckException(a[0],
a[1],
- regnum)
+ reglen)
def __call__(self):
b = bytes([self.opcode])
@@ -193,7 +193,7 @@ class InstructionNotFoundException(Exception):
class Program:
def asm_push_line(self, ins, args):
l = Line(ins, args)
- l.check_line(self.labnum, self.regnum)
+ l.check_line(self.lablen, self.reglen)
self.asm.append(l)
def parse_asm_line(self, line):
@@ -214,8 +214,8 @@ class Program:
b = b + line()
return b
- def __init__(self, labnum=16, regnum=16):
+ def __init__(self, lablen=16, reglen=16):
self.asm = []
- self.labnum = labnum
- self.regnum = regnum
+ self.lablen = lablen
+ self.reglen = reglen
diff --git a/asm/test.py b/asm/test.py
index 73568cc..bddf0a3 100644
--- a/asm/test.py
+++ b/asm/test.py
@@ -47,7 +47,7 @@ class PushTest(unittest.TestCase):
self.assertEqual(cm.exception.argtypelen, 1)
def test_large_reg(self):
- p = Program(regnum=0x8000000)
+ p = Program(reglen=0x8000000)
p.parse_asm_line("PUSH r134217727")
b = p()
self.assertEqual(b, b'\x01\xFC\x87\xbf\xbf\xbf\xbf\x00')
@@ -78,6 +78,26 @@ class PushTest(unittest.TestCase):
self.assertEqual(ex.cenv.prg[1].w[1], 0)
self.assertEqual(ex.cenv.prg[1].w[2], 0)
+ def test_push_many(self):
+ p = Program()
+ stklen = 40
+ for n in range(0,stklen):
+ p.parse_asm_line("PUSH 5")
+ ex = ffi.Environment(stklen=stklen)
+ self.assertEqual(ex.load(p()), ffi.CompileRet.OK)
+ self.assertEqual(ex(), ffi.RunRet.STOP)
+ for n in range(0,stklen):
+ self.assertEqual(ex.cenv.stk[n], 5)
+
+ def test_push_overflow(self):
+ p = Program()
+ stklen = 40
+ for n in range(0, stklen + 1):
+ p.parse_asm_line("PUSH 5")
+ ex = ffi.Environment(stklen=stklen)
+ self.assertEqual(ex.load(p()), ffi.CompileRet.OK)
+ self.assertEqual(ex(), ffi.RunRet.STACK_OVERFLOW)
+
class PopTest(unittest.TestCase):
def test_compile_pop_reg(self):
p = Program()
@@ -117,18 +137,33 @@ class PopTest(unittest.TestCase):
def test_compile_throw_argument_overflow(self):
p = Program()
with self.assertRaises(TypecheckLenException) as cm:
- p.parse_asm_line("push r1 r2")
- self.assertEqual(cm.exception.opcode, 1)
+ p.parse_asm_line("pop r1 r2")
+ self.assertEqual(cm.exception.opcode, 2)
self.assertEqual(cm.exception.insargs, ["r1", "r2"])
self.assertEqual(cm.exception.argtypelen, 1)
def test_catch_typecheck_argument_underflow(self):
p = Program()
with self.assertRaises(TypecheckLenException) as cm:
- p.parse_asm_line("push")
- self.assertEqual(cm.exception.opcode, 1)
+ p.parse_asm_line("pop")
+ self.assertEqual(cm.exception.opcode, 2)
self.assertEqual(cm.exception.insargs, [])
- self.assertEqual(cm.exception.argtypelen, 1)
+
+ def test_pop_underflow(self):
+ p = Program()
+ p.parse_asm_line("pop r0")
+ ex = ffi.Environment()
+ self.assertEqual(ex.load(p()), ffi.CompileRet.OK)
+ self.assertEqual(ex(), ffi.RunRet.STACK_UNDERFLOW)
+
+ def test_pop_underflow_2(self):
+ p = Program()
+ p.parse_asm_line("push 5")
+ p.parse_asm_line("pop r0")
+ p.parse_asm_line("pop r1")
+ ex = ffi.Environment()
+ self.assertEqual(ex.load(p()), ffi.CompileRet.OK)
+ self.assertEqual(ex(), ffi.RunRet.STACK_UNDERFLOW)
class AddTest(unittest.TestCase):
def test_exec_add(self):
@@ -150,7 +185,6 @@ class AddTest(unittest.TestCase):
self.assertEqual(ex.cenv.reg[0], 30)
self.assertEqual(ex.cenv.reg[1], word_2c(10))
-class AddTest(unittest.TestCase):
def test_exec_mul_throw_imm(self):
p = Program()
with self.assertRaises(TypecheckException) as cm:
@@ -187,6 +221,7 @@ class AddTest(unittest.TestCase):
self.assertEqual(cm.exception.i, 2)
self.assertEqual(cm.exception.opcode, 3)
+class MulTest(unittest.TestCase):
def test_exec_mul_imm_imm(self):
p = Program()
p.parse_asm_line("mul r0 2 2")
='insertions'>+3 git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@105 53a565d1-3bb7-0310-b661-cf11e63c67ab 2003-03-26add raw1394_new_handle_on_port() convenience functionGravatar dmaas 2-1/+41 git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@104 53a565d1-3bb7-0310-b661-cf11e63c67ab 2003-02-22Updates for new rawiso ioctl interface.Gravatar bencollins 3-37/+125 git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@103 53a565d1-3bb7-0310-b661-cf11e63c67ab 2003-01-15add iso_xmit_sync() and iso_xmit_write(); clean up iso handling a bitGravatar dmaas 5-39/+161 git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@102 53a565d1-3bb7-0310-b661-cf11e63c67ab 2003-01-15implement tag matching for rawiso receptionGravatar dmaas 3-4/+12 git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@101 53a565d1-3bb7-0310-b661-cf11e63c67ab 2003-01-06back out previous commit - don't drop the legacy API just yetGravatar dmaas 6-173/+130 git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@100 53a565d1-3bb7-0310-b661-cf11e63c67ab 2003-01-05emulate legacy ISO reception API on top of new rawiso APIGravatar dmaas 7-131/+174 git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@99 53a565d1-3bb7-0310-b661-cf11e63c67ab 2002-12-24update iso API for multi-channel reception and new packet buffer layoutGravatar dmaas 4-123/+236 git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@98 53a565d1-3bb7-0310-b661-cf11e63c67ab 2002-12-20oops, irq_interval needs to be signedGravatar anonymous 1-1/+1 git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@97 53a565d1-3bb7-0310-b661-cf11e63c67ab 2002-12-20dmaas - renamed exported arm definitions into the raw1394_ namespace; ↵Gravatar anonymous 3-124/+48 brought kernel-raw1394.h back in sync with the kernel version git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@96 53a565d1-3bb7-0310-b661-cf11e63c67ab 2002-12-16rawiso updates:Gravatar dmaas 3-18/+25 - changed return type of rawiso xmit/recv handlers from int to enum raw1394_iso_disposition - added an ioctl (RAW1394_ISO_QUEUE_ACTIVITY) to force an ISO_ACTIVITY event into the queue. This is needed for handling RAW1394_ISO_DEFER, to kick us out of the next read() instead of sleeping forever. - removed references to "8-byte" isochronous header - this is an OHCI-specific implementation detail git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@95 53a565d1-3bb7-0310-b661-cf11e63c67ab 2002-11-18fix cplusplus extern C blockGravatar ddennedy 1-4/+4 git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@94 53a565d1-3bb7-0310-b661-cf11e63c67ab 2002-11-18merged rawiso branchGravatar ddennedy 7-6/+488 git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@93 53a565d1-3bb7-0310-b661-cf11e63c67ab