aboutsummaryrefslogtreecommitdiff
path: root/test.py
diff options
context:
space:
mode:
authorPavel I. Kryukov <pavel.igorevich.kryukov@gmail.com>2022-05-17 20:13:53 +0300
committerGitHub <noreply@github.com>2022-05-17 10:13:53 -0700
commitf9272e8d496a8259f29b952797f595eb9e81078d (patch)
tree53c656baa3ac737bf6e75898567eb7cf033db891 /test.py
parent301686e5b6b93d24ad85200f00ec60197ada86b6 (diff)
downloadriscv-opcodes-f9272e8d496a8259f29b952797f595eb9e81078d.zip
riscv-opcodes-f9272e8d496a8259f29b952797f595eb9e81078d.tar.gz
riscv-opcodes-f9272e8d496a8259f29b952797f595eb9e81078d.tar.bz2
Test error inputs handling, fix few bugs (#119)
* Test error inputs handling * Add mask tests * Apply code review fix
Diffstat (limited to 'test.py')
-rw-r--r--test.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/test.py b/test.py
new file mode 100644
index 0000000..89c014d
--- /dev/null
+++ b/test.py
@@ -0,0 +1,44 @@
+#!/usr/bin/env python3
+
+from parse import *
+import logging
+import unittest
+
+class ConstantParseTest(unittest.TestCase):
+ def test_constant(self):
+ self.assertEqual(parse_constant('10'), 10)
+ self.assertEqual(parse_constant('0xa'), 10)
+ self.assertEqual(parse_constant('0xA'), 10)
+ self.assertEqual(parse_constant('0b1010'), 10)
+
+class EncodingLineTest(unittest.TestCase):
+ def setUp(self):
+ logger = logging.getLogger()
+ logger.disabled = True
+
+ def assertError(self, string):
+ self.assertRaises(SystemExit, process_enc_line, string, 'rv_i')
+
+ def test_lui(self):
+ name, data = process_enc_line('lui rd imm20 6..2=0x0D 1..0=3', 'rv_i')
+ self.assertEqual(name, 'lui')
+ self.assertEqual(data['extension'], ['rv_i'])
+ self.assertEqual(data['match'], '0x37')
+ self.assertEqual(data['mask'], '0x7f')
+
+ def test_overlapping(self):
+ self.assertError('jol rd jimm20 6..2=0x00 3..0=7')
+
+ def test_invalid_order(self):
+ self.assertError('jol 2..6=0x1b')
+
+ def test_illegal_value(self):
+ self.assertError('jol rd jimm20 2..0=10')
+ self.assertError('jol rd jimm20 2..0=0xB')
+
+ @unittest.skip('not implemented')
+ def test_overlapping_field(self):
+ self.assertError('jol rd rs1 jimm20 6..2=0x1b 1..0=3')
+
+ def test_illegal_field(self):
+ self.assertError('jol rd jimm128 2..0=10')