Files
templates/python/tests/test_altera_logic.py

58 lines
2.2 KiB
Python

"""Golden RTL vectors through the Python FFI (no Python production codec)."""
import tempfile
import unittest
from pathlib import Path
from altera_logic import NativeAnalyzer
class AnalyzerTests(unittest.TestCase):
def test_rtl_info_and_first_configuration_vector(self):
core = NativeAnalyzer()
self.assertEqual(core.next_request(), bytes.fromhex("A5 01 00 00 00 A4"))
self.assertEqual(core.next_request(), b"")
for byte in bytes.fromhex("5A 81 00 10 00 10 32 01 E8"):
core.feed(bytes([byte]))
self.assertEqual(core.state, core.READY)
with self.assertRaises(ValueError):
core.start(49, 1, 0, 1, 1)
core.start(49, 0, 0, 1, 1)
self.assertEqual(core.next_request(), bytes.fromhex("A5 02 31 00 00 96"))
core.feed(bytes.fromhex("5A 82 00 D8"))
self.assertEqual(core.next_request(), bytes.fromhex("A5 03 00 00 00 A6"))
def test_error_response_is_short_even_for_info(self):
core = NativeAnalyzer()
core.next_request()
core.feed(bytes.fromhex("5A 81 01 DA"))
self.assertEqual(core.state, core.ERROR)
self.assertEqual(core.get(1), 3)
def test_partial_response_times_out_without_retry(self):
core = NativeAnalyzer()
core.next_request()
core.feed(bytes.fromhex("5A 81 00"))
core.tick(1000)
self.assertEqual(core.get(1), 4)
self.assertEqual(core.next_request(), b"")
def test_demo_export_uses_capture_rate_not_current_ui_settings(self):
core = NativeAnalyzer()
core.reset(demo=True)
core.start(49)
capture = core.capture()
self.assertEqual(len(capture.samples), 4096)
self.assertEqual(capture.sample_rate, 1000000)
self.assertEqual(capture.trigger_index, 2048)
self.assertTrue(capture.demo)
with tempfile.TemporaryDirectory() as directory:
path = Path(directory)/"capture.csv"
capture.save_csv(path)
rows = path.read_text().splitlines()
self.assertEqual(len(rows), 4097)
self.assertIn("time_s", rows[0])
self.assertEqual(rows[2049].split(",")[1], "0.0")
if __name__ == "__main__":
unittest.main()