summaryrefslogtreecommitdiff
path: root/prototype/fw/test/microcobs.py
diff options
context:
space:
mode:
Diffstat (limited to 'prototype/fw/test/microcobs.py')
-rw-r--r--prototype/fw/test/microcobs.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/prototype/fw/test/microcobs.py b/prototype/fw/test/microcobs.py
index 1d09efd..39cffd1 100644
--- a/prototype/fw/test/microcobs.py
+++ b/prototype/fw/test/microcobs.py
@@ -143,3 +143,53 @@ class MicrocobsTest(unittest.TestCase):
for i in range(10000):
self.do_test(os.urandom(random.randint(0, 600)))
+class MicrocobsDecodeTest(unittest.TestCase):
+ def do_test(self, data):
+ enc = cobs.encode(data)
+ input = binascii.hexlify(enc)
+
+ debug_file = tempfile.NamedTemporaryFile(prefix='microcobs_test_', delete=False)
+ debug_file.write(input)
+
+ try:
+ test = subprocess.check_output(os.getenv('MICROCOBS_DECODE_TEST_BINARY', 'build/microcobs_decode_test'),
+ input=input, stderr=subprocess.DEVNULL)
+ test = binascii.unhexlify(test.strip())
+
+ self.assertEqual(data, test, f'Mismatched output for input {debug_file.name}')
+
+ debug_file.close()
+ os.remove(debug_file.name)
+ except Exception as e:
+ raise SystemError(f'Test error for input {debug_file.name}') from e
+
+
+ def test_one_byte(self):
+ for i in range(256):
+ self.do_test(bytes([i]))
+
+ def test_lengths(self):
+ for i in range(260):
+ self.do_test(bytes([0xff] * i))
+
+ def test_null_then_lengths(self):
+ for i in range(256):
+ self.do_test(bytes([0] + [0xff] * i))
+
+ def test_lengths_then_null(self):
+ for i in range(256):
+ self.do_test(bytes([0xff] * i + [0]))
+
+ def test_two_byte(self):
+ for i in range(4):
+ for j in range(4):
+ self.do_test(bytes([i, j]))
+
+ def test_long(self):
+ for i in range(5):
+ self.do_test(b'A' * (100 + 256*i))
+
+ def test_random(self):
+ for i in range(10000):
+ self.do_test(os.urandom(random.randint(0, 600)))
+